Fix: Products edit form vat and st were mixed in combobox.

Fix: Removed MinimumLevel and MaximumLevel from products.
This commit is contained in:
Amritanshu
2013-11-30 16:42:08 +05:30
parent c36240398f
commit 82f3b6b3e7
9 changed files with 166 additions and 370 deletions

View File

@ -34,6 +34,8 @@ ALTER TABLE dbo.Products DROP COLUMN timestamp;
ALTER TABLE dbo.Products DROP COLUMN PurchasePrice;
ALTER TABLE dbo.Products DROP COLUMN SaleLedgerID;
ALTER TABLE dbo.Products DROP COLUMN PurchaseLedgerID;
ALTER TABLE dbo.Products DROP COLUMN MinimumLevel;
ALTER TABLE dbo.Products DROP COLUMN MaximumLevel;
ALTER TABLE dbo.Waiters DROP COLUMN timestamp;
ALTER TABLE dbo.Vouchers DROP COLUMN Ref;
ALTER TABLE dbo.Vouchers DROP COLUMN Type;
@ -53,6 +55,22 @@ exec sp_rename 'dbo.ProductGroups.ProductTypeID', 'ProductGroupID', 'COLUMN';
exec sp_rename 'dbo.Products.ProductTypeID', 'ProductGroupID', 'COLUMN';
exec sp_rename 'dbo.Products.PurchaseTaxID', 'ServiceTaxID', 'COLUMN';
exec sp_rename 'dbo.Products.SaleTaxID', 'VatID', 'COLUMN';
INSERT INTO Tax(TaxID, Name, Rate, Type) VALUES ('27B6FA07-F9D2-49C6-8E37-31A5EFC04FBB', '4.944% Service Tax', 0.049444, 'V');
UPDATE Products SET ServiceTaxID = '3D1413EE-D3EA-412F-B762-BAE37BD503B6' WHERE VatID != '8C200738-374B-484E-B239-9BD0CB9CCF36';
UPDATE Products SET ServiceTaxID = '27B6FA07-F9D2-49C6-8E37-31A5EFC04FBB' WHERE VatID = '8C200738-374B-484E-B239-9BD0CB9CCF36';
UPDATE Products SET VatID = '48E10C74-9508-44CB-9D7D-7B71ABDAA289' WHERE VatID ='8C200738-374B-484E-B239-9BD0CB9CCF36';
update Products set productgroupid = 'A331DC08-EAA5-4C87-8DE0-0F9CBA2558F7'
where productgroupid in (
'80EC988A-448E-4F81-B753-1B70FF8B233C',
'28846C15-6391-48D4-A50E-2A40BA8156C0',
'B75B3C3A-4364-4B36-8DEA-C0C0247449B2',
'F76B54C6-21CE-450F-AC73-E1A3A43DAB43',
'CC099265-97FF-45CA-80A6-F7BB189C18B7',
'389A3E09-AC97-4C4B-BCE1-342D2CF991DB'
);
delete from productgroups where productgroupid not in (
select distinct productgroupid from products)
update inventory set servicetax = 0.04944, vat = 0.12500 from inventory where vat = 0.17444
COMMIT
-- ROLLBACK

View File

@ -14,8 +14,6 @@ namespace Tanshu.Accounts.Contracts
public decimal SalePrice { get; set; }
public Guid ServiceTaxID { get; set; }
public bool Discontinued { get; set; }
public decimal MinimumLevel { get; set; }
public decimal MaximumLevel { get; set; }
public int SortOrder { get; set; }
}
}

View File

@ -8,7 +8,9 @@ namespace Tanshu.Accounts.Contracts
public int Code { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public string Category { get; set; }
public string ProuctGroup { get; set; }
public string Vat { get; set; }
public string ServiceTax { get; set; }
public Guid ProductID { get; set; }
}
}

View File

