context: using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Text;
  using System.Windows.Forms;
  using C1.Win.C1Ribbon;
  using Biruni.Master.List;
  using Biruni.Master.Entry;
  using Biruni.Sales.List;
  using Biruni.Purchasing.List;
  using Biruni.Inventory.List;
  using Biruni.Security.List;
  using Biruni.Security.Entry;
  using Biruni.Reports;
  using Biruni.Shared;
  using Biruni.Shared.Data;
  using Biruni.Shared.Logging;
  using Biruni.Shared.Templates;
  using Biruni.FE.Properties;
  
  namespace Biruni.FE
  {
      public partial class frmMain : C1RibbonForm
      {
          public frmMain()
          {
              InitializeComponent();
              InitializeForm();
              InitializeRibbonStyleMenu();
              InitializeMenu();
              InitializeStatusBar();
          }
  
          private void InitializeForm()
          {
              this.Text = Application.ProductName;
              this.StartPosition = FormStartPosition.Manual;
              this.Top = 0;
              this.Left = 0;
              this.Width = Screen.PrimaryScreen.WorkingArea.Width;
              this.Height = Screen.PrimaryScreen.WorkingArea.Height;
              this.ribbonLabel3.Text = "User: " + AppHelper.appUserName + " - Logged As: " + AppHelper.appRoleName;
              this.ribbonLabel1.Text = "Connected to: " + AppHelper.dbServer + " (" + AppHelper.dbName + ")";
              this.ribbonLabel4.Text = Application.ProductName + " (Version: " + Application.ProductVersion + ")";
              AppHelper.ApplyFormStyle(this);
              AppHelper.ApplyVisualStyle(this.Controls);
          }
  
          private void InitializeMenu()
          {
              HideAllMenus();
              ShowAllowedMenus();
              // redisplay default menu
              tabApplication.Visible = true;
              grpApplication.Visible = true;
              grpWindow.Visible = true;
              switchWindowsMenu.Visible = true;
              switchWindowsToggleGroup.Visible = true;
              ribbonToggleGroup1.Visible = true;
              btnHelp.Visible = true;
              btnAppExit.Visible = true;
              btnStyles.Visible = true;
              tabTransactions.Selected = true;
          }
  
          private void InitializeStatusBar()
          {
              timer1.Enabled = true;
              timer1.Start();
              ribbonLabel2.Text = DateTime.Now.ToString("dd MMMM yyyy - HH:mm:ss");
          }
  
          protected override void OnClosing(CancelEventArgs e)
          {
              DialogResult res;
  
              res = RibbonMessageBox.Show("Do you want to quit " + Application.ProductName + "?",
                  Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  
              if (res == DialogResult.Yes)
                  e.Cancel = false;
              else
                  e.Cancel = true;
  
              if (!e.Cancel)
                  Logger.DebugRoutine("Application Closed.\n=====================================\n\n");
  
              base.OnClosing(e);
          }
  
          #region Application Menu Initialization
  
          /// <summary>
          /// This function will read from database based on current user
          /// and then will display all aplication menu button allowed for that user
          /// </summary>
          private void ShowAllowedMenus()
          {
              try
              {
                  dsSecurity1.EnforceConstraints = false;
                  daApplicationRoles.Connection = AppHelper.GetDbConnection();
                  daApplicationRoles.FillByUserID(dsSecurity1.ApplicationRoles, AppHelper.appUserID);
                  foreach (dsSecurity.ApplicationRolesRow row in dsSecurity1.ApplicationRoles.Rows)
                      if (row.AllowRead) ShowMenu(row.ApplicationCode);
              }
              catch (Exception ex)
              {
                  Logger.ErrorRoutine(ex);
                  RibbonMessageBox.Show("Kesalahan terjadi saat inisialisasi menu aplikasi: " + ex.Message,
                      Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
              }
          }
  
          private void ShowMenu(string appCode)
          {
              switch (appCode)
              {
                  case "IMS-01001":  // Sales Quotations
                      btnSalesQuotations.Visible = true;
                      grpSales.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-01002":  // Sales Orders
                      btnSalesOrders.Visible = true;
                      grpSales.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-01003":  // Delivery Orders
                      btnDeliveryOrders.Visible = true;
                      grpSales.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-01004":  // Sales Invoices
                      ribbonSeparator4.Visible = true;
                      btnSalesInvoice.Visible = true;
                      grpSales.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-01005":  // Customer Payment
                      ribbonSeparator4.Visible = true;
                      btnSalesPayment.Visible = true;
                      grpSales.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-02001":  // Purchase Quotations
                      break;
                  case "IMS-02002":  // Supplier Selection
                      break;
                  case "IMS-02003":  // Purchase Orders
                      btnPurchaseOrders.Visible = true;
                      grpPurchasing.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-02004":  // Receiving Reports
                      btnReceivingReports.Visible = true;
                      grpPurchasing.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-02005":  // Purchase Invoices
                      ribbonSeparator5.Visible = true;
                      btnPurchaseInvoice.Visible = true;
                      grpPurchasing.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-02006":  // Vendor Payments
                      ribbonSeparator5.Visible = true;
                      btnPurchasePayment.Visible = true;
                      grpPurchasing.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-03001":  // Company Information
                      btnCompanyInfo.Visible = true;
                      grpAdmin.Visible = true;
                      tabApplication.Visible = true;
                      break;
                  case "IMS-03002":  // Customer Information
                      btnCustomerInfo.Visible = true;
                      grpMasterTrx.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03003":  // Vendor Information
                      btnVendorInfo.Visible = true;
                      grpMasterTrx.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03004":  // Currency Types
                      btnCurrencyTypes.Visible = true;
                      grpMasterTrx.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03005":  // Item Information
                      btnItemInfo.Visible = true;
                      grpMasterInv.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03006":  // Item Categories
                      btnItemCategories.Visible = true;
                      grpMasterInv.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03007":  // Warehouses
                      btnWarehouses.Visible = true;
                      grpMasterInv.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03101":  // Opeinng Balance Customer
                      btnBalanceCustomer.Visible = true;
                      grpMasterBalance.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-03102":  // Opeinng Balance Vendor
                      btnBalanceVendor.Visible = true;
                      grpMasterBalance.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-04002":  // Inventory Adjustment
                      btnInventoryAdjustment.Visible = true;
                      grpInventory.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-04001":  // Inventory Status
                      btnInventoryStatus.Visible = true;
                      grpInventory.Visible = true;
                      tabTransactions.Visible = true;
                      break;
                  case "IMS-03008":  // Unit of Measures
                      btnUnitMeasures.Visible = true;
                      grpMasterInv.Visible = true;
                      tabMaster.Visible = true;
                      break;
                  case "IMS-91001":  // Application Roles
                      btnAppRoles.Visible = true;
                      grpAdmin.Visible = true;
                      tabApplication.Visible = true;
                      break;
  
gt:                 case "IMS-91002":  // Application Users