Example #1
0
        private void Export(LocalReport Report)
        {
            string strMessage = string.Empty;

            EMFDeviceInfo emfdi = this.ReadSetting(out strMessage);

            string strDeviceInfo = emfdi.DeviceInfoString;

            emfdi = null;

            Microsoft.Reporting.WinForms.Warning[] Warnings;

            this.m_EMFStreams = new System.Collections.Generic.List <System.IO.Stream>();

            Report.Render("Image", strDeviceInfo, this.CreateStream, out Warnings);

            foreach (System.IO.Stream s in this.m_EMFStreams)
            {
                s.Position = 0;
            }
        }
Example #2
0
        private EMFDeviceInfo ReadSetting(out string WarningMessage)
        {
            WarningMessage = string.Empty;

            System.Data.DataSet dsXML = new DataSet();

            EMFDeviceInfo emfdi = new EMFDeviceInfo();

            dsXML.ReadXml(System.Windows.Forms.Application.StartupPath + @"\ReportSettings.xml");

            System.Data.DataTable dtXML = new DataTable();

            foreach (System.Data.DataTable dt in dsXML.Tables)
            {
                if (dt.TableName == this.m_ReportName)
                {
                    dtXML = dt;
                    break;
                }
            }

            if (dtXML.Rows.Count != 0)
            {
                System.Data.DataRow dr = dtXML.Rows[0];
                if (Printer.PrinterInList(dr["PrinterName"].ToString()))
                {
                    base.PrinterSettings.PrinterName = dr["PrinterName"].ToString();
                    if (Printer.FormInPrinter(dr["PrinterName"].ToString(), dr["PaperName"].ToString()))
                    {
                        if (Printer.FormSameSize(dr["PrinterName"].ToString(), dr["PaperName"].ToString(), System.Convert.ToDecimal(dr["PageWidth"]), System.Convert.ToDecimal(dr["PageHeight"])))
                        {
                            bool bolExist = false;

                            foreach (System.Drawing.Printing.PaperSize ps in base.PrinterSettings.PaperSizes)
                            {
                                if (ps.PaperName == dr["PaperName"].ToString())
                                {
                                    base.PrinterSettings.DefaultPageSettings.PaperSize = ps;
                                    base.DefaultPageSettings.PaperSize = ps;
                                    bolExist = true;
                                    break;
                                }
                            }

                            if (!bolExist)
                            {
                                WarningMessage += "\r\n Can not use the customized paper, because the printer selected does not the customized papersize!";

                                if (dtXML != null)
                                {
                                    dtXML.Dispose();
                                }
                                if (dsXML != null)
                                {
                                    dsXML.Clear();
                                    dsXML = null;
                                }

                                return(null);
                            }

                            if (dr["Orientation"].ToString() == "Z")
                            {
                                base.DefaultPageSettings.Landscape = false;
                                base.PrinterSettings.DefaultPageSettings.Landscape = false;
                                emfdi.Landscape = false;
                            }
                            else
                            {
                                base.DefaultPageSettings.Landscape = true;
                                base.PrinterSettings.DefaultPageSettings.Landscape = true;
                                emfdi.Landscape = true;
                            }

                            this.bolOrientation = emfdi.Landscape;

                            emfdi.PageWidth    = System.Convert.ToDecimal(dr["PageWidth"].ToString());
                            emfdi.PageHeight   = System.Convert.ToDecimal(dr["PageHeight"].ToString());
                            emfdi.MarginTop    = System.Convert.ToDecimal(dr["MarginTop"].ToString());
                            emfdi.MarginBottom = System.Convert.ToDecimal(dr["MarginBottom"].ToString());
                            emfdi.MarginLeft   = System.Convert.ToDecimal(dr["MarginLeft"].ToString());
                            emfdi.MarginRight  = System.Convert.ToDecimal(dr["MarginRight"].ToString());

                            base.PrinterSettings.PrinterName = dr["PrinterName"].ToString();

                            if (dtXML != null)
                            {
                                dtXML.Dispose();
                            }
                            if (dsXML != null)
                            {
                                dsXML.Clear();
                                dsXML = null;
                            }
                            WarningMessage = string.Empty;
                            return(emfdi);
                        }
                        else
                        {
                            WarningMessage += "\r\n Papersize defined in the config file is not the same with the one in the system!";
                        }
                    }
                    else
                    {
                        WarningMessage += "\r\n Printer defined in the config file does not support the customized papersize!";
                    }
                }
                else
                {
                    WarningMessage += "\r\n Printer defined in the config file is not in the available printer list!";
                }
            }
            else
            {
                WarningMessage += "\r\n Can not get any information about the report in the config file!";
            }

            if (dtXML != null)
            {
                dtXML.Dispose();
            }
            if (dsXML != null)
            {
                dsXML.Clear();
                dsXML = null;
            }
            return(null);
        }