@ -13,12 +13,13 @@ namespace Tanshu.Accounts.Helpers
{
public class SelectProduct : Tanshu.Data.BaseSelector<ProductDisplaySmallBO>
{
public event ProductEventHandler productEvent;
public SelectProduct(GetData<ProductDisplaySmallBO> getData, bool autoClose)
: base(getData, true, "List of Products")
: base(getData, autoClose, "List of Products")
{
List<string> filters = new List<string>();
filters.Add("Name");
filters.Add("Type");
filters.Add("ProductGroup");
SetFilterColumns(filters);
grid.Columns["ProductID"].Visible = false;
}
@ -37,10 +38,26 @@ namespace Tanshu.Accounts.Helpers
DisplayLabel = string.Format("Chosen Product {0} with rate Rs. {1}", item.Name, item.Price);
}
protected override ProductDisplaySmallBO HandleKeydown(object sender, ExtendedKeyEventArgs e)
{
var product = bindingSource.Current as ProductDisplaySmallBO;
if (productEvent == null)
{
e.Handled = false;
return null;
}
Guid? id = null;
if ((product != null) && (e.KeyCode == Keys.F2))
id = product.ProductID;
if ((e.KeyCode == Keys.F1) || (e.KeyCode == Keys.F2))
{
var updatedProduct = productEvent(sender, new ProductEventArgs(id));
if (updatedProduct != null)
product = new ProductDisplaySmallBO() { ProductID = updatedProduct.ProductID, Code = product.Code };
e.Handled = product != null;
}
return product;
}
#region Designer Code
/// <summary>
/// Required designer variable.
@ -74,4 +91,17 @@ namespace Tanshu.Accounts.Helpers
#endregion
#endregion
}
public delegate ProductBO ProductEventHandler(object sender, ProductEventArgs e);
public class ProductEventArgs : EventArgs
{
public ProductEventArgs(Guid? productID)
{
ProductID = productID;
}
public Guid? ProductID
{
get;
private set;
}
}
}

View File

@ -208,9 +208,19 @@ namespace Tanshu.Accounts.PointOfSale
}
else
{
ProductsForm form = new ProductsForm();
using (SelectProduct selectProduct = new SelectProduct(new ProductBI().GetFilteredProducts, false))
{
selectProduct.productEvent += new ProductEventHandler(selectProduct_productEvent);
selectProduct.ShowDialog();
}
}
}
ProductBO selectProduct_productEvent(object sender, ProductEventArgs e)
{
using (var form = new ProductsForm(e.ProductID))
{
form.ShowDialog();
form.Dispose();
return form.Product;
}
}

View File

