예제 #1
0
        /// <summary>
        /// 填充数据,获取报表
        /// </summary>
        /// <param name="workId">机构ID</param>
        /// <param name="reportNo">报表的编码</param>
        /// <param name="printerIndex">打印机索引</param>
        /// <param name="para">报表参数</param>
        /// <param name="datasource">报表数据源</param>
        /// <returns></returns>
        public static GridReport GetReport(int workId, int reportNo, int printerIndex, Dictionary <string, Object> para, DataTable datasource)
        {
            //判断服务器没有报表则创建空报表
            //判断本地没有报表文件则下载报表
            //验证本机报表文件的修改时间与服务器上时间对比,如果小于服务器上时间则下载替换本地报表
            DataRow[] drs = reportData.Select(String.Format("EnumValue={0} and WorkID={1}", reportNo, workId));
            if (drs.Length == 0)//服务器不存在此报表
            {
                MessageBox.Show("请先在报表配置界面增加【" + reportNo + "】此编号的报表!");
                return(new GridReport());
            }
            else
            {
                int      reportID    = Convert.ToInt32(drs[0]["ID"]);
                string   reportFile  = drs[0]["FileName"].ToString();
                DateTime updateTime  = Convert.ToDateTime(Convert.ToDateTime(drs[0]["UpdateTime"]).ToString("yyyy-MM-dd HH:ss:mm"));
                string   _reportFile = EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + @"Report\\" + reportFile;
                if (File.Exists(_reportFile) == false)//本地没有报表文件,下载报表文件
                {
                    Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                    {
                        request.AddData(reportID);
                    });
                    ServiceResponseData retdata = InvokeWcfService("MainFrame.Service", "ReportController", "GetReportFile", requestAction);
                    byte[] data = retdata.GetData <byte[]>(0);
                    using (FileStream fsWrite = new FileStream(_reportFile, FileMode.Create))
                    {
                        fsWrite.Write(data, 0, data.Length);
                    }

                    UpgradeFileConfigManager.AddReport(reportFile, updateTime);

                    return(GetReport(reportFile, printerIndex, para, datasource));
                }
                else//有报表文件
                {
                    //判断文件修改时间
                    if (UpgradeFileConfigManager.GetReportUpdateTime(reportFile) == null || UpgradeFileConfigManager.GetReportUpdateTime(reportFile) < updateTime)//小于服务更新时间,则下载报表文件
                    {
                        File.Delete(_reportFile);
                        Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                        {
                            request.AddData(reportID);
                        });
                        ServiceResponseData retdata = InvokeWcfService("MainFrame.Service", "ReportController", "GetReportFile", requestAction);
                        byte[] data = retdata.GetData <byte[]>(0);
                        using (FileStream fsWrite = new FileStream(_reportFile, FileMode.Create))
                        {
                            fsWrite.Write(data, 0, data.Length);
                        }
                        UpgradeFileConfigManager.AddReport(reportFile, updateTime);
                        return(GetReport(reportFile, printerIndex, para, datasource));
                    }
                    else//等于或者大于服务更新时间
                    {
                        return(GetReport(reportFile, printerIndex, para, datasource));
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 验证报表文件
        /// </summary>
        /// <param name="id">报表ID</param>
        /// <param name="filename">文件吗</param>
        /// <param name="reportfile">输出报表文件</param>
        /// <param name="updatetime">修改时间</param>
        /// <returns>true:验证通过</returns>
        private bool verifyReport(out int id, out string filename, out string reportfile, out DateTime updatetime)
        {
            DataTable          dt     = gridReport.DataSource as DataTable;
            Basic_ReportConfig report = EFWCoreLib.CoreFrame.Common.ConvertExtend.ToObject <Basic_ReportConfig>(dt, gridReport.CurrentCell.RowIndex);

            id         = report.ID;
            filename   = string.IsNullOrEmpty(report.FileName) ? (report.EnumValue + "." + report.ReportTitle + ".grf") : report.FileName;
            reportfile = EFWCoreLib.CoreFrame.Init.AppGlobal.AppRootPath + @"Report\\" + filename;
            updatetime = report.UpdateTime.AddMinutes(1);

            //1.创建空报表
            //2.本地没有报表从服务器上下载报表
            if (File.Exists(reportfile) == false)
            {
                if (string.IsNullOrEmpty(report.FileName))
                {
                    if (MessageBox.Show("该报表没有对应的报表文件,是否生成一张空报表?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
                    {
                        return(false);
                    }
                    else
                    {
                        //生成空报表
                        createEmptyReport(reportfile);
                        UpgradeFileConfigManager.AddReport(filename, updatetime);
                        MessageBoxShowSimple("空报表创建成功!");
                        return(true);
                    }
                }
                else
                {
                    if (MessageBox.Show("本地没有该报表文件,是否从服务器上下载此报表文件?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
                    {
                        return(false);
                    }
                    else
                    {
                        InvokeController("GetReportFile", id, filename, reportfile, updatetime);
                        return(true);
                    }
                }
            }

            //3.本地报表的没有服务器上报表
            if (UpgradeFileConfigManager.GetReportUpdateTime(filename) == null || UpgradeFileConfigManager.GetReportUpdateTime(filename) < report.UpdateTime)
            {
                //小于服务更新时间,则下载报表文件
                if (MessageBox.Show("该报表文件服务器上有最新版本,是否从服务器上下载此报表文件?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
                {
                    return(false);
                }
                else
                {
                    InvokeController("GetReportFile", id, filename, reportfile, updatetime);
                    return(true);
                }
            }

            return(true);
        }
예제 #3
0
 /// <summary>
 /// 设计报表
 /// </summary>
 /// <param name="sender">控件</param>
 /// <param name="e">参数</param>
 private void btnDesReport_Click(object sender, EventArgs e)
 {
     if (gridReport.CurrentCell != null)
     {
         int      id;
         string   filename;
         string   reportfile;
         DateTime updateTime;
         if (verifyReport(out id, out filename, out reportfile, out updateTime))
         {
             //设计报表文件
             UpgradeFileConfigManager.AddReport(filename, updateTime);
             System.Diagnostics.Process.Start(reportfile);
         }
     }
 }
예제 #4
0
 /// <summary>
 /// 上传报表
 /// </summary>
 /// <param name="sender">控件</param>
 /// <param name="e">参数</param>
 private void btnUpload_Click(object sender, EventArgs e)
 {
     if (gridReport.CurrentCell != null)
     {
         int      id;
         string   filename;
         string   reportfile;
         DateTime updateTime;
         if (verifyReport(out id, out filename, out reportfile, out updateTime))
         {
             if (MessageBox.Show("是否将该报表本地的报表文件上传到服务器?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
             {
                 InvokeController("UploadReportFile", id, filename, reportfile, updateTime);
                 UpgradeFileConfigManager.AddReport(filename, updateTime);
                 InvokeController("GetReportData", getWorkId, getSysType, txtSearchChar.Text);
             }
         }
     }
 }
예제 #5
0
        public void GetReportFile(int id, string filename, string reportfile, DateTime updateTime)
        {
            var retdata = InvokeWcfService(
                "BaseProject.Service",
                "ReportController",
                "GetReportFile",
                (request) =>
            {
                request.AddData(id);
            });

            byte[] data = retdata.GetData <byte[]>(0);
            using (FileStream fsWrite = new FileStream(reportfile, FileMode.Create))
            {
                fsWrite.Write(data, 0, data.Length);
            }

            UpgradeFileConfigManager.AddReport(filename, updateTime);

            MessageBoxShowSimple("报表文件下载完成!");
        }