Ejemplo n.º 1
0
        internal bool UpgradeArchitectureToRemote(out Exception ex)
        {
            ex = null;
            int errCount = 0;

            try
            {
                Architecture      a     = this.CurrentArchitecture;
                List <Action>     atcs  = a.Acts;
                List <Department> deps  = a.Deps;
                List <Module>     mods  = a.Mods;
                List <Permission> perms = a.Pers;
                List <Role>       roles = a.Roles;
                List <UserGroup>  ugrps = a.Ugroups;
                List <User>       users = a.Users;
                ActionLogic.GetInstance().UpgradeList(atcs);
                DepartmentLogic.GetInstance().UpgradeList(deps);
                ModuleLogic.GetInstance().UpgradeList(mods);
                PermissionLogic.GetInstance().UpgradeList(perms);
                RoleLogic.GetInstance().UpgradeList(roles);
                UserGroupLogic.GetInstance().UpgradeList(ugrps);
                UserLogic.GetInstance().UpgradeList(users);
            }
            catch (Exception e)
            {
                errCount++;
                ex = e;
            }
            return(errCount == 0);
        }
Ejemplo n.º 2
0
        private static Architecture GetRemoteArchitecture()
        {
            Architecture a = Architecture.Empty;

            a.Deps    = DepartmentLogic.GetInstance().GetAllDepartments();
            a.Ugroups = UserGroupLogic.GetInstance().GetAllUserGroups();
            a.Users   = UserLogic.GetInstance().GetAllUsers();
            a.Mods    = ModuleLogic.GetInstance().GetAllModules();
            a.Acts    = ActionLogic.GetInstance().GetAllActions();
            a.Pers    = PermissionLogic.GetInstance().GetAllPermissions();
            a.Roles   = RoleLogic.GetInstance().GetAllRoles();
            return(a);
        }
Ejemplo n.º 3
0
 private void btn_Role_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         Role role = new Role();
         role.ID     = data[comboBox1.SelectedIndex].ID;
         role.Name   = textBox1.Text.Trim();
         role.Flag   = checkBox1.Checked;
         role.Remark = textBox2.Text;
         RoleLogic rl = RoleLogic.GetInstance();
         if (rl.ExistsNameOther(role.Name, role.ID))
         {
             if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
             {
                 if (rl.UpdateRole(role))
                 {
                     data[comboBox1.SelectedIndex].Name   = role.Name;
                     data[comboBox1.SelectedIndex].Flag   = role.Flag;
                     data[comboBox1.SelectedIndex].Remark = role.Remark;
                     RefreshInfo();
                     MessageBox.Show("修改成功!");
                 }
             }
             else
             {
                 textBox1.Focus();
                 textBox1.SelectAll();
             }
         }
         else
         {
             if (rl.UpdateRole(role))
             {
                 data[comboBox1.SelectedIndex].Name   = role.Name;
                 data[comboBox1.SelectedIndex].Flag   = role.Flag;
                 data[comboBox1.SelectedIndex].Remark = role.Remark;
                 RefreshInfo();
                 MessageBox.Show("修改成功!");
             }
         }
     }
     else
     {
         MessageBox.Show("先选定要修改的项目!");
     }
 }
Ejemplo n.º 4
0
        public static List <int> GetRoleIds(string roleids, RoleLogic rl = null)
        {
            List <int> roles = new List <int>();

            string[] ids = roleids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (rl == null)
            {
                rl = RoleLogic.GetInstance();
            }
            foreach (string id in ids)
            {
                int I;
                if (int.TryParse(id, out I))
                {
                    roles.Add(I);
                }
            }
            return(roles);
        }
Ejemplo n.º 5
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         if (MessageBox.Show("确定要删除该项目?", "删除提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         {
             Role role = data[comboBox1.SelectedIndex];
             if (RoleLogic.GetInstance().DeleteRole(role))
             {
                 data.RemoveAt(comboBox1.SelectedIndex);
                 RefreshInfo();
             }
         }
     }
     else
     {
         MessageBox.Show("先选定要删除的项目!");
     }
 }
