Chore: Removed Waiter as it was not ever used.

Refactor: Changed the user list form to a normal form.
Feature: Service Charge disabled setting removes it from the Product Form.
This commit is contained in:
tanshu
2016-01-18 16:13:43 +05:30
parent caf9b3106c
commit 69560cfb07
30 changed files with 776 additions and 528 deletions

View File

@ -33,7 +33,7 @@
this.bsProductGroups = new System.Windows.Forms.BindingSource(this.components);
this.Label7 = new System.Windows.Forms.Label();
this.bsServiceTax = new System.Windows.Forms.BindingSource(this.components);
this.label5 = new System.Windows.Forms.Label();
this.lblServiceCharge = new System.Windows.Forms.Label();
this.Label2 = new System.Windows.Forms.Label();
this.txtUnits = new System.Windows.Forms.TextBox();
this.txtName = new System.Windows.Forms.TextBox();
@ -46,12 +46,13 @@
this.cmbProductGroup = new System.Windows.Forms.ComboBox();
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.txtFullPrice = new System.Windows.Forms.TextBox();
this.cmbServiceTax = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.chkIsScTaxable = new System.Windows.Forms.CheckBox();
this.chkIsNotAvailable = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.txtFullPrice = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.bsProductGroups)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsServiceTax)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsVat)).BeginInit();
@ -60,11 +61,11 @@
// Label4
//
this.Label4.AutoSize = true;
this.Label4.Location = new System.Drawing.Point(19, 41);
this.Label4.Location = new System.Drawing.Point(75, 41);
this.Label4.Name = "Label4";
this.Label4.Size = new System.Drawing.Size(85, 13);
this.Label4.Size = new System.Drawing.Size(31, 13);
this.Label4.TabIndex = 15;
this.Label4.Text = "Price / Full Price";
this.Label4.Text = "Price";
//
// bsProductGroups
//
@ -73,24 +74,24 @@
// Label7
//
this.Label7.AutoSize = true;
this.Label7.Location = new System.Drawing.Point(70, 143);
this.Label7.Location = new System.Drawing.Point(70, 172);
this.Label7.Name = "Label7";
this.Label7.Size = new System.Drawing.Size(36, 13);
this.Label7.TabIndex = 17;
this.Label7.TabIndex = 20;
this.Label7.Text = "Group";
//
// bsServiceTax
//
this.bsServiceTax.DataSource = typeof(Tanshu.Accounts.Entities.Tax);
//
// label5
// lblServiceCharge
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(26, 117);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 13);
this.label5.TabIndex = 16;
this.label5.Text = "Service Charge";
this.lblServiceCharge.AutoSize = true;
this.lblServiceCharge.Location = new System.Drawing.Point(26, 146);
this.lblServiceCharge.Name = "lblServiceCharge";
this.lblServiceCharge.Size = new System.Drawing.Size(80, 13);
this.lblServiceCharge.TabIndex = 19;
this.lblServiceCharge.Text = "Service Charge";
//
// Label2
//
@ -107,7 +108,7 @@
this.txtUnits.Location = new System.Drawing.Point(307, 12);
this.txtUnits.Name = "txtUnits";
this.txtUnits.Size = new System.Drawing.Size(96, 20);
this.txtUnits.TabIndex = 2;
this.txtUnits.TabIndex = 1;
//
// txtName
//
@ -115,12 +116,12 @@
this.txtName.Location = new System.Drawing.Point(112, 12);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(189, 20);
this.txtName.TabIndex = 1;
this.txtName.TabIndex = 0;
//
// txtPrice
//
this.txtPrice.AccessibleName = "";
this.txtPrice.Location = new System.Drawing.Point(112, 38);
this.txtPrice.Location = new System.Drawing.Point(112, 64);
this.txtPrice.Name = "txtPrice";
this.txtPrice.Size = new System.Drawing.Size(104, 20);
this.txtPrice.TabIndex = 3;
@ -131,10 +132,10 @@
this.cmbVat.DataSource = this.bsVat;
this.cmbVat.DisplayMember = "Name";
this.cmbVat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbVat.Location = new System.Drawing.Point(112, 88);
this.cmbVat.Location = new System.Drawing.Point(112, 117);
this.cmbVat.Name = "cmbVat";
this.cmbVat.Size = new System.Drawing.Size(189, 21);
this.cmbVat.TabIndex = 4;
this.cmbVat.TabIndex = 6;
this.cmbVat.ValueMember = "TaxID";
//
// bsVat
@ -144,132 +145,141 @@
// chkIsActive
//
this.chkIsActive.AutoSize = true;
this.chkIsActive.Location = new System.Drawing.Point(307, 66);
this.chkIsActive.Location = new System.Drawing.Point(307, 95);
this.chkIsActive.Name = "chkIsActive";
this.chkIsActive.Size = new System.Drawing.Size(67, 17);
this.chkIsActive.TabIndex = 7;
this.chkIsActive.TabIndex = 5;
this.chkIsActive.Text = "Is Active";
this.chkIsActive.UseVisualStyleBackColor = true;
//
// txtServiceCharge
//
this.txtServiceCharge.AccessibleName = "Phone 1";
this.txtServiceCharge.Location = new System.Drawing.Point(112, 115);
this.txtServiceCharge.Location = new System.Drawing.Point(112, 144);
this.txtServiceCharge.Name = "txtServiceCharge";
this.txtServiceCharge.Size = new System.Drawing.Size(189, 20);
this.txtServiceCharge.TabIndex = 5;
this.txtServiceCharge.TabIndex = 8;
this.txtServiceCharge.Text = "0";
//
// btnAddProductGroup
//
this.btnAddProductGroup.Location = new System.Drawing.Point(307, 141);
this.btnAddProductGroup.Location = new System.Drawing.Point(307, 170);
this.btnAddProductGroup.Name = "btnAddProductGroup";
this.btnAddProductGroup.Size = new System.Drawing.Size(96, 21);
this.btnAddProductGroup.TabIndex = 9;
this.btnAddProductGroup.TabIndex = 11;
this.btnAddProductGroup.Text = "Add Group";
//
// cmbProductGroup
//
this.cmbProductGroup.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsProductGroups, "ProductGroupID", true));
this.cmbProductGroup.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bsProductGroups, "Name", true));
this.cmbProductGroup.DataSource = this.bsProductGroups;
this.cmbProductGroup.DisplayMember = "Name";
this.cmbProductGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbProductGroup.Location = new System.Drawing.Point(112, 141);
this.cmbProductGroup.Location = new System.Drawing.Point(112, 170);
this.cmbProductGroup.Name = "cmbProductGroup";
this.cmbProductGroup.Size = new System.Drawing.Size(189, 21);
this.cmbProductGroup.TabIndex = 8;
this.cmbProductGroup.TabIndex = 10;
this.cmbProductGroup.ValueMember = "ProductGroupID";
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(328, 169);
this.btnCancel.Location = new System.Drawing.Point(328, 198);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 11;
this.btnCancel.TabIndex = 13;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnOk
//
this.btnOk.Location = new System.Drawing.Point(247, 169);
this.btnOk.Location = new System.Drawing.Point(247, 198);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 75);
this.btnOk.TabIndex = 10;
this.btnOk.TabIndex = 12;
this.btnOk.Text = "&Ok";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// txtFullPrice
//
this.txtFullPrice.AccessibleName = "";
this.txtFullPrice.Location = new System.Drawing.Point(222, 38);
this.txtFullPrice.Name = "txtFullPrice";
this.txtFullPrice.Size = new System.Drawing.Size(79, 20);
this.txtFullPrice.TabIndex = 19;
this.txtFullPrice.Text = "0";
//
// cmbServiceTax
//
this.cmbServiceTax.DataSource = this.bsServiceTax;
this.cmbServiceTax.DisplayMember = "Name";
this.cmbServiceTax.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbServiceTax.Location = new System.Drawing.Point(112, 61);
this.cmbServiceTax.Location = new System.Drawing.Point(112, 90);
this.cmbServiceTax.Name = "cmbServiceTax";
this.cmbServiceTax.Size = new System.Drawing.Size(189, 21);
this.cmbServiceTax.TabIndex = 20;
this.cmbServiceTax.TabIndex = 4;
this.cmbServiceTax.ValueMember = "TaxID";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(42, 67);
this.label6.Location = new System.Drawing.Point(42, 96);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(64, 13);
this.label6.TabIndex = 21;
this.label6.TabIndex = 17;
this.label6.Text = "Service Tax";
//
// chkIsScTaxable
//
this.chkIsScTaxable.AutoSize = true;
this.chkIsScTaxable.Location = new System.Drawing.Point(307, 118);
this.chkIsScTaxable.Location = new System.Drawing.Point(307, 147);
this.chkIsScTaxable.Name = "chkIsScTaxable";
this.chkIsScTaxable.Size = new System.Drawing.Size(91, 17);
this.chkIsScTaxable.TabIndex = 22;
this.chkIsScTaxable.TabIndex = 9;
this.chkIsScTaxable.Text = "Is Sc Taxable";
this.chkIsScTaxable.UseVisualStyleBackColor = true;
//
// chkIsNotAvailable
//
this.chkIsNotAvailable.AutoSize = true;
this.chkIsNotAvailable.Location = new System.Drawing.Point(307, 93);
this.chkIsNotAvailable.Location = new System.Drawing.Point(307, 122);
this.chkIsNotAvailable.Name = "chkIsNotAvailable";
this.chkIsNotAvailable.Size = new System.Drawing.Size(57, 17);
this.chkIsNotAvailable.TabIndex = 23;
this.chkIsNotAvailable.TabIndex = 7;
this.chkIsNotAvailable.Text = "Is N/A";
this.chkIsNotAvailable.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(78, 94);
this.label1.Location = new System.Drawing.Point(78, 123);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(28, 13);
this.label1.TabIndex = 24;
this.label1.TabIndex = 18;
this.label1.Text = "VAT";
//
// txtFullPrice
//
this.txtFullPrice.AccessibleName = "";
this.txtFullPrice.Location = new System.Drawing.Point(112, 38);
this.txtFullPrice.Name = "txtFullPrice";
this.txtFullPrice.Size = new System.Drawing.Size(104, 20);
this.txtFullPrice.TabIndex = 2;
this.txtFullPrice.Text = "0";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(15, 67);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(91, 13);
this.label3.TabIndex = 16;
this.label3.Text = "Happy Hour Price";
//
// ProductForm
//
this.AcceptButton = this.btnOk;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(415, 282);
this.ClientSize = new System.Drawing.Size(415, 285);
this.Controls.Add(this.txtFullPrice);
this.Controls.Add(this.label3);
this.Controls.Add(this.label1);
this.Controls.Add(this.chkIsNotAvailable);
this.Controls.Add(this.chkIsScTaxable);
this.Controls.Add(this.label6);
this.Controls.Add(this.cmbServiceTax);
this.Controls.Add(this.txtFullPrice);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.btnAddProductGroup);
@ -278,7 +288,7 @@
this.Controls.Add(this.txtServiceCharge);
this.Controls.Add(this.Label7);
this.Controls.Add(this.txtPrice);
this.Controls.Add(this.label5);
this.Controls.Add(this.lblServiceCharge);
this.Controls.Add(this.cmbVat);
this.Controls.Add(this.txtUnits);
this.Controls.Add(this.txtName);
@ -304,7 +314,7 @@
internal System.Windows.Forms.Label Label7;
private System.Windows.Forms.BindingSource bsProductGroups;
private System.Windows.Forms.BindingSource bsServiceTax;
internal System.Windows.Forms.Label label5;
internal System.Windows.Forms.Label lblServiceCharge;
internal System.Windows.Forms.Label Label2;
internal System.Windows.Forms.TextBox txtUnits;
internal System.Windows.Forms.TextBox txtName;
@ -316,12 +326,13 @@
internal System.Windows.Forms.ComboBox cmbProductGroup;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
internal System.Windows.Forms.TextBox txtFullPrice;
internal System.Windows.Forms.ComboBox cmbServiceTax;
internal System.Windows.Forms.Label label6;
private System.Windows.Forms.CheckBox chkIsScTaxable;
private System.Windows.Forms.BindingSource bsVat;
private System.Windows.Forms.CheckBox chkIsNotAvailable;
internal System.Windows.Forms.Label label1;
internal System.Windows.Forms.TextBox txtFullPrice;
internal System.Windows.Forms.Label label3;
}
}

