59909a5ee7
Must use the Repositories with Using or else bad things will happen.
109 lines
3.2 KiB
C#
109 lines
3.2 KiB
C#
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)
|
|
{
|
|
using (var bi = new CustomerBI(false))
|
|
customer = bi.Get(x => x.CustomerID == 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)
|
|
{
|
|
using (var bi = new CustomerBI())
|
|
bi.Delete(x => x.CustomerID == 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;
|
|
using (var bi = new CustomerBI())
|
|
if (customer.CustomerID == 0)
|
|
bi.Insert(customer);
|
|
else
|
|
bi.Update(customer);
|
|
}
|
|
private void Delete(int customerID)
|
|
{
|
|
using (var bi = new CustomerBI())
|
|
bi.Delete(x => x.CustomerID == customerID);
|
|
}
|
|
#endregion
|
|
|
|
public Customer Customer
|
|
{
|
|
get { return customer; }
|
|
}
|
|
}
|
|
}
|