Regression: BillItemKey added the compare methods back
Regression: PrintLocation added the compare methods back Breaking: Kot.Code is now integers Breaking: Kot Update is now via Stored Procedure to get DB Values Breaking: Reprints Insert is now via Stored Procedure to get DV Values Breaking: Voucher.BillID and KotID are now integers Breaking: Voucher Insert/Update is now via Stored Procedures to get DV Values also Dirty Checking for Voucher has been overwritten to set dirty for LastEditDate update Fix: Login forms simplified Feature: PrintLocation and Products are cached application wide.
This commit is contained in:
parent
45831e2e4d
commit
3ca8b29e04
Sql
Tanshu.Accounts.Contracts
Data Contracts Display
Data Contracts
Tanshu.Accounts.PointOfSale
Tanshu.Accounts.Print
Tanshu.Accounts.Repository
Binary file not shown.
@ -51,7 +51,6 @@ UPDATE Auth_Roles SET Name = 'Merge Kots' WHERE RoleID = 24;
|
||||
UPDATE Auth_Roles SET Name = 'Move Kot to New Table' WHERE RoleID = 25;
|
||||
UPDATE Auth_Roles SET Name = 'Bill Details' WHERE RoleID = 26;
|
||||
UPDATE Auth_Roles SET Name = 'Open Bill' WHERE RoleID = 27;
|
||||
INSERT INTO Auth_Roles (RoleID, Name) VALUES(Newid(), 'Modifiers')
|
||||
COMMIT
|
||||
GO
|
||||
USE Sales
|
||||
@ -80,17 +79,17 @@ from Gets.dbo.Entities_FoodTables as ft;
|
||||
INSERT INTO Vouchers (VoucherID, Date, Pax, UserID, CreationDate, LastEditDate, BillID, TableID, WaiterID, CustomerID, Narration, Void, VoidReason, Printed, VoucherType, KotID)
|
||||
SELECT ID, Date, Pax,
|
||||
(SELECT u.ID FROM Gets.dbo.Auth_Users u WHERE u.UserID = v.UserID),
|
||||
CreationDate, LastEditDate, BillID,
|
||||
CreationDate, LastEditDate, CASE WHEN BillID LIKE 'K-%' THEN null ELSE CAST(REPLACE(REPLACE(REPLACE(BillID, '-', ''), 'NC', ''), 'ST','') AS int) END,
|
||||
(SELECT t.ID FROM Gets.dbo.Entities_FoodTables t WHERE t.Name = v.TableID),
|
||||
(SELECT w.ID FROM Gets.dbo.Entities_Waiters w WHERE w.WaiterID = v.WaiterID),
|
||||
(SELECT c.ID FROM Gets.dbo.Entities_Customers c WHERE c.CustomerID = v.CustomerID),
|
||||
Narration, Void, VoidReason, Printed, VoucherType, KotID
|
||||
Narration, Void, VoidReason, Printed, VoucherType, CAST(REPLACE(KotID, 'K-', '') AS int)
|
||||
from Gets.dbo.Entities_Vouchers as V;
|
||||
|
||||
INSERT INTO Kots (KotID, VoucherID, Code, TableID, Printed, Date, UserID)
|
||||
SELECT ID,
|
||||
(SELECT v.ID FROM Gets.dbo.Entities_Vouchers v WHERE v.VoucherID = k.VoucherID),
|
||||
Code,
|
||||
CAST(REPLACE(Code, 'S-', '') AS int),
|
||||
(SELECT t.ID FROM Gets.dbo.Entities_FoodTables t WHERE t.Name = k.TableID),
|
||||
Printed, Date,
|
||||
(SELECT u.ID FROM Gets.dbo.Auth_Users u WHERE u.UserID = k.UserID)
|
||||
|
@ -156,7 +156,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
Product = null;
|
||||
ProductID = kot.KotID;
|
||||
Discount = 0;
|
||||
Name = string.Format("Kot: {0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name);
|
||||
Name = string.Format("Kot: S-{0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name);
|
||||
Price = 0;
|
||||
FullPrice = 0;
|
||||
Printed = true;
|
||||
|
@ -5,9 +5,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
public enum BillItemType
|
||||
{
|
||||
Product,
|
||||
Kot,
|
||||
Information,
|
||||
Total
|
||||
Kot
|
||||
}
|
||||
public class BillItemKey
|
||||
{
|
||||
@ -34,5 +32,38 @@ namespace Tanshu.Accounts.Contracts
|
||||
public Guid KotID { get; private set; }
|
||||
|
||||
public BillItemType BillItemType { get; private set; }
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return BillItemType.GetHashCode() ^ KotID.GetHashCode() ^ ProductID.GetHashCode();
|
||||
}
|
||||
public static bool operator ==(BillItemKey a, BillItemKey b)
|
||||
{
|
||||
if (object.ReferenceEquals(null, a))
|
||||
return object.ReferenceEquals(null, b);
|
||||
|
||||
if (!(a is BillItemKey))
|
||||
return false;
|
||||
if (!(b is BillItemKey))
|
||||
return false;
|
||||
|
||||
if (a.BillItemType != b.BillItemType)
|
||||
return false;
|
||||
|
||||
return a.KotID == b.KotID && a.BillItemType == b.BillItemType && a.ProductID == b.ProductID;
|
||||
}
|
||||
public static bool operator !=(BillItemKey a, BillItemKey b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is BillItemKey)
|
||||
return (this == (BillItemKey)obj);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace Tanshu.Accounts.Entities
|
||||
}
|
||||
public virtual Guid KotID { get; set; }
|
||||
public virtual Voucher Voucher { get; set; }
|
||||
public virtual string Code { get; set; }
|
||||
public virtual int Code { get; set; }
|
||||
public virtual FoodTable Table { get; set; }
|
||||
public virtual bool Printed { get; set; }
|
||||
public virtual DateTime Date { get; set; }
|
||||
@ -32,10 +32,20 @@ namespace Tanshu.Accounts.Entities
|
||||
Table("Kots");
|
||||
Schema("dbo");
|
||||
Lazy(true);
|
||||
SqlInsert(@"exec KotInsert ?,?,?,?,?");
|
||||
Id(x => x.KotID, map => map.Generator(Generators.GuidComb));
|
||||
Property(x => x.Code, map => { map.NotNullable(true); map.Unique(true); });
|
||||
Property(x => x.Code, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Unique(true);
|
||||
map.Generated(PropertyGeneration.Insert);
|
||||
});
|
||||
Property(x => x.Printed, map => map.NotNullable(true));
|
||||
Property(x => x.Date, map => map.NotNullable(true));
|
||||
Property(x => x.Date, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Generated(PropertyGeneration.Insert);
|
||||
});
|
||||
ManyToOne(x => x.Voucher, map =>
|
||||
{
|
||||
map.Column("VoucherID");
|
||||
|
@ -13,6 +13,37 @@ namespace Tanshu.Accounts.Entities
|
||||
public virtual string Printer { get; set; }
|
||||
public virtual int Copies { get; set; }
|
||||
public virtual string CutCode { get; set; }
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Location.GetHashCode() ^ Printer.GetHashCode() ^ Copies.GetHashCode() ^ CutCode.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(PrintLocation a, PrintLocation b)
|
||||
{
|
||||
if (object.ReferenceEquals(null, a))
|
||||
return object.ReferenceEquals(null, b);
|
||||
|
||||
if (!(a is PrintLocation))
|
||||
return false;
|
||||
if (!(b is PrintLocation))
|
||||
return false;
|
||||
|
||||
return a.Location == b.Location && a.Printer == b.Printer && a.Copies == b.Copies && a.CutCode == b.CutCode;
|
||||
}
|
||||
|
||||
public static bool operator !=(PrintLocation a, PrintLocation b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override bool Equals(System.Object obj)
|
||||
{
|
||||
if (obj is PrintLocation)
|
||||
return (this == (PrintLocation)obj);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class PrintLocationMap : ClassMapping<PrintLocation>
|
||||
{
|
||||
|
@ -20,8 +20,13 @@ namespace Tanshu.Accounts.Entities
|
||||
Table("Reprints");
|
||||
Schema("dbo");
|
||||
Lazy(true);
|
||||
SqlInsert(@"exec ReprintInsert ?,?,?");
|
||||
Id(x => x.ReprintID, map => map.Generator(Generators.GuidComb));
|
||||
Property(x => x.Date, map => map.NotNullable(true));
|
||||
Property(x => x.Date, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Generated(PropertyGeneration.Insert);
|
||||
});
|
||||
ManyToOne(x => x.User, map =>
|
||||
{
|
||||
map.Column("UserID");
|
||||
|
@ -43,7 +43,7 @@ namespace Tanshu.Accounts.Entities
|
||||
public virtual User User { get; set; }
|
||||
public virtual DateTime CreationDate { get; set; }
|
||||
public virtual DateTime LastEditDate { get; set; }
|
||||
public virtual string BillID { get; set; }
|
||||
public virtual int? BillID { get; set; }
|
||||
public virtual FoodTable Table { get; set; }
|
||||
public virtual Waiter Waiter { get; set; }
|
||||
public virtual Customer Customer { get; set; }
|
||||
@ -53,31 +53,48 @@ namespace Tanshu.Accounts.Entities
|
||||
public virtual string VoidReason { get; set; }
|
||||
public virtual bool Printed { get; set; }
|
||||
public virtual VoucherType VoucherType { get; set; }
|
||||
public virtual string KotID { get; set; }
|
||||
public virtual int KotID { get; set; }
|
||||
public virtual IList<Kot> Kots { get; set; }
|
||||
public virtual IList<Reprint> Reprints { get; set; }
|
||||
}
|
||||
|
||||
public class VoucherMap : ClassMapping<Voucher>
|
||||
{
|
||||
|
||||
public VoucherMap()
|
||||
{
|
||||
Table("Vouchers");
|
||||
Schema("dbo");
|
||||
Lazy(true);
|
||||
SqlInsert(@"exec VoucherInsert ?,?,?,?,?,?,?,?,?,?,?");
|
||||
SqlUpdate(@"exec VoucherUpdate ?,?,?,?,?,?,?,?,?,?,?");
|
||||
Id(x => x.VoucherID, map => map.Generator(Generators.GuidComb));
|
||||
Property(x => x.Date, map => map.NotNullable(true));
|
||||
Property(x => x.Date, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Generated(PropertyGeneration.Always);
|
||||
});
|
||||
Property(x => x.Pax);
|
||||
Property(x => x.VoucherType, map => map.NotNullable(true));
|
||||
Property(x => x.Narration);
|
||||
Property(x => x.CreationDate, map => map.NotNullable(true));
|
||||
Property(x => x.LastEditDate, map => map.NotNullable(true));
|
||||
Property(x => x.BillID, map => map.NotNullable(true));
|
||||
Property(x => x.CreationDate, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Generated(PropertyGeneration.Insert);
|
||||
});
|
||||
Property(x => x.LastEditDate, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Generated(PropertyGeneration.Always);
|
||||
});
|
||||
Property(x => x.BillID, map => map.Generated(PropertyGeneration.Always));
|
||||
Property(x => x.Void, map => map.NotNullable(true));
|
||||
Property(x => x.VoidReason);
|
||||
Property(x => x.Printed, map => map.NotNullable(true));
|
||||
Property(x => x.KotID, map => map.NotNullable(true));
|
||||
Property(x => x.KotID, map =>
|
||||
{
|
||||
map.NotNullable(true);
|
||||
map.Generated(PropertyGeneration.Insert);
|
||||
});
|
||||
ManyToOne(x => x.User, map =>
|
||||
{
|
||||
map.Column("UserID");
|
||||
|
@ -15,16 +15,17 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
return LoginUser(true);
|
||||
}
|
||||
bool LoginUser(bool setThreadPrincipal)
|
||||
bool LoginUser(bool setSession)
|
||||
{
|
||||
using (LoginForm login = new LoginForm(new KeyboardControl()))
|
||||
using (LoginForm frm = new LoginForm(new KeyboardControl()))
|
||||
{
|
||||
string userName;
|
||||
login.ShowDialog();
|
||||
bool authenticated = login.UserName(out userName);
|
||||
if (authenticated && setThreadPrincipal)
|
||||
SetThreadPrincipal(userName);
|
||||
return authenticated;
|
||||
frm.ShowDialog();
|
||||
var user = frm.User();
|
||||
if (user != null && setSession)
|
||||
{
|
||||
Session.User = user;
|
||||
}
|
||||
return user != null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -34,14 +35,5 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
Session.User = null;
|
||||
return true;
|
||||
}
|
||||
static void SetThreadPrincipal(string userName)
|
||||
{
|
||||
if (userName.Contains(":"))
|
||||
userName = userName.Substring(userName.IndexOf(":") + 1);
|
||||
|
||||
using (var bi = new UserBI())
|
||||
Session.User = bi.Get(x => x.Name == userName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -41,17 +41,16 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
private void btnLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var bi = new UserBI())
|
||||
_user = bi.ValidateUser(txtUserName.Text.Trim(), Common.Md5.Hash(txtPassword.Text, "v2"));
|
||||
_user = bi.ValidateUser(txtUserName.Text.Trim(), txtPassword.Text);
|
||||
if (_user != null)
|
||||
this.Close();
|
||||
else
|
||||
MessageBox.Show("Username or password is not valid");
|
||||
}
|
||||
|
||||
public bool UserName(out string userName)
|
||||
public User User()
|
||||
{
|
||||
userName = this._user == null ? "" : this._user.Name;
|
||||
return this._user != null;
|
||||
return _user;
|
||||
}
|
||||
|
||||
private void btnExit_Click(object sender, EventArgs e)
|
||||
|
@ -11,19 +11,17 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
return LoginUser(true);
|
||||
}
|
||||
|
||||
static bool LoginUser(bool setThreadPrincipal)
|
||||
static bool LoginUser(bool setSession)
|
||||
{
|
||||
using (var frm = new MsrLoginForm(false))
|
||||
{
|
||||
string userName;
|
||||
frm.ShowDialog();
|
||||
var authenticated = frm.UserName(out userName);
|
||||
if (authenticated && setThreadPrincipal)
|
||||
using (var bi = new UserBI())
|
||||
{
|
||||
Session.User = bi.Get(x => x.Name == userName);
|
||||
}
|
||||
return authenticated;
|
||||
var user = frm.User();
|
||||
if (user != null && setSession)
|
||||
{
|
||||
Session.User = user;
|
||||
}
|
||||
return user != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
using (var bi = new UserBI())
|
||||
{
|
||||
var user = bi.MsrValidateUser(_loginString);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
this._user = user;
|
||||
@ -38,15 +37,14 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
else
|
||||
{
|
||||
this._user = new User() { Name = _loginString };
|
||||
this._user = new User() { MsrString = _loginString };
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public bool UserName(out string userName)
|
||||
public User User()
|
||||
{
|
||||
userName = this._user == null ? "" : this._user.Name;
|
||||
return this._user != null;
|
||||
return _user;
|
||||
}
|
||||
|
||||
private void MsrLoginForm_KeyPress(object sender, KeyPressEventArgs e)
|
||||
|
@ -773,7 +773,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
using (var bi = new ReprintBI())
|
||||
{
|
||||
bi.Insert(new Reprint() { Date = DbValues.Date, User = Session.User, Voucher = _billInfo });
|
||||
bi.Insert(new Reprint() { User = Session.User, Voucher = _billInfo });
|
||||
bi.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
public enum LoginType
|
||||
{
|
||||
Keyboard,
|
||||
Msr
|
||||
}
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
public MainForm()
|
||||
@ -49,14 +44,18 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
|
||||
private void btnLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoginUser(LoginType.Keyboard);
|
||||
LoginUser(new KeyboardLogin());
|
||||
}
|
||||
|
||||
private void btnSale_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Session.IsAllowed("Sales"))
|
||||
using (var frmSale = new SalesForm(new BillController(null, true)))
|
||||
{
|
||||
frmSale.ShowDialog();
|
||||
Cache.Invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnProduct_Click(object sender, EventArgs e)
|
||||
@ -182,24 +181,11 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
|
||||
private void btnSwipeLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoginUser(LoginType.Msr);
|
||||
LoginUser(new MsrLogin());
|
||||
}
|
||||
|
||||
private void LoginUser(LoginType loginType)
|
||||
private void LoginUser(ILogin login)
|
||||
{
|
||||
ILogin login;
|
||||
switch (loginType)
|
||||
{
|
||||
case LoginType.Keyboard:
|
||||
login = new KeyboardLogin();
|
||||
break;
|
||||
case LoginType.Msr:
|
||||
login = new MsrLogin();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Session.IsAuthenticated)
|
||||
{
|
||||
if (login.LoginUser())
|
||||
@ -226,9 +212,10 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
var result = InputBox.Show("Bill Number", "0", InputBox_Validating);
|
||||
if (!result.OK)
|
||||
return;
|
||||
var billID = int.Parse(result.Text.Replace("-",""));
|
||||
Voucher voucher;
|
||||
using (var bi = new VoucherBI())
|
||||
voucher = bi.Get(x => x.BillID == result.Text);
|
||||
voucher = bi.Get(x => x.BillID == billID);
|
||||
if (Session.IsAllowed("Sales"))
|
||||
using (var frmSale = new SalesForm(new BillController(voucher.VoucherID, true)))
|
||||
frmSale.ShowDialog();
|
||||
|
@ -12,25 +12,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
{
|
||||
public partial class SalesForm : Form, ISaleForm
|
||||
{
|
||||
private readonly IDictionary<Guid, IList<Product>> _productDictionary;
|
||||
private readonly IList<ProductGroup> _productGroupList;
|
||||
private ProductGroup _currentProductGroup;
|
||||
public SalesForm(BillController billController)
|
||||
{
|
||||
InitializeComponent();
|
||||
_productDictionary = new Dictionary<Guid, IList<Product>>();
|
||||
|
||||
this._billController = billController;
|
||||
_billController = billController;
|
||||
billController.InitGui(this);
|
||||
using (var bi = new ProductGroupBI())
|
||||
_productGroupList = bi.List(x => x.IsActive);
|
||||
using (var bi = new ProductBI())
|
||||
foreach (var item in _productGroupList)
|
||||
_productDictionary.Add(item.ProductGroupID, bi.List(x => x.ProductGroup.ProductGroupID == item.ProductGroupID && x.IsActive));
|
||||
}
|
||||
|
||||
#region ISaleForm Members
|
||||
|
||||
public void SetUserName(string name)
|
||||
{
|
||||
Text = name;
|
||||
@ -55,8 +45,11 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
}
|
||||
else
|
||||
{
|
||||
txtBillID.Text = voucher.BillID;
|
||||
txtKotID.Text = voucher.KotID;
|
||||
if (voucher.BillID.HasValue)
|
||||
{
|
||||
txtBillID.Text = voucher.BillID.Value.ToString();
|
||||
}
|
||||
txtKotID.Text = "K-" + voucher.KotID.ToString();
|
||||
txtCreationDate.Text = voucher.CreationDate.ToString("HH:mm dd-MMM-yyyy");
|
||||
txtDate.Text = voucher.Date.Value.ToString("HH:mm dd-MMM-yyyy");
|
||||
txtLastEditDate.Text = voucher.LastEditDate.ToString("HH:mm dd-MMM-yyyy");
|
||||
@ -334,7 +327,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
flpGroup.Controls.Clear();
|
||||
flpMain.Controls.Clear();
|
||||
if (value == SaleFormState.Billing)
|
||||
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, _productGroupList, productTypeButton_Click, productTypePage_Click);
|
||||
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, Cache.ProductGroups(), productTypeButton_Click, productTypePage_Click);
|
||||
else
|
||||
using (var bi = new FoodTableBI())
|
||||
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, bi.List(x => x.IsActive), tableButton_Click, tablePage_Click);
|
||||
@ -351,7 +344,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
return;
|
||||
_currentProductGroup = item;
|
||||
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0,
|
||||
_productDictionary[item.ProductGroupID], productButton_Click, productPage_Click);
|
||||
item.Products, productButton_Click, productPage_Click);
|
||||
}
|
||||
|
||||
private void productTypePage_Click(object sender, EventArgs e)
|
||||
@ -362,7 +355,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
var start = (int)button.Tag;
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, _productGroupList, productTypeButton_Click, productTypePage_Click);
|
||||
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, Cache.ProductGroups(), productTypeButton_Click, productTypePage_Click);
|
||||
}
|
||||
|
||||
private void productButton_Click(object sender, EventArgs e)
|
||||
@ -385,7 +378,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
var start = (int)button.Tag;
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, _productDictionary[_currentProductGroup.ProductGroupID], productButton_Click, productPage_Click);
|
||||
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, _currentProductGroup.Products, productButton_Click, productPage_Click);
|
||||
}
|
||||
|
||||
private void tableButton_Click(object sender, EventArgs e)
|
||||
|
@ -320,6 +320,7 @@
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Reports\BillDetailsForm.resx">
|
||||
<DependentUpon>BillDetailsForm.cs</DependentUpon>
|
||||
|
@ -36,8 +36,8 @@
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.txtConfirmPassword = new System.Windows.Forms.TextBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.btnCreateUSer = new System.Windows.Forms.Button();
|
||||
this.btnCancel = new System.Windows.Forms.Button();
|
||||
this.btnChangePassword = new System.Windows.Forms.Button();
|
||||
this.btnMsr = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -113,25 +113,25 @@
|
||||
this.label4.Text = "Confirm Password";
|
||||
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||
//
|
||||
// button2
|
||||
// btnCancel
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(211, 116);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(55, 23);
|
||||
this.button2.TabIndex = 5;
|
||||
this.button2.Text = "Ca&ncel";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
this.btnCancel.Location = new System.Drawing.Point(211, 116);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Size = new System.Drawing.Size(55, 23);
|
||||
this.btnCancel.TabIndex = 5;
|
||||
this.btnCancel.Text = "Ca&ncel";
|
||||
this.btnCancel.UseVisualStyleBackColor = true;
|
||||
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
|
||||
//
|
||||
// btnCreateUSer
|
||||
// btnChangePassword
|
||||
//
|
||||
this.btnCreateUSer.Location = new System.Drawing.Point(84, 116);
|
||||
this.btnCreateUSer.Name = "btnCreateUSer";
|
||||
this.btnCreateUSer.Size = new System.Drawing.Size(121, 23);
|
||||
this.btnCreateUSer.TabIndex = 4;
|
||||
this.btnCreateUSer.Text = "&Change Password";
|
||||
this.btnCreateUSer.UseVisualStyleBackColor = true;
|
||||
this.btnCreateUSer.Click += new System.EventHandler(this.btnCreateUSer_Click);
|
||||
this.btnChangePassword.Location = new System.Drawing.Point(84, 116);
|
||||
this.btnChangePassword.Name = "btnChangePassword";
|
||||
this.btnChangePassword.Size = new System.Drawing.Size(121, 23);
|
||||
this.btnChangePassword.TabIndex = 4;
|
||||
this.btnChangePassword.Text = "&Change Password";
|
||||
this.btnChangePassword.UseVisualStyleBackColor = true;
|
||||
this.btnChangePassword.Click += new System.EventHandler(this.btnChangePassword_Click);
|
||||
//
|
||||
// btnMsr
|
||||
//
|
||||
@ -149,8 +149,8 @@
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(287, 185);
|
||||
this.Controls.Add(this.btnMsr);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.btnCreateUSer);
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Controls.Add(this.btnChangePassword);
|
||||
this.Controls.Add(this.txtConfirmPassword);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.txtnewPassword);
|
||||
@ -179,8 +179,8 @@
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.TextBox txtConfirmPassword;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button btnCreateUSer;
|
||||
private System.Windows.Forms.Button btnCancel;
|
||||
private System.Windows.Forms.Button btnChangePassword;
|
||||
private System.Windows.Forms.Button btnMsr;
|
||||
}
|
||||
}
|
@ -32,12 +32,12 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
txtUsername.Text = Session.User.Name;
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void btnCreateUSer_Click(object sender, EventArgs e)
|
||||
private void btnChangePassword_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (txtPassword.Text.Trim() == "")
|
||||
MessageBox.Show("Old password can not be blank", "Blank not allowed");
|
||||
@ -53,7 +53,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
if (ChangeUserPassword())
|
||||
{
|
||||
MessageBox.Show("Password changed", "Confirm");
|
||||
this.Close();
|
||||
}
|
||||
else
|
||||
@ -65,43 +64,38 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
|
||||
private bool ChangeUserPassword()
|
||||
{
|
||||
var userEntity = new User();
|
||||
userEntity.Name = txtUsername.Text.Trim();
|
||||
userEntity.Password = Tanshu.Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
|
||||
|
||||
using (var bi = new UserBI())
|
||||
if (bi.ValidateUser(userEntity.Name, userEntity.Password) != null)
|
||||
return bi.ChangePassword(userEntity, Tanshu.Common.Md5.Hash(txtnewPassword.Text.Trim(), "v2"));
|
||||
else
|
||||
{
|
||||
var user = bi.ValidateUser(Session.User.Name, txtPassword.Text.Trim());
|
||||
if (user == null)
|
||||
return false;
|
||||
bi.ChangePassword(user, txtnewPassword.Text.Trim());
|
||||
bi.SaveChanges();
|
||||
MessageBox.Show("Password changed", "Confirm");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnMsr_Click(object sender, EventArgs e)
|
||||
{
|
||||
var user = new User();
|
||||
user.Name = txtUsername.Text.Trim();
|
||||
user.Password = Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
|
||||
|
||||
using (var bi = new UserBI())
|
||||
if (bi.ValidateUser(user.Name, user.Password) == null)
|
||||
return;
|
||||
using (var frm = new MsrLoginForm(true))
|
||||
{
|
||||
frm.ShowDialog();
|
||||
string userName;
|
||||
frm.UserName(out userName);
|
||||
if (MessageBox.Show("Update Msr Card", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
|
||||
DialogResult.Yes)
|
||||
var user = bi.ValidateUser(Session.User.Name, txtPassword.Text.Trim());
|
||||
if (user == null)
|
||||
return;
|
||||
using (var bi = new UserBI())
|
||||
using (var frm = new MsrLoginForm(true))
|
||||
{
|
||||
user = bi.Get(x => x.Name == user.Name);
|
||||
user.MsrString = userName;
|
||||
frm.ShowDialog();
|
||||
var msrString = frm.User().MsrString;
|
||||
if (MessageBox.Show("Update Msr Card", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
|
||||
DialogResult.Yes)
|
||||
return;
|
||||
user.MsrString = msrString;
|
||||
bi.Update(user);
|
||||
bi.SaveChanges();
|
||||
MessageBox.Show("Msr Card Updated");
|
||||
this.Close();
|
||||
}
|
||||
MessageBox.Show("Msr Card Updated");
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace Tanshu.Accounts.Print
|
||||
var billText = "\n\r" + "KOT / BOT".Center42();
|
||||
billText += "\n\r" + string.Format("Copy No. {0}", copyNumber).Center42();
|
||||
billText += DrawLine;
|
||||
billText += string.Format("\n\rKOT ID : {0,-7}/{1,-7} {2:dd-MMM-yyyy HH:mm}", voucher.KotID, kot.Code, kot.Date);
|
||||
billText += string.Format("\n\rKOT ID : K-{0,-5}/S-{1,-5} {2:dd-MMM-yyyy HH:mm}", voucher.KotID, kot.Code, kot.Date);
|
||||
billText += string.Format("\n\rTable No.: {0} / {1}", voucher.Table.Name, waiter.Name);
|
||||
billText += DrawLine;
|
||||
billText += "\n\r Qty. x Name ";
|
||||
@ -130,7 +130,7 @@ namespace Tanshu.Accounts.Print
|
||||
|
||||
if (details.DiscountString.Length > 0)
|
||||
billText += details.DiscountString;
|
||||
return PrintRaw(PrintLocationBI.BasePrinter, billText, "Closing");
|
||||
return PrintRaw(Cache.BasePrinter, billText, "Closing");
|
||||
}
|
||||
|
||||
public static string FormatPrintNum(string inputString)
|
||||
@ -141,7 +141,7 @@ namespace Tanshu.Accounts.Print
|
||||
|
||||
public static void PrintBill(Guid voucherID)
|
||||
{
|
||||
PrintRaw(PrintLocationBI.BasePrinter, DesignBill(voucherID), "Bill");
|
||||
PrintRaw(Cache.BasePrinter, DesignBill(voucherID), "Bill");
|
||||
}
|
||||
|
||||
public static void PrintKot(Guid voucherID, Guid kotID)
|
||||
@ -151,8 +151,7 @@ namespace Tanshu.Accounts.Print
|
||||
Voucher voucher;
|
||||
using (var bi = new VoucherBI())
|
||||
voucher = bi.Get(x => x.VoucherID == voucherID);
|
||||
var dict = new Dictionary<Guid, List<Inventory>>();
|
||||
var printers = new Dictionary<Guid, PrintLocation>();
|
||||
var dict = new Dictionary<PrintLocation, List<Inventory>>();
|
||||
var kot = voucher.Kots.SingleOrDefault(x => x.KotID == kotID);
|
||||
if (kot == null)
|
||||
return;
|
||||
@ -160,23 +159,22 @@ namespace Tanshu.Accounts.Print
|
||||
foreach (var inventory in kot.Inventories)
|
||||
{
|
||||
var type = inventory.Product.ProductGroup.ProductGroupID;
|
||||
var printer = PrintLocationBI.KotPrinter(type);
|
||||
if (!printers.ContainsKey(printer.PrintLocationID))
|
||||
var printer = Cache.KotPrinter(type);
|
||||
if (!dict.ContainsKey(printer))
|
||||
{
|
||||
printers.Add(printer.PrintLocationID, printer);
|
||||
dict.Add(printer.PrintLocationID, new List<Inventory>());
|
||||
dict.Add(printer, new List<Inventory>());
|
||||
}
|
||||
dict[printer.PrintLocationID].Add(inventory);
|
||||
dict[printer].Add(inventory);
|
||||
}
|
||||
stopwatch.Stop();
|
||||
Trace.TraceWarning("kot and printers built in {0} ms", stopwatch.ElapsedMilliseconds);
|
||||
stopwatch.Reset();
|
||||
foreach (var item in dict)
|
||||
{
|
||||
for (var i = 0; i < printers[item.Key].Copies; i++)
|
||||
for (var i = 0; i < item.Key.Copies; i++)
|
||||
{
|
||||
stopwatch.Start();
|
||||
PrintRaw(printers[item.Key], DesignKot(voucher, kot, item.Value, i), "KOT");
|
||||
PrintRaw(item.Key, DesignKot(voucher, kot, item.Value, i), "KOT");
|
||||
stopwatch.Stop();
|
||||
Trace.TraceWarning("kot designed and printed in {0} ms", stopwatch.ElapsedMilliseconds);
|
||||
stopwatch.Reset();
|
||||
@ -202,7 +200,7 @@ namespace Tanshu.Accounts.Print
|
||||
printText += "\n\r" + DrawEqual;
|
||||
printText += string.Format("\n\r Total = {0,10:#,##0}", total);
|
||||
printText += DrawLine;
|
||||
return PrintRaw(PrintLocationBI.BasePrinter, printText, "Closing/Opening for " + user);
|
||||
return PrintRaw(Cache.BasePrinter, printText, "Closing/Opening for " + user);
|
||||
}
|
||||
|
||||
public static Boolean PrintSale(string user, IList<SalesAnalysis> det, DateTime startDate, DateTime endDate)
|
||||
@ -219,7 +217,7 @@ namespace Tanshu.Accounts.Print
|
||||
printText += string.Format("\n\r {0,-22} {1,9:#,##0}", d.GroupType, d.Amount);
|
||||
}
|
||||
printText += DrawEqual;
|
||||
return PrintRaw(PrintLocationBI.BasePrinter, printText, "Sale Detail " + user);
|
||||
return PrintRaw(Cache.BasePrinter, printText, "Sale Detail " + user);
|
||||
}
|
||||
|
||||
public static Boolean PrintSale(string user, IList<SalesAnalysisDetail> list, DateTime startDate,
|
||||
@ -237,7 +235,7 @@ namespace Tanshu.Accounts.Print
|
||||
printText += string.Format("\n\r{0,-22} {1,9:#,##0.00} {2,9:#,##0.00} {3,9:#,##0.00}", item.Product, item.Sale, item.NC, item.Staff);
|
||||
}
|
||||
printText += DrawEqual;
|
||||
return PrintRaw(PrintLocationBI.BasePrinter, printText, "Sale Detail " + user);
|
||||
return PrintRaw(Cache.BasePrinter, printText, "Sale Detail " + user);
|
||||
}
|
||||
|
||||
private static string CashLine(IDictionary<int, int> amount, int key)
|
||||
|
@ -110,7 +110,22 @@ namespace Tanshu.Accounts.Print
|
||||
}
|
||||
private static string Products(Voucher voucher, IList<Inventory> list)
|
||||
{
|
||||
var billNo = voucher.BillID.Substring(voucher.BillID.IndexOf("-") + 1);
|
||||
string billNo;
|
||||
switch (voucher.VoucherType)
|
||||
{
|
||||
case VoucherType.NoCharge:
|
||||
billNo = "NC-" + voucher.BillID.Value.ToString();
|
||||
break;
|
||||
case VoucherType.Staff:
|
||||
billNo = "ST-" + voucher.BillID.Value.ToString();
|
||||
break;
|
||||
case VoucherType.TakeAway:
|
||||
case VoucherType.Regular:
|
||||
default:
|
||||
billNo = (voucher.BillID.Value % 10000).ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
var billText = "";
|
||||
billText += "\n\r" + string.Format("Bill No: {0,-12} {1:dd-MMM-yyyy HH:mm:ss}", billNo, voucher.Date);
|
||||
|
67
Tanshu.Accounts.Repository/Cache.cs
Normal file
67
Tanshu.Accounts.Repository/Cache.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class Cache
|
||||
{
|
||||
private static IList<ProductGroup> cache = null;
|
||||
private static Dictionary<int, PrintLocation> locations = new Dictionary<int, PrintLocation>();
|
||||
private static string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
|
||||
public static IList<ProductGroup> ProductGroups()
|
||||
{
|
||||
if (cache == null)
|
||||
{
|
||||
using (var bi = new ProductGroupBI())
|
||||
{
|
||||
var list = bi.SaleList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
NHibernateUtil.Initialize(item.Products);
|
||||
}
|
||||
cache = list;
|
||||
}
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
public static PrintLocation BasePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!locations.ContainsKey(location.GetHashCode()))
|
||||
{
|
||||
using (var bi = new PrintLocationBI())
|
||||
{
|
||||
var loc = bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
locations.Add(location.GetHashCode(), loc);
|
||||
}
|
||||
}
|
||||
return locations[location.GetHashCode()];
|
||||
}
|
||||
}
|
||||
public static PrintLocation KotPrinter(Guid productGroupID)
|
||||
{
|
||||
if (!locations.ContainsKey(location.GetHashCode() ^ productGroupID.GetHashCode()))
|
||||
{
|
||||
using (var bi = new PrintLocationBI())
|
||||
{
|
||||
var loc = bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ??
|
||||
bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
locations.Add(location.GetHashCode() ^ productGroupID.GetHashCode(), loc);
|
||||
}
|
||||
}
|
||||
return locations[location.GetHashCode() ^ productGroupID.GetHashCode()];
|
||||
}
|
||||
public static void Invalidate()
|
||||
{
|
||||
cache = null;
|
||||
locations = new Dictionary<int, PrintLocation>();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class DbValues
|
||||
{
|
||||
public static DateTime Date
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var query = session.CreateSQLQuery("SELECT Getdate();");
|
||||
return (DateTime)query.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string KotID
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"SELECT ISNULL('K-' + CAST(MAX(CAST(SUBSTRING(KotID, 3,8) AS int)) + 1 AS nvarchar(8)), 'K-1') FROM Vouchers";
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string KotCode
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"SELECT ISNULL('S-' + CAST(MAX(CAST(SUBSTRING(Code, 3,8) AS int)) + 1 AS nvarchar(8)), 'S-1') FROM Kots";
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string BillID(VoucherType voucherType)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var query = "";
|
||||
switch (voucherType)
|
||||
{
|
||||
case VoucherType.Regular:
|
||||
case VoucherType.TakeAway:
|
||||
query = @"
|
||||
DECLARE @BillID nvarchar(10)
|
||||
SELECT @BillID = ISNULL(CAST(MAX(CAST(REPLACE(BillID, '-', '') AS int)) + 1 AS nvarchar(9)), '010001') FROM Vouchers WHERE BillID LIKE '__-____'
|
||||
AND BillID NOT LIKE 'NC-%' AND BillID NOT LIKE 'ST-%'
|
||||
IF LEN(@BillID) = 5
|
||||
SET @BillID = '0' + @BillID
|
||||
SET @BillID = SUBSTRING(@BillID, 1, 2) + '-' + SUBSTRING(@BillID, 3, 7)
|
||||
IF SUBSTRING(@BillID,3,7) = '-0000'
|
||||
SET @BillID = SUBSTRING(@BillID, 1, 2) + '-0001'
|
||||
SELECT @BillID";
|
||||
break;
|
||||
case VoucherType.NoCharge:
|
||||
query = @"SELECT ISNULL('NC-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'NC-1') FROM Vouchers WHERE BillID LIKE 'NC-%'";
|
||||
break;
|
||||
case VoucherType.Staff:
|
||||
query = @"SELECT ISNULL('ST-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'ST-1') FROM Vouchers WHERE BillID LIKE 'ST-%'";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("voucherType");
|
||||
}
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -143,20 +143,21 @@ order by v.Date desc
|
||||
.SetParameter("staff", VoucherType.Staff)
|
||||
.SetMaxResults(1)
|
||||
.UniqueResult();
|
||||
var newID = lastBill == null ? "01-0001" : GetNewID((string)lastBill);
|
||||
var newID = lastBill == null ? 10001 : GetNewID((int)lastBill);
|
||||
var list = _session.QueryOver<Voucher>().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff && x.Void == false).OrderBy(x => x.Date).Asc.List();
|
||||
foreach (var voucher in list)
|
||||
{
|
||||
if (voucher.BillID != newID)
|
||||
{
|
||||
voucher.BillID = newID;
|
||||
throw new NotImplementedException();
|
||||
//voucher.BillID = newID;
|
||||
_session.Update(voucher);
|
||||
}
|
||||
newID = GetNewID(newID);
|
||||
}
|
||||
|
||||
query = @"
|
||||
select v.BillID
|
||||
select isnull(v.BillID + 1, 1)
|
||||
from Voucher v
|
||||
where v.Date < :startDate and v.Void = false and v.VoucherType = :nc
|
||||
order by v.Date desc
|
||||
@ -167,53 +168,26 @@ order by v.Date desc
|
||||
.SetParameter("nc", VoucherType.NoCharge)
|
||||
.SetMaxResults(1)
|
||||
.UniqueResult();
|
||||
newID = lastBill == null ? "NC-1" : GetNewNc((string)lastBill);
|
||||
newID = (int)lastBill;
|
||||
list = _session.QueryOver<Voucher>().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.NoCharge && x.Void == false).OrderBy(x => x.Date).Asc.List();
|
||||
foreach (var voucher in list)
|
||||
{
|
||||
if (voucher.BillID != newID)
|
||||
{
|
||||
voucher.BillID = newID;
|
||||
throw new NotImplementedException();
|
||||
//voucher.BillID = newID;
|
||||
_session.Update(voucher);
|
||||
}
|
||||
newID = GetNewNc(newID);
|
||||
newID += 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetNewNc(string lastBill)
|
||||
private static int GetNewID(int lastBill)
|
||||
{
|
||||
var parts = lastBill.Split('-');
|
||||
if (parts.Length != 2)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
int one;
|
||||
if (parts[0] != "NC")
|
||||
throw new ArgumentOutOfRangeException();
|
||||
if (!int.TryParse(parts[1], out one))
|
||||
throw new ArgumentOutOfRangeException();
|
||||
one += 1;
|
||||
return string.Format("NC-{0}", one);
|
||||
}
|
||||
|
||||
private static string GetNewID(string lastBill)
|
||||
{
|
||||
var parts = lastBill.Split('-');
|
||||
if (parts.Length != 2)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
int one, two;
|
||||
if (!int.TryParse(parts[0], out one))
|
||||
throw new ArgumentOutOfRangeException();
|
||||
if (!int.TryParse(parts[1], out two))
|
||||
throw new ArgumentOutOfRangeException();
|
||||
if (two >= 9999)
|
||||
{
|
||||
one += 1;
|
||||
two = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
two += 1;
|
||||
}
|
||||
return string.Format("{0:00}-{1:0000}", one, two);
|
||||
lastBill += 1;
|
||||
if (lastBill % 10000 == 0)
|
||||
lastBill += 1;
|
||||
return lastBill;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1,31 +1,8 @@
|
||||
using System.Configuration;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using System;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class PrintLocationBI : UnitOfWork<PrintLocation>
|
||||
{
|
||||
public static PrintLocation BasePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
{
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static PrintLocation KotPrinter(Guid productGroupID)
|
||||
{
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
{
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ??
|
||||
bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using NHibernate;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate.Transform;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -17,12 +19,29 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
public new IList<ProductGroup> List(Expression<Func<ProductGroup, bool>> query)
|
||||
{
|
||||
_session.FlushMode = FlushMode.Never;
|
||||
return _session.QueryOver<ProductGroup>()
|
||||
.Where(query)
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
}
|
||||
public IList<ProductGroup> SaleList()
|
||||
{
|
||||
ProductGroup pgAlias = null;
|
||||
Product pAlias = null;
|
||||
ICriterion isActive = Restrictions.Where<Product>(x => x.IsActive);
|
||||
|
||||
return _session.QueryOver<ProductGroup>(() => pgAlias)
|
||||
.Left.JoinAlias(x => x.Products, () => pAlias, isActive)
|
||||
.Where(x => x.IsActive)
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.ThenBy(() => pAlias.SortOrder).Asc
|
||||
.ThenBy(() => pAlias.Name).Asc
|
||||
.TransformUsing(Transformers.DistinctRootEntity)
|
||||
.List();
|
||||
}
|
||||
public IList<string> GetProductGroupTypes()
|
||||
{
|
||||
const string query = @"select distinct(pg.GroupType) from ProductGroup pg order by pg.GroupType";
|
||||
|
145
Tanshu.Accounts.Repository/QueryStore.cs
Normal file
145
Tanshu.Accounts.Repository/QueryStore.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using NHibernate;
|
||||
using NHibernate.SqlCommand;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
// Add the following in app settings in the config file to enable logging
|
||||
//<add key="nhibernate-logger" value="Tanshu.Accounts.Repository.EventsLogFactory, Tanshu.Accounts.Repository"/>
|
||||
public class EventsLogger : IInternalLogger
|
||||
{
|
||||
private readonly string _key;
|
||||
public EventsLogger(string key)
|
||||
{
|
||||
_key = key;
|
||||
}
|
||||
public bool IsDebugEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsErrorEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsFatalEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsInfoEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsWarnEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#region Methods (14)
|
||||
|
||||
// Public Methods (14)
|
||||
|
||||
public void Debug(object message)
|
||||
{
|
||||
if (message == null) return;
|
||||
var msg = message.ToString();
|
||||
if (!msg.Contains("oucher") && !_key.Contains("oucher")) return;
|
||||
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
||||
Console.WriteLine(message.ToString().Trim());
|
||||
}
|
||||
|
||||
public void Debug(object message, Exception exception)
|
||||
{
|
||||
if (message == null || exception == null) return;
|
||||
var msg = message.ToString();
|
||||
if (!msg.Contains("oucher") && !_key.Contains("oucher")) return;
|
||||
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
||||
Console.WriteLine(message.ToString().Trim());
|
||||
Console.WriteLine(exception.ToString());
|
||||
}
|
||||
|
||||
public void DebugFormat(string format, params object[] args)
|
||||
{
|
||||
Console.Write(new[]
|
||||
{
|
||||
string.Format("---+ {0} +---", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")),
|
||||
string.Format(format, args),
|
||||
});
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Error(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void ErrorFormat(string format, params object[] args)
|
||||
{
|
||||
DebugFormat(format, args);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Fatal(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Info(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void InfoFormat(string format, params object[] args)
|
||||
{
|
||||
DebugFormat(format, args);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Warn(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void WarnFormat(string format, params object[] args)
|
||||
{
|
||||
DebugFormat(format, args);
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
public class EventsLogFactory : ILoggerFactory
|
||||
{
|
||||
public IInternalLogger LoggerFor(Type type)
|
||||
{
|
||||
return new EventsLogger(type.ToString());
|
||||
}
|
||||
|
||||
public IInternalLogger LoggerFor(string keyName)
|
||||
{
|
||||
return new EventsLogger(keyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -250,7 +250,7 @@ order by v.BillID, s.Settled
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = item.Date,
|
||||
BillID = item.Voucher.BillID,
|
||||
BillID = item.Voucher.BillID.Value.ToString(),
|
||||
Settlement = string.Format("Reprinted by {0}", item.User.Name),
|
||||
Amount = item.Voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1
|
||||
});
|
||||
|
@ -79,7 +79,6 @@ namespace Tanshu.Accounts.Repository
|
||||
db.Driver<NHibernate.Driver.SqlClientDriver>();
|
||||
db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
|
||||
db.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
|
||||
db.ConnectionStringName = "Con";
|
||||
db.Timeout = 10;
|
||||
|
||||
@ -91,8 +90,9 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
var mapping = GetMappings();
|
||||
configure.AddDeserializedMapping(mapping, "NHSchemaTest");
|
||||
SchemaMetadataUpdater.QuoteTableAndColumns(configure);
|
||||
|
||||
//SchemaMetadataUpdater.QuoteTableAndColumns(configure);
|
||||
//configure.SetInterceptor(new NHSQLInterceptor());
|
||||
configure.SetInterceptor(new VoucherDirty());
|
||||
return configure;
|
||||
}
|
||||
private static HbmMapping GetMappings()
|
||||
@ -122,7 +122,6 @@ namespace Tanshu.Accounts.Repository
|
||||
};
|
||||
mapper.AddMappings(entities);
|
||||
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CheckoutBI.cs" />
|
||||
<Compile Include="Cache.cs" />
|
||||
<Compile Include="GroupBI.cs" />
|
||||
<Compile Include="CustomerBI.cs" />
|
||||
<Compile Include="FoodTableBI.cs" />
|
||||
@ -76,6 +77,7 @@
|
||||
<Compile Include="ProductBI.cs" />
|
||||
<Compile Include="ProductGroupBI.cs" />
|
||||
<Compile Include="ProductGroupModifierBI.cs" />
|
||||
<Compile Include="QueryStore.cs" />
|
||||
<Compile Include="ReprintBI.cs" />
|
||||
<Compile Include="RoleBI.cs" />
|
||||
<Compile Include="SalesAnalysisBI.cs" />
|
||||
@ -85,10 +87,10 @@
|
||||
</Compile>
|
||||
<Compile Include="UserBI.cs" />
|
||||
<Compile Include="VoucherBI.cs" />
|
||||
<Compile Include="VoucherDirtyInterceptor.cs" />
|
||||
<Compile Include="VoucherSettlementBI.cs" />
|
||||
<Compile Include="WaiterBI.cs" />
|
||||
<Compile Include="Session.cs" />
|
||||
<Compile Include="DbValues.cs" />
|
||||
<Compile Include="SetupStore.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -21,17 +21,14 @@ namespace Tanshu.Accounts.Repository
|
||||
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Name"]))
|
||||
.List();
|
||||
}
|
||||
public bool ChangePassword(User userData, string newPassword)
|
||||
public void ChangePassword(User user, string password)
|
||||
{
|
||||
var dbUser = Get(x => x.Name == userData.Name && x.Password == userData.Password);
|
||||
if (dbUser == null)
|
||||
return false;
|
||||
dbUser.Password = newPassword;
|
||||
_session.Update(dbUser);
|
||||
return true;
|
||||
user.Password = Tanshu.Common.Md5.Hash(password, "v2");
|
||||
_session.Update(user);
|
||||
}
|
||||
public User ValidateUser(string name, string password)
|
||||
{
|
||||
password = Tanshu.Common.Md5.Hash(password, "v2");
|
||||
return Get(x => x.Name == name && x.Password == password);
|
||||
}
|
||||
public User MsrValidateUser(string msrString)
|
||||
|
@ -13,24 +13,15 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public new Guid Insert(Voucher voucher)
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.CreationDate = dt;
|
||||
voucher.LastEditDate = dt;
|
||||
voucher.Date = dt;
|
||||
voucher.KotID = DbValues.KotID;
|
||||
voucher.BillID = voucher.Printed ? DbValues.BillID(voucher.VoucherType) : voucher.KotID;
|
||||
_session.Save(voucher);
|
||||
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == Guid.Empty))
|
||||
{
|
||||
addedKot = item;
|
||||
item.Voucher = voucher;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.Table = voucher.Table;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
UpdateBillType(voucher);
|
||||
_session.Save(item);
|
||||
foreach (var inv in item.Inventories)
|
||||
@ -70,13 +61,6 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
public new Guid? Update(Voucher voucher)
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.LastEditDate = dt;
|
||||
if (voucher.Date == null)
|
||||
{
|
||||
voucher.Date = dt;
|
||||
voucher.BillID = DbValues.BillID(voucher.VoucherType);
|
||||
}
|
||||
_session.Update(voucher);
|
||||
|
||||
Kot addedKot = null;
|
||||
@ -84,11 +68,9 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
addedKot = item;
|
||||
item.Voucher = voucher;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.Table = voucher.Table;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
_session.Save(item);
|
||||
foreach (var inv in item.Inventories)
|
||||
{
|
||||
@ -285,6 +267,7 @@ namespace Tanshu.Accounts.Repository
|
||||
Update(oldVoucher);
|
||||
|
||||
var status = oldVoucher.Printed ? "printed" : "running";
|
||||
|
||||
var tableFirst = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == first.Table.FoodTableID).SingleOrDefault();
|
||||
if (tableFirst.VoucherID.HasValue)
|
||||
throw new ValidationException("A bill exists on this table, cannot overwrite");
|
||||
|
43
Tanshu.Accounts.Repository/VoucherDirtyInterceptor.cs
Normal file
43
Tanshu.Accounts.Repository/VoucherDirtyInterceptor.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class VoucherDirty : EmptyInterceptor
|
||||
{
|
||||
public override int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
|
||||
{
|
||||
var result = new List<int>();
|
||||
|
||||
// we do not care about other entities here
|
||||
if (!(entity is Voucher))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var length = propertyNames.Length;
|
||||
|
||||
// iterate all properties
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
bool areEqual;
|
||||
if (currentState[i] == null)
|
||||
areEqual = previousState[i] == null;
|
||||
else
|
||||
areEqual = currentState[i].Equals(previousState[i]);
|
||||
var isResettingProperty = propertyNames[i] == "LastEditDate";
|
||||
|
||||
if (!areEqual || isResettingProperty)
|
||||
{
|
||||
result.Add(i); // the index of "Code" property will be added always
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -64,7 +64,6 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
}
|
||||
voucher.User = user;
|
||||
voucher.LastEditDate = DbValues.Date;
|
||||
_session.Update(voucher);
|
||||
|
||||
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) == 0 || voucher.Void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user