2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Helpers;
|
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ProductsForm : Form
|
|
|
|
|
{
|
|
|
|
|
bool createOnly = false;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
IList<Product> productList = new List<Product>();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
#region Form Load
|
|
|
|
|
public ProductsForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Products_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2011-01-22 12:38:30 +00:00
|
|
|
|
productList = ProductBI.GetProducts();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
bsProducts.DataSource = productList;
|
|
|
|
|
FillCombos();
|
|
|
|
|
bsProducts.MoveFirst();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillCombos()
|
|
|
|
|
{
|
|
|
|
|
bsUnits.DataSource = new StringType[17] {new StringType ( "Cms"),
|
|
|
|
|
new StringType ("Meter"),
|
|
|
|
|
new StringType ("Quintal"),
|
|
|
|
|
new StringType ("Can"),
|
|
|
|
|
new StringType ("Gms"),
|
|
|
|
|
new StringType ("Rs."),
|
|
|
|
|
new StringType ("Piece"),
|
|
|
|
|
new StringType ("Petti"),
|
|
|
|
|
new StringType ("No.'s"),
|
|
|
|
|
new StringType ("Liter"),
|
|
|
|
|
new StringType ("Box"),
|
|
|
|
|
new StringType ("Tin"),
|
|
|
|
|
new StringType ("Dibbi"),
|
|
|
|
|
new StringType ("Plate"),
|
|
|
|
|
new StringType ("Kg."),
|
|
|
|
|
new StringType ("Bottle"),
|
|
|
|
|
new StringType ("Pack" )};
|
|
|
|
|
|
2011-01-22 12:38:30 +00:00
|
|
|
|
bsTypes.DataSource = new ProductGroupBI().GetProductGroups();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
//bsPurchaseLedgers.DataSource = new LedgerBI().GetLedgersOfType('P');
|
|
|
|
|
//bsSalesLedgers.DataSource = new LedgerBI().GetLedgersOfType('X');
|
|
|
|
|
//bsSalesTax.DataSource = new LedgerBI().GetLedgersOfType('T');
|
|
|
|
|
//bsPurchaseTax.DataSource = new LedgerBI().GetLedgersOfType('T');
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Buttons
|
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (btnAdd.Text == "&Add")
|
|
|
|
|
{
|
|
|
|
|
bsProducts.AddNew();
|
|
|
|
|
LockControls(true);
|
|
|
|
|
this.lblNavLocation.Text = "Add New";
|
|
|
|
|
txtName.Select();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!ValidateValues())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Missing Information: Please check the form.");
|
|
|
|
|
bsProducts.CancelEdit();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bsProducts.EndEdit();
|
|
|
|
|
Save(true);
|
|
|
|
|
if (createOnly)
|
|
|
|
|
btnExit_Click(sender, e);
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-01-22 12:38:30 +00:00
|
|
|
|
productList = ProductBI.GetProducts();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
bsProducts.DataSource = productList;
|
|
|
|
|
LockControls(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (btnDelete.Text == "&Delete")
|
|
|
|
|
{
|
|
|
|
|
if (productList.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
|
|
|
|
{
|
2011-01-22 12:38:30 +00:00
|
|
|
|
if (ProductBI.Delete(productList.Single(p => p.Code == Convert.ToInt32(txtUniqueID.Text)).ProductID))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-01-22 12:38:30 +00:00
|
|
|
|
productList = ProductBI.GetProducts();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
btnNavFirst_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LockControls(false);
|
|
|
|
|
bsProducts.CancelEdit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnUpdate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("Are you sure?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
Save(false);
|
|
|
|
|
bsProducts.ResetItem(bsProducts.Position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Add / Edit / Delete
|
|
|
|
|
private bool ValidateValues()
|
|
|
|
|
{
|
|
|
|
|
bool returnType;
|
|
|
|
|
returnType = (bool)(txtName.Text.Trim().Length > 0 ? true : false);
|
|
|
|
|
returnType = (cmbSalesLedger.SelectedValue == null ? false : true);
|
|
|
|
|
returnType = (cmbSalesTax.SelectedValue == null ? false : true);
|
|
|
|
|
return returnType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool Save(bool addNew)
|
|
|
|
|
{
|
|
|
|
|
#region Setup Products
|
2011-01-30 07:14:05 +00:00
|
|
|
|
User user = Session.User;
|
|
|
|
|
Product product = new Product();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
if (!addNew)
|
2011-01-22 12:38:30 +00:00
|
|
|
|
product = ProductBI.GetProduct(productList.ElementAt(bsProducts.Position).ProductID);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
product.Name = txtName.Text;
|
|
|
|
|
product.Units = cmbUnits.Text;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
product.ProductGroup = new ProductGroupBI().GetProductGroup((int)cmbProductTypes.SelectedValue);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
product.SalePrice = Convert.ToDecimal(txtSalePrice.Text);
|
|
|
|
|
product.Discontinued = chkDiscontinued.Checked;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
product.Tax = new Tax();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
if (addNew)
|
2011-01-22 12:38:30 +00:00
|
|
|
|
ProductBI.Insert(product);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
else
|
2011-01-22 12:38:30 +00:00
|
|
|
|
ProductBI.Update(product);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LockControls(bool enable)
|
|
|
|
|
{
|
|
|
|
|
if (enable)
|
|
|
|
|
{
|
|
|
|
|
btnAdd.Text = "&Save";
|
|
|
|
|
btnDelete.Text = "&Cancel";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
btnAdd.Text = "&Add";
|
|
|
|
|
btnDelete.Text = "&Delete";
|
|
|
|
|
}
|
|
|
|
|
btnExit.Enabled = !enable;
|
|
|
|
|
btnLast.Enabled = !enable;
|
|
|
|
|
btnNavPrev.Enabled = !enable;
|
|
|
|
|
btnNavNext.Enabled = !enable;
|
|
|
|
|
btnUpdate.Enabled = !enable;
|
|
|
|
|
btnNavFirst.Enabled = !enable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnAddCategory_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ProductTypes frm = new ProductTypes();
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
frm.Dispose();
|
|
|
|
|
FillCombos();
|
|
|
|
|
cmbProductTypes.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Move Buttons
|
|
|
|
|
private void btnNavFirst_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.bsProducts.MoveFirst();
|
|
|
|
|
}
|
|
|
|
|
private void btnNavPrev_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.bsProducts.MovePrevious();
|
|
|
|
|
}
|
|
|
|
|
private void btnNavNext_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.bsProducts.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
private void btnLast_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.bsProducts.MoveLast();
|
|
|
|
|
}
|
|
|
|
|
private void lblNavLocation_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2011-01-22 12:38:30 +00:00
|
|
|
|
using (SelectProduct selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
selectProduct.ShowDialog();
|
|
|
|
|
if (selectProduct.SelectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
bsProducts.Position = GetPosition(productList, selectProduct.SelectedItem.ProductID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region Binding Source Events
|
|
|
|
|
private void bsProducts_AddingNew(object sender, AddingNewEventArgs e)
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
e.NewObject = new Product();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bsProducts_PositionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.lblNavLocation.Text = string.Format("{0} of {1}", bsProducts.Position + 1, bsProducts.Count);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2011-01-30 07:14:05 +00:00
|
|
|
|
private int GetPosition(IList<Product> list, int id)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (list[i].ProductID == id)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|