Exemplo n.º 1
0
        /// <summary>
        /// 更新本地报表以及参数
        /// </summary>
        /// <param name="lReportTemplateID"></param>
        public static void ResetLocalReport(long lReportTemplateID, DataSet dsSource, DataRow drRecord)
        {
            DataTable dtReportTemplateConfig = ReportHelper.GetReportTemplateByID(lReportTemplateID);

            if (dtReportTemplateConfig.Rows.Count == 0)
            {
                return;
            }
            DataRow drReportTemplateConfig = dtReportTemplateConfig.Rows[0];

            byte[]   reportTempleData         = (byte[])drReportTemplateConfig["TemplateData"];
            long     lReportTypeID            = Convert.ToInt64(drReportTemplateConfig["ReportTypeID"]);
            DateTime dtTemplateFileTime       = DateTime.Parse(drReportTemplateConfig["TemplateFileTime"].ToString());
            string   strReportTemplateName    = drReportTemplateConfig["ReportTemplateName"].ToString().Trim();
            string   strReportTemplateNameExt = drReportTemplateConfig["ReportTemplateNameExt"].ToString().Trim();
            //检测本地是否存在报表文件,如果不存在或者与服务器比本地文件新时更新本地文件
            string strFileFullName = WriteReportWithCheck(lReportTemplateID, strReportTemplateName, dtTemplateFileTime, reportTempleData, strReportTemplateNameExt);

            ReportRequestArgs args = new ReportRequestArgs(lReportTemplateID, lReportTypeID, dsSource, drRecord);

            using (FastReport.Report report = new FastReport.Report())
            {
                report.Load(strFileFullName);
                BuildParmsAndData(args, report, enBuildParmsAndDataActionType.ReSet);
                report.Save(strFileFullName);
                File.SetLastWriteTime(strFileFullName, DateTime.Now);
            }
        }
