narsil/Tanshu.Accounts.PointOfSale/Sales/CustomersForm.cs
2011-01-06 12:47:00 +05:30

111 lines
3.3 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.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)
{
bsLedgers.DataSource = new CustomerBI().GetCustomerLedgers();
if (customerID.HasValue)
{
customer = new CustomerBI().GetCustomer(customerID.Value);
btnDelete.Enabled = true;
txtName.Text = customer.Name;
cmbLedger.SelectedValue = customer.LedgerID;
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)
{
if (cmbLedger.SelectedValue == null)
return false;
}
else
return false;
return returnType;
}
private void Save()
{
if (customer == null)
customer = new CustomerBO();
UserBO user = Session.User;
customer.Name = txtName.Text;
customer.LedgerID = (Guid)cmbLedger.SelectedValue;
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; }
}
}
}