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

@ -30,7 +30,8 @@ namespace Tanshu.Accounts.PointOfSale
}
private void FillDataGrid()
{
dgExpenses.DataSource = new AdvanceBI().GetAdvances(dtpFrom.Value, dtpTo.Value, false);
using (var bi = new AdvanceBI(false))
dgExpenses.DataSource = bi.GetAdvances(dtpFrom.Value, dtpTo.Value, false);
}
private void dtpFrom_ValueChanged(object sender, EventArgs e)
{
@ -40,16 +41,17 @@ namespace Tanshu.Accounts.PointOfSale
private void btnSelect_Click(object sender, EventArgs e)
{
var item = (Advance)dgExpenses.SelectedRows[0].DataBoundItem;
txtCashier.Text = item.CashierIn.Name;
txtNarration.Tag = item.AdvanceID;
txtNarration.Text = item.Narration;
txtAmount.Text = item.Amount.ToString();
var item = (Advance)dgExpenses.SelectedRows[0].DataBoundItem;
txtCashier.Text = item.CashierIn.Name;
txtNarration.Tag = item.AdvanceID;
txtNarration.Text = item.Narration;
txtAmount.Text = item.Amount.ToString();
}
private void btnAdjust_Click(object sender, EventArgs e)
{
new AdvanceBI().Adjust((int)txtNarration.Tag, Session.User.UserID);
using (var bi = new AdvanceBI())
bi.Adjust((int)txtNarration.Tag, Session.User.UserID);
FillDataGrid();
}
}

View File

@ -27,7 +27,8 @@ namespace Tanshu.Accounts.PointOfSale
using (var bi = new UserBI())
adv.CashierIn = bi.Get(x => x.UserID == (int)txtCashier.Tag);
adv.DateIn = DateTime.Now;
new AdvanceBI().Insert(adv);
using (var bi = new AdvanceBI())
bi.Insert(adv);
GridBind();
PrintAdvances();
}
@ -49,8 +50,8 @@ namespace Tanshu.Accounts.PointOfSale
private void GridBind()
{
var advance = new AdvanceBI().GetAdvances(dtpFrom.Value, dtpTo.Value, true);
dgExpenses.DataSource = advance;
using (var bi = new AdvanceBI(false))
dgExpenses.DataSource = bi.GetAdvances(dtpFrom.Value, dtpTo.Value, true);
}
private void dtpFrom_ValueChanged(object sender, EventArgs e)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="FluentCon" connectionString="Server=Sovereign;Initial Catalog=Pets;User ID=sa;Password=123456" />
<add name="FluentCon" connectionString="Server=sovereign;Initial Catalog=Pets;User ID=sa;Password=123456" />
</connectionStrings>
<appSettings>
<add key ="Location" value ="Office"/>

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))

View File

@ -2,6 +2,7 @@
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.PointOfSale.Sales;
@ -244,7 +245,9 @@ namespace Tanshu.Accounts.PointOfSale
var result = InputBox.Show("Bill Number", "0", InputBox_Validating);
if (!result.OK)
return;
var voucher = VoucherBI.Get(result.Text);
Voucher voucher;
using (var bi = new VoucherBI(false))
voucher = bi.Get(result.Text);
if (Session.IsAllowed(RoleConstants.SALES))
using (var frmSale = new SalesForm(new BillController(voucher.VoucherID, true)))
frmSale.ShowDialog();

View File

