narsil/Tanshu.Accounts.PointOfSale/ProductsForm.cs
Amritanshu 82f3b6b3e7 Fix: Products edit form vat and st were mixed in combobox.
Fix: Removed MinimumLevel and MaximumLevel from products.
2013-11-30 16:42:08 +05:30

134 lines
4.6 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.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;
#region Form Load
public ProductsForm(Guid? productID)
{
_productID = productID;
InitializeComponent();
}
private void Products_Load(object sender, EventArgs e)
{
FillCombos();
if (_productID.HasValue)
{
product = new ProductBI().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;
}
}
private void FillCombos()
{
string[] units = { "Can", "Gms", "Rs.", "Piece", "Liter", "Plate", "Kg.", "Bottle", "Pack" };
bsUnits.DataSource = units;
bsProductGroups.DataSource = new ProductBI().GetProductGroups();
bsVat.DataSource = new ProductBI().GetTaxes();
bsServiceTax.DataSource = new ProductBI().GetTaxes();
}
#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;
if (new ProductBI().Delete(product.ProductID))
{
btnCancel_Click(sender, e);
}
}
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)
{
Save();
btnCancel_Click(sender, e);
}
}
#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);
return returnType;
}
private void Save()
{
if (product == null)
product = new ProductBO();
product.Name = txtName.Text;
product.Units = cmbUnits.Text;
product.ProductGroupID = new Guid(cmbProductGroups.SelectedValue.ToString());
product.SalePrice = Convert.ToDecimal(txtSalePrice.Text);
if (cmbServiceTax.SelectedValue != null)
product.ServiceTaxID = new Guid(cmbServiceTax.SelectedValue.ToString());
product.Discontinued = chkDiscontinued.Checked;
product.VatID = new Guid(cmbVat.SelectedValue.ToString());
if (product.ProductID == new Guid())
new ProductBI().Insert(product);
else
new ProductBI().Update(product);
}
#endregion
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnAddCategory_Click(object sender, EventArgs e)
{
using (var frm = new ProductGroups())
{
frm.ShowDialog();
}
FillCombos();
cmbProductGroups.SelectedIndex = 0;
}
public ProductBO Product
{
get { return null; }
}
}
}