2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
2016-03-31 06:57:39 +00:00
|
|
|
|
public partial class CustomerForm : Form
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
private Guid? _customerID;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
private Customer _customer;
|
|
|
|
|
private readonly string phone;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
#region Form Load
|
2016-03-31 06:57:39 +00:00
|
|
|
|
public CustomerForm(Guid? customerID)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this._customerID = customerID;
|
|
|
|
|
}
|
|
|
|
|
public CustomerForm(Guid? customerID, string phone)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2011-12-05 09:41:02 +00:00
|
|
|
|
this._customerID = customerID;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
this.phone = phone;
|
|
|
|
|
}
|
2016-03-31 06:57:39 +00:00
|
|
|
|
private void CustomerForm_Load(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
if (_customerID.HasValue)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
_customer = CustomerBI.Get(_customerID.Value);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
btnDelete.Enabled = true;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
txtName.Text = _customer.Name;
|
|
|
|
|
txtPhone.Text = _customer.Phone;
|
|
|
|
|
txtAddress.Text = _customer.Address;
|
|
|
|
|
txtRemarks.Text = _customer.Remarks;
|
|
|
|
|
chkImportant.Checked = _customer.Important;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
txtPhone.Text = phone;
|
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
btnSave.Text = _customerID.HasValue ? "&Update" : "&Save";
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
#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)
|
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
CustomerBI.Delete(_customer.CustomerID);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
btnCancel_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Add / Edit / Delete
|
|
|
|
|
private bool ValidateValues()
|
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
return txtName.Text.Trim().Length != 0;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
2010-03-02 17:56:21 +00:00
|
|
|
|
private void Save()
|
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
if (_customer == null)
|
|
|
|
|
_customer = new Customer();
|
|
|
|
|
|
|
|
|
|
_customer.Name = txtName.Text;
|
|
|
|
|
_customer.Phone = txtPhone.Text;
|
|
|
|
|
_customer.Address = txtAddress.Text;
|
|
|
|
|
_customer.Remarks = txtRemarks.Text;
|
|
|
|
|
_customer.Important = chkImportant.Checked;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
if (_customer.CustomerID == Guid.Empty)
|
|
|
|
|
CustomerBI.Insert(_customer);
|
|
|
|
|
else
|
|
|
|
|
CustomerBI.Update(_customer);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2014-10-12 09:41:45 +00:00
|
|
|
|
private void Delete(Guid customerID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
CustomerBI.Delete(customerID);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public Customer Customer
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
get { return _customer; }
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|