• 葡萄城报表-核心代码展示


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Text;
    using GrapeCity.ActiveReports;
    using RMMIS.StorageManagerMod.GetMaterialMod.BLL;
    using RMMIS.StorageManagerMod.SendMaterialMod.BLL;
    using Frame.DataMiddleware.Common;
    using Frame.Common;
    public partial class Report_BillPrint : System.Web.UI.Page
    {
        public string billtype = string.Empty;
        public string billcode = string.Empty;
    
        public DataTable mainDt;
        public DataTable detailDt;
    
        private BLLRmstorGiveMatlDt _BllRmstorGiveMatlDt;
        private BLLRmstorGiveMatlMt _BllRmstorGiveMatlMt;
        private BLLRmstorReceiveMatlDt _BllRmstorReceiveMatlDt;
        private BLLRmstorReceiveMatlMt _BllRmstorReceiveMatlMt;
    
        GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
        GrapeCity.ActiveReports.SectionReport rpt1 = new GrapeCity.ActiveReports.SectionReport();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            ConnectionUtil.SetConnectionString(System.Configuration.ConfigurationManager.AppSettings["OracleSys"]);
            //初始化BLL		
            _BllRmstorGiveMatlDt = SpringUtil.get("BLLRmstorGiveMatlDt") as BLLRmstorGiveMatlDt;
            _BllRmstorGiveMatlMt = SpringUtil.get("BLLRmstorGiveMatlMt") as BLLRmstorGiveMatlMt;
            _BllRmstorReceiveMatlDt = SpringUtil.get("BLLRmstorReceiveMatlDt") as BLLRmstorReceiveMatlDt;
            _BllRmstorReceiveMatlMt = SpringUtil.get("BLLRmstorReceiveMatlMt") as BLLRmstorReceiveMatlMt;
    
    
            billtype = Request.QueryString["BillType"];
            billcode = Request.QueryString["BillCode"];
    
            string[] codelength = billcode.Split(',');
    
            // 创建用于合并全部报表的主报表
            report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("rdlx//Temp1.rdlx")));
           
           
            #region 页面报表
    
            // 在主报表中循环加载全部子报表
            for (int i = 1; i <= codelength.Length; i++)
            {
                // 创建 Container 控件,用户加载 Subreport 控件
                GrapeCity.ActiveReports.PageReportModel.Container container = new GrapeCity.ActiveReports.PageReportModel.Container();
                container.Name = string.Format("Container{0}", i);
                container.Width = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("1cm");
                container.Height = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("1cm");
                container.Left = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("0cm");
                container.Top = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length((1 * (i - 1)).ToString() + "cm");
                container.PageBreakAtEnd = true;
                container.PageBreakAtStart = false;
    
                // 创建 Subreport 控件,用户加载实际报表模板
                GrapeCity.ActiveReports.PageReportModel.Subreport subreport = new GrapeCity.ActiveReports.PageReportModel.Subreport();
                subreport.Name = string.Format("SubReport{0}", i);
                subreport.Width = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("1cm");
                subreport.Height = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("1cm");
                subreport.Left = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("0cm");
                subreport.Top = new GrapeCity.ActiveReports.Extensibility.Definition.Components.Length("0cm");
                GrapeCity.ActiveReports.PageReportModel.Parameter pid = new GrapeCity.ActiveReports.PageReportModel.Parameter();
                pid.Name = "billcode";
                pid.Value = codelength[i-1].ToString();
                subreport.Parameters.Add(pid);
                //如果是收料单
                if (billtype == RMMIS.Common.BillType.SLD)
                {
                    subreport.ReportName = "IBMTFormNew.rdlx";
                }
                //如果是出库单
                if (billtype == RMMIS.Common.BillType.RKD)
                {
                    subreport.ReportName = "IBMTFormNew.rdlx";
                }
                container.ReportItems.Add(subreport);
    
                report.Report.Body.ReportItems.Add(container);
            }
    
            report.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(pageDocument_LocateDataSource);
    
            WebViewer1.Report = report;
            #endregion
        }
        private void pageDocument_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
        {
            //查询数据
            //GetDataSource((string)args.Report.Parameters[0].Values[0].Value,ref mainDt,ref detailDt); 
            string type = string.Empty;
            if (args.DataSetName == "DataMain")
            {
                type = "main";
                GetDataSource((string)args.Report.Parameters[0].Values[0].Value, type, ref mainDt);
                args.Data = mainDt;
            }
    
            if (args.DataSetName == "DataDetail")
            {
                type = "detail";
                GetDataSource((string)args.Report.Parameters[0].Values[0].Value, type, ref detailDt);
                args.Data = detailDt;
            }
    
    
        }
        private DataTable GetDataSource(string billCode, string type, ref DataTable dt)
        {
            //如果是收料
            if (billtype == RMMIS.Common.BillType.SLD)
            {
                if (type == "main")
                {
                    dt = _BllRmstorReceiveMatlMt.GetBillReceiveMt(billCode);
                }
                else
                {
                    dt = _BllRmstorReceiveMatlDt.GetBillReceiveDt(billCode);
                }
               
            }
            return dt;
        }
    
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //#region 页面报表支持
            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //// Provide settings for your rendering output.
            //GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings
            //excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
            //excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
            ////excelSetting.MultiSheet = false;
            //GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;
            ////Set the rendering extension and render the report.
            //GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension
            //excelRenderingExtension = new
            //GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
            //GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
            //report.Document.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
            //Response.ContentType = "application/vnd.ms-excel";
            //Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
            //outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
            //Response.BinaryWrite(ms.ToArray());
            //Response.End();
           
            GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
            XlsExport1.Export(report.Document, ms);
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=MyExport.xlsx"));
            Response.BinaryWrite(ms.ToArray());
            Response.End();
        }
    }

  • 相关阅读:
    【PC Basic】CPU、核、多线程的那些事儿
    为什么要使用 do while(0)?
    DPDK CAS(compare and set)操作
    编程中Foo,Bar 到底是什么意思
    如何用Python进行ARP攻击?
    有哪些有趣的化学方程式?
    1636. 按照频率将数组升序排序
    1046. 最后一块石头的重量
    1122. 数组的相对排序
    459. 重复的子字符串
  • 原文地址:https://www.cnblogs.com/xzpblog/p/5117901.html
Copyright © 2020-2023  润新知