public static u_UserRights_DL GetUserRightObj(string formID, string user) { u_UserRights objUserRight = new u_UserRights(); objUserRight.User = new u_User(); objUserRight.MenuTag = new u_MenuTag(); objUserRight.User.strUserID = Globals.g_strUser; objUserRight.MenuTag.strMenuID = formID.Trim(); u_UserRights_DL objURightDL = new u_UserRights_DL(); u_UserRights_DL dtAllMenuItems = objURightDL.GetUserRightsForOneMenu(objUserRight); return(dtAllMenuItems); }
public u_UserRights_DL CreateUserRights_DL(DataTable dtUserRights) { u_UserRights_DL bl = new u_UserRights_DL(); for (int i = 0; i < dtUserRights.Rows.Count; i++) { strRight = dtUserRights.Rows[i]["Menu Rights"].ToString(); //if (strRight == null) // //return dtUserRights; for (int j = 0; j < (strRight.Trim()).Length; j++) { if (strRight[j] == 'A') { bl.boolAccess = true; } if (strRight[j] == 'C') { bl.boolCreate = true; } if (strRight[j] == 'M') { bl.boolModify = true; } if (strRight[j] == 'D') { bl.boolDelete = true; } if (strRight[j] == 'P') { bl.boolPrint = true; } } } return(bl); }
/*FunctionButtonStatus Was created by Asanga Chandrakumara on 12:18 PM 6/24/2015*/ /// <summary> /// THis function will enable and disable the button status as required /// </summary> /// <param name="typex">Enumaration to function type</param> public void FunctionButtonStatus(xEnums.PerformanceType typex) { u_UserRights objUserRight = new u_UserRights(); objUserRight.User = new u_User(); objUserRight.MenuTag = new u_MenuTag(); objUserRight.User.strUserID = Globals.g_strUser; objUserRight.MenuTag.strMenuID = formID.Trim(); u_UserRights_DL objURightDL = new u_UserRights_DL(); u_UserRights_DL dtAllMenuItems = objURightDL.GetUserRightsForOneMenu(objUserRight); switch (typex) { case xEnums.PerformanceType.Save: if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; btn_cancel.Enabled = false; btn_save.Enabled = false; btn_delete.Enabled = dtAllMenuItems.boolDelete; btn_edit.Enabled = dtAllMenuItems.boolModify; btn_print.Enabled = dtAllMenuItems.boolPrint; } else { btn_cancel.Enabled = false; btn_save.Enabled = false; btn_new.Enabled = true; btn_delete.Enabled = dtAllMenuItems.boolDelete; btn_edit.Enabled = dtAllMenuItems.boolModify; btn_print.Enabled = dtAllMenuItems.boolPrint; } break; case xEnums.PerformanceType.Delete: //when press the delete button if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; } else { btn_cancel.Enabled = false; btn_save.Enabled = false; btn_new.Enabled = true; btn_delete.Enabled = false; btn_edit.Enabled = false; btn_print.Enabled = false; } break; case xEnums.PerformanceType.Existing: //enter existing item to system if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; } else { btn_cancel.Enabled = true; btn_save.Enabled = false; btn_new.Enabled = false; btn_delete.Enabled = dtAllMenuItems.boolDelete; btn_edit.Enabled = dtAllMenuItems.boolModify; btn_print.Enabled = dtAllMenuItems.boolPrint; } break; case xEnums.PerformanceType.Edit: //enter existing item to system and press edit if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; btn_cancel.Enabled = true; btn_save.Enabled = true; btn_new.Enabled = dtAllMenuItems.boolCreate; btn_delete.Enabled = dtAllMenuItems.boolDelete; btn_edit.Enabled = false; btn_print.Enabled = dtAllMenuItems.boolPrint; } else { btn_cancel.Enabled = true; btn_save.Enabled = true; btn_new.Enabled = false; btn_delete.Enabled = false; btn_edit.Enabled = false; btn_print.Enabled = false; } break; case xEnums.PerformanceType.Exit: break; case xEnums.PerformanceType.New: if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; } else { btn_cancel.Enabled = true; btn_save.Enabled = true; btn_new.Enabled = false; btn_delete.Enabled = false; btn_edit.Enabled = false; btn_print.Enabled = false; } break; case xEnums.PerformanceType.Default: if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; btn_delete.Enabled = dtAllMenuItems.boolDelete; btn_edit.Enabled = dtAllMenuItems.boolModify; btn_print.Enabled = dtAllMenuItems.boolPrint; btn_save.Enabled = false; btn_cancel.Enabled = false; } else { btn_cancel.Enabled = false; btn_save.Enabled = false; btn_new.Enabled = true; btn_delete.Enabled = dtAllMenuItems.boolDelete; btn_edit.Enabled = dtAllMenuItems.boolModify; btn_print.Enabled = dtAllMenuItems.boolPrint; } break; case xEnums.PerformanceType.Cancel: if (dtAllMenuItems.boolCreate == false) { btn_new.Enabled = false; } else { btn_cancel.Enabled = false; btn_save.Enabled = false; btn_new.Enabled = true; btn_delete.Enabled = false; btn_edit.Enabled = false; btn_print.Enabled = false; } break; } }
/// <summary> /// This will disable menues if they don't have acccess to incoming user searched by the Menu ID /// So when ever you change the text of the form will not effect to this method /// just put the tlStrpMenuItem_ +menu ID to the menu name and all done /// </summary> public void MenuStripItemsVisible() { u_UserRights objUserRight = new u_UserRights(); objUserRight.User = new u_User(); objUserRight.MenuTag = new u_MenuTag(); u_UserRights_BL objUserRghtsBL = new u_UserRights_BL(); objUserRight.User.strUserID = Globals.g_strUser; objUserRight.MenuTag.strMenuID = Globals.g_MenuId; u_UserRights_DL objURightDL = new u_UserRights_DL(); DataTable dtAllMenuItems = objURightDL.GetUserRights(objUserRight); //DataTable dtAllMenuItems = objUserRghtsBL.GetUserRights(objUserRight); if (Globals.g_strUser.Trim().ToUpper() != "ADMIN") { if (dtAllMenuItems.Rows.Count != 0) { for (int i = 0; i < dtAllMenuItems.Rows.Count; i++) { if (Convert.ToBoolean(dtAllMenuItems.Rows[i]["dtAccess"].ToString()) == false) { string strEditUIName = (dtAllMenuItems.Rows[i]["Code"].ToString()).Replace(" ", ""); string strtlStrpMenuItemName = strEditUIName; List <ToolStripMenuItem> myItems = GetItems(this.menuStrip); foreach (var item in myItems) { item.ForeColor = Color.FromArgb(126, 26, 29); item.Text = item.Text.ToUpper(); if (item.Name == strtlStrpMenuItemName) { item.Enabled = false; } } foreach (ToolStripItem ctrl in this.toolStrip.Items) { ctrl.Text = ctrl.Text.ToUpper(); if (ctrl.Name.Trim().ToUpper() == "T" + strtlStrpMenuItemName.Trim().ToUpper()) { ctrl.Enabled = false; } } foreach (ToolStripItem ctrl in this.contextMenuStrip1.Items) { ctrl.Text = ctrl.Text.ToUpper(); ctrl.ForeColor = Color.FromArgb(126, 26, 29); if (ctrl.Name.Trim().ToUpper() == "C" + strtlStrpMenuItemName.Trim().ToUpper()) { ctrl.Enabled = false; } } } else { string strEditUIName = (dtAllMenuItems.Rows[i]["Code"].ToString()).Replace(" ", ""); string strtlStrpMenuItemName = strEditUIName; List <ToolStripMenuItem> myItems = GetItems(this.menuStrip); foreach (var item in myItems) { item.ForeColor = Color.FromArgb(126, 26, 29); item.Text = item.Text.ToUpper(); if (item.Name == strtlStrpMenuItemName) { item.Enabled = true; } } foreach (ToolStripItem ctrl in this.toolStrip.Items) { ctrl.Text = ctrl.Text.ToUpper(); if (ctrl.Name.Trim().ToUpper() == "T" + strtlStrpMenuItemName.Trim().ToUpper()) { ctrl.Enabled = true; } } foreach (ToolStripItem ctrl in this.contextMenuStrip1.Items) { ctrl.Text = ctrl.Text.ToUpper(); ctrl.ForeColor = Color.FromArgb(126, 26, 29); if (ctrl.Name.Trim().ToUpper() == "C" + strtlStrpMenuItemName.Trim().ToUpper()) { ctrl.Enabled = true; } } } } } else { //implement locking system List <ToolStripMenuItem> myItems = GetItems(this.menuStrip); foreach (var item in myItems) { item.ForeColor = Color.FromArgb(126, 26, 29); item.Text = item.Text.ToUpper(); item.Enabled = false; } foreach (ToolStripItem ctrl in this.toolStrip.Items) { if (ctrl.Name.Trim().ToUpper() == "shutdown_ToolBar".Trim().ToUpper()) { } else { ctrl.Text = ctrl.Text.ToUpper(); ctrl.Enabled = false; } } foreach (ToolStripItem ctrl in this.contextMenuStrip1.Items) { ctrl.Text = ctrl.Text.ToUpper(); ctrl.ForeColor = Color.FromArgb(126, 26, 29); ctrl.Enabled = false; } } } else { // if login user is administrator } }