narsil/Tanshu.Accounts.PointOfSale/MainForm.cs
tanshu da929ad036 Breaking Change: Changed Kot/Voucher Table Name to Guid Foreign key
Breaking Change: Renamed Discontinued to IsActive and added NA field to products.
Cleanup: Removed not used attributes
Change: RoleConstants changed to simple string
Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form
Feature: Bills now show the Tax name from the database and not a hack
2014-10-16 16:41:55 +05:30

291 lines
9.2 KiB
C#

using System;
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.Management;
using Tanshu.Accounts.PointOfSale.Sales;
using Tanshu.Accounts.Repository;
using Tanshu.Common;
using Tanshu.Common.KeyboardControl;
using NHibernate.Tool.hbm2ddl;
using System.Collections.Generic;
namespace Tanshu.Accounts.PointOfSale
{
public enum LoginType
{
Keyboard,
Msr
}
public partial class MainForm : Form
{
public MainForm()
{
//using (var frm = new SplashForm())
// frm.ShowDialog();
SessionManager.Initialize();
//new SchemaExport(SessionManager.Configuration).Create(false, true);
InitializeComponent();
}
private User form_userEvent(object sender, UserEventArgs e)
{
var user = e.User;
if (user == null)
using (var form = new UserForm(null))
form.ShowDialog();
else
using (var form = new UserForm(user.UserID))
form.ShowDialog();
e.Handled = true;
return new User();
}
private void btnLogin_Click(object sender, EventArgs e)
{
LoginUser(LoginType.Keyboard);
}
private void btnSale_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Sales"))
using (var frmSale = new SalesForm(new BillController(null, true)))
frmSale.ShowDialog();
}
private void btnProduct_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Products"))
using (var frm = new ProductListForm())
frm.ShowDialog();
}
private void btnProductGroup_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Products"))
using (var frm = new ProductGroupListForm())
frm.ShowDialog();
}
private void btnCustomer_Click(object sender, EventArgs e)
{
using (var frm = new CustomersForm(null, ""))
frm.ShowDialog();
}
private void btnExit_Click(object sender, EventArgs e)
{
Close();
}
private void btnCreateUser_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Roles"))
using (var bi = new UserBI())
{
using (var form = new SelectUser(bi.GetFilteredUsers, true))
{
form.UserEvent += form_userEvent;
form.ShowDialog();
}
}
}
private void btnUserRoles_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Roles"))
using (var frm = new AssignUserGroups())
frm.ShowDialog();
}
private void btnChangePassword_Click(object sender, EventArgs e)
{
using (var frm = new ChangePassword(new KeyboardControl()))
frm.ShowDialog();
}
private void btnCashierCheckout_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Cashier Checkout"))
using (var frm = new CashierCheckoutForm())
frm.ShowDialog();
}
private void btnSaleAnalysis_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Sales Analysis"))
using (var frm = new frmSaleAnalysisForm())
frm.ShowDialog();
}
private void btnSaleDetail_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Sales Detail"))
using (var frm = new FrmSaleDetail())
frm.ShowDialog();
}
private void MainForm_Load(object sender, EventArgs e)
{
#if (DEBUG)
MessageBox.Show("This software does not print kots!!!", "Debug Mode", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
#endif
CheckRoles();
}
private void CheckRoles()
{
btnSale.Visible = Session.IsAllowed("Sales");
btnProduct.Visible = Session.IsAllowed("Products");
btnProductGroup.Visible = Session.IsAllowed("Products");
btnModifiers.Visible = Session.IsAllowed("Modifiers");
btnReorderTables.Visible = Session.IsAllowed("Tables");
btnOpenBill.Visible = Session.IsAllowed("Open Bill");
btnCustomer.Visible = Session.IsAllowed("Customers");
btnCreateUser.Visible = Session.IsAllowed("Users");
btnUserRoles.Visible = Session.IsAllowed("Users");
btnGroupRoles.Visible = Session.IsAllowed("Roles");
btnCashierCheckout.Visible = Session.IsAllowed("Cashier Checkout");
btnSaleAnalysis.Visible = Session.IsAllowed("Sales Analysis");
btnSaleDetail.Visible = Session.IsAllowed("Sales Detail");
btnBillDetails.Visible = Session.IsAllowed("Bill Details");
btnVoidOrReprints.Visible = Session.IsAllowed("Void or Reprinted Bill Report");
btnDiscountReport.Visible = Session.IsAllowed("Discount Report");
btnChangePassword.Visible = Session.IsAuthenticated;
#if (DEBUG)
btnManagement.Visible = true;
#else
btnManagement.Visible = false;
#endif
}
private void btnGroupRoles_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Roles"))
using (var frm = new AssignGroupRoles())
frm.ShowDialog();
}
private void btnSwipeLogin_Click(object sender, EventArgs e)
{
LoginUser(LoginType.Msr);
}
private void LoginUser(LoginType loginType)
{
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())
{
Text = "Main Menu - User: " + Session.User.Name;
btnLogin.Text = "Logout";
btnSwipeLogin.Visible = false;
}
}
else
{
login.LogoutUser();
Text = "Main Menu - Login";
btnLogin.Text = "Login";
btnSwipeLogin.Visible = true;
}
CheckRoles();
}
private void btnOpenBill_Click(object sender, EventArgs e)
{
if (!Session.IsAllowed("Open Bill"))
return;
var result = InputBox.Show("Bill Number", "0", InputBox_Validating);
if (!result.OK)
return;
Voucher voucher;
using (var bi = new VoucherBI())
voucher = bi.Get(x => x.BillID == result.Text);
if (Session.IsAllowed("Sales"))
using (var frmSale = new SalesForm(new BillController(voucher.VoucherID, true)))
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)
{
if (Session.IsAllowed("Bill Details"))
using (var frm = new BillDetailsForm())
frm.ShowDialog();
}
private void btnVoidOrReprints_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Void or Reprinted Bill Report"))
using (var frm = new VoidReprintedForm())
frm.ShowDialog();
}
private void btnDiscountReport_Click(object sender, EventArgs e)
{
if (Session.IsAllowed("Discount Report"))
using (var frm = new DiscountReportForm())
frm.ShowDialog();
}
private void btnManagement_Click(object sender, EventArgs e)
{
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();
}
}
}
}