Exemplo n.º 1
0
        public static XtraForm Preview(XtraForm mainForm, PLDynRepType ReportType, 
            DataSet Source, string[] FieldNames, string[] Captions, int[] ExpectedWidths,
            string Title, string SubTitle)
        {
            ParameterFields Params = null;
            try
            {
                #region Mở rộng nếu có thêm Report mới
                PLBlankReport frm = new PLBlankReport();
                PLCrystalReportViewer view = new PLCrystalReportViewer();
                if (ReportType == PLDynRepType.HSheet)
                {
                    HSheetReport Report = new HSheetReport();
                    DynamicSheetReport.ToSheetReport(Report, out Params, Source,
                        FieldNames, Captions, ExpectedWidths, Title, SubTitle);
                    //view._I.ReportSource = Report;//phiên bản 12
                    view.ReportSource = Report;//phiên bản 10
                }
                else if (ReportType == PLDynRepType.VSheet)
                {
                    VSheetReport Report = new VSheetReport();
                    DynamicSheetReport.ToSheetReport(Report, out Params, Source,
                        FieldNames, Captions, ExpectedWidths, Title, SubTitle);
                    //view._I.ReportSource = Report;//phien bản 12
                    view.ReportSource = Report;//phien bản 10
                }
                #endregion

                //view._I.ParameterFieldInfo = Params;//phien bản 12
                //view.ParameterFieldInfo = Params;//phien bản 10
                frm.WindowState = FormWindowState.Maximized;
                view.Dock = DockStyle.Fill;
                frm.Controls.Add(view);

                return frm;
            }
            catch (Exception ex){
                PLException.AddException(ex);
                return null;
            }
        }
