rdlc报表 矩阵控件下的按组分页

场景:
使用rdlc开发报表,例如订单产品报表,显示多个订单,一个订单有动态生成的固定的多个产品组成,同时统计每个订单里多个产品数量总数。
数据库层面分析:
此报表属于交叉报表,例如5个订单,3个产品,总共的数据库记录应该为15条,而不是5条。
 
存在的技术难点:
(1)动态列生成
使用Matrix矩阵控件
(2)统计每个订单里多个产品数量总数
确保每个订单的第一条数据是正确的,第二条或第三条数据为NULL都没关系
(3)控制每页显示33条记录,而不是通过默认的高度来控制分页
(4)由于是使用矩阵控件,所以分页下序列号需从数据库中控制好
 
最终完成的效果:
 
(1)数据库方面:
  1 --Finally page procedure

  2 create procedure RP_BIREPORTSO

  3     @year INT,

  4     @month INT

  5 as

  6 begin

  7     WITH table_group AS (

  8         SELECT ROW_NUMBER() OVER(ORDER BY a.item_id) num_groupby,

  9                a.item_id

 10         FROM   (

 11                    SELECT wite.item_id,

 12                    wite.create_datetime

 13                    FROM   (

 14                               SELECT waus.user_id,

 15                                      waac.action_id

 16                               FROM   ws_account_action waac

 17                                      JOIN ws_account_user waus

 18                                           ON  waac.ws_uid = waus.ws_uid

 19                               WHERE  waac.parent_action_id IS NULL

 20                                      AND waac.ws_action_type = 'BI'

 21                                      AND waac.the_year = @year

 22                                      AND waac.the_month = @month

 23                           ) AS waac

 24                           JOIN (

 25                                    SELECT wite.item_id,

 26                                           ware.action_id,

 27                                           wite.create_datetime

 28                                    FROM   ws_account_request ware

 29                                           LEFT JOIN ws_item wite

 30                                                ON  ware.item_id = wite.item_id

 31                                    WHERE  wite.enable_flg = 1

 32                                    

 33                                ) AS wite

 34                                ON  wite.action_id = waac.action_id

 35                    UNION

 36                    SELECT wite.item_id,

 37                    wite.create_datetime

 38                    FROM   ws_item wite,

 39                           (

 40                               SELECT waus.user_id

 41                               FROM   ws_account_action waac

 42                                      JOIN ws_account_user waus

 43                                           ON  waac.ws_uid = waus.ws_uid

 44                               WHERE  waac.parent_action_id IS NULL

 45                                      AND waac.ws_action_type = 'BI'

 46                                      AND waac.the_year = @year

 47                                      AND waac.the_month = @month

 48                                      AND waac.action_id NOT IN (SELECT DISTINCT 

 49                                                                        action_id

 50                                                                 FROM   

 51                                                                        ws_account_request)

 52                           ) AS waac

 53                    WHERE  wite.enable_flg = 1

 54                    

 55                ) a

 56         GROUP BY

 57                a.item_id

 58     )

 59     --Union exist relation data and other need display data

 60     SELECT 

 61             tg.num_groupby,

 62             alldata.item_id,

 63            alldata.ledge_folio,

 64            alldata.item_desc_en,

 65            alldata.unit,

 66            alldata.create_datetime,

 67            alldata.quantity_issued_count,

 68            alldata.user_id,

 69            alldata.quantity_issued_total

 70            

 71     FROM   (

 72                SELECT wite.item_id,

 73                       wite.ledge_folio,

 74                       wite.item_desc_en,

 75                       wite.unit,

 76                       wite.create_datetime,

 77                       wite.approved_qty AS quantity_issued_count,

 78                       waac.user_id,

 79                       (

 80                           SELECT SUM(ware2.approved_qty)

 81                           FROM   ws_account_request ware2

 82                                  LEFT JOIN ws_item wite2

 83                                       ON  ware2.item_id = wite2.item_id

 84                           WHERE  wite2.enable_flg = 1

 85                                  AND wite2.item_id = wite.item_id

 86                           GROUP BY

 87                                  wite2.item_id

 88                       ) AS quantity_issued_total

 89                FROM   (

 90                           SELECT waus.user_id,

 91                                  waac.action_id

 92                           FROM   ws_account_action waac

 93                                  JOIN ws_account_user waus

 94                                       ON  waac.ws_uid = waus.ws_uid

 95                           WHERE  waac.parent_action_id IS NULL

 96                                  AND waac.ws_action_type = 'BI'

 97                                  AND waac.the_year = @year

 98                                  AND waac.the_month = @month

 99                       ) AS waac

100                       JOIN (

101                                SELECT wite.item_id,

102                                       wite.ledge_folio,

103                                       wite.item_desc_en,

104                                       wite.unit,

105                                       wite.create_datetime,

106                                       ware.approved_qty,

107                                       ware.action_id

108                                FROM   ws_account_request ware

109                                       LEFT JOIN ws_item wite

110                                            ON  ware.item_id = wite.item_id

111                                WHERE  wite.enable_flg = 1

112                            ) AS wite

113                            ON  wite.action_id = waac.action_id

114                UNION

115                SELECT wite.item_id,

116                       wite.ledge_folio,

117                       wite.item_desc_en,

118                       wite.unit,

119                       wite.create_datetime,

120                       0 AS quantity_issued_count,

121                       waac.user_id,

122                       (

123                           SELECT SUM(ware2.approved_qty)

124                           FROM   ws_account_request ware2

125                                  LEFT JOIN ws_item wite2

126                                       ON  ware2.item_id = wite2.item_id

127                           WHERE  wite2.enable_flg = 1

128                                  AND wite2.item_id = wite.item_id

129                                  and waac.action_id = ware2.action_id

130                           GROUP BY

131                                  wite2.item_id

132                       ) AS quantity_issued_total

133                FROM   ws_item wite,

134                       (

135                           SELECT waus.user_id,waac.action_id

136                           FROM   ws_account_action waac

137                                  JOIN ws_account_user waus

138                                       ON  waac.ws_uid = waus.ws_uid

139                           WHERE  waac.parent_action_id IS NULL

140                                  AND waac.ws_action_type = 'BI'

141                                  AND waac.the_year = @year

142                                  AND waac.the_month = @month

143                                  AND waac.action_id NOT IN (SELECT DISTINCT 

144                                                                    action_id

145                                                             FROM   

146                                                                    ws_account_request)

147                       ) AS waac

148                WHERE  wite.enable_flg = 1

149            ) alldata

150            LEFT JOIN table_group tg

151                 ON  alldata.item_id = tg.item_id

152 end

153 go

SQL查询结果:

 
(2)rdlc报表配置方面:
  • 矩阵控件
  • 添加分组,分组表达式控制分页
  • rdlc内置函数的使用
    =IIF(Fields!quantity_issued_count.Value <> 0,Fields!quantity_issued_count.Value,"---")
    =IIf(IsNothing(Fields!quantity_issued_total.Value),0,Fields!quantity_issued_total.Value)

你可能感兴趣的:(分页)