View File

@ -2,6 +2,7 @@
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities;
using System.Text.RegularExpressions;
namespace Tanshu.Accounts.PointOfSale
{
@ -17,6 +18,9 @@ namespace Tanshu.Accounts.PointOfSale
private void Products_Load(object sender, EventArgs e)
{
FillCombos();
using (var bis = new SettingBI())
ShowServiceChargeControls(bis.Get(x => x.Name == "Service Charge Enabled").Details == "yes");
if (_productID.HasValue)
{
Product product;
@ -40,6 +44,12 @@ namespace Tanshu.Accounts.PointOfSale
}
}
private void ShowServiceChargeControls(bool enabled)
{
lblServiceCharge.Visible = enabled;
txtServiceCharge.Visible = enabled;
chkIsScTaxable.Visible = enabled;
}
private void FillCombos()
{
using (var bi = new ProductGroupBI())
@ -59,68 +69,77 @@ namespace Tanshu.Accounts.PointOfSale
cmbProductGroup.SelectedIndex = -1;
}
private Product IsFormValid()
private void btnOk_Click(object sender, EventArgs e)
{
var product = new Product();
if (_productID.HasValue)
product.ProductID = _productID.Value;
if (string.IsNullOrEmpty(txtName.Text.Trim()))
return null;
{
MessageBox.Show("Product name cannot be blank.");
txtName.Focus();
return;
}
product.Name = txtName.Text.Trim();
product.Units = txtUnits.Text.Trim();
decimal price;
if (string.IsNullOrEmpty(txtPrice.Text.Trim()))
txtPrice.Text = "0";
if (!Regex.IsMatch(txtPrice.Text, @"^\d*([.]\d{1,5})?$"))
{
price = 0;
MessageBox.Show("Price is not valid, it must be a decimal >= 0");
txtPrice.Focus();
return;
}
else
{
if (!decimal.TryParse(txtPrice.Text.Trim(), out price))
return null;
}
if (price < 0)
return null;
product.Price = price;
product.Price = decimal.Parse(txtPrice.Text.Trim());
if (string.IsNullOrEmpty(txtFullPrice.Text.Trim()))
txtFullPrice.Text = "0";
if (!Regex.IsMatch(txtFullPrice.Text, @"^\d*([.]\d{1,5})?$"))
{
price = 0;
MessageBox.Show("Full Price is not valid, it must be a decimal >= 0");
txtFullPrice.Focus();
return;
}
else
product.FullPrice = decimal.Parse(txtFullPrice.Text.Trim());
if (product.FullPrice < product.Price)
{
if (!decimal.TryParse(txtFullPrice.Text.Trim(), out price))
return null;
MessageBox.Show("Full Price cannot be less than the actual price.");
txtFullPrice.Focus();
return;
}
if (price < 0 || price < product.Price)
return null;
product.FullPrice = price;
// Tax
if (cmbVat.SelectedItem == null)
return null;
{
MessageBox.Show("Please choose VAT");
cmbVat.Focus();
return;
}
product.Vat = (Tax)cmbVat.SelectedItem;
if (cmbServiceTax.SelectedItem == null)
return null;
{
MessageBox.Show("Please choose Service Tax");
cmbServiceTax.Focus();
return;
}
product.ServiceTax = (Tax)cmbServiceTax.SelectedItem;
decimal serviceCharge;
if (string.IsNullOrEmpty(txtServiceCharge.Text.Trim()))
txtServiceCharge.Text = "0";
if (!Regex.IsMatch(txtServiceCharge.Text, @"^0*([.]\d{1,5})?$"))
{
serviceCharge = 0;
MessageBox.Show("Service Charge is not valid, it must be a decimal >= 0 and < 1");
txtServiceCharge.Focus();
return;
}
else
{
if (!decimal.TryParse(txtServiceCharge.Text.Trim(), out serviceCharge))
return null;
}
if (serviceCharge < 0 || serviceCharge > 1)
return null;
product.ServiceCharge = serviceCharge;
product.ServiceCharge = decimal.Parse(txtServiceCharge.Text.Trim());
product.IsScTaxable = chkIsScTaxable.Checked;
product.IsActive = chkIsActive.Checked;
@ -128,29 +147,23 @@ namespace Tanshu.Accounts.PointOfSale
//Group
if (cmbProductGroup.SelectedItem == null)
return null;
product.ProductGroup = (ProductGroup)cmbProductGroup.SelectedItem;
return product;
}
private void btnOk_Click(object sender, EventArgs e)
{
var product = IsFormValid();
if (product != null)
{
using (var bi = new ProductBI())
{
if (_productID.HasValue)
bi.Update(product);
else
bi.Insert(product);
bi.SaveChanges();
}
MessageBox.Show("Update / Save Successful");
this.Close();
MessageBox.Show("Please choose Product Group");
cmbProductGroup.Focus();
return;
}
product.ProductGroup = (ProductGroup)cmbProductGroup.SelectedItem;
using (var bi = new ProductBI())
{
if (_productID.HasValue)
bi.Update(product);
else
bi.Insert(product);
bi.SaveChanges();
}
else
MessageBox.Show("The form is not valid");
MessageBox.Show("Update / Save Successful");
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)