@ -31,32 +31,21 @@
this.components = new System.ComponentModel.Container();
this.Label4 = new System.Windows.Forms.Label();
this.txtSalePrice = new System.Windows.Forms.TextBox();
this.bsProducts = new System.Windows.Forms.BindingSource(this.components);
this.GroupBox1 = new System.Windows.Forms.GroupBox();
this.btnAddCategory = new System.Windows.Forms.Button();
this.cmbProductGroups = new System.Windows.Forms.ComboBox();
this.bsTypes = new System.Windows.Forms.BindingSource(this.components);
this.bsProductGroups = new System.Windows.Forms.BindingSource(this.components);
this.cmbUnits = new System.Windows.Forms.ComboBox();
this.bsUnits = new System.Windows.Forms.BindingSource(this.components);
this.Label7 = new System.Windows.Forms.Label();
this.Label3 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.Label2 = new System.Windows.Forms.Label();
this.btnNavFirst = new System.Windows.Forms.Button();
this.btnNavPrev = new System.Windows.Forms.Button();
this.lblNavLocation = new System.Windows.Forms.Label();
this.btnNavNext = new System.Windows.Forms.Button();
this.btnLast = new System.Windows.Forms.Button();
this.txtUniqueID = new System.Windows.Forms.TextBox();
this.Label1 = new System.Windows.Forms.Label();
this.btnAdd = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.btnUpdate = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.txtMinimumLevel = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtMaximumLevel = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.btnSave = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.chkDiscontinued = new System.Windows.Forms.CheckBox();
this.cmbVat = new System.Windows.Forms.ComboBox();
this.bsVat = new System.Windows.Forms.BindingSource(this.components);
@ -64,9 +53,8 @@
this.cmbServiceTax = new System.Windows.Forms.ComboBox();
this.bsServiceTax = new System.Windows.Forms.BindingSource(this.components);
this.label8 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.bsProducts)).BeginInit();
this.GroupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.bsTypes)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsProductGroups)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsUnits)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsVat)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsServiceTax)).BeginInit();
@ -84,19 +72,12 @@
// txtSalePrice
//
this.txtSalePrice.AccessibleName = "Phone 1";
this.txtSalePrice.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProducts, "SalePrice", true));
this.txtSalePrice.Location = new System.Drawing.Point(13, 164);
this.txtSalePrice.Name = "txtSalePrice";
this.txtSalePrice.Size = new System.Drawing.Size(74, 20);
this.txtSalePrice.TabIndex = 53;
this.txtSalePrice.Text = "0";
//
// bsProducts
//
this.bsProducts.DataSource = typeof(Tanshu.Accounts.Contracts.ProductBO);
this.bsProducts.AddingNew += new System.ComponentModel.AddingNewEventHandler(this.bsProducts_AddingNew);
this.bsProducts.PositionChanged += new System.EventHandler(this.bsProducts_PositionChanged);
//
// GroupBox1
//
this.GroupBox1.Controls.Add(this.btnAddCategory);
@ -123,8 +104,7 @@
//
// cmbProductGroups
//
this.cmbProductGroups.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsProducts, "ProductGroupID", true));
this.cmbProductGroups.DataSource = this.bsTypes;
this.cmbProductGroups.DataSource = this.bsProductGroups;
this.cmbProductGroups.DisplayMember = "Name";
this.cmbProductGroups.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbProductGroups.Location = new System.Drawing.Point(94, 72);
@ -133,13 +113,12 @@
this.cmbProductGroups.TabIndex = 35;
this.cmbProductGroups.ValueMember = "ProductGroupID";
//
// bsTypes
// bsProductGroups
//
this.bsTypes.DataSource = typeof(Tanshu.Accounts.Contracts.ProductGroupBO);
this.bsProductGroups.DataSource = typeof(Tanshu.Accounts.Contracts.ProductGroupBO);
//
// cmbUnits
//
this.cmbUnits.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsProducts, "Units", true));
this.cmbUnits.DataSource = this.bsUnits;
this.cmbUnits.DisplayMember = "Description";
this.cmbUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@ -174,7 +153,6 @@
// txtName
//
this.txtName.AccessibleName = "";
this.txtName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProducts, "Name", true));
this.txtName.Location = new System.Drawing.Point(94, 19);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(212, 20);
@ -189,58 +167,9 @@
this.Label2.TabIndex = 28;
this.Label2.Text = "Name";
//
// btnNavFirst
//
this.btnNavFirst.Location = new System.Drawing.Point(40, 334);
this.btnNavFirst.Name = "btnNavFirst";
this.btnNavFirst.Size = new System.Drawing.Size(40, 23);
this.btnNavFirst.TabIndex = 44;
this.btnNavFirst.Text = "<<";
this.btnNavFirst.Click += new System.EventHandler(this.btnNavFirst_Click);
//
// btnNavPrev
//
this.btnNavPrev.Location = new System.Drawing.Point(86, 334);
this.btnNavPrev.Name = "btnNavPrev";
this.btnNavPrev.Size = new System.Drawing.Size(35, 23);
this.btnNavPrev.TabIndex = 45;
this.btnNavPrev.Text = "<";
this.btnNavPrev.Click += new System.EventHandler(this.btnNavPrev_Click);
//
// lblNavLocation
//
this.lblNavLocation.BackColor = System.Drawing.Color.White;
this.lblNavLocation.Location = new System.Drawing.Point(118, 334);
this.lblNavLocation.Name = "lblNavLocation";
this.lblNavLocation.Size = new System.Drawing.Size(95, 23);
this.lblNavLocation.TabIndex = 46;
this.lblNavLocation.Text = "No Records";
this.lblNavLocation.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblNavLocation.Click += new System.EventHandler(this.lblNavLocation_Click);
//
// btnNavNext
//
this.btnNavNext.Location = new System.Drawing.Point(214, 334);
this.btnNavNext.Name = "btnNavNext";
this.btnNavNext.Size = new System.Drawing.Size(35, 23);
this.btnNavNext.TabIndex = 47;
this.btnNavNext.Text = ">";
this.btnNavNext.Click += new System.EventHandler(this.btnNavNext_Click);
//
// btnLast
//
this.btnLast.Location = new System.Drawing.Point(254, 334);
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(40, 23);
this.btnLast.TabIndex = 48;
this.btnLast.Text = ">>";
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// txtUniqueID
//
this.txtUniqueID.AccessibleName = "Unique ID";
this.txtUniqueID.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProducts, "Code", true));
this.txtUniqueID.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.bsProducts, "ProductID", true));
this.txtUniqueID.Enabled = false;
this.txtUniqueID.Location = new System.Drawing.Point(75, 12);
this.txtUniqueID.Name = "txtUniqueID";
@ -259,87 +188,39 @@
this.Label1.Text = "Code";
this.Label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(9, 300);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 72;
this.btnAdd.Text = "&Add";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(91, 300);
this.btnDelete.Location = new System.Drawing.Point(90, 214);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(75, 23);
this.btnDelete.TabIndex = 73;
this.btnDelete.Text = "&Delete";
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// btnUpdate
// btnSave
//
this.btnUpdate.AccessibleName = "Done";
this.btnUpdate.Location = new System.Drawing.Point(173, 300);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.Size = new System.Drawing.Size(72, 24);
this.btnUpdate.TabIndex = 71;
this.btnUpdate.Text = "&Update";
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
this.btnSave.AccessibleName = "Done";
this.btnSave.Location = new System.Drawing.Point(12, 213);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(72, 24);
this.btnSave.TabIndex = 71;
this.btnSave.Text = "&Save";
this.btnSave.Click += new System.EventHandler(this.btnUpdate_Click);
//
// btnExit
// btnCancel
//
this.btnExit.AccessibleName = "Done";
this.btnExit.Location = new System.Drawing.Point(252, 300);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(72, 24);
this.btnExit.TabIndex = 70;
this.btnExit.Text = "E&xit";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// txtMinimumLevel
//
this.txtMinimumLevel.AccessibleName = "Phone 1";
this.txtMinimumLevel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProducts, "MinimumLevel", true));
this.txtMinimumLevel.Location = new System.Drawing.Point(10, 264);
this.txtMinimumLevel.Name = "txtMinimumLevel";
this.txtMinimumLevel.Size = new System.Drawing.Size(77, 20);
this.txtMinimumLevel.TabIndex = 75;
this.txtMinimumLevel.Text = "0";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(10, 248);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(77, 13);
this.label6.TabIndex = 74;
this.label6.Text = "Minimum Level";
//
// txtMaximumLevel
//
this.txtMaximumLevel.AccessibleName = "Phone 1";
this.txtMaximumLevel.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProducts, "MaximumLevel", true));
this.txtMaximumLevel.Location = new System.Drawing.Point(96, 264);
this.txtMaximumLevel.Name = "txtMaximumLevel";
this.txtMaximumLevel.Size = new System.Drawing.Size(85, 20);
this.txtMaximumLevel.TabIndex = 77;
this.txtMaximumLevel.Text = "0";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(93, 249);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(80, 13);
this.label9.TabIndex = 76;
this.label9.Text = "Maximum Level";
this.btnCancel.AccessibleName = "Done";
this.btnCancel.Location = new System.Drawing.Point(255, 214);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(72, 24);
this.btnCancel.TabIndex = 70;
this.btnCancel.Text = "&Cancel";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// chkDiscontinued
//
this.chkDiscontinued.AutoSize = true;
this.chkDiscontinued.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bsProducts, "Discontinued", true));
this.chkDiscontinued.Location = new System.Drawing.Point(233, 272);
this.chkDiscontinued.Location = new System.Drawing.Point(16, 190);
this.chkDiscontinued.Name = "chkDiscontinued";
this.chkDiscontinued.Size = new System.Drawing.Size(88, 17);
this.chkDiscontinued.TabIndex = 78;
@ -348,11 +229,10 @@
//
// cmbVat
//
this.cmbVat.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsProducts, "VatID", true));
this.cmbVat.DataSource = this.bsVat;
this.cmbVat.DisplayMember = "Name";
this.cmbVat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbVat.Location = new System.Drawing.Point(236, 163);
this.cmbVat.Location = new System.Drawing.Point(106, 163);
this.cmbVat.Name = "cmbVat";
this.cmbVat.Size = new System.Drawing.Size(91, 21);
this.cmbVat.TabIndex = 82;
@ -365,7 +245,7 @@
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(241, 148);
this.label10.Location = new System.Drawing.Point(111, 148);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(23, 13);
this.label10.TabIndex = 81;
@ -373,11 +253,10 @@
//
// cmbServiceTax
//
this.cmbServiceTax.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsProducts, "VatID", true));
this.cmbServiceTax.DataSource = this.bsServiceTax;
this.cmbServiceTax.DisplayMember = "Name";
this.cmbServiceTax.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbServiceTax.Location = new System.Drawing.Point(236, 205);
this.cmbServiceTax.Location = new System.Drawing.Point(227, 164);
this.cmbServiceTax.Name = "cmbServiceTax";
this.cmbServiceTax.Size = new System.Drawing.Size(91, 21);
this.cmbServiceTax.TabIndex = 84;
@ -390,7 +269,7 @@
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(241, 190);
this.label8.Location = new System.Drawing.Point(223, 148);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(64, 13);
this.label8.TabIndex = 83;
@ -400,29 +279,19 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(336, 365);
this.ClientSize = new System.Drawing.Size(336, 249);
this.Controls.Add(this.cmbServiceTax);
this.Controls.Add(this.label8);
this.Controls.Add(this.cmbVat);
this.Controls.Add(this.Label1);
this.Controls.Add(this.label10);
this.Controls.Add(this.chkDiscontinued);
this.Controls.Add(this.txtMaximumLevel);
this.Controls.Add(this.label9);
this.Controls.Add(this.txtMinimumLevel);
this.Controls.Add(this.label6);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.Label4);
this.Controls.Add(this.txtSalePrice);
this.Controls.Add(this.GroupBox1);
this.Controls.Add(this.btnNavFirst);
this.Controls.Add(this.btnNavPrev);
this.Controls.Add(this.lblNavLocation);
this.Controls.Add(this.btnNavNext);
this.Controls.Add(this.btnLast);
this.Controls.Add(this.txtUniqueID);
this.MaximizeBox = false;
this.MinimizeBox = false;
@ -430,10 +299,9 @@
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Products";
this.Load += new System.EventHandler(this.Products_Load);
((System.ComponentModel.ISupportInitialize)(this.bsProducts)).EndInit();
this.GroupBox1.ResumeLayout(false);
this.GroupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.bsTypes)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsProductGroups)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsUnits)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsVat)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsServiceTax)).EndInit();
@ -454,27 +322,16 @@
internal System.Windows.Forms.Label Label3;
internal System.Windows.Forms.TextBox txtName;
internal System.Windows.Forms.Label Label2;
internal System.Windows.Forms.Button btnNavFirst;
internal System.Windows.Forms.Button btnNavPrev;
internal System.Windows.Forms.Label lblNavLocation;
internal System.Windows.Forms.Button btnNavNext;
internal System.Windows.Forms.Button btnLast;
internal System.Windows.Forms.TextBox txtUniqueID;
internal System.Windows.Forms.Label Label1;
internal System.Windows.Forms.Button btnAdd;
internal System.Windows.Forms.Button btnDelete;
internal System.Windows.Forms.Button btnUpdate;
internal System.Windows.Forms.Button btnExit;
internal System.Windows.Forms.TextBox txtMinimumLevel;
internal System.Windows.Forms.Label label6;
internal System.Windows.Forms.TextBox txtMaximumLevel;
internal System.Windows.Forms.Label label9;
internal System.Windows.Forms.Button btnSave;
internal System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.CheckBox chkDiscontinued;
internal System.Windows.Forms.ComboBox cmbVat;
internal System.Windows.Forms.Label label10;
private System.Windows.Forms.BindingSource bsProducts;
private System.Windows.Forms.BindingSource bsUnits;
private System.Windows.Forms.BindingSource bsTypes;
private System.Windows.Forms.BindingSource bsProductGroups;
private System.Windows.Forms.BindingSource bsVat;
private System.Windows.Forms.BindingSource bsServiceTax;
internal System.Windows.Forms.ComboBox cmbServiceTax;

