Here is the code
public static Form nextForm;
private Company company = new Company();
public LoginDAL loginDAL = new LoginDAL();
public CompanyDAL companyDAL = new CompanyDAL();
public frmController()
{
InitializeComponent();
}
private void frmController_Load(object sender, EventArgs e)
{
backColor = this.BackColor;
foreColor = this.ForeColor;
lblCompanyName.Text = GetCompanyName();
this.Show();
if (company == null)
{
MessageBox.Show(
"An error has occurred accessing database -\n" +
" contact system administrator", "Database Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
else
{
apUser = new AccountProUser();
Form login = new frmLogin(this);
login.ShowDialog(this);
if (apUser != null)
{
Form menu = new frmMenu(this);
nextForm.ShowDialog(this);
}
else
{
Application.Exit();
}
}
}
private string GetCompanyName()
{
company.FirstName = companyDAL.GetCompanyName;
return company.FirstName;
}
}
public partial class **frmMenu** : Form
{
private List<apallowablemodules> allowableModules = new List<apallowablemodules>();
private List<apmodule> lstMenuOptions;
private Form nextForm = new Form();
public frmMenu(frmController frmController)
{
InitializeComponent();
this.CenterToParent();
this.BackColor = frmController.BackColor;
this.ForeColor = frmController.ForeColor;
UIMenu uiMenu = new UIMenu();
lstMenuOptions = uiMenu.GetMenuOptions();
FlowLayoutPanel flp = uiMenu.SetupMenu(lstMenuOptions, this.ToString(), true, "Main Menu");
foreach (Button button in flp.Controls.OfType<Button>())
{
switch (button.Text)
{
case "Accounts Payable":
{
button.Click += btnAccountsPayable_Click;
break;
}
case "Accounts Receivable":
{
button.Click += btnAccountsReceivable_Click;
break;
}
case "General Ledger":
{
button.Click += btnGeneralLedger_Click;
break;
}
case "Inventory Control":
{
button.Click += btnInventoryControl_Click;
break;
}
case "Payroll":
{
button.Click += btnPayroll_Click;
break;
}
case "Sales Analysis":
{
button.Click += btnSalesAnalysis_Click;
break;
}
case "Maintain AccountPro":
{
button.Click += btnMaintainAccountPro_Click;
break;
}
}
}
flp.Location = new Point(
(this.Width - flp.Width) / 2,
((this.Height - flp.Height) / 2) - 70);
this.Controls.Add(flp);
this.ShowDialog();
}
public void btnAccountsPayable_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmAccountsPayableMenu();
this.Close();
}
public void btnAccountsReceivable_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmAccountsReceivableMenu();
this.Close();
}
public void btnGeneralLedger_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmGeneralLedgerMenu();
this.Close();
}
public void btnInventoryControl_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmInventoryControlMenu();
this.Close();
}
public void btnPayroll_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmPayrollMenu();
this.Close();
}
public void btnSalesAnalysis_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmSalesAnalysisMenu();
this.Close();
}
public void btnMaintainAccountPro_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmMaintainAccountProMenu();
this.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
public override string ToString()
{
return "MainMenu";
}
}
public partial class **frmInventoryControlMenu** : Form
{
private List<apallowablemodules> allowableModules = new List<apallowablemodules>();
private List<apmodule> lstMenuOptions;
public frmInventoryControlMenu()
{
InitializeComponent();
this.CenterToParent();
this.BackColor = frmController.backColor;
this.ForeColor = frmController.foreColor;
UIMenu uiMenu = new UIMenu();
lstMenuOptions = uiMenu.GetMenuOptions("Inventory Control", frmController.apUser);
FlowLayoutPanel flp = uiMenu.SetupMenu(lstMenuOptions, this.ToString(), false, "Inventory Control Menu");
foreach (Button button in flp.Controls.OfType<Button>())
{
switch (button.Text)
{
case "Maintain Inventory":
{
button.Click += btnMaintainInventory_Click;
break;
}
case "Receive Inventory":
{
button.Click += btnReceiveInventory_Click;
break;
}
case "Print Pick Tickets":
{
button.Click += btnPrintPickTickets_Click;
break;
}
case "End Of Period Processing":
{
button.Click += btnEndOfPeriodProcessing_Click;
break;
}
}
}
flp.Location = new Point(
(this.Width - flp.Width) / 2,
((this.Height - flp.Height) / 2) - 70);
this.Controls.Add(flp);
this.ShowDialog();
}
private void btnMaintainInventory_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmMaintainInventory();
this.Close();
}
private void btnReceiveInventory_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmReceiveInventory();
this.Close();
}
private void btnPrintPickTickets_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmPrintPickTickets();
this.Close();
}
private void btnEndOfPeriodProcessing_Click(object sender, EventArgs e)
{
frmController.nextForm = new frmEndOfPeriodProcessing();
this.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
</apmodule></apallowablemodules></apallowablemodules></apmodule></apallowablemodules></apallowablemodules>