narsil/Tanshu.Accounts.PointOfSale/Products/ProductGroupForm.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

87 lines
3.0 KiB
C#

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
{
private Guid? _productGroupID;
public ProductGroupForm(Guid? productGroupID)
{
_productGroupID = productGroupID;
InitializeComponent();
}
private void ProductGroupForm_Load(object sender, EventArgs e)
{
if (_productGroupID.HasValue)
{
ProductGroup productGroup;
using (var bi = new ProductGroupBI())
productGroup = bi.Get(x => x.ProductGroupID == _productGroupID.Value);
txtProductGroupID.Text = _productGroupID.Value.ToString();
txtName.Text = productGroup.Name;
txtDiscountLimit.Text = productGroup.DiscountLimit.ToString();
chkModifierCompulsory.Checked = productGroup.IsModifierCompulsory;
txtGroupType.Text = productGroup.GroupType;
chkDiscontinued.Checked = productGroup.Discontinued;
}
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)
{
using (var bi = new ProductGroupBI())
{
if (_productGroupID.HasValue)
bi.Update(productGroup);
else
bi.Insert(productGroup);
bi.SaveChanges();
}
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;
productGroup.Discontinued = chkDiscontinued.Checked;
if (string.IsNullOrEmpty(txtGroupType.Text.Trim()))
return null;
productGroup.GroupType = txtGroupType.Text.Trim();
return productGroup;
}
}
}