/// <summary>
        /// 使用遞歸刪除用戶的權限以及下層權限
        /// </summary>
        /// <param name="EmpNo"></param>
        /// <param name="user"></param>
        /// <param name="PrivilegeId"></param>
        /// <param name="Counter"></param>
        /// <param name="DB"></param>
        public void Delete(string EmpNo, C_USER user, string PrivilegeId, ref Int32 Counter, OleExec DB)
        {
            if (user == null)
            {
                List <C_USER> Users = DB.ORM.Queryable <C_USER>().Where(u => u.EMP_NO == EmpNo).ToList();
                if (Users.Count > 0)
                {
                    user = Users.First();
                }
                else
                {
                    return;
                }
            }

            bool exist = DB.ORM.Queryable <C_USER_PRIVILEGE>().Where(up => up.USER_ID == user.ID && up.PRIVILEGE_ID == PrivilegeId).Any();

            if (exist)
            {
                List <C_PRIVILEGE> ChildPrivileges = DB.ORM.Queryable <C_PRIVILEGE, C_MENU, C_PRIVILEGE>((p1, c1, p2) => p1.MENU_ID == c1.PARENT_CODE && c1.ID == p2.MENU_ID)
                                                     .Where((p1, c1, p2) => p1.ID == PrivilegeId).Select((p1, c1, p2) => p2).ToList();
                foreach (C_PRIVILEGE p in ChildPrivileges)
                {
                    Delete(EmpNo, user, p.ID, ref Counter, DB);
                }
                Counter += DB.ORM.Deleteable <C_USER_PRIVILEGE>().Where(up => up.USER_ID == user.ID && up.PRIVILEGE_ID == PrivilegeId).ExecuteCommand();
            }
        }
Exemple #2
0
        /// <summary>
        /// 給用戶添加角色,并且根據前端選擇是否可以編輯角色將 C_USER 中的 EMP_LEVEL 值改變(改變 C_USER 中的 EMP_LEVEL 我覺得沒必要)
        /// </summary>
        /// <param name="EmpNo"></param>
        /// <param name="RoleId"></param>
        /// <param name="LevelFlag"></param>
        /// <param name="BuName"></param>
        /// <param name="UserName"></param>
        /// <param name="SystemName"></param>
        /// <param name="DB"></param>
        /// <returns></returns>
        public int Add(string EmpNo, string RoleId, string LevelFlag, string BuName, string UserName, string SystemName, OleExec DB)
        {
            List <C_USER> users = DB.ORM.Queryable <C_USER>().Where(u => u.EMP_NO == EmpNo).ToList();
            int           i     = 0;

            if (users.Count > 0)
            {
                //插入到 C_USER_ROLE 中
                C_USER u     = users.First();
                bool   exist = DB.ORM.Queryable <C_USER_ROLE>().Where(ur => ur.USER_ID == u.ID && ur.ROLE_ID == RoleId).Any();
                if (!exist)
                {
                    i += DB.ORM.Insertable <C_USER_ROLE>(new C_USER_ROLE()
                    {
                        ID           = GetNewID(BuName, DB),
                        USER_ID      = u.ID,
                        ROLE_ID      = RoleId,
                        SYSTEM_NAME  = SystemName,
                        EDIT_TIME    = GetDBDateTime(DB),
                        EDIT_EMP     = UserName,
                        OPERATE_FLAG = LevelFlag
                    }).ExecuteCommand();

                    //更新 C_USER 表中的 EMP_LEVEL
                    u.EMP_LEVEL = LevelFlag;
                    u.EDIT_EMP  = UserName;
                    u.EDIT_TIME = GetDBDateTime(DB);
                    i          += DB.ORM.Updateable <C_USER>(u).Where(t => t.ID == u.ID).ExecuteCommand();
                }
            }
            return(i);
        }
        /// <summary>
        /// 使用遞歸給用戶添加權限以及上層權限
        /// </summary>
        /// <param name="EmpNo"></param>
        /// <param name="user"></param>
        /// <param name="PrivilegeId"></param>
        /// <param name="Bu"></param>
        /// <param name="SystemName"></param>
        /// <param name="EditEmp"></param>
        /// <param name="Counter"></param>
        /// <param name="DB"></param>
        public void Add(string EmpNo, C_USER user, string PrivilegeId, string Bu, string SystemName, string EditEmp, ref Int32 Counter, OleExec DB)
        {
            if (user == null)
            {
                List <C_USER> Users = DB.ORM.Queryable <C_USER>().Where(u => u.EMP_NO == EmpNo).ToList();
                if (Users.Count > 0)
                {
                    user = Users.First();
                }
                else
                {
                    return;
                }
            }

            bool exist = DB.ORM.Queryable <C_USER_PRIVILEGE>().Where(up => up.USER_ID == user.ID && up.PRIVILEGE_ID == PrivilegeId).Any();

            if (!exist)
            {
                List <C_PRIVILEGE> ParentPrivileges = DB.ORM.Queryable <C_PRIVILEGE, C_MENU, C_PRIVILEGE>((p1, c1, p2) => p1.MENU_ID == c1.ID && c1.PARENT_CODE == p2.MENU_ID)
                                                      .Where((p1, c1, p2) => p1.ID == PrivilegeId).Select((p1, c1, p2) => p2).ToList();
                foreach (C_PRIVILEGE p in ParentPrivileges)
                {
                    Add(EmpNo, user, p.ID, Bu, SystemName, EditEmp, ref Counter, DB);
                }
                C_USER_PRIVILEGE up = new C_USER_PRIVILEGE()
                {
                    ID           = GetNewID(Bu, DB),
                    USER_ID      = user.ID,
                    PRIVILEGE_ID = PrivilegeId,
                    SYSTEM_NAME  = SystemName,
                    EDIT_TIME    = GetDBDateTime(DB),
                    EDIT_EMP     = EditEmp
                };
                Counter += DB.ORM.Insertable <C_USER_PRIVILEGE>(up).ExecuteCommand();
                //Counter +=DB.ORM.Insertable(up).ExecuteCommand();
            }
        }