View File

@ -13,111 +13,72 @@ namespace Tanshu.Accounts.PointOfSale
{
bool createOnly = false;
List<ProductDisplayBO> productList = new List<ProductDisplayBO>();
Guid? _productID;
ProductBO product;
#region Form Load
public ProductsForm()
public ProductsForm(Guid? productID)
{
_productID = productID;
InitializeComponent();
}
private void Products_Load(object sender, EventArgs e)
{
productList = new ProductBI().GetProducts();
bsProducts.DataSource = productList;
FillCombos();
bsProducts.MoveFirst();
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()
{
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" )};
bsTypes.DataSource = new ProductBI().GetProductGroups();
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 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
{
productList = new ProductBI().GetProducts();
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)
{
if (new ProductBI().Delete(productList.Single(p => p.Code == Convert.ToInt32(txtUniqueID.Text)).ProductID))
{
productList = new ProductBI().GetProducts();
btnNavFirst_Click(sender, e);
}
}
}
}
if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return;
else
if (new ProductBI().Delete(product.ProductID))
{
LockControls(false);
bsProducts.CancelEdit();
btnCancel_Click(sender, e);
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
if (!ValidateValues())
{
Save(false);
bsProducts.ResetItem(bsProducts.Position);
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
@ -132,16 +93,11 @@ namespace Tanshu.Accounts.PointOfSale
return returnType;
}
private bool Save(bool addNew)
private void Save()
{
#region Setup Products
UserBO user = CurrentUser.user;
ProductBO product = new ProductBO();
if (!addNew)
product = new ProductBI().GetProduct(productList.ElementAt(bsProducts.Position).ProductID);
if (product == null)
product = new ProductBO();
product.Name = txtName.Text;
product.MinimumLevel = Convert.ToDecimal(txtMinimumLevel.Text);
product.MaximumLevel = Convert.ToDecimal(txtMaximumLevel.Text);
product.Units = cmbUnits.Text;
product.ProductGroupID = new Guid(cmbProductGroups.SelectedValue.ToString());
product.SalePrice = Convert.ToDecimal(txtSalePrice.Text);
@ -149,100 +105,30 @@ namespace Tanshu.Accounts.PointOfSale
product.ServiceTaxID = new Guid(cmbServiceTax.SelectedValue.ToString());
product.Discontinued = chkDiscontinued.Checked;
product.VatID = new Guid(cmbVat.SelectedValue.ToString());
if (addNew)
if (product.ProductID == new Guid())
new ProductBI().Insert(product);
else
new ProductBI().Update(product);
return true;
#endregion
}
#endregion
private void btnExit_Click(object sender, EventArgs e)
private void btnCancel_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)
{
ProductGroups frm = new ProductGroups();
using (var frm = new ProductGroups())
{
frm.ShowDialog();
frm.Dispose();
}
FillCombos();
cmbProductGroups.SelectedIndex = 0;
}
#region Move Buttons
private void btnNavFirst_Click(object sender, EventArgs e)
public ProductBO Product
{
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)
{
using (SelectProduct selectProduct = new SelectProduct(new ProductBI().GetFilteredProducts, true))
{
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)
{
e.NewObject = new ProductDisplayBO();
}
private void bsProducts_PositionChanged(object sender, EventArgs e)
{
this.lblNavLocation.Text = string.Format("{0} of {1}", bsProducts.Position + 1, bsProducts.Count);
}
#endregion
private int GetPosition(List<ProductDisplayBO> list, Guid id)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].ProductID == id)
return i;
}
return 0;
get { return null; }
}
}
}