@ -48,6 +48,8 @@
this.cmbProductGroup = new System.Windows.Forms.ComboBox();
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.txtSortOrder = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.bsProductGroups)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsTax)).BeginInit();
this.SuspendLayout();
@ -58,7 +60,7 @@
this.Label4.Location = new System.Drawing.Point(22, 67);
this.Label4.Name = "Label4";
this.Label4.Size = new System.Drawing.Size(84, 13);
this.Label4.TabIndex = 59;
this.Label4.TabIndex = 15;
this.Label4.Text = "Sale Price / Tax";
//
// bsProductGroups
@ -68,10 +70,10 @@
// Label7
//
this.Label7.AutoSize = true;
this.Label7.Location = new System.Drawing.Point(30, 120);
this.Label7.Location = new System.Drawing.Point(70, 119);
this.Label7.Name = "Label7";
this.Label7.Size = new System.Drawing.Size(36, 13);
this.Label7.TabIndex = 33;
this.Label7.TabIndex = 17;
this.Label7.Text = "Group";
//
// bsTax
@ -84,7 +86,7 @@
this.label5.Location = new System.Drawing.Point(26, 93);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 13);
this.label5.TabIndex = 84;
this.label5.TabIndex = 16;
this.label5.Text = "Service Charge";
//
// label3
@ -93,7 +95,7 @@
this.label3.Location = new System.Drawing.Point(12, 15);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(94, 13);
this.label3.TabIndex = 86;
this.label3.TabIndex = 13;
this.label3.Text = "Product ID / Code";
//
// txtProductID
@ -102,16 +104,15 @@
this.txtProductID.Name = "txtProductID";
this.txtProductID.ReadOnly = true;
this.txtProductID.Size = new System.Drawing.Size(189, 20);
this.txtProductID.TabIndex = 87;
this.txtProductID.TabIndex = 12;
//
// txtCode
//
this.txtCode.AccessibleName = "";
this.txtCode.Enabled = false;
this.txtCode.Location = new System.Drawing.Point(307, 12);
this.txtCode.Name = "txtCode";
this.txtCode.Size = new System.Drawing.Size(96, 20);
this.txtCode.TabIndex = 88;
this.txtCode.TabIndex = 0;
this.txtCode.WordWrap = false;
//
// Label2
@ -120,7 +121,7 @@
this.Label2.Location = new System.Drawing.Point(36, 41);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(70, 13);
this.Label2.TabIndex = 89;
this.Label2.TabIndex = 14;
this.Label2.Text = "Name / Units";
//
// txtUnits
@ -129,7 +130,7 @@
this.txtUnits.Location = new System.Drawing.Point(307, 38);
this.txtUnits.Name = "txtUnits";
this.txtUnits.Size = new System.Drawing.Size(96, 20);
this.txtUnits.TabIndex = 91;
this.txtUnits.TabIndex = 2;
//
// txtName
//
@ -137,7 +138,7 @@
this.txtName.Location = new System.Drawing.Point(112, 38);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(189, 20);
this.txtName.TabIndex = 90;
this.txtName.TabIndex = 1;
//
// txtSalePrice
//
@ -145,7 +146,7 @@
this.txtSalePrice.Location = new System.Drawing.Point(112, 64);
this.txtSalePrice.Name = "txtSalePrice";
this.txtSalePrice.Size = new System.Drawing.Size(189, 20);
this.txtSalePrice.TabIndex = 92;
this.txtSalePrice.TabIndex = 3;
this.txtSalePrice.Text = "0";
//
// cmbTax
@ -156,7 +157,7 @@
this.cmbTax.Location = new System.Drawing.Point(307, 65);
this.cmbTax.Name = "cmbTax";
this.cmbTax.Size = new System.Drawing.Size(96, 21);
this.cmbTax.TabIndex = 93;
this.cmbTax.TabIndex = 4;
this.cmbTax.ValueMember = "TaxID";
//
// chkDiscontinued
@ -165,7 +166,7 @@
this.chkDiscontinued.Location = new System.Drawing.Point(307, 92);
this.chkDiscontinued.Name = "chkDiscontinued";
this.chkDiscontinued.Size = new System.Drawing.Size(88, 17);
this.chkDiscontinued.TabIndex = 94;
this.chkDiscontinued.TabIndex = 7;
this.chkDiscontinued.Text = "Discontinued";
this.chkDiscontinued.UseVisualStyleBackColor = true;
//
@ -174,8 +175,8 @@
this.txtServiceCharge.AccessibleName = "Phone 1";
this.txtServiceCharge.Location = new System.Drawing.Point(112, 90);
this.txtServiceCharge.Name = "txtServiceCharge";
this.txtServiceCharge.Size = new System.Drawing.Size(189, 20);
this.txtServiceCharge.TabIndex = 95;
this.txtServiceCharge.Size = new System.Drawing.Size(73, 20);
this.txtServiceCharge.TabIndex = 5;
this.txtServiceCharge.Text = "0";
//
// btnAddProductGroup
@ -183,7 +184,7 @@
this.btnAddProductGroup.Location = new System.Drawing.Point(307, 116);
this.btnAddProductGroup.Name = "btnAddProductGroup";
this.btnAddProductGroup.Size = new System.Drawing.Size(96, 21);
this.btnAddProductGroup.TabIndex = 97;
this.btnAddProductGroup.TabIndex = 9;
this.btnAddProductGroup.Text = "Add Group";
//
// cmbProductGroup
@ -196,7 +197,7 @@
this.cmbProductGroup.Location = new System.Drawing.Point(112, 116);
this.cmbProductGroup.Name = "cmbProductGroup";
this.cmbProductGroup.Size = new System.Drawing.Size(189, 21);
this.cmbProductGroup.TabIndex = 96;
this.cmbProductGroup.TabIndex = 8;
this.cmbProductGroup.ValueMember = "ProductGroupID";
//
// btnCancel
@ -204,7 +205,7 @@
this.btnCancel.Location = new System.Drawing.Point(328, 143);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 99;
this.btnCancel.TabIndex = 11;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
@ -214,16 +215,36 @@
this.btnOk.Location = new System.Drawing.Point(247, 143);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 75);
this.btnOk.TabIndex = 98;
this.btnOk.TabIndex = 10;
this.btnOk.Text = "&Ok";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(196, 93);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(26, 13);
this.label1.TabIndex = 18;
this.label1.Text = "Sort";
//
// txtSortOrder
//
this.txtSortOrder.AccessibleName = "";
this.txtSortOrder.Location = new System.Drawing.Point(228, 90);
this.txtSortOrder.Name = "txtSortOrder";
this.txtSortOrder.Size = new System.Drawing.Size(73, 20);
this.txtSortOrder.TabIndex = 6;
this.txtSortOrder.Text = "0";
//
// ProductForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(415, 230);
this.Controls.Add(this.txtSortOrder);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.btnAddProductGroup);
@ -275,5 +296,7 @@
internal System.Windows.Forms.ComboBox cmbProductGroup;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
internal System.Windows.Forms.Label label1;
internal System.Windows.Forms.TextBox txtSortOrder;
}
}

