narsil/Tanshu.Accounts.PointOfSale/MainForm.cs
2011-02-01 02:03:22 +05:30

256 lines
7.5 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;
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)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_SALES_BILL))
{
if (roleBI.IsAllowed)
{
using (SalesForm frmSale = new SalesForm(new BillController()))
frmSale.ShowDialog();
}
}
}
private void btnProduct_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.MASTER_PRODUCTS))
{
if (roleBI.IsAllowed)
using (ProductsForm frm = new ProductsForm())
frm.ShowDialog();
}
}
private void btnProductGroup_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.MASTER_PRODUCTS))
{
if (roleBI.IsAllowed)
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)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.MASTER_OWNER))
{
if (roleBI.IsAllowed)
{
Fixtures.CreateSchema();
MessageBox.Show("Schema Recreated");
}
}
}
private void btnAdvanceReceive_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_SALES_BILL))
{
if (roleBI.IsAllowed)
{
using (RecieveAdvanceForm frm = new RecieveAdvanceForm())
frm.ShowDialog();
}
}
}
private void btnAdvanceAdjust_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_SALES_BILL))
{
if (roleBI.IsAllowed)
{
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)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SECURITY_MANAGE_ROLES))
{
if (roleBI.IsAllowed)
using (SelectUser form = new SelectUser(UserBI.GetFilteredUsers, true))
{
form.userEvent += new UserEventHandler(form_userEvent);
form.ShowDialog();
}
}
}
private void btnAssignRoles_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SECURITY_MANAGE_ROLES))
{
if (roleBI.IsAllowed)
using (AssignRoles frm = new AssignRoles())
frm.ShowDialog();
}
}
private void btnChangePassword_Click(object sender, EventArgs e)
{
using (ChangePassword frm = new ChangePassword())
frm.ShowDialog();
}
private void btnCashierCheckout_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_CHECKOUT))
{
if (roleBI.IsAllowed)
using (Cashier_Checkout_Form frm = new Cashier_Checkout_Form())
frm.ShowDialog();
}
}
private void btnSaleAnalysis_Click(object sender, EventArgs e)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_SALE_DETAIL))
{
if (roleBI.IsAllowed)
using (frmSaleAnalysisForm frm = new frmSaleAnalysisForm())
frm.ShowDialog();
}
}
private void MainForm_Load(object sender, EventArgs e)
{
//foreach (Control item in this.flowLayoutPanel1.Controls)
//{
// Button but = item as Button;
// if (but != null)
// {
// }
//}
CheckRoles();
}
private void CheckRoles()
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.MASTER_OWNER))
{
if (roleBI.IsAllowed)
{
btnInitial.Visible = true;
}
else
{
btnInitial.Visible = false;
}
}
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_SALES_BILL))
{
if (roleBI.IsAllowed)
{
btnSale.Visible = true;
btnCustomer.Visible = true;
}
else
{
btnSale.Visible = false;
btnCustomer.Visible = true;
}
}
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.MASTER_PRODUCTS))
{
if (roleBI.IsAllowed)
{
btnProduct.Visible = true;
btnProductGroup.Visible = true;
}
else
{
btnProduct.Visible = false;
btnProductGroup.Visible = false;
}
}
}
}
}