narsil/Tanshu.Accounts.PointOfSale/ProductsForm.cs

160 lines
5.4 KiB
C#
Raw Permalink Normal View History

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>();
Guid? _productID;
ProductBO product;
2010-03-02 17:56:21 +00:00
#region Form Load
public ProductsForm(Guid? productID)
2010-03-02 17:56:21 +00:00
{
_productID = productID;
2010-03-02 17:56:21 +00:00
InitializeComponent();
}
private void Products_Load(object sender, EventArgs e)
{
FillCombos();
if (_productID.HasValue)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.ProductDAO(connection))
{
product = dao.GetProduct(_productID.Value);
}
}
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()
{
string[] units = { "Can", "Gms", "Rs.", "Piece", "Liter", "Plate", "Kg.", "Bottle", "Pack" };
bsUnits.DataSource = units;
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)
{
if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return;
2010-03-02 17:56:21 +00:00
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +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)
{
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
{
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);
returnType = (cmbVat.SelectedValue == null ? false : true);
returnType = (cmbServiceTax.SelectedValue == null ? false : true);
2010-03-02 17:56:21 +00:00
return returnType;
}
private void Save()
2010-03-02 17:56:21 +00:00
{
if (product == null)
product = new ProductBO();
2010-03-02 17:56:21 +00:00
product.Name = txtName.Text;
product.Units = cmbUnits.Text;
product.ProductGroupID = new Guid(cmbProductGroups.SelectedValue.ToString());
2010-03-02 17:56:21 +00:00
product.SalePrice = Convert.ToDecimal(txtSalePrice.Text);
if (cmbServiceTax.SelectedValue != null)
product.ServiceTaxID = new Guid(cmbServiceTax.SelectedValue.ToString());
2010-03-02 17:56:21 +00:00
product.Discontinued = chkDiscontinued.Checked;
product.VatID = new Guid(cmbVat.SelectedValue.ToString());
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
private void btnCancel_Click(object sender, EventArgs e)
2010-03-02 17:56:21 +00:00
{
this.Close();
}
private void btnAddCategory_Click(object sender, EventArgs e)
2010-03-02 17:56:21 +00:00
{
using (var frm = new ProductGroups())
2010-03-02 17:56:21 +00:00
{
frm.ShowDialog();
2010-03-02 17:56:21 +00:00
}
FillCombos();
cmbProductGroups.SelectedIndex = 0;
2010-03-02 17:56:21 +00:00
}
public ProductBO Product
2010-03-02 17:56:21 +00:00
{
get { return null; }
2010-03-02 17:56:21 +00:00
}
}
}