View File

@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.PointOfSale
{
@ -37,6 +31,7 @@ namespace Tanshu.Accounts.PointOfSale
txtServiceCharge.Text = product.ServiceCharge.ToString("#.##");
chkDiscontinued.Checked = product.Discontinued;
cmbProductGroup.SelectedValue = product.ProductGroup.ProductGroupID;
txtSortOrder.Text = product.SortOrder.ToString();
}
else
{
@ -78,8 +73,8 @@ namespace Tanshu.Accounts.PointOfSale
if (string.IsNullOrEmpty(txtName.Text.Trim()))
return null;
product.Name = txtName.Text.Trim();
if (string.IsNullOrEmpty(txtUnits.Text.Trim()))
return null;
//if (string.IsNullOrEmpty(txtUnits.Text.Trim()))
// return null;
product.Units = txtUnits.Text.Trim();
decimal salePrice;
@ -102,6 +97,10 @@ namespace Tanshu.Accounts.PointOfSale
product.ServiceCharge = serviceCharge;
product.Discontinued = chkDiscontinued.Checked;
int sortOrder;
if (!int.TryParse(txtSortOrder.Text, out sortOrder))
return null;
product.SortOrder = sortOrder;
//Group
if (cmbProductGroup.SelectedItem == null)

View File

@ -39,6 +39,9 @@
this.label3 = new System.Windows.Forms.Label();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.chkDiscontinued = new System.Windows.Forms.CheckBox();
this.txtSortOrder = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtName
@ -47,7 +50,7 @@
this.txtName.Location = new System.Drawing.Point(94, 38);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(267, 20);
this.txtName.TabIndex = 57;
this.txtName.TabIndex = 0;
//
// txtProductGroupID
//
@ -57,7 +60,7 @@
this.txtProductGroupID.Name = "txtProductGroupID";
this.txtProductGroupID.ReadOnly = true;
this.txtProductGroupID.Size = new System.Drawing.Size(267, 20);
this.txtProductGroupID.TabIndex = 60;
this.txtProductGroupID.TabIndex = 8;
this.txtProductGroupID.Text = "ProductGroupID";
this.txtProductGroupID.WordWrap = false;
//
@ -67,7 +70,7 @@
this.Label2.Location = new System.Drawing.Point(53, 41);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(35, 13);
this.Label2.TabIndex = 58;
this.Label2.TabIndex = 10;
this.Label2.Text = "Name";
//
// Label1
@ -76,7 +79,7 @@
this.Label1.Location = new System.Drawing.Point(70, 15);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(18, 13);
this.Label1.TabIndex = 59;
this.Label1.TabIndex = 9;
this.Label1.Text = "ID";
//
// txtDiscountLimit
@ -85,7 +88,7 @@
this.txtDiscountLimit.Location = new System.Drawing.Point(94, 64);
this.txtDiscountLimit.Name = "txtDiscountLimit";
this.txtDiscountLimit.Size = new System.Drawing.Size(65, 20);
this.txtDiscountLimit.TabIndex = 72;
this.txtDiscountLimit.TabIndex = 1;
this.txtDiscountLimit.Text = "0";
this.txtDiscountLimit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
@ -95,7 +98,7 @@
this.Label5.Location = new System.Drawing.Point(15, 67);
this.Label5.Name = "Label5";
this.Label5.Size = new System.Drawing.Size(73, 13);
this.Label5.TabIndex = 73;
this.Label5.TabIndex = 11;
this.Label5.Text = "Discount Limit";
//
// chkModifierCompulsory
@ -104,7 +107,7 @@
this.chkModifierCompulsory.Location = new System.Drawing.Point(94, 90);
this.chkModifierCompulsory.Name = "chkModifierCompulsory";
this.chkModifierCompulsory.Size = new System.Drawing.Size(137, 17);
this.chkModifierCompulsory.TabIndex = 74;
this.chkModifierCompulsory.TabIndex = 3;
this.chkModifierCompulsory.Text = "Is Modifier Compulsory?";
this.chkModifierCompulsory.UseVisualStyleBackColor = true;
//
@ -114,7 +117,7 @@
this.txtGroupType.Location = new System.Drawing.Point(94, 113);
this.txtGroupType.Name = "txtGroupType";
this.txtGroupType.Size = new System.Drawing.Size(267, 20);
this.txtGroupType.TabIndex = 75;
this.txtGroupType.TabIndex = 5;
//
// label3
//
@ -122,7 +125,7 @@
this.label3.Location = new System.Drawing.Point(25, 116);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(63, 13);
this.label3.TabIndex = 76;
this.label3.TabIndex = 12;
this.label3.Text = "Group Type";
//
// btnOk
@ -130,7 +133,7 @@
this.btnOk.Location = new System.Drawing.Point(205, 139);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 75);
this.btnOk.TabIndex = 77;
this.btnOk.TabIndex = 6;
this.btnOk.Text = "&Ok";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
@ -140,16 +143,45 @@
this.btnCancel.Location = new System.Drawing.Point(286, 139);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 78;
this.btnCancel.TabIndex = 7;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// chkDiscontinued
//
this.chkDiscontinued.AutoSize = true;
this.chkDiscontinued.Location = new System.Drawing.Point(237, 90);
this.chkDiscontinued.Name = "chkDiscontinued";
this.chkDiscontinued.Size = new System.Drawing.Size(88, 17);
this.chkDiscontinued.TabIndex = 4;
this.chkDiscontinued.Text = "Discontinued";
this.chkDiscontinued.UseVisualStyleBackColor = true;
//
// txtSortOrder
//
this.txtSortOrder.Location = new System.Drawing.Point(261, 64);
this.txtSortOrder.Name = "txtSortOrder";
this.txtSortOrder.Size = new System.Drawing.Size(100, 20);
this.txtSortOrder.TabIndex = 2;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(200, 67);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 13);
this.label4.TabIndex = 13;
this.label4.Text = "Sort Order";
//
// ProductGroupForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(373, 226);
this.Controls.Add(this.label4);
this.Controls.Add(this.txtSortOrder);
this.Controls.Add(this.chkDiscontinued);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.txtGroupType);
@ -185,5 +217,8 @@
internal System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.CheckBox chkDiscontinued;
private System.Windows.Forms.TextBox txtSortOrder;
internal System.Windows.Forms.Label label4;
}
}

