private void initMainPage(DataTable myDT) { loginClicked = true; GF.username = myDT.Rows[0]["USERNAME"].ToString(); GF.user_id = Convert.ToInt32(myDT.Rows[0]["USER_ID"].ToString()); AUTH.setMenu(GF.mainPage, GF.username, GF.user_id.ToString()); // INIT USER PARAMETERS GF.mainPage.statusStrip1.Items[1].ForeColor = Color.LightCoral; if (GF.username == "admin") { GF.mainPage.statusStrip1.Items[1].Text = "SYSTEM ADMINISTRATOR"; GF.can_approve = true; } else { GF.mainPage.statusStrip1.Items[1].Text = myDT.Rows[0]["FULLNAME"].ToString(); GF.can_approve = (myDT.Rows[0]["CAN_APPROVE"].ToString() == "1" ? true : false); } GF.mainPage.statusStrip1.Items[3].ForeColor = Color.LightCoral; GF.mainPage.statusStrip1.Items[3].Text = myDT.Rows[0]["last_login"].ToString(); if (GF.username == "admin") { GF.emp_id = 0; } else if (myDT.Rows[0]["emp_id"].ToString() != "") { GF.emp_id = Convert.ToInt32(myDT.Rows[0]["emp_id"].ToString()); } GF.is_logged_in = true; /*PRINT printPage = new PRINT(false, "INVOICE", "", this, "255703020001"); * GF.selected_id = 207; * PRINT print = new PRINT(false, "SPA_CARD_NEW", "SPA_CARD_NEW.jpg", this, "8");*/ //return; this.Hide(); GF.mainPage.MainMenuStrip.Items["logOutTopToolStripMenuItem"].Select(); /*card_print printPage = new card_print(); * printPage.card_type = 2; * //GF.selected_id = 28; // SPA PROGRAM * GF.selected_id = 29; // MONEY * printPage.ShowDialog();*/ //mainPage.timenow_sl.Text = ""; GF.mainPage.Show(); GF.mainPage.BringToFront(); GF.mainPage.Activate(); }
public static void setMenu(main_page mainPage, String username, String user_id) { String[,] auth; //GET USER AUTH using (DataTable authDT = DB.getS("SELECT ISNULL(MENU_ID, -1) MENU_ID, ISNULL(SUB_MENU_ID, -1) SUB_MENU_ID, ISNULL(SUB_MENU2_ID, -1) SUB_MENU2_ID FROM USERS_AUTH WHERE user_id = " + user_id, null, "CHECK AUTH FOR USER_ID[" + user_id + "]", false)) { if (authDT.Rows.Count == 0 && username != "admin") { return; } auth = new String[authDT.Rows.Count, 3]; int index = 0; foreach (DataRow authRow in authDT.Rows) { auth[index, 0] = authRow["MENU_ID"].ToString(); auth[index, 1] = authRow["SUB_MENU_ID"].ToString(); auth[index, 2] = authRow["SUB_MENU2_ID"].ToString(); index++; } } /*for (int arrayIndex = 0; arrayIndex < auth.GetLength(0); arrayIndex++) * { * GF.doDebug("[ " + arrayIndex + " ] >>> " + auth[arrayIndex, 0] + " , " + auth[arrayIndex, 1] + " , " + auth[arrayIndex, 2]); * }*/ //MAIN MENU foreach (ToolStripMenuItem menu in mainPage.MainMenuStrip.Items) { menu.Visible = false; if (menu.Tag.ToString() == String.Empty) { menu.Visible = false; } else if (menu.Tag.ToString() == "SKIP" || username == "admin" || AUTH.mainMenuAuth(auth, menu.Tag.ToString())) { menu.Visible = true; bool foundBefore = false; bool foundLater = false; bool foundSep = false; //SUB MENU LEVEL 1 foreach (Object sub1Item in menu.DropDown.Items) { if (((ToolStripItem)sub1Item).Name.IndexOf("toolStripSeparator") != -1) { foundSep = true; } else { ((ToolStripItem)sub1Item).Visible = false; if (((ToolStripItem)sub1Item).Tag.ToString() == String.Empty) { ((ToolStripItem)sub1Item).Visible = false; } else if (username == "admin" || AUTH.subMenuAuth(auth, menu.Tag.ToString(), ((ToolStripItem)sub1Item).Tag.ToString())) { if (((ToolStripItem)sub1Item).Tag.ToString() != "SKIP") { ((ToolStripItem)sub1Item).Visible = true; } if (!foundSep) { foundBefore = true; } else { foundLater = true; } if (sub1Item.GetType().Equals(typeof(ToolStripMenuItem))) //if we get the desired object type. { ToolStripMenuItem sub2 = (ToolStripMenuItem)sub1Item; // cast to ToolStripMenuItem if (sub2.HasDropDownItems) // if subMenu has children { // SUB MENU LEVEL 2 bool subFoundBefore = false; bool subFoundLater = false; bool subFoundSep = false; foreach (Object sub2Item in sub2.DropDown.Items) { if (((ToolStripItem)sub2Item).Name.IndexOf("toolStripSeparator") != -1) { subFoundSep = true; } else { //GF.doDebug("[ " + ((ToolStripItem)sub1Item).Text + " ] >>> " + ((ToolStripItem)sub2Item).Text); if (((ToolStripItem)sub1Item).Tag.ToString() == String.Empty) { ((ToolStripItem)sub1Item).Visible = false; } else if (((ToolStripItem)sub2Item).Tag == null) { ((ToolStripItem)sub2Item).Visible = true; } else { ((ToolStripItem)sub2Item).Visible = false; if (username == "admin" || AUTH.sub2MenuAuth(auth, menu.Tag.ToString(), ((ToolStripItem)sub1Item).Tag.ToString(), ((ToolStripItem)sub2Item).Tag.ToString())) { if (((ToolStripItem)sub2Item).Tag.ToString() != "SKIP") { ((ToolStripItem)sub2Item).Visible = true; } if (!subFoundSep) { subFoundBefore = true; } else { subFoundLater = true; } } } } } foreach (ToolStripItem sub2Item in sub2.DropDown.Items) { if (sub2Item.GetType() == typeof(ToolStripSeparator)) { if (subFoundBefore && subFoundLater) { sub2Item.Visible = true; } else { sub2Item.Visible = false; } } } } } } } } foreach (ToolStripItem sub1 in menu.DropDown.Items) { if (sub1.GetType() == typeof(ToolStripSeparator)) { if (foundBefore && foundLater) { sub1.Visible = true; } else { sub1.Visible = false; } } } } } }