Updated NH, Code Refactoring, made all DB transactions atomic.

Must use the Repositories with Using or else bad things will happen.
This commit is contained in:
unknown
2011-06-30 01:57:07 +05:30
parent d8ecec8bb6
commit 59909a5ee7
56 changed files with 1964 additions and 1227 deletions

View File

@ -27,7 +27,8 @@ namespace Tanshu.Accounts.PointOfSale
{
if (customerID.HasValue)
{
customer = new CustomerBI().GetCustomer(customerID.Value);
using (var bi = new CustomerBI(false))
customer = bi.Get(x => x.CustomerID == customerID.Value);
btnDelete.Enabled = true;
txtName.Text = customer.Name;
txtPhone.Text = customer.Phone;
@ -58,7 +59,8 @@ namespace Tanshu.Accounts.PointOfSale
}
private void btnDelete_Click(object sender, EventArgs e)
{
new CustomerBI().Delete(customer.CustomerID);
using (var bi = new CustomerBI())
bi.Delete(x => x.CustomerID == customer.CustomerID);
btnCancel_Click(sender, e);
}
private void btnCancel_Click(object sender, EventArgs e)
@ -85,14 +87,16 @@ namespace Tanshu.Accounts.PointOfSale
customer.Address = txtAddress.Text;
customer.Remarks = txtRemarks.Text;
customer.Important = chkImportant.Checked;
if (customer.CustomerID == 0)
new CustomerBI().Insert(customer);
else
new CustomerBI().Update(customer);
using (var bi = new CustomerBI())
if (customer.CustomerID == 0)
bi.Insert(customer);
else
bi.Update(customer);
}
private bool Delete(int customerID)
private void Delete(int customerID)
{
return new CustomerBI().Delete(customerID);
using (var bi = new CustomerBI())
bi.Delete(x => x.CustomerID == customerID);
}
#endregion

View File

@ -13,21 +13,21 @@ namespace Tanshu.Accounts.PointOfSale.Sales
{
public partial class SalesForm : Form, ISaleForm
{
private readonly IDictionary<int, IList<Product>> productDictionary;
private readonly IDictionary<int, IList<Product>> _productDictionary;
private readonly IList<ProductGroup> _productGroupList;
private ProductGroup _currentProductGroup;
public SalesForm(BillController billController)
{
InitializeComponent();
productDictionary = new Dictionary<int, IList<Product>>();
_productDictionary = new Dictionary<int, IList<Product>>();
this._billController = billController;
billController.InitGui(this);
using (var bi = new ProductGroupBI())
_productGroupList = bi.List();
_productGroupList = bi.List(x => x.Discontinued == false);
using (var bi = new ProductBI())
foreach (var item in _productGroupList)
productDictionary.Add(item.ProductGroupID, bi.List(x => x.ProductGroup.ProductGroupID == item.ProductGroupID));
_productDictionary.Add(item.ProductGroupID, bi.List(x => x.ProductGroup.ProductGroupID == item.ProductGroupID && x.Discontinued == false));
}
#region ISaleForm Members
@ -369,7 +369,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
{
_currentProductGroup = item;
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0,
productDictionary[item.ProductGroupID], productButton_Click);
_productDictionary[item.ProductGroupID], productButton_Click);
}
}
@ -384,7 +384,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
int start = item.ProductID;
if (start < 0)
start = 0;
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, productDictionary[_currentProductGroup.ProductGroupID], productButton_Click);
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, _productDictionary[_currentProductGroup.ProductGroupID], productButton_Click);
}
else
{