private void New() { var per = new TB_Permission(); per.Name = txtName.Value.Trim(); per.Image = hidImage.Value; per.Delete = false; per.IsDefault = isDefault.Checked; per.Url = txtURL.Value.Trim(); // 父级菜单,为空时默认为顶级菜单 var parent = int.Parse("" == hidParent.Value ? "0" : hidParent.Value); per.Parent = parent; var brothers = PermissionInstance.FindList(p => p.Parent == parent); per.DisplayOrder = brothers.Count(); per.AddTime = DateTime.Now; per.Description = txtDescription.Value.Trim(); PermissionInstance.Add(per); // 记录历史 SaveHistory(new TB_AccountHistory { ActionId = ActionInstance.Find(f => f.Name.Equals("AddPermission")).id, ObjectA = "[id=" + per.id + "] " + per.Name }); UpdateRole(per); ShowNotification("./permission_list.aspx", "Success: You added a new menu.", true); }
protected void bt_Delete_Click(object sender, EventArgs e) { if ("" != hidID.Value) { var ids = GetIdList(hidID.Value.Split(new char[] { ',' })); var list = PermissionInstance.FindList(f => ids.Contains(f.id)); foreach (var tmp in list) { tmp.Delete = true; Update(tmp); var his = new TB_AccountHistory(); his.Account = Account.id; his.ActionId = ActionInstance.Find(f => f.Name.Equals("DeletePermission")).id; his.Ip = Utility.GetClientIP(this.Context); his.ObjectA = "[id=" + tmp.id + "] " + tmp.Name; SaveHistory(his); } ShowNotification("./permission_list.aspx", "Success: You have delete " + ids.Count() + " permission(s)."); } }
/// <summary> /// 更改显示顺序 /// </summary> /// <param name="toupper">true=往上调,false=往下调</param> private void ChangeDisplayOrder(bool toupper) { var id = int.Parse(Utility.Decrypt(hidID.Value)); var obj = PermissionInstance.Find(f => f.id == id); var brothers = PermissionInstance.FindList(f => f.Parent == obj.Parent).OrderBy(o => o.DisplayOrder); if (obj.DisplayOrder == 0) { // 原始顺序在第一位时,只有向下调 if (!toupper) { var t = brothers.FirstOrDefault(f => f.DisplayOrder == obj.DisplayOrder + 1); ChangeDisplayOrder(obj, t, toupper); } } else if (obj.DisplayOrder == brothers.Count() - 1) { // 原始顺序在最后一位时,只有向上调 if (toupper) { var t = brothers.FirstOrDefault(f => f.DisplayOrder == obj.DisplayOrder - 1); ChangeDisplayOrder(obj, t, toupper); } } else { var t = brothers.FirstOrDefault(f => f.DisplayOrder == (toupper ? (obj.DisplayOrder - 1) : (obj.DisplayOrder + 1))); ChangeDisplayOrder(obj, t, toupper); } var his = new TB_AccountHistory(); his.Account = Account.id; his.ActionId = ActionInstance.Find(f => f.Name.Equals("EditPermission")).id; his.Ip = Utility.GetClientIP(this.Context); his.ObjectA = "[id=" + obj.id + "] " + obj.Name + ", change display order to " + (toupper ? "lower" : "upper"); SaveHistory(his); ShowNotification("./permission_list.aspx", "Success: You have changed the display order of " + obj.Name + "."); }