Ejemplo n.º 6
0
        public List <User> GetAllUsers()
        {
            List <User> users = new List <User>();
            string      sql   = "select * from TF_User";
            DataTable   dt    = sqlHelper.Query(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                DepartmentLogic dl = DepartmentLogic.GetInstance();
                RoleLogic       rl = RoleLogic.GetInstance();
                UserGroupLogic  ul = UserGroupLogic.GetInstance();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    User user = new User();
                    user.ID          = Convert.ToInt32(dt.Rows[i]["ID"]);
                    user.Username    = dt.Rows[i]["Username"].ToString();
                    user.Departments = Common.GetDepartments(dt.Rows[i]["Depart"].ToString(), dl);
                    user.Flag        = Convert.ToInt32(dt.Rows[i]["Flag"]);
                    if (dt.Rows[i]["Password"] != null && dt.Rows[i]["Password"] != DBNull.Value)
                    {
                        user.Password = dt.Rows[i]["Password"].ToString();
                    }
                    else
                    {
                        user.Password = "";
                    }
                    if (dt.Rows[i]["Roles"] != null && dt.Rows[i]["Roles"] != DBNull.Value)
                    {
                        user.Roles = Common.GetRoles(dt.Rows[i]["Roles"].ToString(), rl);
                    }
                    if (dt.Rows[i]["Usergroup"] != null && dt.Rows[i]["Usergroup"] != DBNull.Value)
                    {
                        user.Usergroups = Common.GetUserGroups(dt.Rows[i]["Usergroup"].ToString(), ul);
                    }
                    if (dt.Rows[i]["Remark"] != null && dt.Rows[i]["Remark"] != DBNull.Value)
                    {
                        user.Remark = dt.Rows[i]["Remark"].ToString();
                    }
                    users.Add(user);
                }
            }
            return(users);
        }
Ejemplo n.º 7
0
        public static RoleCollection GetRoles(string roleids, RoleLogic rl = null)
        {
            RoleCollection roles = new RoleCollection();

            string[] ids = roleids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (rl == null)
            {
                rl = RoleLogic.GetInstance();
            }
            foreach (string id in ids)
            {
                int I;
                if (int.TryParse(id, out I))
                {
                    Role role = rl.GetRole(I);
                    roles.Add(role);
                }
            }
            return(roles);
        }
Ejemplo n.º 8
0
        private void button10_Click(object sender, EventArgs e)
        {
            Role role = new Role();

            role.Name   = textBox1.Text.Trim();
            role.Flag   = checkBox1.Checked;
            role.Remark = textBox2.Text;
            RoleLogic rl = RoleLogic.GetInstance();

            if (rl.ExistsName(role.Name))
            {
                if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    int id = rl.AddRole(role);
                    if (id > 0)
                    {
                        role.ID = id;
                        data.Add(role);
                        RefreshInfo();
                        MessageBox.Show("添加成功!");
                    }
                }
                else
                {
                    textBox1.Focus();
                    textBox1.SelectAll();
                }
            }
            else
            {
                int id = rl.AddRole(role);
                if (id > 0)
                {
                    role.ID = id;
                    data.Add(role);
                    RefreshInfo();
                    MessageBox.Show("添加成功!");
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取当前用户拥有的所有权限
        /// </summary>
        public static List <int> GetAllPermissions(this User user)
        {
            List <int> ps      = new List <int>();
            List <int> roleIds = new List <int>();

            foreach (Role role in user.Roles)
            {
                roleIds.Add(role.ID);
            }
            foreach (int r in roleIds)
            {
                Tuple <bool, List <int> > tuple = RoleLogic.GetInstance().GetRoleFlagPermissions(r);
                if (tuple.Item1)
                {
                    foreach (int p in tuple.Item2)
                    {
                        if (!ps.ContainsPermission(p))
                        {
                            ps.Add(p);
                        }
                    }
                }
            }
            foreach (Department d in user.Departments)
            {
                roleIds.Clear();
                foreach (Role role in d.Roles)
                {
                    roleIds.Add(role.ID);
                }
                foreach (int r in roleIds)
                {
                    Tuple <bool, List <int> > tuple = RoleLogic.GetInstance().GetRoleFlagPermissions(r);
                    if (tuple.Item1)
                    {
                        foreach (int p in tuple.Item2)
                        {
                            if (!ps.ContainsPermission(p))
                            {
                                ps.Add(p);
                            }
                        }
                    }
                }
            }
            foreach (UserGroup ug in user.Usergroups)
            {
                roleIds.Clear();
                foreach (Role role in ug.Roles)
                {
                    roleIds.Add(role.ID);
                }
                foreach (int r in roleIds)
                {
                    Tuple <bool, List <int> > tuple = RoleLogic.GetInstance().GetRoleFlagPermissions(r);
                    if (tuple.Item1)
                    {
                        foreach (int p in tuple.Item2)
                        {
                            if (!ps.ContainsPermission(p))
                            {
                                ps.Add(p);
                            }
                        }
                    }
                }
            }
            return(ps);
        }