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;
|
|
|
|
|
using Tanshu.Accounts.BI;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ProductsForm : Form
|
|
|
|
|
{
|
|
|
|
|
bool createOnly = false;
|
|
|
|
|
List<ProductDisplayBO> productList = new List<ProductDisplayBO>();
|
2013-11-30 11:12:08 +00:00
|
|
|
|
Guid? _productID;
|
|
|
|
|
ProductBO product;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
#region Form Load
|
2013-11-30 11:12:08 +00:00
|
|
|
|
public ProductsForm(Guid? productID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
_productID = productID;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Products_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FillCombos();
|
2013-11-30 11:12:08 +00:00
|
|
|
|
if (_productID.HasValue)
|
|
|
|
|
{
|
2014-08-08 12:05:38 +00:00
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
|
|
|
{
|
|
|
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
product = dao.GetProduct(_productID.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-30 11:12:08 +00:00
|
|
|
|
txtUniqueID.Text = product.Code.ToString();
|
|
|
|
|
txtName.Text = product.Name;
|
|
|
|
|
cmbUnits.SelectedItem = product.Units;
|
|
|
|
|
cmbProductGroups.SelectedValue = product.ProductGroupID;
|
|
|
|
|
txtSalePrice.Text = product.SalePrice.ToString();
|
|
|
|
|
cmbVat.SelectedValue = product.VatID;
|
|
|
|
|
cmbServiceTax.SelectedValue = product.ServiceTaxID;
|
|
|
|
|
chkDiscontinued.Checked = product.Discontinued;
|
|
|
|
|
btnSave.Text = "&Update";
|
|
|
|
|
btnDelete.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
btnSave.Text = "&Save";
|
|
|
|
|
btnDelete.Enabled = false;
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillCombos()
|
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
string[] units = { "Can", "Gms", "Rs.", "Piece", "Liter", "Plate", "Kg.", "Bottle", "Pack" };
|
|
|
|
|
bsUnits.DataSource = units;
|
2014-08-08 12:05:38 +00:00
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
|
|
|
{
|
|
|
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
bsProductGroups.DataSource = dao.GetProductGroups();
|
|
|
|
|
bsVat.DataSource = dao.GetTaxes();
|
|
|
|
|
bsServiceTax.DataSource = dao.GetTaxes();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Buttons
|
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
|
|
|
|
|
return;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
2014-08-08 12:05:38 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-08-08 12:05:38 +00:00
|
|
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
if (dao.Delete(product.ProductID))
|
|
|
|
|
{
|
|
|
|
|
btnCancel_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnUpdate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
if (!ValidateValues())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Missing Information: Please check the form.");
|
|
|
|
|
txtName.Focus();
|
|
|
|
|
}
|
|
|
|
|
else if (MessageBox.Show("Are you sure?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
Save();
|
|
|
|
|
btnCancel_Click(sender, e);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Add / Edit / Delete
|
|
|
|
|
private bool ValidateValues()
|
|
|
|
|
{
|
|
|
|
|
bool returnType;
|
|
|
|
|
returnType = (bool)(txtName.Text.Trim().Length > 0 ? true : false);
|
2013-11-28 10:39:33 +00:00
|
|
|
|
returnType = (cmbVat.SelectedValue == null ? false : true);
|
|
|
|
|
returnType = (cmbServiceTax.SelectedValue == null ? false : true);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
return returnType;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-30 11:12:08 +00:00
|
|
|
|
private void Save()
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
if (product == null)
|
|
|
|
|
product = new ProductBO();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
product.Name = txtName.Text;
|
|
|
|
|
product.Units = cmbUnits.Text;
|
2013-11-28 10:39:33 +00:00
|
|
|
|
product.ProductGroupID = new Guid(cmbProductGroups.SelectedValue.ToString());
|
2010-03-02 17:56:21 +00:00
|
|
|
|
product.SalePrice = Convert.ToDecimal(txtSalePrice.Text);
|
2013-11-28 10:39:33 +00:00
|
|
|
|
if (cmbServiceTax.SelectedValue != null)
|
|
|
|
|
product.ServiceTaxID = new Guid(cmbServiceTax.SelectedValue.ToString());
|
2010-03-02 17:56:21 +00:00
|
|
|
|
product.Discontinued = chkDiscontinued.Checked;
|
2013-11-28 10:39:33 +00:00
|
|
|
|
product.VatID = new Guid(cmbVat.SelectedValue.ToString());
|
2014-08-08 12:05:38 +00:00
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
|
|
|
|
{
|
|
|
|
|
using (var dao = new SqlDAO.ProductDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
if (product.ProductID == new Guid())
|
|
|
|
|
dao.Insert(product);
|
|
|
|
|
else
|
|
|
|
|
dao.Update(product);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2013-11-30 11:12:08 +00:00
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-30 11:12:08 +00:00
|
|
|
|
private void btnAddCategory_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
using (var frm = new ProductGroups())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
FillCombos();
|
2013-11-28 10:39:33 +00:00
|
|
|
|
cmbProductGroups.SelectedIndex = 0;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2013-11-30 11:12:08 +00:00
|
|
|
|
public ProductBO Product
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-30 11:12:08 +00:00
|
|
|
|
get { return null; }
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|