using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Forms; using Tanshu.Accounts.Helpers; using Tanshu.Accounts.BI; using Tanshu.Accounts.Contracts; namespace Tanshu.Accounts.PointOfSale { public partial class CustomersForm : Form { private Guid? customerID; private CustomerBO customer; private string phone; #region Form Load public CustomersForm(Guid? customerID, string phone) { InitializeComponent(); this.customerID = customerID; this.phone = phone; } private void CustomersForm_Load(object sender, EventArgs e) { if (customerID.HasValue) { customer = new CustomerBI().GetCustomer(customerID.Value); btnDelete.Enabled = true; txtName.Text = customer.Name; txtPhone.Text = customer.Phone; txtAddress.Text = customer.Address; txtRemarks.Text = customer.Remarks; chkImportant.Checked = customer.Important; } else txtPhone.Text = phone; btnSave.Text = customerID.HasValue ? "&Update" : "&Save"; } #endregion #region Buttons private void btnSave_Click(object sender, EventArgs e) { if (!ValidateValues()) { MessageBox.Show("Missing Information: Please check the form."); txtName.Focus(); } else { Save(); btnCancel_Click(sender, e); } } private void btnDelete_Click(object sender, EventArgs e) { new CustomerBI().Delete(customer.CustomerID); btnCancel_Click(sender, e); } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } #endregion #region Add / Edit / Delete private bool ValidateValues() { bool returnType = true; if (txtName.Text.Trim().Length == 0) return false; return returnType; } private void Save() { if (customer == null) customer = new CustomerBO(); UserBO user = CurrentUser.user; customer.Name = txtName.Text; customer.Phone = txtPhone.Text; customer.Address = txtAddress.Text; customer.Remarks = txtRemarks.Text; customer.Important = chkImportant.Checked; if (customer.CustomerID == new Guid()) new CustomerBI().Insert(customer); else new CustomerBI().Update(customer); } private bool Delete(Guid customerID) { return new CustomerBI().Delete(customerID); } #endregion public CustomerBO Customer { get { return customer; } } } }