View File

@ -28,6 +28,8 @@ namespace Tanshu.Accounts.PointOfSale
txtDiscountLimit.Text = productGroup.DiscountLimit.ToString();
chkModifierCompulsory.Checked = productGroup.IsModifierCompulsory;
txtGroupType.Text = productGroup.GroupType;
chkDiscontinued.Checked = productGroup.Discontinued;
txtSortOrder.Text = productGroup.SortOrder.ToString();
}
else
{
@ -71,7 +73,12 @@ namespace Tanshu.Accounts.PointOfSale
if (discount < 0 || discount > 1)
return null;
productGroup.DiscountLimit = discount;
int sortOrder;
if (!int.TryParse(txtSortOrder.Text, out sortOrder))
return null;
productGroup.SortOrder = sortOrder;
productGroup.IsModifierCompulsory = chkModifierCompulsory.Checked;
productGroup.Discontinued = chkDiscontinued.Checked;
if (string.IsNullOrEmpty(txtGroupType.Text.Trim()))
return null;
productGroup.GroupType = txtGroupType.Text.Trim();

View File

@ -29,7 +29,7 @@
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.btnAdd = new System.Windows.Forms.Button();
this.btnEdit = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
@ -38,6 +38,7 @@
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.discountLimitDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupTypeDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.SortOrder = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dgvProductTypes)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit();
this.SuspendLayout();
@ -88,7 +89,8 @@
this.dgvProductTypes.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.nameDataGridViewTextBoxColumn,
this.discountLimitDataGridViewTextBoxColumn,
this.groupTypeDataGridViewTextBoxColumn});
this.groupTypeDataGridViewTextBoxColumn,
this.SortOrder});
this.dgvProductTypes.DataSource = this.bsList;
this.dgvProductTypes.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
this.dgvProductTypes.Location = new System.Drawing.Point(12, 12);
@ -116,9 +118,9 @@
// discountLimitDataGridViewTextBoxColumn
//
this.discountLimitDataGridViewTextBoxColumn.DataPropertyName = "DiscountLimit";
dataGridViewCellStyle2.Format = "P0";
dataGridViewCellStyle2.NullValue = null;
this.discountLimitDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2;
dataGridViewCellStyle1.Format = "P0";
dataGridViewCellStyle1.NullValue = null;
this.discountLimitDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle1;
this.discountLimitDataGridViewTextBoxColumn.HeaderText = "Discount";
this.discountLimitDataGridViewTextBoxColumn.Name = "discountLimitDataGridViewTextBoxColumn";
this.discountLimitDataGridViewTextBoxColumn.ReadOnly = true;
@ -132,6 +134,14 @@
this.groupTypeDataGridViewTextBoxColumn.ReadOnly = true;
this.groupTypeDataGridViewTextBoxColumn.Width = 56;
//
// SortOrder
//
this.SortOrder.DataPropertyName = "SortOrder";
this.SortOrder.HeaderText = "SortOrder";
this.SortOrder.Name = "SortOrder";
this.SortOrder.ReadOnly = true;
this.SortOrder.Width = 77;
//
// ProductGroupListForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -163,5 +173,6 @@
private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn discountLimitDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn groupTypeDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn SortOrder;
}
}

View File

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="SortOrder.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="bsList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Repository;

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
{