private List <object> LoadChucNangCon(List <object> obj, int menuID, int k) { List <FunctionInfo> lists = FunctionController.GetInstance().GetByParentID(menuID); foreach (var item in lists) { string tmp = ""; for (int i = 0; i < k; i++) { tmp += "- "; } obj.Add(new { ID = item.ID, Description = tmp + " " + item.Description }); obj = LoadChucNangCon(obj, item.ID, k + 1); } return(obj); }
public void cbxChucNangChaStore_OnRefreshData(object sender, StoreRefreshDataEventArgs e) { List <FunctionInfo> lists = FunctionController.GetInstance().GetFunctionByMenuId(int.Parse("0" + hdfTreeNodeID.Text)); List <object> obj = new List <object>(); obj.Add(new { ID = -1, Description = "Là gốc" }); foreach (FunctionInfo item in lists) { if (item.ParentID == -1) { obj.Add(new { ID = item.ID, Description = item.Description }); obj = LoadChucNangCon(obj, item.ID, 1); } } cbxChucNangChaStore.DataSource = obj; cbxChucNangChaStore.DataBind(); }
protected void btnAddFunction_Click(object sender, DirectEventArgs e) { try { FunctionInfo info = new FunctionInfo() { ControlText = txtControlText.Text, Description = txtDescription.Text, MenuID = int.Parse(hdfTreeNodeID.Text), ParentID = int.Parse(cbxChucNangCha.SelectedItem.Value.ToString()) }; FunctionController.GetInstance().CreateFunction(info); if (e.ExtraParams["Continue"] == "No") { wdFunction.Hide(); } if (string.IsNullOrEmpty(hdfRoleID.Text) == false || AjaxSearchUser.GetValue() != null) { Dialog.ShowNotification(GlobalResourceManager.GetInstance().GetLanguageValue("SetPermissionSuccess")); } else { Dialog.ShowNotification(GlobalResourceManager.GetInstance().GetLanguageValue("AddFunctionSuccess")); } ResourceManager1.RegisterClientScriptBlock("ds", "resetWdFunction();"); } catch (Exception ex) { Dialog.ShowError(GlobalResourceManager.GetInstance().GetErrorMessageValue("DefaultErrorMessage")); NhatkyTruycapInfo accessDiary = new NhatkyTruycapInfo() { CHUCNANG = GlobalResourceManager.GetInstance().GetHistoryAccessValue("AddFunction") + " Default/btnAddFunction_Click", MOTA = ex.Message.Replace("'", " "), IsError = true, USERNAME = CurrentUser.UserName, THOIGIAN = DateTime.Now, MANGHIEPVU = "Functions", TENMAY = Util.GetInstance().GetComputerName(Request.UserHostAddress), IPMAY = Request.UserHostAddress, THAMCHIEU = "", }; new SoftCore.AccessHistory.AccessHistoryController().AddAccessHistory(accessDiary); } }
public void LoadMenuOfRole() { List <int> menuID = MenuController.GetInstance().GetMenuIDOfRole(int.Parse(hdfRecordID.Text), false); //Chỉ lấy các node được checked, còn undefine thì ko lấy hdfMenusOfRole.Text = ""; foreach (var item in menuID) { hdfMenusOfRole.Text += item + ","; } //Lấy các function của role hdfFunctionOfMenu.Text = ""; List <FunctionFullInfo> functionList = FunctionController.GetInstance().GetFunctionsOfRole(int.Parse(hdfRecordID.Text)); foreach (var item in functionList) { hdfFunctionOfMenu.Text += item.ID + ";" + item.IsUndefined + ","; } //List<Function_RoleInfo> funcRoleList = FunctionController.GetInstance().Get RM.RegisterClientScriptBlock("ds", "checkItem();"); }
public void UpdateRoleForMenu(string checkedNode, string undefinedNode, string selectedFunction) { try { //Thêm các node được check, tức là ko undefined string[] roleArr = checkedNode.Split(','); string menuIDNeedToDelete = ""; int roleID = int.Parse(hdfRecordID.Text); FunctionController.GetInstance().RemoveRoleInAllFunction(roleID); //xóa tất cả các chức năng của role để thiết lập lại cho dễ foreach (var item in roleArr) { if (string.IsNullOrEmpty(item)) { continue; } if (!string.IsNullOrEmpty(item) && item.StartsWith("F") == false) { MenuController.GetInstance().AddRole(int.Parse(item), roleID, CurrentUser.ID, false); menuIDNeedToDelete += item + ","; } } //thêm các nút undefined string[] undefinedRoleArr = undefinedNode.Split(','); foreach (var item in undefinedRoleArr) { if (string.IsNullOrEmpty(item)) { continue; } if (item.StartsWith("F") == false) { MenuController.GetInstance().AddRole(int.Parse(item), roleID, CurrentUser.ID, true); menuIDNeedToDelete += item + ","; } } //Xóa đi những menu mà bị hủy khỏi role if (menuIDNeedToDelete.LastIndexOf(',') != -1) { DataHandler.GetInstance().ExecuteNonQuery("delete from Menu_Role where RoleID = " + hdfRecordID.Text + " and MenuID not in (" + menuIDNeedToDelete.Remove(menuIDNeedToDelete.LastIndexOf(',')) + ")"); } else { DataHandler.GetInstance().ExecuteNonQuery("delete from Menu_Role where RoleID = " + hdfRecordID.Text); } //Lưu function string[] tmpFunction = selectedFunction.Split(','); foreach (var item in tmpFunction) { if (!string.IsNullOrEmpty(item)) { //FunctionController.GetInstance().AddRoleToFunction(int.Parse(item), roleID); string[] tmp = item.Split(';'); Function_RoleInfo funcInfo = new Function_RoleInfo() { RoleID = roleID, FunctionID = int.Parse(tmp[0]), IsUndefined = bool.Parse(tmp[1]), CreatedBy = CurrentUser.ID, CreatedDate = DateTime.Now }; Function_RoleInfo funcRoleInfo = FunctionController.GetInstance().GetFunctionRoleByMenuIDAndFunctionID(int.Parse(tmp[0]), roleID); if (funcRoleInfo == null) // chưa có { FunctionController.GetInstance().AddRoleToFunction(funcInfo); } else { funcInfo.ID = funcRoleInfo.ID; FunctionController.GetInstance().UpdateFunctionRole(funcInfo); } } } Dialog.ShowNotification("Thiết lập quyền thành công"); } catch (Exception ex) { X.MessageBox.Alert("Có lỗi xảy ra", ex.Message).Show(); } }