using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Forms; using Tanshu.Accounts.Helpers; using Tanshu.Accounts.Repository; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Entities; using Tanshu.Accounts.Entities.Auth; namespace Tanshu.Accounts.PointOfSale { public partial class CustomersForm : Form { private int? customerID; private Customer customer; private string phone; #region Form Load public CustomersForm(int? 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 Customer(); User user = Session.User; customer.Name = txtName.Text; customer.Phone = txtPhone.Text; customer.Address = txtAddress.Text; customer.Remarks = txtRemarks.Text; customer.Important = chkImportant.Checked; if (customer.CustomerID == 0) new CustomerBI().Insert(customer); else new CustomerBI().Update(customer); } private bool Delete(int customerID) { return new CustomerBI().Delete(customerID); } #endregion public Customer Customer { get { return customer; } } } }