Esempio n. 1
0
        /// <summary>
        /// GetTreeGrid 获取权限目录树(新)
        /// 2017-04-18  Tim  Add
        /// </summary>
        /// <param name="privilegeMaster">权限分类1角色,2用户</param>
        /// <param name="privilegeValue">权限值</param>
        /// <param name="gridParams">gird参数</param>
        /// <returns></returns>
        public DataTable GetTreeGrid(string parentId, int privilegeMaster, string privilegeValue, ref GridParams gridParams)
        {
            var pageParam = Mapper.Map <GridParams, PageParam>(gridParams);

            if (string.IsNullOrEmpty(pageParam.PrimaryKey))
            {
                pageParam.PrimaryKey = "Program_ID";
            }

            if (string.IsNullOrEmpty(pageParam.Order))
            {
                pageParam.Order = " Rn, Program_ID ";
            }
            else if (string.IsNullOrEmpty(pageParam.Order.Trim()))
            {
                pageParam.Order = " Rn, Program_ID ";
            }

            pageParam.PreSql = string.Format(@" WITH P AS ( SELECT   Program_ID ,
                        Parent_ID ,
                        Program_Name ,
                        1 AS Access_Master ,
                        PR.Privilege_ID AS Checked ,
                        PR.Branch_Member ,
                        PR.Operation_ID ,
                        PR.Valid_From,
                        PR.Valid_Until,
                        Is_Identity
               FROM     tbLOG_Program P
                        LEFT JOIN dbo.tbLOG_Privilege PR ON PR.Access_Value = P.Program_ID
                                                            AND PR.Access_Master = 1
                                                            AND PR.Privilege_Master = @privilegeMaster
                                                            AND PR.Privilege_Value = @privilegeValue
               WHERE    P.Status_Flag = 0
                        AND P.Is_Visible = 0
                        AND P.Parent_ID <> 0 {0}) ", string.IsNullOrEmpty(parentId)?"": " AND P.Parent_ID = @parentId");

            pageParam.TableName = @"(SELECT  Program_ID ,
                        Program_Name ,
                        1 AS Access_Master ,
                        0 AS _parentId ,
                        Checked ,
                        Branch_Member ,
                        Operation_ID ,
                        CONVERT(VARCHAR(12), Valid_From) Valid_From ,
                        CONVERT(VARCHAR(12), Valid_Until) Valid_Until,
                        Is_Identity,
                        Program_ID as Rn
                FROM    P
                UNION
                SELECT  Program_Button_ID AS Program_ID ,
                        Button_Text AS Program_Name ,
                        2 AS Access_Master ,
                        PB.Program_ID AS _parentId ,
                        P.Privilege_ID AS Checked ,
                        0 AS Branch_Member ,
                        Operation_ID ,
                        CONVERT(VARCHAR(12), Valid_From) Valid_From,
                        CONVERT(VARCHAR(12), Valid_Until) Valid_Until,
                        Is_Identity,
                        PB.Program_ID as Rn
                FROM    dbo.tbLOG_Program_Button PB
                        INNER JOIN dbo.tbLOG_Button B ON B.Button_ID = PB.Button_ID
                        LEFT JOIN dbo.tbLOG_Privilege P ON P.Access_Value = PB.Program_Button_ID
                                                           AND P.Access_Master = 2
                                                           AND P.Privilege_Master = @privilegeMaster
                                                           AND P.Privilege_Value = @privilegeValue
                WHERE   PB.Program_ID IN ( SELECT   Program_ID
                                           FROM     P )) AS TEMP ";

            pageParam.SqlParamList = new List <SqlParameter>()
            {
                new SqlParameter("@privilegeMaster", privilegeMaster),
                new SqlParameter("@privilegeValue", privilegeValue)
            };

            if (!string.IsNullOrEmpty(parentId))
            {
                pageParam.SqlParamList.Add(new SqlParameter("@parentId", int.Parse(parentId)));
            }

            var dt = DbHelperSql.QueryByPage(ref pageParam);

            gridParams.TotalCount = pageParam.TotalCount;

            return(dt);
        }