2011-06-23 12:47:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ProductGroupForm : Form
|
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
private Guid? _productGroupID;
|
|
|
|
|
public ProductGroupForm(Guid? productGroupID)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
{
|
|
|
|
|
_productGroupID = productGroupID;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProductGroupForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_productGroupID.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ProductGroup productGroup;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
productGroup = ProductGroupBI.Get(_productGroupID.Value);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
txtProductGroupID.Text = _productGroupID.Value.ToString();
|
|
|
|
|
|
|
|
|
|
txtName.Text = productGroup.Name;
|
|
|
|
|
txtDiscountLimit.Text = productGroup.DiscountLimit.ToString();
|
|
|
|
|
chkModifierCompulsory.Checked = productGroup.IsModifierCompulsory;
|
|
|
|
|
txtGroupType.Text = productGroup.GroupType;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
chkIsActive.Checked = productGroup.IsActive;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
txtProductGroupID.Text = "(Auto)";
|
|
|
|
|
txtName.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var productGroup = IsFormValid();
|
|
|
|
|
if (productGroup != null)
|
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
if (_productGroupID.HasValue)
|
|
|
|
|
ProductGroupBI.Update(productGroup);
|
|
|
|
|
else
|
|
|
|
|
ProductGroupBI.Insert(productGroup);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
MessageBox.Show("Update / Save Successful");
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
MessageBox.Show("The form is not valid");
|
|
|
|
|
}
|
|
|
|
|
private ProductGroup IsFormValid()
|
|
|
|
|
{
|
|
|
|
|
var productGroup = new ProductGroup();
|
|
|
|
|
if (_productGroupID.HasValue)
|
|
|
|
|
productGroup.ProductGroupID = _productGroupID.Value;
|
|
|
|
|
if (string.IsNullOrEmpty(txtName.Text.Trim()))
|
|
|
|
|
return null;
|
|
|
|
|
productGroup.Name = txtName.Text.Trim();
|
|
|
|
|
decimal discount;
|
|
|
|
|
if (!decimal.TryParse(txtDiscountLimit.Text, out discount))
|
|
|
|
|
return null;
|
|
|
|
|
if (discount < 0 || discount > 1)
|
|
|
|
|
return null;
|
|
|
|
|
productGroup.DiscountLimit = discount;
|
|
|
|
|
productGroup.IsModifierCompulsory = chkModifierCompulsory.Checked;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
productGroup.IsActive = chkIsActive.Checked;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (string.IsNullOrEmpty(txtGroupType.Text.Trim()))
|
|
|
|
|
return null;
|
|
|
|
|
productGroup.GroupType = txtGroupType.Text.Trim();
|
|
|
|
|
return productGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|