BaseReportForm 为用户展现RDLC报表
个人开发框架总结(五)

    及报表打印
个人开发框架总结(五)

    属性
    UseDefaultConfigFile:使用默认的配置文件
    QueryConfigFile:指定查询配置文件
    PrintConfigFile:指定打印配置文件

    重载方法
    QuerySetTypeListData
    QuerySetTypeTreeData

    报表配置可在Config下建立 窗体类名.pcs 文件:

配置文件(Config/*.rps)
<ReportConfig>
  <Title> 报表标题
  <ColumnConfigFile> 使用的*.cls配置文件名
  <PaperSize>
    <Height> 高
    <Width> 宽
  </PaperSize>
  <Margins>
     <Left> 左边距
     <Top> 顶边距
     <Right> 右边距
     <Bottom> 底边距
  </Margins>
  <Landscape> 是否横向打印
  <DataColumns />
  <Header>
    <Objects>
      <Label>
        <Text> 标题
        <HAlign> 对齐
        <AutoCenter> 是否自动居中
        <AutoRight> 是否自动居右
        <VAlign> 垂直对齐
        <Font>
          <Name> 字体
          <Size> 大小
        </Font>
        <Key> 对象名称
        <Location>
          <X> 左
          <Y> 右
        </Location>
        <Size>
          <Width> 宽
          <Height> 高
        </Size>
      </Label>
    </Objects>
    <Height> 高度
  </Header>
  <Footer>
    <Height> 高度
    <Objects>
    </Objects>
  </Footer>
</ReportConfig>

    这里分两节,Header和Footer,每个节的Objects里可建立多个Label对象,使用不同的Key以便在程序里可以使用FindControl来查找,AutoCenter 属性指的是,标签居于报表表格的中间,AutoRight 是居右。ColumnConfigFile 引用的是对应的*.cls 文件,如:


  <Title>消费明细报表</Title>
  
<ColumnConfigFile>frmConsumeDetailReport</ColumnConfigFile>
  
<PaperSize>
    
<Height>21</Height>
    
<Width>29.7</Width>
  
</PaperSize>
  
<Margins>
     
<Left>0.5</Left>
     
<Top>0.5</Top>
     
<Right>0.5</Right>
     
<Bottom>0.5</Bottom>
  
</Margins>
  
<Landscape>false</Landscape>
  
<DataColumns />
  
<Header>
    
<Objects>
      
<Label>
        
<Text></Text>
        
<HAlign>Center</HAlign>
        
<AutoCenter>True</AutoCenter>
        
<VAlign>Middle</VAlign>
        
<Font>
          
<Name>黑体</Name>
          
<Size>15</Size>
        
</Font>
        
<Key>Company</Key>
        
<Location>
          
<X>0</X>
          
<Y>0.2</Y>
        
</Location>
        
<Size>
          
<Width>0</Width>
          
<Height>0.6</Height>
        
</Size>
      
</Label>
      
<Label>
        
<Text></Text>
        
<HAlign>Center</HAlign>
        
<AutoCenter>True</AutoCenter>
        
<VAlign>Middle</VAlign>
        
<Font>
          
<Name>黑体</Name>
          
<Size>15</Size>
        
</Font>
        
<Key>Title</Key>
        
<Location>
          
<X>0</X>
          
<Y>0.8</Y>
        
</Location>
        
<Size>
          
<Width>0</Width>
          
<Height>0.6</Height>
        
</Size>
      
</Label>
      
<Label>
        
<Text>操作员:{0}</Text>
        
<HAlign>Left</HAlign>
        
<VAlign>Middle</VAlign>
        
<Key>Employee</Key>
        
<Location>
          
<X>0</X>
          
<Y>1.4</Y>
        
</Location>
        
<Size>
          
<Width>5</Width>
          
<Height>0.6</Height>
        
</Size>
      
</Label>
      
<Label>
        
<Text>="打印日期:" + Today.ToString("D")</Text>
        
<HAlign>Right</HAlign>
        
<AutoRight>True</AutoRight>
        
<VAlign>Middle</VAlign>
        
<Key>PrintDate</Key>
        
<Location>
          
<X>0</X>
          
<Y>1.4</Y>
        
</Location>
        
<Size>
          
<Width>5</Width>
          
<Height>0.6</Height>
        
</Size>
      
</Label>
    
</Objects>
    
<Height>2</Height>
  
</Header>
  
<Footer>
    
<Height>0.7</Height>
    
<Objects>
      
<Label>
        
<Text>="第" &amp; Globals!PageNumber &amp; "页 共" &amp; Globals!TotalPages &amp; "页"</Text>
        
<HAlign>Right</HAlign>
        
<AutoRight>True</AutoRight>
        
<VAlign>Middle</VAlign>
        
<Key>Page</Key>
        
<Location>
          
<X>0</X>
          
<Y>0.1</Y>
        
</Location>
        
<Size>
          
<Width>5</Width>
          
<Height>0.4</Height>
        
</Size>
      
</Label>
    
</Objects>
  
</Footer>
</ReportConfig>

    在代码里,可以重写SetReportConfig方法来设置报表标签的文本:

        /// 设置报表配置
        
/// </summary>
        
/// <param name="config"></param>
        protected override void SetReportConfig(FaibClass.Common.Windows.Config.ReportConfig config)
        {
            
base.SetReportConfig(config);
            
object lbl = config.Header.FindObject("Company");
            
if (lbl != null)
            {
                ((FaibClass.Common.Windows.Report.ReportLabel)lbl).Text 
= ContextArgs.Instance.CompanyName;
            }
            lbl 
= config.Header.FindObject("Employee");
            
if (lbl != null)
            {
                
string text = ((FaibClass.Common.Windows.Report.ReportLabel)lbl).Text;
                ((FaibClass.Common.Windows.Report.ReportLabel)lbl).Text 
= string.Format(text, ContextArgs.Instance.UserName);
            }
        }

    如果报表使用查询,也要建立相应的*.pcs文件。

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2021-05-05
  • 2021-08-17
  • 2021-07-09
  • 2021-06-14
  • 2021-05-28
  • 2021-08-05
猜你喜欢
  • 2021-06-04
  • 2021-06-28
  • 2021-09-15
  • 2021-12-30
  • 2021-10-01
  • 2021-08-12
  • 2021-12-06
相关资源
相似解决方案