Exemplo n.º 2
0
        private void preview()
        {
            string reportFile = "";
            try
            {
                if (this.splitContainerControl1.Panel2.Controls.Count > 0 && this.treeList1.Selection[0].Tag != null)
                {
                    IReportFilter filter = (IReportFilter)this.splitContainerControl1.Panel2.Controls[0];

                    //Kiểm tra lỗi
                    Error.ClearErrors();
                    filter.ValidateFilter(Error);
                    if (Error.HasErrors) return;

                    #region Khởi tạo Main DataSet
                    DataSet ds = null;
                    ds = filter.getDataSet();
                    if (showEmptyReport==false)
                    {
                        if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        {
                            HelpMsgBox.ShowNotificationMessage("Không tìm thấy dữ liệu báo cáo.");
                            return;
                        }
                    }
                    ReportInfo info = (ReportInfo)this.treeList1.Selection[0].Tag;
                    ParameterFields Params = null;
                    ReportClass Report = null;
                    if (this.splitContainerControl1.Panel2.Controls[0] is IDynSheetReportFilter)
                    {
                        string Title = null;
                        string SubTitle = null;
                        string[] FieldNames = null;
                        string[] Captions = null;
                        int[] Widths = null;
                        bool IsVertical = false;
                        //Alignment[] aligns = null;

                        ((IDynSheetReportFilter)this.splitContainerControl1.Panel2.Controls[0]).GetParam(
                            out Title, out SubTitle, out FieldNames,
                            out Captions, out Widths, out IsVertical);

                        if (IsVertical)
                        {
                            Report = new VSheetReport();
                        }
                        else
                        {
                            Report = new HSheetReport();
                        }

                        DynamicSheetReport.ToSheetReport(Report, out Params, ds,
                            FieldNames,
                            Captions,
                            Widths, Title, SubTitle);

                    }
                    #endregion
                    FrameworkParams.wait = new WaitingMsg();

                    #region Thêm 1 Viewer
                    DevExpress.XtraTab.XtraTabPage page = null;
                    bool usingXtraReport = info.ReportFile.StartsWith("EMBXTRA");
                    PLCrystalReportViewer view = null;
                    PLXtraPreview xtraview = null;
                    Control viewCtrl = null;
                    if (usingXtraReport)
                    {
                        xtraview = new PLXtraPreview();
                        viewCtrl = xtraview;
                    }
                    else
                    {
                        view = new PLCrystalReportViewer();
                        view._SetSupportRefresh(false);
                        viewCtrl = view;
                    }
                    lock(AddPageFlag){
                        if (AddPageFlag.Value == true)
                        {
                            page = new DevExpress.XtraTab.XtraTabPage();
                            page.Text = this.treeList1.Selection[0].GetValue(0).ToString();
                            page.Controls.Add(viewCtrl);
                            AddPageFlag.Value = false;

                            this.xtraTabControl1.TabPages.Add(page);
                            page.Tag = this.splitContainerControl1.Panel2.Controls[0];
                            this.xtraTabControl1.SelectedTabPage = page;
                        }
                        else
                        {
                            page = this.xtraTabControl1.SelectedTabPage;
                            page.Controls.Clear();
                            page.Controls.Add(viewCtrl);
                        }
                    }
                    viewCtrl.Dock = DockStyle.Fill;
                    //DevExpress.XtraTab.XtraTabPage page = new DevExpress.XtraTab.XtraTabPage();
                    //page.Text = this.treeList1.Selection[0].GetValue(0).ToString();
                    //PLCrystalReportViewer view = new PLCrystalReportViewer();
                    //page.Controls.Add(view);

                    //view.Dock = DockStyle.Fill;
                    #endregion
                    XtraReport xtraReport = null;
                    if (this.splitContainerControl1.Panel2.Controls[0] is IDynSheetReportFilter)
                    {
                        #region Phiên bản 14
                        //view._I.ParameterFieldInfo = Params;
                        //view._SetSupportRefresh(false);
                        ////EnableParameterPrompting
                        //view._I.ReportSource = Report;
                        #endregion
                        #region Phiên bản 10
                        view.ParameterFieldInfo = Params;
                        view._SetSupportRefresh(false);
                        //EnableParameterPrompting
                        view.ReportSource = Report;
                        #endregion
                    }
                    else {
                        #region Lấy 1 ReportDocument

                        if (this.splitContainerControl1.Panel2.Controls[0] is IAdvanceReportFilter)
                            info.ReportFile = ((IAdvanceReportFilter)this.splitContainerControl1.Panel2.Controls[0]).getReportFile();
                        reportFile = info.ReportFile;
                        ReportDocument report = new ReportDocument();

                        if (reportFile.StartsWith("EMBXTRA"))
                        {
                            reportFile = reportFile.Substring(7);
                            try { xtraReport = (DevExpress.XtraReports.UI.XtraReport)GenerateClass.initObject(reportFile); }
                            catch { }
                        }
                        else if (reportFile.StartsWith("EMB"))
                        {
                            reportFile = reportFile.Substring(3);
                            try { report = (ReportDocument)GenerateClass.initObject(reportFile); }
                            catch { }
                        }
                        else if (reportFile.StartsWith("PATH"))
                        {
                            reportFile = reportFile.Substring(4);
                            report.Load(reportFile);
                        }
                        else //if (reportFile.StartsWith("\\report"))
                        { //Load theo dạng file
                            reportFile = RadParams.RUNTIME_PATH + reportFile;
                            report.Load(reportFile);
                        }

                        #endregion

                        #region Gán DataSet
                        if (usingXtraReport == false)
                        {
                            view._DSList = new List<DataSet>();
                            //Set DataSet cho Main Report
                            view._DSList.Add(ds);
                            for (int i = 0; i < ds.Tables.Count; i++)
                            {
                                report.Database.Tables[i].SetDataSource(ds.Tables[i]);
                            }
                            //Set DataSet cho SubReport
                            DataSet[] dsArray = filter.getSubReports();
                            if (dsArray != null)
                            {
                                for (int i = 0; i < dsArray.Length; i++)
                                {
                                    report.Subreports[i].SetDataSource(dsArray[i]);
                                    view._DSList.Add(dsArray[i]);
                                }
                            }
                            #region Parameter
                            Dictionary<string, object> dic = filter.GetParamFieldValue();
                            foreach (CrystalDecisions.Shared.ParameterField pa in report.ParameterFields)
                            {
                                if (dic.ContainsKey(pa.Name))
                                {
                                    report.SetParameterValue(pa.Name, dic[pa.Name]);
                                }
                            }
                            if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
                            //view._SetSupportRefresh(true);
                            //view._I.ReportSource = report;//phiên bản 12
                            view.ReportSource = report;//phiên bản 10
                            #endregion

                            report.RefreshReport += new EventHandler(report_RefreshReport);
                        }
                        else//XtraReport
                        {
                            xtraReport.DataSource = ds;
                            //Dạng có Main Report + Sub Report
                            DataSet[] dsArray = filter.getSubReports();
                            if (dsArray != null)
                            {
                                List<XRSubreport> subreport = new List<XRSubreport>();
                                foreach (Band band in xtraReport.Bands)//getBands(xtraReport))
                                {
                                    foreach (XRControl xrControl in band.Controls)
                                    {
                                        if (xrControl is XRSubreport)
                                        {
                                            subreport.Add((XRSubreport)xrControl);
                                        }
                                    }
                                }

                                //for (int i = 0; i < dsArray.Length; i++)
                                //{
                                //    subreport[i].ReportSource.DataSource = dsArray[i];
                                //}
                                //duchs: gan dataset cho datasource cua subreport dua vao ten bang
                                for (int i = 0; i < dsArray.Length; i++)
                                {
                                    foreach (XRSubreport itemreport in subreport)
                                    {
                                        try
                                        {
                                            //DataSet ds=(DataSet)itemreport.DataSource;
                                            if (itemreport.ReportSource.DataMember.ToUpper().Equals(dsArray[i].Tables[0].TableName))
                                            {
                                                itemreport.ReportSource.DataSource = dsArray[i].Tables[0];
                                                break;
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                            #region Parameter
                            Dictionary<string, object> dic = filter.GetParamFieldValue();
                            foreach (DevExpress.XtraReports.Parameters.Parameter par in xtraReport.Parameters)
                            {
                                if (dic.ContainsKey(par.Name))
                                {
                                    xtraReport.Parameters[par.Name].Value = dic[par.Name];
                                }
                            }
                            xtraReport.PrintingSystem.SetCommandVisibility(DevExpress.XtraPrinting.PrintingSystemCommand.ClosePreview, DevExpress.XtraPrinting.CommandVisibility.None);
                            //ẩn phần nhập Parameters
                            xtraReport.RequestParameters = false;
                            xtraview.PrintingSystem = xtraReport.PrintingSystem;
                            xtraReport.CreateDocument();
                            //ẩn nút Parameters trên toolbar
                            xtraReport.PrintingSystem.SetCommandVisibility(DevExpress.XtraPrinting.PrintingSystemCommand.Parameters, DevExpress.XtraPrinting.CommandVisibility.None);
                            //MessageBox.Show(view.PrintingSystem.Pages.Count.ToString());
                            #endregion
                        }
                        #endregion

                    }

                    if (FrameworkParams.isFax == true)
                    {
                        frmFax frmFax = new frmFax(info.Caption, FrameworkParams.TEMP_FOLDER + @"\" + "$faxdoc.pdf", "Thông tin người nhận", "Điện thoại");
                        view.frmFax = frmFax;
                    }

                    //this.xtraTabControl1.TabPages.Add(page);
                    //page.Tag = this.splitContainerControl1.Panel2.Controls[0];

                    //this.xtraTabControl1.SelectedTabPage = page;

                }
                //if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
            }
            catch(Exception e){
                if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
                HelpMsgBox.ShowNotificationMessage("Tập tin " + reportFile + " không tồn tại.\nVui lòng liên hệ Công ty P R O T O C O L.");
                PLException.AddException(e);
            }
            finally {
                if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
            }
        }
Exemplo n.º 3
0
        private void preview()
        {
            string reportFile = "";
            try
            {
                if (this.splitContainerControl1.Panel2.Controls.Count > 0 && this.treeList1.Selection[0].Tag != null)
                {
                    IReportFilter filter = (IReportFilter)this.splitContainerControl1.Panel2.Controls[0];

                    //Kiểm tra lỗi
                    Error.ClearErrors();
                    filter.ValidateFilter(Error);
                    if (Error.HasErrors) return;

                    #region Khởi tạo Main DataSet
                    DataSet ds = null;
                    ds = filter.getDataSet();
                    if (showEmptyReport == false)
                    {
                        if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        {
                            HelpMsgBox.ShowNotificationMessage("Không tìm thấy dữ liệu báo cáo.");
                            return;
                        }
                    }
                    ReportInfo info = (ReportInfo)this.treeList1.Selection[0].Tag;
                    ParameterFields Params = null;
                    ReportClass Report = null;
                    if (this.splitContainerControl1.Panel2.Controls[0] is IDynSheetReportFilter)
                    {
                        string Title = null;
                        string SubTitle = null;
                        string[] FieldNames = null;
                        string[] Captions = null;
                        int[] Widths = null;
                        bool IsVertical = false;
                        //Alignment[] aligns = null;

                        ((IDynSheetReportFilter)this.splitContainerControl1.Panel2.Controls[0]).GetParam(
                            out Title, out SubTitle, out FieldNames,
                            out Captions, out Widths, out IsVertical);

                        if (IsVertical)
                        {
                            Report = new VSheetReport();
                        }
                        else
                        {
                            Report = new HSheetReport();
                        }

                        DynamicSheetReport.ToSheetReport(Report, out Params, ds,
                            FieldNames,
                            Captions,
                            Widths, Title, SubTitle);

                    }
                    #endregion
                    FrameworkParams.wait = new WaitingMsg();

                    #region Thêm 1 Viewer
                    DevExpress.XtraTab.XtraTabPage page = null;
                    PLCrystalReportViewer view = new PLCrystalReportViewer();
                    view._SetSupportRefresh(false);

                    lock(AddPageFlag){
                        if (AddPageFlag.Value == true)
                        {
                            page = new DevExpress.XtraTab.XtraTabPage();
                            page.Text = this.treeList1.Selection[0].GetValue(0).ToString();
                            page.Controls.Add(view);
                            AddPageFlag.Value = false;

                            this.xtraTabControl1.TabPages.Add(page);
                            page.Tag = this.splitContainerControl1.Panel2.Controls[0];
                            this.xtraTabControl1.SelectedTabPage = page;
                        }
                        else
                        {
                            page = this.xtraTabControl1.SelectedTabPage;
                            page.Controls.Clear();
                            page.Controls.Add(view);
                        }
                    }
                    view.Dock = DockStyle.Fill;
                    //DevExpress.XtraTab.XtraTabPage page = new DevExpress.XtraTab.XtraTabPage();
                    //page.Text = this.treeList1.Selection[0].GetValue(0).ToString();
                    //PLCrystalReportViewer view = new PLCrystalReportViewer();
                    //page.Controls.Add(view);

                    //view.Dock = DockStyle.Fill;
                    #endregion

                    if (this.splitContainerControl1.Panel2.Controls[0] is IDynSheetReportFilter)
                    {
                        //#region Phiên bản 12
                        //view._I.ParameterFieldInfo = Params;
                        //view._SetSupportRefresh(false);
                        ////EnableParameterPrompting
                        //view._I.ReportSource = Report;
                        //#endregion
                        #region Phiên bản 10
                        view.ParameterFieldInfo = Params;
                        view._SetSupportRefresh(false);
                        //EnableParameterPrompting
                        view.ReportSource = Report;
                        #endregion
                    }
                    else {
                        #region Lấy 1 ReportDocument
                        ReportDocument report = new ReportDocument();
                        if (this.splitContainerControl1.Panel2.Controls[0] is IAdvanceReportFilter)
                            info.ReportFile = ((IAdvanceReportFilter)this.splitContainerControl1.Panel2.Controls[0]).getReportFile();
                        reportFile = info.ReportFile;
                        if (reportFile.StartsWith("EMB"))
                        {
                            reportFile = reportFile.Substring(3);
                            try { report = (ReportDocument)GenerateClass.initObject(reportFile); }
                            catch { }
                        }
                        else if (reportFile.StartsWith("PATH"))
                        {
                            reportFile = reportFile.Substring(4);
                            report.Load(reportFile);
                        }
                        else //if (reportFile.StartsWith("\\report"))
                        { //Load theo dạng file
                            reportFile = RadParams.RUNTIME_PATH + reportFile;
                            report.Load(reportFile);
                        }

                        #endregion

                        #region Gán DataSet
                        //2008
                        view._DSList = new List<DataSet>();
                        ////Set DataSet cho Main Report
                        view._DSList.Add(ds);
                        for (int i = 0; i < ds.Tables.Count; i++)
                        {
                            report.Database.Tables[i].SetDataSource(ds.Tables[i]);
                        }

                        //Set DataSet cho SubReport
                        DataSet[] dsArray = filter.getSubReports();
                        if(dsArray!=null){
                            for (int i = 0; i < dsArray.Length; i++)
                            {
                                report.Subreports[i].SetDataSource(dsArray[i]);
                                view._DSList.Add(dsArray[i]);
                            }
                        }
                        #endregion

                        #region Parameter
                        Dictionary<string, object> dic = filter.GetParamFieldValue();
                        foreach (CrystalDecisions.Shared.ParameterField pa in report.ParameterFields)
                        {
                            if (dic.ContainsKey(pa.Name))
                            {
                                report.SetParameterValue(pa.Name, dic[pa.Name]);
                            }
                        }
                        //view._SetSupportRefresh(true);
                        if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();

                        //view._I.ReportSource = report;//phiên bản 12
                        view.ReportSource = report;//phiên bản 10
                        #endregion

                        report.RefreshReport += new EventHandler(report_RefreshReport);
                    }

                    if (FrameworkParams.isFax == true)
                    {
                        frmFax frmFax = new frmFax(info.Caption, FrameworkParams.TEMP_FOLDER + @"\" + "$faxdoc.pdf", "Thông tin người nhận", "Điện thoại");
                        view.frmFax = frmFax;
                    }

                    //this.xtraTabControl1.TabPages.Add(page);
                    //page.Tag = this.splitContainerControl1.Panel2.Controls[0];

                    //this.xtraTabControl1.SelectedTabPage = page;

                }
                //if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
            }
            catch(Exception e){
                if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
                //HelpMsgBox.ShowNotificationMessage("Tập tin " + reportFile + " không tồn tại.\nVui lòng liên hệ Công ty P R O T O C O L.");
                HelpMsgBox.ShowNotificationMessage("Quá trình tạo báo cáo không thành công. \nVui lòng thực thực hiện lại.");
                PLException.AddException(e);
            }
            finally {
                if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
            }
        }
Exemplo n.º 4
0
        /// <summary>Xem trước khi in
        /// </summary>
        /// <returns></returns>
        public XtraForm preview()
        {
            try
            {
                PLBlankReport frm = new PLBlankReport();
                PLCrystalReportViewer view = new PLCrystalReportViewer();
                ReportDocument report = GetRepObj();
                report.SetDataSource(mMainDataSet);
                view._DSList = FillDataForSubReport(report);
                view._DSList.Insert(0, mMainDataSet);

                FillParams(view);
                //view._I.ReportSource = report;//phien bản 12
                view.ReportSource = report;//phien bản 10
                frm.WindowState = FormWindowState.Maximized;
                view.Dock = DockStyle.Fill;
                frm.Controls.Add(view);

                return frm;
            }
            catch (Exception ex)
            {
                PLMessageBox.ShowErrorMessage("Không kết nối được với máy in.\nVui lòng kiểm tra lại kết nối với máy in.");
                PLException.AddException(ex);
                return null;
            }
        }
Exemplo n.º 5
0
 private void FillParams(PLCrystalReportViewer view)
 {
     if (mParameters != null)
     {
         CrystalDecisions.Shared.ParameterFields pars = new CrystalDecisions.Shared.ParameterFields();
         foreach (string varKey in mParameters.Keys)
         {
             object tempValue;
             mParameters.TryGetValue(varKey, out tempValue);
             CrystalDecisions.Shared.ParameterField paramField = new CrystalDecisions.Shared.ParameterField();
             paramField.Name = varKey;
             CrystalDecisions.Shared.ParameterDiscreteValue paramDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
             paramDiscreteValue.Value = tempValue;
             paramField.CurrentValues.Add(paramDiscreteValue);
             pars.Add(paramField);
         }
         //view._I.ParameterFieldInfo = pars;//phien bản 12
         view.ParameterFieldInfo = pars;//phien bản 10
     }
 }
Exemplo n.º 6
0
        public void printSelectedPrinter()
        {
            try
            {
                ReportDocument report = GetRepObj();
                report.SetDataSource(mMainDataSet);//gan nguon cho main report
                List<DataSet> DSList = FillDataForSubReport(report);
                DSList.Insert(0, mMainDataSet);

                FillParams(report);
                //#region Phiên bản 12
                //PLCrystalReportViewer view = new PLCrystalReportViewer();
                //view._I.ReportSource = report;
                //view._DSList = DSList;
                //view._I.PrintReport();
                //#endregion
                #region Phiên bản 10
                PLCrystalReportViewer view = new PLCrystalReportViewer();
                view.ReportSource = report;
                view._DSList = DSList;
                view.PrintReport();
                #endregion
            }
            catch (Exception ex)
            {
                HelpMsgBox.ShowNotificationMessage("Lỗi máy in");
                PLException.AddException(ex);
            }
        }