139 lines
4.8 KiB
C#
139 lines
4.8 KiB
C#
|
using System;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Accounts.Proxy;
|
|||
|
|
|||
|
namespace Accounts.PointOfSale
|
|||
|
{
|
|||
|
public partial class CustomerForm : Form
|
|||
|
{
|
|||
|
Nullable<Guid> customerID;
|
|||
|
FormMode formMode;
|
|||
|
FormMode editMode;
|
|||
|
public CustomerForm(FormMode mode, Nullable<Guid> customerID)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
formMode = mode;
|
|||
|
this.customerID = customerID;
|
|||
|
bsLedger.DataSource = DataAccess.GetCustomerLedgers();
|
|||
|
if (formMode == FormMode.Edit)
|
|||
|
bsMain.DataSource = CustomerProxy.GetSingleCustomerList(customerID.Value);
|
|||
|
else
|
|||
|
bsMain.DataSource = CustomerProxy.GetCustomers(null);
|
|||
|
}
|
|||
|
|
|||
|
private void CustomerForm_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
SetFormMode();
|
|||
|
SetNavigation(editMode);
|
|||
|
}
|
|||
|
private void SetFormMode()
|
|||
|
{
|
|||
|
if (formMode == FormMode.Edit)
|
|||
|
{
|
|||
|
bsMain.Position = 0;
|
|||
|
bindingNavigatorSaveItem.Enabled = true;
|
|||
|
editMode = formMode;
|
|||
|
}
|
|||
|
else if (formMode == FormMode.AddNew)
|
|||
|
{
|
|||
|
bsMain.AddNew();
|
|||
|
bindingNavigatorEditItem.Enabled = false;
|
|||
|
editMode = formMode;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
editMode = FormMode.Normal;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SetNavigation(FormMode mode)
|
|||
|
{
|
|||
|
bool enableEdit;
|
|||
|
if (mode == FormMode.Normal)
|
|||
|
enableEdit = false;
|
|||
|
else //FormMode.AddNew || FormMode.Edit
|
|||
|
enableEdit = true;
|
|||
|
// Controls
|
|||
|
txtName.ReadOnly = !enableEdit;
|
|||
|
cmbLedger.Enabled = enableEdit;
|
|||
|
txtPhone.ReadOnly = !enableEdit;
|
|||
|
txtAddress.ReadOnly = !enableEdit;
|
|||
|
txtRemarks.ReadOnly = !enableEdit;
|
|||
|
chkImportant.Enabled = enableEdit;
|
|||
|
// Other Controls
|
|||
|
bnMain.AddNewItem.Enabled = !enableEdit;
|
|||
|
bindingNavigatorDeleteItem.Enabled = !enableEdit;
|
|||
|
bindingNavigatorSaveItem.Visible = enableEdit;
|
|||
|
bindingNavigatorCancelItem.Visible = enableEdit;
|
|||
|
bindingNavigatorEditItem.Visible = !enableEdit;
|
|||
|
// Move Controls
|
|||
|
bnMain.MoveFirstItem.Enabled = !enableEdit;
|
|||
|
bnMain.MoveLastItem.Enabled = !enableEdit;
|
|||
|
bnMain.MoveNextItem.Enabled = !enableEdit;
|
|||
|
bnMain.MovePreviousItem.Enabled = !enableEdit;
|
|||
|
bnMain.PositionItem.Enabled = !enableEdit;
|
|||
|
}
|
|||
|
|
|||
|
private void bindingNavigatorSaveItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.Validate();
|
|||
|
Customer customer = new Customer();
|
|||
|
if (formMode == FormMode.AddNew)
|
|||
|
customer.CustomerID = Guid.NewGuid();
|
|||
|
else
|
|||
|
customer.CustomerID = customerID.Value;
|
|||
|
customer.Name = txtName.Text;
|
|||
|
customer.LedgerID = ((Ledger)bsLedger.Current).LedgerID;
|
|||
|
customer.Phone = txtPhone.Text;
|
|||
|
customer.Address = txtAddress.Text;
|
|||
|
customer.Remarks = txtRemarks.Text;
|
|||
|
customer.Important = chkImportant.Checked;
|
|||
|
customer.CompanyID = Accounts.Security.CurrentUser.user.CompanyID;
|
|||
|
if (formMode == FormMode.AddNew)
|
|||
|
{
|
|||
|
customer.Code = CustomerProxy.MaxCode;
|
|||
|
CustomerProxy.AddCustomer(customer);
|
|||
|
MessageBox.Show("Record Saved");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CustomerProxy.UpdateCustomer(customer);
|
|||
|
MessageBox.Show("Record updated");
|
|||
|
}
|
|||
|
txtName.Text = "";
|
|||
|
txtAddress.Text = "";
|
|||
|
txtRemarks.Text = "";
|
|||
|
txtPhone.Text = "";
|
|||
|
chkImportant.Checked = false;
|
|||
|
this.Dispose();
|
|||
|
}
|
|||
|
|
|||
|
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void bindingNavigatorCancelItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (formMode != FormMode.Normal)
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
|
|||
|
private void bindingNavigatorEditItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Customer customer = new Customer();
|
|||
|
customer.Name = txtName.Text;
|
|||
|
customer.CustomerID = (Guid)customerID;
|
|||
|
customer.LedgerID = ((Ledger)bsLedger.Current).LedgerID;
|
|||
|
customer.Phone = txtPhone.Text;
|
|||
|
customer.Address = txtAddress.Text;
|
|||
|
customer.Remarks = txtRemarks.Text;
|
|||
|
customer.Important = chkImportant.Checked;
|
|||
|
customer.CompanyID = Accounts.Security.CurrentUser.user.CompanyID;
|
|||
|
CustomerProxy.UpdateCustomer(customer);
|
|||
|
MessageBox.Show("Record Updated");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|