2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
2016-01-04 05:22:01 +00:00
|
|
|
|
using System.Linq.Expressions;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2011-06-29 20:27:07 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2011-01-31 20:33:22 +00:00
|
|
|
|
using Tanshu.Accounts.Helpers;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
using Tanshu.Accounts.Management;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using Tanshu.Accounts.PointOfSale.Sales;
|
2011-01-31 20:33:22 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using Tanshu.Common;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using Tanshu.Common.KeyboardControl;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class MainForm : Form
|
|
|
|
|
{
|
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
SessionManager.Initialize();
|
2014-10-12 09:41:45 +00:00
|
|
|
|
//new SchemaExport(SessionManager.Configuration).Create(false, true);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
InitializeComponent();
|
2016-01-04 05:22:01 +00:00
|
|
|
|
Text = "Point of Sale: Login (" + Environment.MachineName + ")";
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnLogin_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
LoginUser(new KeyboardLogin());
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnSale_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Sales"))
|
2014-11-20 08:12:20 +00:00
|
|
|
|
using (var frmSale = new SalesForm(new BillController(null)))
|
2014-11-02 08:03:31 +00:00
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
frmSale.ShowDialog();
|
2014-11-02 08:03:31 +00:00
|
|
|
|
Cache.Invalidate();
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnProduct_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Products"))
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var frm = new ProductListForm())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnProductGroup_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Products"))
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var frm = new ProductGroupListForm())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnCustomer_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2016-03-31 06:57:39 +00:00
|
|
|
|
using (var frm = new CustomerListForm())
|
2011-04-11 12:55:45 +00:00
|
|
|
|
frm.ShowDialog();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
Close();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
private void btnUsers_Click(object sender, EventArgs e)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Roles"))
|
2016-01-18 10:43:43 +00:00
|
|
|
|
using (var frm = new UserListForm())
|
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
private void btnUserRoles_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Roles"))
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using (var frm = new AssignUserGroups())
|
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnChangePassword_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using (var frm = new ChangePassword(new KeyboardControl()))
|
2011-01-31 20:33:22 +00:00
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnCashierCheckout_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Cashier Checkout"))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using (var frm = new CashierCheckoutForm())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void btnSaleAnalysis_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Sales Analysis"))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using (var frm = new frmSaleAnalysisForm())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
private void btnSaleDetail_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Sales Detail"))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using (var frm = new FrmSaleDetail())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2012-04-08 12:28:15 +00:00
|
|
|
|
#if (DEBUG)
|
2014-10-16 11:11:55 +00:00
|
|
|
|
MessageBox.Show("This software does not print kots!!!", "Debug Mode", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
2012-04-08 12:28:15 +00:00
|
|
|
|
#endif
|
2016-01-04 05:22:01 +00:00
|
|
|
|
CheckMachine();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
CheckRoles();
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2016-01-04 05:22:01 +00:00
|
|
|
|
private void CheckMachine()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Cache.Location))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("No Machine Location");
|
|
|
|
|
using (var frm = new MachineEditForm(Environment.MachineName))
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
if (string.IsNullOrEmpty(Cache.Location))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Machine Location not set");
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
private void CheckRoles()
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnSale.Visible = Session.IsAllowed("Sales");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnProduct.Visible = Session.IsAllowed("Products");
|
|
|
|
|
btnProductGroup.Visible = Session.IsAllowed("Products");
|
|
|
|
|
btnModifiers.Visible = Session.IsAllowed("Modifiers");
|
|
|
|
|
btnReorderTables.Visible = Session.IsAllowed("Tables");
|
2016-01-04 05:22:01 +00:00
|
|
|
|
btnMachines.Visible = Session.IsAllowed("Machines");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnOpenBill.Visible = Session.IsAllowed("Open Bill");
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnCustomer.Visible = Session.IsAllowed("Customers");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
btnUsers.Visible = Session.IsAllowed("Users");
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnUserRoles.Visible = Session.IsAllowed("Users");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnGroupRoles.Visible = Session.IsAllowed("Roles");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnCashierCheckout.Visible = Session.IsAllowed("Cashier Checkout");
|
|
|
|
|
btnSaleAnalysis.Visible = Session.IsAllowed("Sales Analysis");
|
2016-01-04 05:22:01 +00:00
|
|
|
|
btnTaxAnalysis.Visible = Session.IsAllowed("Tax Analysis");
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnSaleDetail.Visible = Session.IsAllowed("Sales Detail");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
btnBillDetails.Visible = Session.IsAllowed("Bill Details");
|
|
|
|
|
btnVoidOrReprints.Visible = Session.IsAllowed("Void or Reprinted Bill Report");
|
|
|
|
|
btnDiscountReport.Visible = Session.IsAllowed("Discount Report");
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
btnChangePassword.Visible = Session.IsAuthenticated;
|
2012-12-01 09:48:02 +00:00
|
|
|
|
#if (DEBUG)
|
2013-02-12 13:25:10 +00:00
|
|
|
|
btnManagement.Visible = true;
|
2012-12-01 09:48:02 +00:00
|
|
|
|
#else
|
2013-02-12 13:25:10 +00:00
|
|
|
|
btnManagement.Visible = false;
|
2012-12-01 09:48:02 +00:00
|
|
|
|
#endif
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnGroupRoles_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Roles"))
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using (var frm = new AssignGroupRoles())
|
|
|
|
|
frm.ShowDialog();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2011-02-18 16:54:48 +00:00
|
|
|
|
private void btnSwipeLogin_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
LoginUser(new MsrLogin());
|
2011-02-18 16:54:48 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2014-11-02 08:03:31 +00:00
|
|
|
|
private void LoginUser(ILogin login)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Session.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
if (login.LoginUser())
|
|
|
|
|
{
|
2016-01-04 05:22:01 +00:00
|
|
|
|
Text = "Point of Sale: " + Session.User.Name + " (" + Environment.MachineName + ")";
|
2011-02-18 16:54:48 +00:00
|
|
|
|
btnLogin.Text = "Logout";
|
|
|
|
|
btnSwipeLogin.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
login.LogoutUser();
|
2016-01-04 05:22:01 +00:00
|
|
|
|
Text = "Point of Sale: Login (" + Environment.MachineName + ")";
|
2011-02-18 16:54:48 +00:00
|
|
|
|
btnLogin.Text = "Login";
|
|
|
|
|
btnSwipeLogin.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
CheckRoles();
|
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
|
|
|
|
|
private void btnOpenBill_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (!Session.IsAllowed("Open Bill"))
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return;
|
|
|
|
|
var result = InputBox.Show("Bill Number", "0", InputBox_Validating);
|
|
|
|
|
if (!result.OK)
|
|
|
|
|
return;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
|
|
|
|
|
Expression<Func<Voucher, bool>> query;
|
|
|
|
|
int billID;
|
|
|
|
|
if (Regex.IsMatch(result.Text, @"^\d{2,}-\d{4}$"))
|
|
|
|
|
{
|
|
|
|
|
billID = int.Parse(result.Text.Replace("-", ""));
|
|
|
|
|
query = x => x.BillID == billID && (x.VoucherType == VoucherType.Regular || x.VoucherType == VoucherType.TakeAway);
|
|
|
|
|
}
|
|
|
|
|
else if (Regex.IsMatch(result.Text, @"^NC-\d+$"))
|
|
|
|
|
{
|
|
|
|
|
billID = int.Parse(result.Text.Replace("NC-", ""));
|
|
|
|
|
query = x => x.BillID == billID && x.VoucherType == VoucherType.NoCharge;
|
|
|
|
|
}
|
|
|
|
|
else if (Regex.IsMatch(result.Text, @"^ST-\d+$"))
|
|
|
|
|
{
|
|
|
|
|
billID = int.Parse(result.Text.Replace("ST-", ""));
|
|
|
|
|
query = x => x.BillID == billID && x.VoucherType == VoucherType.Staff;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
|
2011-06-29 20:27:07 +00:00
|
|
|
|
Voucher voucher;
|
2014-10-12 09:41:45 +00:00
|
|
|
|
using (var bi = new VoucherBI())
|
2014-11-06 10:39:11 +00:00
|
|
|
|
voucher = bi.Get(query);
|
|
|
|
|
if (voucher == null)
|
|
|
|
|
return;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Sales"))
|
2014-11-20 08:12:20 +00:00
|
|
|
|
using (var frmSale = new SalesForm(new BillController(voucher.VoucherID)))
|
2011-06-23 12:47:48 +00:00
|
|
|
|
frmSale.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Regex.IsMatch(e.Text, @"^\d+-\d\d\d\d")) return;
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
e.Message = "Bill No should be in format ##-####";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnBillDetails_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Bill Details"))
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var frm = new BillDetailsForm())
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-28 12:17:15 +00:00
|
|
|
|
private void btnVoidOrReprints_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Void or Reprinted Bill Report"))
|
2011-12-05 09:41:02 +00:00
|
|
|
|
using (var frm = new VoidReprintedForm())
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 09:48:02 +00:00
|
|
|
|
private void btnDiscountReport_Click(object sender, EventArgs e)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Discount Report"))
|
|
|
|
|
using (var frm = new DiscountReportForm())
|
|
|
|
|
frm.ShowDialog();
|
2012-12-01 09:48:02 +00:00
|
|
|
|
|
2011-08-28 12:17:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 13:25:10 +00:00
|
|
|
|
private void btnManagement_Click(object sender, EventArgs e)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (Session.IsAllowed("Owner"))
|
|
|
|
|
using (var frm = new ManagementForm())
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnReorderTables_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Session.IsAllowed("Tables"))
|
|
|
|
|
using (var frm = new ReorderTableForm())
|
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnModifiers_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Session.IsAllowed("Modifiers"))
|
|
|
|
|
using (var frm = new ModifierListForm())
|
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
2012-12-01 09:48:02 +00:00
|
|
|
|
}
|
2016-01-04 05:22:01 +00:00
|
|
|
|
|
|
|
|
|
private void btnMachines_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Session.IsAllowed("Machines"))
|
|
|
|
|
using (var frm = new MachineListForm())
|
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnTaxAnalysis_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Session.IsAllowed("Tax Analysis"))
|
|
|
|
|
using (var frm = new frmTaxAnalysisForm())
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|