d8ecec8bb6
BillInventory Renamed. Refactored Bill to be more usable. Added Bill Detail Report. Added Open Bill and Bill Details Roles. Zero Rate Products have Yellow background Color. Refactored UserBI, FoodTableBI, ModifierBI, PrintLocationBI, ProductBI, ProductGroupBI, TaxBI, UserBI, Cached the Products List. Product and Product Group Form Working.
269 lines
8.5 KiB
C#
269 lines
8.5 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Accounts.Entities.Auth;
|
|
using Tanshu.Accounts.Helpers;
|
|
using Tanshu.Accounts.PointOfSale.Sales;
|
|
using Tanshu.Accounts.Repository;
|
|
using Tanshu.Common;
|
|
using Tanshu.Common.KeyboardControl;
|
|
|
|
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();
|
|
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(RoleConstants.SALES))
|
|
using (var frmSale = new SalesForm(new BillController(null, true)))
|
|
frmSale.ShowDialog();
|
|
}
|
|
|
|
private void btnProduct_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.PRODUCTS))
|
|
using (var frm = new ProductListForm())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
private void btnProductGroup_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.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 btnInitial_Click(object sender, EventArgs e)
|
|
{
|
|
#if (DEBUG)
|
|
if (Session.IsAllowed(RoleConstants.MASTER_OWNER))
|
|
{
|
|
Fixtures.CreateSchema();
|
|
MessageBox.Show("Schema Recreated");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private void btnAdvanceReceive_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.SALES))
|
|
using (var frm = new frmRecieveAdvance())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
private void btnAdvanceAdjust_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.SALES))
|
|
using (var frm = new frmAdjustAdvance())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void btnCreateUser_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.SECURITY_MANAGE_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(RoleConstants.SECURITY_MANAGE_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(RoleConstants.CASHIER_CHECKOUT))
|
|
using (var frm = new CashierCheckoutForm())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
private void btnSaleAnalysis_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.SALE_ANALYSIS))
|
|
using (var frm = new frmSaleAnalysisForm())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
private void btnSaleDetail_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.SALE_DETAIL))
|
|
using (var frm = new FrmSaleDetail())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
CheckRoles();
|
|
}
|
|
|
|
private void CheckRoles()
|
|
{
|
|
#if (DEBUG)
|
|
btnInitial.Visible = Session.IsAllowed(RoleConstants.MASTER_OWNER);
|
|
#else
|
|
btnInitial.Visible = false;
|
|
#endif
|
|
|
|
btnSale.Visible = Session.IsAllowed(RoleConstants.SALES);
|
|
|
|
btnProduct.Visible = Session.IsAllowed(RoleConstants.PRODUCTS);
|
|
btnProductGroup.Visible = Session.IsAllowed(RoleConstants.PRODUCTS);
|
|
|
|
btnOpenBill.Visible = Session.IsAllowed(RoleConstants.OPEN_BILL);
|
|
|
|
btnCustomer.Visible = Session.IsAllowed(RoleConstants.CUSTOMERS);
|
|
|
|
btnAdvanceReceive.Visible = Session.IsAllowed(RoleConstants.RECEIVE_ADVANCE);
|
|
|
|
btnAdvanceAdjust.Visible = Session.IsAllowed(RoleConstants.ADJUST_ADVANCE);
|
|
|
|
btnCreateUser.Visible = Session.IsAllowed(RoleConstants.SECURITY_MANAGE_USERS);
|
|
btnUserRoles.Visible = Session.IsAllowed(RoleConstants.SECURITY_MANAGE_USERS);
|
|
|
|
btnGroupRoles.Visible = Session.IsAllowed(RoleConstants.SECURITY_MANAGE_ROLES);
|
|
|
|
btnCashierCheckout.Visible = Session.IsAllowed(RoleConstants.CASHIER_CHECKOUT);
|
|
btnSaleAnalysis.Visible = Session.IsAllowed(RoleConstants.SALE_ANALYSIS);
|
|
btnSaleDetail.Visible = Session.IsAllowed(RoleConstants.SALE_DETAIL);
|
|
|
|
btnBillDetails.Visible = Session.IsAllowed(RoleConstants.BILL_DETAILS);
|
|
|
|
btnChangePassword.Visible = Session.IsAuthenticated;
|
|
}
|
|
|
|
private void btnGroupRoles_Click(object sender, EventArgs e)
|
|
{
|
|
if (Session.IsAllowed(RoleConstants.SECURITY_MANAGE_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(RoleConstants.OPEN_BILL))
|
|
return;
|
|
var result = InputBox.Show("Bill Number", "0", InputBox_Validating);
|
|
if (!result.OK)
|
|
return;
|
|
var voucher = VoucherBI.Get(result.Text);
|
|
if (Session.IsAllowed(RoleConstants.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(RoleConstants.BILL_DETAILS))
|
|
using (var frm = new BillDetailsForm())
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
|
|
}
|
|
} |