2011-06-23 12:47:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
2016-01-18 10:43:43 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ProductForm : Form
|
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
private Guid? _productID;
|
|
|
|
|
public ProductForm(Guid? productID)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
{
|
|
|
|
|
_productID = productID;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Products_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FillCombos();
|
2016-01-18 10:43:43 +00:00
|
|
|
|
using (var bis = new SettingBI())
|
|
|
|
|
ShowServiceChargeControls(bis.Get(x => x.Name == "Service Charge Enabled").Details == "yes");
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (_productID.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Product product;
|
|
|
|
|
using (var bi = new ProductBI())
|
|
|
|
|
product = bi.Get(x => x.ProductID == _productID.Value);
|
|
|
|
|
txtName.Text = product.Name;
|
|
|
|
|
txtUnits.Text = product.Units;
|
2011-08-28 12:17:15 +00:00
|
|
|
|
txtPrice.Text = product.Price.ToString("#.##");
|
2016-04-11 07:01:52 +00:00
|
|
|
|
chkHasHappyHour.Checked = product.HasHappyHour;
|
2012-04-08 12:28:15 +00:00
|
|
|
|
cmbVat.SelectedValue = product.Vat.TaxID;
|
|
|
|
|
cmbServiceTax.SelectedValue = product.ServiceTax.TaxID;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
txtServiceCharge.Text = product.ServiceCharge.ToString("#.##");
|
2014-10-16 11:11:55 +00:00
|
|
|
|
chkIsActive.Checked = product.IsActive;
|
2012-04-08 12:28:15 +00:00
|
|
|
|
chkIsScTaxable.Checked = product.IsScTaxable;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
chkIsNotAvailable.Checked = product.IsNotAvailable;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
cmbProductGroup.SelectedValue = product.ProductGroup.ProductGroupID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
txtName.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
private void ShowServiceChargeControls(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
lblServiceCharge.Visible = enabled;
|
|
|
|
|
txtServiceCharge.Visible = enabled;
|
|
|
|
|
chkIsScTaxable.Visible = enabled;
|
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private void FillCombos()
|
|
|
|
|
{
|
|
|
|
|
using (var bi = new ProductGroupBI())
|
|
|
|
|
bsProductGroups.DataSource = bi.List();
|
|
|
|
|
using (var bi = new TaxBI())
|
2012-04-08 12:28:15 +00:00
|
|
|
|
{
|
|
|
|
|
bsServiceTax.DataSource = bi.List();
|
|
|
|
|
bsVat.DataSource = bi.List();
|
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnAddCategory_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (var frm = new ProductGroupListForm())
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
FillCombos();
|
|
|
|
|
cmbProductGroup.SelectedIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
{
|
|
|
|
|
var product = new Product();
|
|
|
|
|
if (_productID.HasValue)
|
|
|
|
|
product.ProductID = _productID.Value;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(txtName.Text.Trim()))
|
2016-01-18 10:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Product name cannot be blank.");
|
|
|
|
|
txtName.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
product.Name = txtName.Text.Trim();
|
|
|
|
|
product.Units = txtUnits.Text.Trim();
|
|
|
|
|
|
2014-12-03 07:13:35 +00:00
|
|
|
|
if (string.IsNullOrEmpty(txtPrice.Text.Trim()))
|
2016-01-18 10:43:43 +00:00
|
|
|
|
txtPrice.Text = "0";
|
|
|
|
|
if (!Regex.IsMatch(txtPrice.Text, @"^\d*([.]\d{1,5})?$"))
|
2014-12-03 07:13:35 +00:00
|
|
|
|
{
|
2016-01-18 10:43:43 +00:00
|
|
|
|
MessageBox.Show("Price is not valid, it must be a decimal >= 0");
|
|
|
|
|
txtPrice.Focus();
|
|
|
|
|
return;
|
2014-12-03 07:13:35 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2016-01-18 10:43:43 +00:00
|
|
|
|
product.Price = decimal.Parse(txtPrice.Text.Trim());
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
2016-05-12 09:11:02 +00:00
|
|
|
|
product.HasHappyHour = chkHasHappyHour.Checked;
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
// Tax
|
2012-04-08 12:28:15 +00:00
|
|
|
|
if (cmbVat.SelectedItem == null)
|
2016-01-18 10:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please choose VAT");
|
|
|
|
|
cmbVat.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-04-08 12:28:15 +00:00
|
|
|
|
product.Vat = (Tax)cmbVat.SelectedItem;
|
|
|
|
|
|
|
|
|
|
if (cmbServiceTax.SelectedItem == null)
|
2016-01-18 10:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please choose Service Tax");
|
|
|
|
|
cmbServiceTax.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-04-08 12:28:15 +00:00
|
|
|
|
product.ServiceTax = (Tax)cmbServiceTax.SelectedItem;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
2014-12-03 07:13:35 +00:00
|
|
|
|
if (string.IsNullOrEmpty(txtServiceCharge.Text.Trim()))
|
2016-01-18 10:43:43 +00:00
|
|
|
|
txtServiceCharge.Text = "0";
|
|
|
|
|
if (!Regex.IsMatch(txtServiceCharge.Text, @"^0*([.]\d{1,5})?$"))
|
2014-12-03 07:13:35 +00:00
|
|
|
|
{
|
2016-01-18 10:43:43 +00:00
|
|
|
|
MessageBox.Show("Service Charge is not valid, it must be a decimal >= 0 and < 1");
|
|
|
|
|
txtServiceCharge.Focus();
|
|
|
|
|
return;
|
2014-12-03 07:13:35 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2016-01-18 10:43:43 +00:00
|
|
|
|
product.ServiceCharge = decimal.Parse(txtServiceCharge.Text.Trim());
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
2012-04-08 12:28:15 +00:00
|
|
|
|
product.IsScTaxable = chkIsScTaxable.Checked;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
product.IsActive = chkIsActive.Checked;
|
|
|
|
|
product.IsNotAvailable = chkIsNotAvailable.Checked;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
|
|
|
|
//Group
|
|
|
|
|
if (cmbProductGroup.SelectedItem == null)
|
2016-01-18 10:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please choose Product Group");
|
|
|
|
|
cmbProductGroup.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
product.ProductGroup = (ProductGroup)cmbProductGroup.SelectedItem;
|
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
using (var bi = new ProductBI())
|
2011-06-23 12:47:48 +00:00
|
|
|
|
{
|
2016-01-18 10:43:43 +00:00
|
|
|
|
if (_productID.HasValue)
|
|
|
|
|
bi.Update(product);
|
|
|
|
|
else
|
|
|
|
|
bi.Insert(product);
|
|
|
|
|
bi.SaveChanges();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
}
|
2016-01-18 10:43:43 +00:00
|
|
|
|
MessageBox.Show("Update / Save Successful");
|
|
|
|
|
this.Close();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|