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

@ -17,7 +17,7 @@ namespace Tanshu.Accounts.PointOfSale
private readonly OrderedDictionary<BillItemKey, BillItemValue> _bill;
private Voucher _billInfo;
private Customer _customer = new CustomerBI().GetCustomer(1);
private Customer _customer;
private int? _editVoucherID;
private readonly bool _print;
@ -29,6 +29,8 @@ namespace Tanshu.Accounts.PointOfSale
this._editVoucherID = editVoucherID;
_print = print;
_bill = new OrderedDictionary<BillItemKey, BillItemValue>();
using (var bi = new CustomerBI(false))
_customer = bi.Get(x => x.CustomerID == 1);
}
public BillItemValue CurrentProduct
@ -79,11 +81,12 @@ namespace Tanshu.Accounts.PointOfSale
public void AddProductToGrid(Product product)
{
AddProduct(product);
if (ProductGroupModifierBI.HasCompulsoryModifier(product.ProductGroup.ProductGroupID))
{
var item = CurrentProduct;
ShowModifiers(product.ProductGroup.ProductGroupID, item);
}
using (var bi = new ProductGroupModifierBI(false))
if (bi.HasCompulsoryModifier(product.ProductGroup.ProductGroupID))
{
var item = CurrentProduct;
ShowModifiers(product.ProductGroup.ProductGroupID, item);
}
ShowAmount();
}
@ -110,7 +113,7 @@ namespace Tanshu.Accounts.PointOfSale
Quantity = 1,
};
var old = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID).SingleOrDefault();
var old = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID).FirstOrDefault();
if (old.Key != null)
{
billItemValue.Discount = old.Value.Discount;
@ -127,11 +130,13 @@ namespace Tanshu.Accounts.PointOfSale
{
if (item.Printed)
return;
var list = ProductGroupModifierBI.GetProductGroupModifiers(productGroupID);
using (var frm = new ModifierForm(list, item.Modifiers))
using (var bi = new ProductGroupModifierBI(false))
{
frm.ShowDialog();
item.Modifiers = frm.Selection;
using (var frm = new ModifierForm(bi.List(productGroupID), item.Modifiers))
{
frm.ShowDialog();
item.Modifiers = frm.Selection;
}
}
ShowAmount();
}
@ -171,7 +176,7 @@ namespace Tanshu.Accounts.PointOfSale
{
if ((_customer.CustomerID == 1) && (!reset))
{
using (var selectCustomer = new SelectCustomer(new CustomerBI().GetFilteredCustomers, true))
using (var selectCustomer = new SelectCustomer(CustomerBI.List, true))
{
selectCustomer.customerEvent += selectCustomer_customerEvent;
selectCustomer.ShowDialog();
@ -182,13 +187,15 @@ namespace Tanshu.Accounts.PointOfSale
}
else
{
_customer = new CustomerBI().GetCustomer(1);
using (var bi = new CustomerBI(false))
_customer = bi.Get(x => x.CustomerID == 1);
}
}
}
else
{
_customer = new CustomerBI().GetCustomer(1);
using (var bi = new CustomerBI(false))
_customer = bi.Get(x => x.CustomerID == 1);
_saleForm.SetCustomerDisplay(_customer.Name);
}
}
@ -208,7 +215,17 @@ namespace Tanshu.Accounts.PointOfSale
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
{
VoucherBI.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description);
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
using (var bi = new VoucherBI(session, false))
bi.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description);
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(_billInfo);
trans.Commit();
}
}
ClearBill();
}
else
@ -326,7 +343,8 @@ namespace Tanshu.Accounts.PointOfSale
ClearBill();
_bill.Clear();
_billInfo = null;
_billInfo = VoucherBI.Get(voucherID);
using (var bi = new VoucherBI(false))
_billInfo = bi.Get(voucherID);
_customer = _billInfo.Customer;
_saleForm.ShowInfo(_billInfo.BillID, _billInfo.KotID, _billInfo.CreationDate, _billInfo.Date.Value,
@ -466,7 +484,8 @@ namespace Tanshu.Accounts.PointOfSale
}
if (options.Count == 0)
return;
VoucherBI.SettleVoucher(Session.User, _billInfo.VoucherID, options);
using (var bi = new VoucherSettlementBI())
bi.SettleVoucher(Session.User, _billInfo.VoucherID, options);
ClearBill();
}
@ -489,8 +508,9 @@ namespace Tanshu.Accounts.PointOfSale
{
if (_billInfo == null)
return;
if (VoucherBI.IsBillPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
using (var bi = new VoucherBI(false))
if (bi.IsVoucherPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
var kot = CurrentKot;
if (kot == null)
return;
@ -518,8 +538,9 @@ namespace Tanshu.Accounts.PointOfSale
{
if (_billInfo == null)
return;
if (VoucherBI.IsBillPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
using (var bi = new VoucherBI(false))
if (bi.IsVoucherPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
var table = GetTableForMove(true);
if (table == null)
return;
@ -531,24 +552,40 @@ namespace Tanshu.Accounts.PointOfSale
if (!Session.IsAllowed(RoleConstants.MOVE_KOT))
return 0;
var voucher = new Voucher
{
Customer = _billInfo.Customer,
TableID = table.Name,
Waiter = _billInfo.Waiter,
Printed = false,
Void = false,
Date = DateTime.Now,
Narration = "",
User = Session.User
};
using (var session = SessionManager.Session)
{
Customer = _billInfo.Customer,
TableID = table.Name,
Waiter = _billInfo.Waiter,
Printed = false,
Void = false,
Date = DateTime.Now,
Narration = "",
User = Session.User
};
VoucherBI.Insert(voucher, true);
return VoucherBI.MergeKot(kot.KotID, voucher);
using (var trans = session.BeginTransaction())
{
using (var bi = new VoucherBI(session, false))
{
bi.Insert(voucher);
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(voucher);
var voucherId = bi.MergeKot(kot.KotID, voucher);
trans.Commit();
return voucherId;
}
}
}
}
private static int MergeKot(BillItemKey kot, FoodTable table)
{
if (!Session.IsAllowed(RoleConstants.MERGE_KOT))
return 0;
return VoucherBI.MergeKot(kot.KotID, table);
using (var bi = new VoucherBI())
return bi.MergeKot(kot.KotID, table);
}
private int MoveTable(FoodTable table)
{
@ -564,7 +601,8 @@ namespace Tanshu.Accounts.PointOfSale
var kots = _bill.Keys.Where(x => x.BillItemType == BillItemType.Kot && x.KotID != 0);
foreach (var item in kots)
MergeKot(item, table);
VoucherBI.Delete(_billInfo.VoucherID);
using (var bi = new VoucherBI())
bi.Delete(_billInfo.VoucherID);
return table.VoucherID;
}
#endregion
@ -574,9 +612,9 @@ namespace Tanshu.Accounts.PointOfSale
{
if (!Session.IsAllowed(RoleConstants.PRINT_BILL))
return;
if ((_billInfo != null) && (VoucherBI.IsBillPrinted(_billInfo.VoucherID)) &&
(!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
using (var bi = new VoucherBI(false))
if ((_billInfo != null) && (bi.IsVoucherPrinted(_billInfo.VoucherID)) && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
if (_bill.Count == 1) //new kot only
return;
ShowDiscount();
@ -593,9 +631,9 @@ namespace Tanshu.Accounts.PointOfSale
{
if (!Session.IsAllowed(RoleConstants.PRINT_KOT))
return;
if ((_billInfo != null) && (VoucherBI.IsBillPrinted(_billInfo.VoucherID)) &&
(!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
using (var bi = new VoucherBI(false))
if ((_billInfo != null) && (bi.IsVoucherPrinted(_billInfo.VoucherID)) && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
if (_bill.Count == 1) //new kot only
return;
var saved = _billInfo == null ? InsertVoucher(false, waiterID, tableID, !_editVoucherID.HasValue) : UpdateVoucher(false, waiterID, tableID, !_editVoucherID.HasValue);
@ -631,7 +669,20 @@ namespace Tanshu.Accounts.PointOfSale
var kot = GetKotForBill();
if (kot != null)
_billInfo.Kots.Add(kot);
return VoucherBI.Insert(_billInfo, updateTable);
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
int? kotID;
using (var bi = new VoucherBI(session, false))
kotID = bi.Insert(_billInfo);
if (updateTable)
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(_billInfo);
trans.Commit();
return kotID;
}
}
}
private int? UpdateVoucher(bool finalBill, int waiterID, string tableID, bool updateTable)
@ -647,8 +698,22 @@ namespace Tanshu.Accounts.PointOfSale
var kot = GetKotForBill();
if (kot != null)
_billInfo.Kots.Add(kot);
return VoucherBI.Update(_billInfo, updateTable);
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
int? kotID;
using (var bi = new VoucherBI(session, false))
kotID = bi.Update(_billInfo);
if (updateTable)
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(_billInfo);
trans.Commit();
return kotID;
}
}
}
private void UpdateKots()
{
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0))