View File

@ -117,10 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bsProducts.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="bsTypes.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="bsProductGroups.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>251, 17</value>
</metadata>
<metadata name="bsUnits.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

View File

@ -20,7 +20,7 @@ namespace Tanshu.Accounts.SqlDAO
product.ProductID = Guid.NewGuid();
SqlCommand cmd = new SqlCommand(@"
SELECT @Code = ISNULL(MAX(Code), 0) + 1 FROM Products;
INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductGroupID, VatID ,SalePrice , ServiceTaxID , Discontinued, MinimumLevel, MaximumLevel, SortOrder) VALUES (@ProductID, @Code, @Name, '', '', @Units, @ProductGroupID, @VatID, @SalePrice ,@ServiceTaxID ,@Discontinued, @MinimumLevel, @MaximumLevel, @SortOrder);");
INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductGroupID, VatID ,SalePrice , ServiceTaxID , Discontinued, SortOrder) VALUES (@ProductID, @Code, @Name, '', '', @Units, @ProductGroupID, @VatID, @SalePrice ,@ServiceTaxID ,@Discontinued, @SortOrder);");
{
cmd.Parameters.AddWithValue("@ProductID", product.ProductID);
cmd.Parameters.Add("@Code", SqlDbType.Int);
@ -32,8 +32,6 @@ INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductG
cmd.Parameters.AddWithValue("@SalePrice", product.SalePrice);
cmd.Parameters.AddWithValue("@ServiceTaxID", product.ServiceTaxID);
cmd.Parameters.AddWithValue("@Discontinued", product.Discontinued);
cmd.Parameters.AddWithValue("@MinimumLevel", product.MinimumLevel);
cmd.Parameters.AddWithValue("@MaximumLevel", product.MaximumLevel);
cmd.Parameters.AddWithValue("@SortOrder", product.SortOrder);
connection.ExecuteNonQuery(cmd);
product.Code = (int)cmd.Parameters["@Code"].Value;
@ -55,7 +53,7 @@ INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductG
}
public bool Update(ProductBO product)
{
SqlCommand cmd = new SqlCommand(@"UPDATE Products SET Code = @Code ,Name = @Name ,Units = @Units ,ProductGroupID = @ProductGroupID ,VatID = @VatID ,SalePrice = @SalePrice ,ServiceTaxID = @ServiceTaxID ,Discontinued = @Discontinued ,MinimumLevel = @MinimumLevel ,MaximumLevel = @MaximumLevel, SortOrder=@SortOrder WHERE ProductID = @ProductID;");
SqlCommand cmd = new SqlCommand(@"UPDATE Products SET Code = @Code ,Name = @Name ,Units = @Units ,ProductGroupID = @ProductGroupID ,VatID = @VatID ,SalePrice = @SalePrice ,ServiceTaxID = @ServiceTaxID ,Discontinued = @Discontinued ,SortOrder=@SortOrder WHERE ProductID = @ProductID;");
cmd.Parameters.AddWithValue("@ProductID", product.ProductID);
cmd.Parameters.AddWithValue("@Code", product.Code);
cmd.Parameters.AddWithValue("@Name", product.Name);
@ -65,8 +63,6 @@ INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductG
cmd.Parameters.AddWithValue("@SalePrice", product.SalePrice);
cmd.Parameters.AddWithValue("@ServiceTaxID", product.ServiceTaxID);
cmd.Parameters.AddWithValue("@Discontinued", product.Discontinued);
cmd.Parameters.AddWithValue("@MinimumLevel", product.MinimumLevel);
cmd.Parameters.AddWithValue("@MaximumLevel", product.MaximumLevel);
cmd.Parameters.AddWithValue("@SortOrder", product.SortOrder);
connection.ExecuteNonQuery(cmd);
return true;
@ -79,8 +75,8 @@ INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductG
}
public List<ProductDisplayBO> GetProducts()
{
//SELECT p.ProductID, p.Picture, p.Code, p.Name, p.Units, p.ProductGroupID, p.VatID, p.SalePrice, p.ServiceTaxID, p.Discontinued, p.MinimumLevel, p.MaximumLevel, p.SortOrder, pt.Name AS Type FROM Products p INNER JOIN ProductGroups pt ON p.ProductGroupID = pt.ProductGroupID ORDER BY p.Name
SqlCommand cmd = new SqlCommand("SELECT p.ProductID, p.Picture, p.Code, p.Name, p.Units, p.ProductGroupID, p.VatID, p.SalePrice, p.ServiceTaxID, p.Discontinued, p.MinimumLevel, p.MaximumLevel, p.SortOrder, pt.Name AS Type FROM Products p INNER JOIN ProductGroups pt ON p.ProductGroupID = pt.ProductGroupID ORDER BY p.Name");
//SELECT p.ProductID, p.Picture, p.Code, p.Name, p.Units, p.ProductGroupID, p.VatID, p.SalePrice, p.ServiceTaxID, p.Discontinued, p.SortOrder, pt.Name AS Type FROM Products p INNER JOIN ProductGroups pt ON p.ProductGroupID = pt.ProductGroupID ORDER BY p.Name
SqlCommand cmd = new SqlCommand("SELECT p.ProductID, p.Picture, p.Code, p.Name, p.Units, p.ProductGroupID, p.VatID, p.SalePrice, p.ServiceTaxID, p.Discontinued, p.SortOrder, pt.Name AS Type FROM Products p INNER JOIN ProductGroups pt ON p.ProductGroupID = pt.ProductGroupID ORDER BY p.Name");
return BusinessObjectDAO<ProductDisplayBO>.GetBusinessObjects(connection.ExecuteReader(cmd));
}
@ -94,11 +90,13 @@ INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductG
{
list.Add(new ProductDisplaySmallBO
{
Category = dr.GetString(4),
ProductID = dr.GetGuid(0),
Code = dr.GetInt32(1),
Name = dr.GetString(2),
Price = dr.GetDecimal(3),
ProductID = dr.GetGuid(0)
Vat = string.Format("{0:#.###%}", dr.GetDecimal(4)),
ServiceTax = string.Format("{0:#.###%}", dr.GetDecimal(5)),
ProuctGroup = dr.GetString(6),
});
}
@ -110,11 +108,11 @@ INSERT INTO Products (ProductID, Code, Name, ShortName, BarCode, Units, ProductG
{
string query = @"
SELECT p.ProductID, p.Code, p.Name + ' (' + p.Units + ') ' + ShortName AS Name,
p.SalePrice * (1 + t.Rate) AS Price,
pt.Name AS Category
FROM Products p INNER JOIN Tax t ON p.VatID = t.TaxID
p.SalePrice, tv.Rate AS Vat, ts.Rate AS ServiceTax, pt.Name AS ProductGroup
FROM Products p INNER JOIN Tax tv ON p.VatID = tv.TaxID
INNER JOIN Tax ts ON p.ServiceTaxID = ts.TaxID
INNER JOIN ProductGroups pt ON p.ProductGroupID = pt.ProductGroupID
WHERE pt.IsForSale = 1 AND p.SalePrice > 0 AND p.Discontinued = 0
WHERE pt.IsForSale = 1 AND p.Discontinued = 0
";
string[] n = filter["Name"].Split(" ".ToCharArray());
@ -122,7 +120,7 @@ WHERE pt.IsForSale = 1 AND p.SalePrice > 0 AND p.Discontinued = 0
if (n1 != null && n1 != string.Empty)
query += string.Format("AND p.Name + ' (' + p.Units + ') ' + ShortName LIKE '%{0}%' \r\n", n1);
n = filter["Type"].ToLower().Split(" ".ToCharArray());
n = filter["ProductGroup"].ToLower().Split(" ".ToCharArray());
foreach (string n1 in n)
if (n1 != null && n1 != string.Empty)
query += string.Format("AND pt.Name LIKE '%{0}%' \r\n", n1);