narsil/Tanshu.Accounts.PointOfSale/MainForm.cs

209 lines
6.6 KiB
C#

using System;
using System.Windows.Forms;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Repository;
using System.Collections.Generic;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
User form_userEvent(object sender, UserEventArgs e)
{
User user = e.User;
if (user == null)
{
using (UserForm form = new UserForm(null))
{
form.ShowDialog();
}
}
else
{
using (UserForm form = new UserForm(user.UserID))
{
form.ShowDialog();
}
}
e.Handled = true;
return new User();
}
private void btnLogin_Click(object sender, EventArgs e)
{
ILogin login = new KeyboardLogin();
if (!Session.IsAuthenticated)
{
if (login.LoginUser())
{
this.Text = "Main Menu - User: " + Session.User.Name;
btnLogin.Text = "Logout";
}
}
else
{
login.LogoutUser();
this.Text = "Main Menu - Login";
btnLogin.Text = "Login";
}
CheckRoles();
}
private void btnSale_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALES))
using (SalesForm frmSale = new SalesForm(new BillController(null)))
frmSale.ShowDialog();
}
private void btnProduct_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.PRODUCTS))
using (ProductsForm frm = new ProductsForm())
frm.ShowDialog();
}
private void btnProductGroup_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.PRODUCTS))
using (var frm = new ProductTypes())
frm.ShowDialog();
}
private void btnCustomer_Click(object sender, EventArgs e)
{
using (CustomersForm Customer = new CustomersForm(null, ""))
{
Customer.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 (RecieveAdvanceForm frm = new RecieveAdvanceForm())
frm.ShowDialog();
}
private void btnAdvanceAdjust_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALES))
using (AdjustAdvanceForm frm = new AdjustAdvanceForm())
frm.ShowDialog();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnCreateUser_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SECURITY_MANAGE_ROLES))
using (SelectUser form = new SelectUser(UserBI.GetFilteredUsers, true))
{
form.userEvent += new UserEventHandler(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 (ChangePassword frm = new ChangePassword(new KeyboardControl()))
frm.ShowDialog();
}
private void btnCashierCheckout_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.CASHIER_CHECKOUT))
using (Cashier_Checkout_Form frm = new Cashier_Checkout_Form())
frm.ShowDialog();
}
private void btnSaleAnalysis_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALE_ANALYSIS))
using (frmSaleAnalysisForm frm = new frmSaleAnalysisForm())
frm.ShowDialog();
}
private void btnSaleDetail_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALE_ANALYSIS))
using (var frm = new frmSaleDetail())
frm.ShowDialog();
}
private void MainForm_Load(object sender, EventArgs e)
{
CheckRoles();
}
private void CheckRoles()
{
btnInitial.Visible = Session.IsAllowed(RoleConstants.MASTER_OWNER);
btnSale.Visible = Session.IsAllowed(RoleConstants.SALES);
btnProduct.Visible = Session.IsAllowed(RoleConstants.PRODUCTS);
btnProductGroup.Visible = Session.IsAllowed(RoleConstants.PRODUCTS);
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.SALE_ANALYSIS);
btnSaleAnalysis.Visible = Session.IsAllowed(RoleConstants.SALE_ANALYSIS);
btnSaleDetail.Visible = Session.IsAllowed(RoleConstants.SALE_DETAIL);
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();
}
}
}