예제 #1
0
        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(sGuid))
            {
                //Add
                Entity.RoleMenu roleMenu = new Entity.RoleMenu();
                roleMenu.role.RoleName    = txt_RoleName.Text;
                roleMenu.role.Description = txt_Description.Text;
                string[] checkmenus = Tree2.GetCheckedNodeIDs();
                foreach (string checkID in checkmenus)
                {
                    Entity.Menu menu = new Entity.Menu();
                    menu.ID = int.Parse(checkID.ToString());
                    roleMenu.menuList.Add(menu);
                }

                int success = DAL.RoleMenu.AddRoleMenu(roleMenu);
                if (success == 1)
                {
                    Alert.ShowInTop(" 保存成功!", MessageBoxIcon.Information);
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.ShowInTop("保存失败!", MessageBoxIcon.Warning);
                }
            }
            else
            {
                //Update
                Entity.RoleMenu roleMenu = new Entity.RoleMenu();
                roleMenu.role.ID          = int.Parse(sGuid);
                roleMenu.role.RoleName    = txt_RoleName.Text;
                roleMenu.role.Description = txt_Description.Text;
                string[] checkmenus = Tree2.GetCheckedNodeIDs();

                int[] check = new int[checkmenus.Length];
                for (int i = 0; i < checkmenus.Length; i++)
                {
                    check[i] = int.Parse(checkmenus[i]);
                }



                StringBuilder   sb       = new StringBuilder();
                Entity.RoleMenu rolemenu = DAL.RoleMenu.GetRoleMenu(sGuid);
                txt_RoleName.Text    = rolemenu.role.RoleName;
                txt_Description.Text = rolemenu.role.Description;
                foreach (Entity.Menu menu in rolemenu.menuList)
                {
                    int             menuID = menu.ID;
                    FineUI.TreeNode tn     = Tree2.FindNode(menuID.ToString());
                    tn.Checked = true;
                    sb.Append(menuID.ToString() + ",");
                }
                old = sb.ToString().Substring(0, sb.Length - 1);
                string[] oldIds = old.Split(',');
                int[]    oldid  = new int[oldIds.Length];
                for (int s = 0; s < oldIds.Length; s++)
                {
                    oldid[s] = int.Parse(oldIds[s]);
                }

                List <int> Checked = new List <int>();
                for (int i = 0; i < checkmenus.Length; i++)
                {
                    Checked.Add(int.Parse(checkmenus[i]));
                }
                List <int> OldID = new List <int>();
                for (int i = 0; i < oldIds.Length; i++)
                {
                    OldID.Add(int.Parse(oldIds[i]));
                }
                List <int> Delete = ListHelper.ExceptList(OldID, Checked);
                List <int> Add    = ListHelper.ExceptList(Checked, OldID);
                foreach (int a in Delete)
                {
                    roleMenu.Delete.Add(a.ToString());
                }
                foreach (int b in Add)
                {
                    roleMenu.NewAdd.Add(b.ToString());
                }
                //var c = oldid.Intersect(check);
                //var d = oldid.Except(check);
                //var f = check.Except(oldid);
                //foreach (var q in d)
                //{
                //    roleMenu.Delete.Add(q.ToString());
                //}
                //foreach (var w in f)
                //{
                //    roleMenu.NewAdd.Add(w.ToString());
                //}
                int success = DAL.RoleMenu.UpdateRoleMenu(roleMenu);
                if (success == 1)
                {
                    Alert.ShowInTop(" 修改成功!", MessageBoxIcon.Information);
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.ShowInTop("修改失败!", MessageBoxIcon.Warning);
                }
            }
        }