Exemplo n.º 2
0
        private void BtnReportViewSingle_Click(object sender, EventArgs e)
        {
            try
            {
                DataRow dr = null;
                long    lReportTemplateID = 0;
                long    lReportTypeID     = 0;
                if (sender is LBToolStripReportViewButton)
                {
                    LBToolStripReportViewButton btnViewReport = sender as LBToolStripReportViewButton;
                    dr = btnViewReport.Tag as DataRow;
                    lReportTemplateID = Convert.ToInt64(dr["ReportTemplateID"]);
                    lReportTypeID     = Convert.ToInt64(dr["ReportTypeID"]);
                }

                ReportRequestArgs args = new Report.ReportRequestArgs(lReportTemplateID, lReportTypeID, null, null);
                OnReportRequest(args);
                if (args.DSDataSource == null && args.RecordDR == null)
                {
                    LB.WinFunction.LBCommonHelper.ShowCommonMessage("未设置数据源,编辑报表失败!");
                }
                else
                {
                    ReportHelper.OpenReportDialog(enRequestReportActionType.Preview, args);
                }
            }
            catch (Exception ex)
            {
                LB.WinFunction.LBCommonHelper.DealWithErrorMessage(ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 预览报表
        /// </summary>
        public static void OpenReportDialog(enRequestReportActionType eActionType, ReportRequestArgs reportRequestArgs)
        {
            ProcessStep.AddStep("OpenReportDialog_Start", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
            //DataRow drReportTemplateConfig = GetReportTemplateRow(reportRequestArgs.ReportTemplateID);
            int iPrintCount = 1;

            DataTable dtReport = ReportHelper.GetReportTemplateByID4Print(reportRequestArgs.ReportTemplateID);

            if (dtReport.Rows.Count > 0)
            {
                DataRow drReportTemplateConfig = dtReport.Rows[0];
                if (eActionType == enRequestReportActionType.DirectPrint)
                {
                    iPrintCount = LBConverter.ToInt32(drReportTemplateConfig["PrintCount"]);
                    if (iPrintCount <= 0)
                    {
                        iPrintCount = 1;
                    }
                }

                ProcessStep.AddStep("GetReportTemplateRow", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                reportRequestArgs.ReportTemplateConfig = drReportTemplateConfig;

                for (int i = 0; i < iPrintCount; i++)
                {
                    ShowReport(eActionType, reportRequestArgs);
                }
            }
            ProcessStep.AddStep("ShowReport_End", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 预览报表
        /// </summary>
        public static void OpenReportDialog(enRequestReportActionType eActionType, ReportRequestArgs reportRequestArgs)
        {
            ProcessStep.AddStep("OpenReportDialog_Start", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
            DataRow drReportTemplateConfig = GetReportTemplateRow(reportRequestArgs.ReportTemplateID);

            ProcessStep.AddStep("GetReportTemplateRow", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
            reportRequestArgs.ReportTemplateConfig = drReportTemplateConfig;
            ShowReport(eActionType, reportRequestArgs);
            ProcessStep.AddStep("ShowReport_End", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
        }
Exemplo n.º 5
0
        public static FastReport.Report GetReport(ReportRequestArgs e)
        {
            DataTable dtReportTemplateConfig = ReportHelper.GetReportTemplateByID(e.ReportTemplateID);

            if (dtReportTemplateConfig.Rows.Count == 0)
            {
                return(null);
            }
            DataRow drReportTemplateConfig = dtReportTemplateConfig.Rows[0];

            e.ReportTemplateConfig = drReportTemplateConfig;

            long lReportTemplateID = Convert.ToInt64(e.ReportTemplateConfig["ReportTemplateID"]);

            byte[]   reportTempleData         = (byte[])e.ReportTemplateConfig["TemplateData"];
            DateTime dtTemplateFileTime       = DateTime.Parse(e.ReportTemplateConfig["TemplateFileTime"].ToString());
            string   strReportTemplateName    = e.ReportTemplateConfig["ReportTemplateName"].ToString().Trim();
            string   strReportTemplateNameExt = e.ReportTemplateConfig["ReportTemplateNameExt"].ToString().Trim();
            //检测本地是否存在报表文件,如果不存在或者与服务器比本地文件新时更新本地文件
            string strFileFullName = WriteReportWithCheck(lReportTemplateID, strReportTemplateName, dtTemplateFileTime, reportTempleData, strReportTemplateNameExt);

            ProcessStep.AddStep("WriteReportWithCheck_End", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);

            // 加载模板
            FastReport.Report report = null;

            //Form frm = null;
            try
            {
                //frm = new Form();
                report = new FastReport.Report();
                ProcessStep.AddStep("Report_New", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                report.FinishReport += Report_FinishReport;
                report.Load(strFileFullName);
                ProcessStep.AddStep("Report_Load", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                // 纸张设置
                //SetPaperAuto(report, iReportTemplateID);

                BuildParmsAndData(e, report, enBuildParmsAndDataActionType.SetValue);
                ProcessStep.AddStep("BuildParmsAndData", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                //ReportPreviewer previewer = new Report.ReportPreviewer(report);

                SetPrintSettings(report, lReportTemplateID);
                ProcessStep.AddStep("SetPrintSettings", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
            }
            catch (Exception ex)
            {
            }
            return(report);
        }
Exemplo n.º 6
0
        public static void BuildParmsAndData(ReportRequestArgs e, FastReport.Report report, enBuildParmsAndDataActionType actionType)
        {
            if (actionType == enBuildParmsAndDataActionType.SetValue)  // 对模板已有参数赋值
            {
                foreach (FastReport.Data.Parameter parm in report.Parameters)
                {
                    // 参数值是从 fastParms.ReportParameters 中传入的
                    foreach (DataColumn dc in e.RecordDR.Table.Columns)
                    {
                        if (parm.Name.Equals(dc.ColumnName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            parm.Value = e.RecordDR[dc.ColumnName];
                            break;
                        }
                    }
                }
            }
            else    // 添加新的参数至模板
            {
                if (e.RecordDR != null)
                {
                    report.Parameters.Clear();
                    foreach (DataColumn dc in e.RecordDR.Table.Columns)
                    {
                        FastReport.Data.Parameter parm = new FastReport.Data.Parameter(dc.ColumnName);
                        parm.DataType = dc.DataType;
                        parm.Value    = e.RecordDR[dc.ColumnName];
                        report.Parameters.Add(parm);
                    }
                }
            }

            if (e.DSDataSource != null)
            {
                for (int i = 0, j = e.DSDataSource.Tables.Count; i < j; i++)
                {
                    DataTable table = e.DSDataSource.Tables[i];
                    string    description;
                    string    strTableName = table.TableName;
                    report.RegisterData(table, strTableName);
                    //report.RegisterData(e.DSDataSource);
                    //report.ReportInfo.Description = table.TableName;
                    DataSourceBase dataSource = report.GetDataSource(strTableName);
                    dataSource.Enabled = true;
                }
            }
        }
Exemplo n.º 7
0
        private void BtnEditReport_Click(object sender, EventArgs e)
        {
            try
            {
                LBToolStripReportViewButton btnEditReport = sender as LBToolStripReportViewButton;
                ReportRequestArgs           args          = new Report.ReportRequestArgs(0, (int)btnEditReport.ReportTypeID, null, null);
                OnReportRequest(args);
                if (args.DSDataSource == null && args.RecordDR == null)
                {
                    LB.WinFunction.LBCommonHelper.ShowCommonMessage("未设置数据源,编辑报表失败!");
                }
                else
                {
                    frmReport frm = new frmReport(args);
                    LBShowForm.ShowDialog(frm);

                    if (mToolStrip != null)
                    {
                        if (mToolStrip.Items.ContainsKey("btnReportEdit"))
                        {
                            mToolStrip.Items.RemoveByKey("btnReportEdit");
                        }
                        if (mToolStrip.Items.ContainsKey("btnReportViewSingle"))
                        {
                            mToolStrip.Items.RemoveByKey("btnReportViewSingle");
                        }
                        if (mToolStrip.Items.ContainsKey("btnReportViewMutli"))
                        {
                            mToolStrip.Items.RemoveByKey("btnReportViewMutli");
                        }
                        this.OnInitToolStripControl(mToolStripReportArgs);
                    }
                }
            }
            catch (Exception ex)
            {
                LB.WinFunction.LBCommonHelper.DealWithErrorMessage(ex);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 添加新报表
        /// </summary>
        /// <param name="e"></param>
        /// <param name="strReportTemplateName"></param>
        /// <returns></returns>
        public static string AddNewReport(ReportRequestArgs e, string strReportTemplateName)
        {
            string strReportPath = "";

            using (FastReport.Report report = new FastReport.Report())
            {
                BuildParmsAndData(e, report, enBuildParmsAndDataActionType.AddNew);

                string strReportFullName = Path.Combine(ReportHelper.ReportPath, strReportTemplateName + ".frx");
                report.Save(strReportFullName);

                strReportPath = strReportFullName;

                //Form frm = new Form();
                //frm.Icon = FastReport.Utils.Config.PreviewSettings.Icon;
                //frm.Show();
                //report.Design();
                report.Dispose();
                //frm.Close();
            }
            return(strReportPath);
        }
Exemplo n.º 9
0
        //public static void BuildReportParmsAndData(FastReport.Report report, ReportArgs reportArgs)
        //{
        //    report.Parameters.Clear();
        //    List<FastReport.Data.Parameter> lstParm = new List<FastReport.Data.Parameter>();

        //    if (reportArgs.RecordDR != null)
        //    {
        //        foreach (DataColumn dc in reportArgs.RecordDR.Table.Columns)
        //        {
        //            FastReport.Data.Parameter parm = new FastReport.Data.Parameter(dc.ColumnName);
        //            parm.DataType = dc.DataType;
        //            parm.Value = reportArgs.RecordDR[dc.ColumnName];
        //            lstParm.Add(parm);
        //        }
        //    }


        //    if (reportArgs.DSDataSource != null)
        //    {
        //        foreach (DataTable dtSource in reportArgs.DSDataSource.Tables)
        //        {
        //            report.RegisterData(dtSource, dtSource.TableName);
        //            report.GetDataSource(dtSource.TableName).Enabled = true;
        //        }
        //    }
        //}

        /// <summary>
        /// 打开报表设计器
        /// </summary>
        /// <param name="lReportTemplateID"></param>
        /// <param name="reportArgs"></param>
        public static void OpenReportDesign(ReportRequestArgs reportArgs)
        {
            string strReportFileName;
            bool   bolExists = RefleshClientReport(reportArgs.ReportTemplateID, out strReportFileName);

            if (bolExists)
            {
                using (FastReport.Report report = new FastReport.Report())
                {
                    BuildParmsAndData(reportArgs, report, enBuildParmsAndDataActionType.AddNew);

                    report.Load(strReportFileName);

                    Form frm = new Form();
                    frm.Icon = FastReport.Utils.Config.PreviewSettings.Icon;
                    frm.Show();
                    report.Design();
                    report.Dispose();
                    frm.Close();
                }
            }
        }
Exemplo n.º 10
0
 public frmReport(ReportRequestArgs reportArgs)
 {
     InitializeComponent();
     mReportArgs = reportArgs;
 }
Exemplo n.º 11
0
        private static void ShowReport(enRequestReportActionType eActionType, ReportRequestArgs e)
        {
            // FastReport 配置
            Config.DesignerSettings.ShowInTaskbar = true;
            Config.DesignerSettings.DefaultFont   = new System.Drawing.Font(Config.DesignerSettings.DefaultFont.FontFamily, 10f);
            //Config.DesignerSettings.Icon = TS.Win.Styles.Sheet.AppIcon;
            Config.DesignerSettings.Text = "报表设计器";
            //Config.PreviewSettings.Buttons = PreviewButtons.Print;
            Config.PreviewSettings.ShowInTaskbar = true;
            //Config.PreviewSettings.Icon = TS.Win.Styles.Sheet.AppIcon;

            long lReportTemplateID = Convert.ToInt64(e.ReportTemplateConfig["ReportTemplateID"]);

            byte[]   reportTempleData         = (byte[])e.ReportTemplateConfig["TemplateData"];
            DateTime dtTemplateFileTime       = DateTime.Parse(e.ReportTemplateConfig["TemplateFileTime"].ToString());
            string   strReportTemplateName    = e.ReportTemplateConfig["ReportTemplateName"].ToString().Trim();
            string   strReportTemplateNameExt = e.ReportTemplateConfig["ReportTemplateNameExt"].ToString().Trim();
            //检测本地是否存在报表文件,如果不存在或者与服务器比本地文件新时更新本地文件
            string strFileFullName = WriteReportWithCheck(lReportTemplateID, strReportTemplateName, dtTemplateFileTime, reportTempleData, strReportTemplateNameExt);

            ProcessStep.AddStep("WriteReportWithCheck_End", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);

            // 加载模板
            FastReport.Report report = null;

            //Form frm = null;
            try
            {
                //frm = new Form();
                report = new FastReport.Report();

                ProcessStep.AddStep("Report_New", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                report.FinishReport += Report_FinishReport;
                report.Load(strFileFullName);
                ProcessStep.AddStep("Report_Load", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                // 纸张设置
                //SetPaperAuto(report, iReportTemplateID);

                BuildParmsAndData(e, report, enBuildParmsAndDataActionType.SetValue);
                ProcessStep.AddStep("BuildParmsAndData", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                //ReportPreviewer previewer = new Report.ReportPreviewer(report);

                SetPrintSettings(report, lReportTemplateID);
                ProcessStep.AddStep("SetPrintSettings", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                if (eActionType == enRequestReportActionType.Preview)//预览
                {
                    //frm.FormBorderStyle = FormBorderStyle.None;
                    //frm.Text = "报表预览[" + strReportTemplateName + "]";
                    //frm.TransparencyKey = frm.BackColor;
                    //frm.Show();

                    //report.Show(true, frm);
                    //LBShowForm.ShowDialog(previewer);
                    report.Show(true);
                }
                else if (eActionType == enRequestReportActionType.DirectPrint)//直接打印
                {
                    report.PrintSettings.ShowDialog = false;
                    report.Print();
                    //string strPrinterStatus =PrinterHelper.GetPrinterStatus(report.PrintSettings.Printer);
                    ProcessStep.AddStep("Print", DateTime.Now.ToString("MMdd HH:mm:ss ") + DateTime.Now.Millisecond);
                }
            }
            finally
            {
                try
                {
                    if (report != null)
                    {
                        report.Dispose();
                        //if (frm != null)
                        //{
                        //    frm.Close();
                        //}
                    }
                }
                catch
                {
                }
            }
        }
Exemplo n.º 12
0
        private void btnSaveReport_Click(object sender, EventArgs e)
        {
            try
            {
                #region -- 保存报表 --
                if (mReportArgs.ReportTemplateID == 0)
                {
                    ReportRequestArgs args = new ReportRequestArgs(0, mReportArgs.ReportTypeID, mReportArgs.DSDataSource, mReportArgs.RecordDR);

                    this.txtReportPath.Text = ReportHelper.AddNewReport(args, this.txtReportTemplateName.Text);

                    if (!File.Exists(this.txtReportPath.Text))
                    {
                        throw new Exception("报表文件不存在,无法保存!");
                    }
                    byte[] bReport = ReportHelper.ConvertToByte(this.txtReportPath.Text);
                    LBDbParameterCollection parms = new LBDbParameterCollection();
                    parms.Add(new LBParameter("ReportTemplateID", enLBDbType.Int64, 0));
                    parms.Add(new LBParameter("ReportTemplateName", enLBDbType.String, this.txtReportTemplateName.Text));
                    parms.Add(new LBParameter("TemplateFileTime", enLBDbType.DateTime, DateTime.Now));
                    parms.Add(new LBParameter("TemplateSeq", enLBDbType.Int32, 0));
                    parms.Add(new LBParameter("Description", enLBDbType.String, this.txtDescription.Text));
                    parms.Add(new LBParameter("TemplateData", enLBDbType.Object, bReport));
                    parms.Add(new LBParameter("ReportTypeID", enLBDbType.Int64, mReportArgs.ReportTypeID));
                    parms.Add(new LBParameter("PrinterName", enLBDbType.String, this.txtPrinterName.Text));
                    parms.Add(new LBParameter("MachineName", enLBDbType.String, LoginInfo.MachineName));
                    parms.Add(new LBParameter("IsManualPaperType", enLBDbType.Boolean, rbManualPaperType.Checked));
                    parms.Add(new LBParameter("PaperType", enLBDbType.String, this.txtPaperType.Text));
                    parms.Add(new LBParameter("IsManualPaperSize", enLBDbType.Boolean, rbManualPaperSize.Checked));
                    if (this.txtPaperSizeHeight.Text != "")
                    {
                        parms.Add(new LBParameter("PaperSizeHeight", enLBDbType.Int32, this.txtPaperSizeHeight.Text));
                    }
                    if (this.txtPaperSizeWidth.Text != "")
                    {
                        parms.Add(new LBParameter("PaperSizeWidth", enLBDbType.Int32, this.txtPaperSizeWidth.Text));
                    }
                    parms.Add(new LBParameter("IsPaperTransverse", enLBDbType.Boolean, rbPaperTransverse.Checked));
                    parms.Add(new LBParameter("PrintCount", enLBDbType.Int32, LBConverter.ToInt32(this.txtPrintCount.Text)));
                    DataSet dsReturn;
                    Dictionary <string, object> dictResult;
                    ExecuteSQL.CallSP(12000, parms, out dsReturn, out dictResult);

                    if (dictResult.ContainsKey("ReportTemplateID"))
                    {
                        if (dictResult["ReportTemplateID"] != null)
                        {
                            mReportArgs.ReportTemplateID = Convert.ToInt64(dictResult["ReportTemplateID"]);
                        }
                    }
                }
                else
                {
                    byte[]   bReport            = null;
                    DateTime dtTemplateFileTime = DateTime.Now;
                    string   strReportPath      = this.txtReportPath.Text;
                    if (strReportPath != "")
                    {
                        if (File.Exists(strReportPath))
                        {
                            bReport = ReportHelper.ConvertToByte(strReportPath);
                            //dtTemplateFileTime = File.GetLastWriteTime(strReportPath);
                        }
                        else
                        {
                            throw new Exception("报表文件不存在,无法保存!");
                        }
                    }
                    else
                    {
                        string strReportFile;
                        bool   bolExists = ReportHelper.RefleshClientReport(mReportArgs.ReportTemplateID, out strReportFile);

                        if (bolExists)
                        {
                            bReport            = ReportHelper.ConvertToByte(strReportFile);
                            dtTemplateFileTime = File.GetLastWriteTime(strReportFile);
                        }
                        else
                        {
                            throw new Exception("报表文件不存在,无法保存!");
                        }
                    }

                    LBDbParameterCollection parms = new LBDbParameterCollection();
                    parms.Add(new LBParameter("ReportTemplateID", enLBDbType.Int64, mReportArgs.ReportTemplateID));
                    parms.Add(new LBParameter("ReportTemplateName", enLBDbType.String, this.txtReportTemplateName.Text));
                    parms.Add(new LBParameter("TemplateFileTime", enLBDbType.DateTime, dtTemplateFileTime));
                    parms.Add(new LBParameter("TemplateSeq", enLBDbType.Int32, 0));
                    parms.Add(new LBParameter("Description", enLBDbType.String, this.txtDescription.Text));
                    parms.Add(new LBParameter("TemplateData", enLBDbType.Object, bReport));
                    parms.Add(new LBParameter("ReportTypeID", enLBDbType.Int64, mReportArgs.ReportTypeID));
                    parms.Add(new LBParameter("PrinterName", enLBDbType.String, this.txtPrinterName.Text));
                    parms.Add(new LBParameter("MachineName", enLBDbType.String, LoginInfo.MachineName));
                    parms.Add(new LBParameter("IsManualPaperType", enLBDbType.Boolean, rbManualPaperType.Checked));
                    parms.Add(new LBParameter("PaperType", enLBDbType.String, this.txtPaperType.Text));
                    parms.Add(new LBParameter("IsManualPaperSize", enLBDbType.Boolean, rbManualPaperSize.Checked));
                    if (this.txtPaperSizeHeight.Text != "")
                    {
                        parms.Add(new LBParameter("PaperSizeHeight", enLBDbType.Int32, this.txtPaperSizeHeight.Text));
                    }
                    if (this.txtPaperSizeWidth.Text != "")
                    {
                        parms.Add(new LBParameter("PaperSizeWidth", enLBDbType.Int32, this.txtPaperSizeWidth.Text));
                    }
                    parms.Add(new LBParameter("IsPaperTransverse", enLBDbType.Boolean, rbPaperTransverse.Checked));
                    parms.Add(new LBParameter("PrintCount", enLBDbType.Int32, LBConverter.ToInt32(this.txtPrintCount.Text)));
                    DataSet dsReturn;
                    Dictionary <string, object> dictResult;
                    ExecuteSQL.CallSP(12001, parms, out dsReturn, out dictResult);
                }
                #endregion -- 保存报表 --

                LB.WinFunction.LBCommonHelper.ShowCommonMessage("保存成功!");
            }
            catch (Exception ex)
            {
                LB.WinFunction.LBCommonHelper.DealWithErrorMessage(ex);
            }
        }