public void GetPdf()
        {
            MetaFile    meta  = GetMetaFile();
            PrintOutPDF prpdf = new PrintOutPDF();

            prpdf.Print(meta);
            prpdf.PDFStream.Seek(0, SeekOrigin.Begin);
            Page.Response.ContentType = "application/pdf";
            Page.Response.BinaryWrite(prpdf.PDFStream.ToArray());
            Page.Response.End();
        }
        private void bsfirst_Click(object sender, EventArgs e)
        {
            if (sender == BExit)
            {
                Close();
            }
            if (sender == bsfirst)
            {
                fmetapr.Page = 0;
                return;
            }
            if (sender == bsprior)
            {
                fmetapr.PriorPage();
                return;
            }
            if (sender == bsnext)
            {
                fmetapr.NextPage();
                return;
            }
            if (sender == bslast)
            {
                fmetapr.LastPage();
                return;
            }
            if (sender == bssearch)
            {
                FindNext();
                return;
            }
            if (sender == BScaleFull)
            {
                fmetapr.AutoScale = AutoScaleType.Real;
//                BScaleFull.Checked = true;
//                BScaleEntire.Pushed = false;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == this.BPageSetup)
            {
                try
                {
                    if (fmetapr.OnPageSetup())
                    {
                        if (fmetapr.MetaFile.Empty)
                        {
                            DisableButtons();
                        }
                        else
                        {
                            EnableButtons();
                        }
                    }
                }
                catch
                {
                    DisableButtons();
                    throw;
                }
                return;
            }
            if (sender == this.BParameters)
            {
                try
                {
                    if (fmetapr.OnReportParams())
                    {
                        if (fmetapr.MetaFile.Empty)
                        {
                            DisableButtons();
                        }
                        else
                        {
                            EnableButtons();
                        }
                    }
                }
                catch
                {
                    DisableButtons();
                    throw;
                }
                return;
            }
            if (sender == BScaleWide)
            {
                fmetapr.AutoScale = AutoScaleType.Wide;
//                BScaleFull.Checked = false;
//                BScaleEntire.Pushed = false;
//                BScaleWide.Checked = true;
                return;
            }
            if (sender == BScaleEntire)
            {
                fmetapr.AutoScale = AutoScaleType.EntirePage;
//                BScaleFull.Checked = false;
//                BScaleEntire.Pushed = true;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == BZoomMinus)
            {
                fmetapr.PreviewScale = fmetapr.PreviewScale - 0.1F;
//                BScaleFull.Checked = false;
//                BScaleEntire.Pushed = false;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == BZoomPlus)
            {
                fmetapr.PreviewScale = fmetapr.PreviewScale + 0.1F;
//                BScaleFull.Checked = false;
//                BScaleEntire.Checked = false;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == BPrint)
            {
                PrintOutWinForms prw = new PrintOutWinForms();
                //				prw.Preview=true;
                if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                    (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                {
                    fmetapr.MetaFile.Clear();
                    fmetapr.MetaFile.BeginPrint(prw);
                }
                prw.ShowPrintDialog = true;
                prw.Print(fmetapr.MetaFile);
                return;
            }
            if (sender == BSave)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    switch (saveFileDialog1.FilterIndex)
                    {
                    case 1:
                    case 2:
                    case 3:
                        PrintOutPDF prpdf = new PrintOutPDF();
                        if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                            (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                        {
                            fmetapr.MetaFile.Clear();
                            fmetapr.MetaFile.BeginPrint(prpdf);
                        }
                        prpdf.Compressed = (saveFileDialog1.FilterIndex == 0);
                        if (saveFileDialog1.FilterIndex != 0)
                        {
                            string nfilename  = saveFileDialog1.FileName;
                            string nextension = System.IO.Path.GetExtension(nfilename).ToUpper();
                            if (nextension != ".PDF")
                            {
                                nfilename = nfilename + ".pdf";
                            }
                            prpdf.FileName = nfilename;
                            prpdf.Print(fmetapr.MetaFile);
                        }
                        else
                        {
                            fmetapr.MetaFile.SaveToFile(saveFileDialog1.FileName, true);
                        }
                        break;

                    case 4:
                    case 5:
                        PrintOutExcel prex = new PrintOutExcel();
                        prex.OneSheet = (saveFileDialog1.FilterIndex == 5);
                        prex.FileName = saveFileDialog1.FileName;

                        if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                            (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                        {
                            fmetapr.MetaFile.Clear();
                            fmetapr.MetaFile.BeginPrint(prex);
                        }
                        prex.Print(fmetapr.MetaFile);
                        break;
                    }
                }
                return;
            }
            if (sender == BMail)
            {
                // Update mail params
                if (fmetapr.OnMail != null)
                {
                    //                    string file_name;
                    string      filename;
                    PrintOutPDF prpdf = new PrintOutPDF();
                    if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                        (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                    {
                        fmetapr.MetaFile.Clear();
                        fmetapr.MetaFile.BeginPrint(prpdf);
                    }
                    filename = System.IO.Path.GetTempFileName();
                    try
                    {
                        prpdf.Compressed = true;
                        prpdf.FileName   = filename;
                        prpdf.Print(fmetapr.MetaFile);
                        fmetapr.OnMail(filename);
                    }
                    finally
                    {
                        System.IO.File.Delete(prpdf.FileName);
                    }
                }
                return;
            }
        }
Example #3
0
        protected override object Run(FacturaPagoSendMail request)
        {
            string msg     = string.Empty;
            Pago   factura = new Pago();

            if (request.Id != default(Int32))
            {
                factura = DbFactory.Factura(request.Id);
                if (factura == default(Pago))
                {
                    msg = string.Format("NO existe factura con Id:'{0}'", request.Id);
                }
            }
            else
            {
                if (request.Numero.IsNullOrEmpty())
                {
                    msg = "Debe Indicar la factura para enviar el correo";
                }
                else
                {
                    factura = DbFactory.Factura(request.Numero);
                    if (factura == default(Pago))
                    {
                        msg = string.Format("NO existe factura con Numero:'{0}'", request.Numero);
                    }
                }
            }

            if (!msg.IsNullOrEmpty())
            {
                return(new FacturaPagoSendMailResponse()
                {
                    Success = false,
                    ResponseStatus = new ResponseStatus()
                    {
                        ErrorCode = "FacturaNoIndicada",
                        Message = msg
                    }
                });
            }

            FileInfo fielInfo = new FileInfo(factura.Id.PdfFileName(Config.PrintOutDirectory));

            if (!fielInfo.Exists)
            {
                try{
                    Report r = new Report();
                    r.LoadFromFile(Path.Combine(Config.MetaFilesDirectory, "factura.rep"));
                    foreach (DataInfo di in r.DataInfo)
                    {
                        r.DataInfo[di.Alias].GetDbItem().ConnectionString = Config.ReportConnection;
                    }
                    r.Params["IDPAGO"].Value = factura.Id.ToString();

                    PrintOutPDF pdfFile = new PrintOutPDF();
                    pdfFile.FileName = factura.Id.PdfFileName(Config.PrintOutDirectory);
                    pdfFile.Print(r.MetaFile);
                }
                catch (Exception e) {
                    return(new FacturaPagoSendMailResponse()
                    {
                        Success = false,
                        ResponseStatus = new ResponseStatus()
                        {
                            ErrorCode = "ErrorImpresion",
                            Message = e.Message
                        }
                    });
                }
            }

            Persona p = DbFactory.Persona(factura.IdPersona);

            if (p.Email.IsValidEmail())
            {
                try{
                    Mail = new Mailer(Config);
                    Mail.Message.Subject    = string.Format("{0} Factura {1}", Config.MensajeAsunto, request.Numero);
                    Mail.Message.IsBodyHtml = true;
                    Mail.Message.Body       = "Cordial saludo.<br />Adjuntamos su factura de pago<br />Gracias por preferirnos";
                    Mail.Message.To.Add(p.Email);
                    Mail.Message.Attachments.Add(new Attachment(fielInfo.FullName, MediaTypeNames.Application.Pdf));
                    Mail.Send();
                }
                catch (Exception e) {
                    return(new FacturaPagoSendMailResponse()
                    {
                        Success = false,
                        ResponseStatus = new ResponseStatus()
                        {
                            ErrorCode = "ErrorMail",
                            Message = e.Message
                        }
                    });
                }
            }
            else
            {
                return(new FacturaPagoSendMailResponse()
                {
                    Success = false,
                    ResponseStatus = new ResponseStatus()
                    {
                        ErrorCode = "ErrorMail",
                        Message = string.Format("Correo no Valido : '{0}'", p.Email)
                    }
                });
            }


            return(new FacturaPagoSendMailResponse()
            {
                Success = true
            });
        }
Example #4
0
        public static void Main(string[] args)
        {
            bool dothrow = false;


            Report rp = new Report();

            try
            {
                bool   asyncexecution  = true;
                bool   stdin           = false;
                bool   pdf             = false;
                bool   showprintdialog = false;
                string filename        = "";
                string pdffilename     = "";
                string fieldsfilename  = "";
                bool   deletereport    = false;
                bool   compressedpdf   = true;
                bool   showfields      = false;
                bool   testconnection  = false;
                string connectionname  = "";
                bool   doprint         = true;
                bool   evaluatetext    = false;
                bool   syntaxcheck     = false;
                bool   doread          = true;
                string evaltext        = "";
                string dataset         = "";
#if REPMAN_DOTNET2
                bool   showproviders     = false;
                string providersfilename = "";
#endif
                try
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i].Length > 0)
                        {
                            switch (args[i].ToUpper())
                            {
                            case "-STDIN":
                                stdin = true;
                                break;

                            case "-SYNCEXECUTION":
                                asyncexecution = false;
                                break;

                            case "-U":
                                compressedpdf = false;
                                break;

                            case "-THROW":
                                dothrow = true;
                                break;

                            case "-PDF":
                                pdf = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    pdffilename = args[i];
                                }
                                break;

                            case "-TESTCONNECTION":
                                doprint        = false;
                                testconnection = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    connectionname = args[i];
                                }
                                break;

                            case "-EVAL":
                                doprint      = false;
                                evaluatetext = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    evaltext = args[i];
                                }
                                break;

                            case "-SYNTAX":
                                doprint     = false;
                                syntaxcheck = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    evaltext = args[i];
                                }
                                break;

                            case "-SHOWFIELDS":
                                showfields = true;
                                doprint    = false;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    dataset = args[i];
                                }
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    fieldsfilename = args[i];
                                }
                                break;

#if REPMAN_DOTNET2
                            case "-GETPROVIDERS":
                                showproviders = true;
                                doprint       = false;
                                doread        = false;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    providersfilename = args[i];
                                }
                                break;
#endif
                            case "-DELETEREPORT":
                                deletereport = true;
                                break;

                            case "-PRINTDIALOG":
                                showprintdialog = true;
                                break;

                            default:
                                if (args[i][0] == '-')
                                {
                                    throw new Exception("Invalid argument:" + args[i]);
                                }
                                if (filename.Length > 0)
                                {
                                    filename = args[i];
                                }
                                else
                                {
                                    filename = args[i];
                                }
                                break;
                            }
                        }
                    }
#if REPMAN_DOTNET2
                    if (showproviders)
                    {
                        int       indexp;
                        DataTable atable = DbProviderFactories.GetFactoryClasses();
                        if (providersfilename.Length == 0)
                        {
                            string messageproviders = "";
                            for (indexp = 0; indexp < atable.Rows.Count; indexp++)
                            {
                                if (messageproviders.Length != 0)
                                {
                                    messageproviders = messageproviders + (char)13 + (char)10;
                                }
                                messageproviders = messageproviders + atable.Rows[indexp][2].ToString();
                            }
                            System.Console.WriteLine(messageproviders);
                        }
                        else
                        {
                            FileStream providersstream = new FileStream(providersfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);
                            try
                            {
                                for (indexp = 0; indexp < atable.Rows.Count; indexp++)
                                {
                                    StreamUtil.SWriteLine(providersstream, atable.Rows[indexp][2].ToString());
                                }
                            }
                            finally
                            {
                                providersstream.Close();
                            }
                        }
                    }
#endif
                    if (doread)
                    {
                        if (stdin)
                        {
                            Stream astream = System.Console.OpenStandardInput();
                            rp.LoadFromStream(astream, 8192);
                        }
                        else
                        {
                            rp.LoadFromFile(filename);
                        }
                    }
                    if (testconnection)
                    {
                        int conindex = rp.DatabaseInfo.IndexOf(connectionname);
                        if (conindex < 0)
                        {
                            throw new Exception("Connection name not found:" + connectionname);
                        }
                        rp.DatabaseInfo[conindex].Connect();
                        System.Console.WriteLine("Connexion successfull:" + connectionname);
                    }
                    if (showfields)
                    {
                        int index = rp.DataInfo.IndexOf(dataset);
                        if (index < 0)
                        {
                            throw new Exception("Dataset not found:" + dataset);
                        }
                        rp.DataInfo[index].Connect();
                        FileStream fstream = new FileStream(fieldsfilename,
                                                            System.IO.FileMode.Create, System.IO.FileAccess.Write,
                                                            System.IO.FileShare.None);
                        try
                        {
                            rp.DataInfo[index].GetFieldsInfo(fstream);
                        }
                        finally
                        {
                            fstream.Close();
                        }
                    }
                    if ((evaluatetext) || (syntaxcheck))
                    {
                        rp.PrintOnlyIfDataAvailable = false;
                        PrintOutPDF printpdf2 = new PrintOutPDF();
                        rp.BeginPrint(printpdf2);
                        if (evaluatetext)
                        {
                            try
                            {
                                Variant aresult = rp.Evaluator.EvaluateText(evaltext);
                                System.Console.WriteLine("Result:" + aresult.ToString());
                            }
                            catch (EvalException e)
                            {
                                System.Console.WriteLine("Error Line: " + e.SourceLine.ToString() +
                                                         " Error position:" + e.SourcePos.ToString() + " - " + e.Message);
                            }
                            catch (Exception E)
                            {
                                System.Console.WriteLine("Error: " + E.Message);
                            }
                        }
                        else
                        {
                            try
                            {
                                rp.Evaluator.CheckSyntax(evaltext);
                                System.Console.WriteLine("Syntax check ok");
                            }
                            catch (Exception E)
                            {
                                System.Console.WriteLine("Error: " + E.Message);
                            }
                        }
                    }
                    if (doprint)
                    {
                        if (pdf)
                        {
                            rp.AsyncExecution = false;
                            PrintOutPDF printpdf = new PrintOutPDF();
                            printpdf.FileName   = pdffilename;
                            printpdf.Compressed = compressedpdf;
                            printpdf.Print(rp.MetaFile);
                        }
                        else
                        {
                            PrintOutNet prw = new PrintOutNet();
                            rp.AsyncExecution = false;
                            prw.Print(rp.MetaFile);
                        }
                    }
                }
                finally
                {
                    if (deletereport)
                    {
                        if (filename.Length > 0)
                        {
                            System.IO.File.Delete(filename);
                        }
                    }
                }
            }
            catch (Exception E)
            {
                if (!dothrow)
                {
                    int    i;
                    string amessage = E.Message + (char)13 + (char)10;
                    for (i = 0; i < args.Length; i++)
                    {
                        amessage = amessage + (char)13 + (char)10 + "Arg" + i.ToString() + ":" + args[i];
                    }
                    Strings astrings = GetParams();
                    for (i = 0; i < astrings.Count; i++)
                    {
                        amessage = amessage + (char)13 + (char)10 + astrings[i];
                    }

                    System.Console.WriteLine(amessage, "Error");
                }
                else
                {
                    PrintParams();
                    throw;
                }
//				Variant.WriteStringToUTF8Stream(amessage,System.Console.OpenStandardError());
            }
        }
Example #5
0
        protected override object Run(FacturaPagoImprimir request)
        {
            string msg     = string.Empty;
            Pago   factura = new Pago();

            if (request.Id != default(Int32))
            {
                factura = DbFactory.Factura(request.Id);
                if (factura == default(Pago))
                {
                    msg = string.Format("NO existe factura con Id:'{0}'", request.Id);
                }
            }
            else
            {
                if (request.Numero.IsNullOrEmpty())
                {
                    msg = "Debe Indicar la factura para Imprimir";
                }
                else
                {
                    factura = DbFactory.Factura(request.Numero);
                    if (factura == default(Pago))
                    {
                        msg = string.Format("NO existe factura con Numero:'{0}'", request.Numero);
                    }
                }
            }

            if (!msg.IsNullOrEmpty())
            {
                return(new FacturaPagoImprimirResponse()
                {
                    Success = false,
                    ResponseStatus = new ResponseStatus()
                    {
                        ErrorCode = "FacturaNoIndicada",
                        Message = msg
                    }
                });
            }

            FileInfo fielInfo = new FileInfo(factura.Id.PdfFileName(Config.PrintOutDirectory));

            if (!fielInfo.Exists || request.Override)
            {
                try{
                    Report r = new Report();
                    r.LoadFromFile(Path.Combine(Config.MetaFilesDirectory, "factura.rep"));
                    foreach (DataInfo di in r.DataInfo)
                    {
                        r.DataInfo[di.Alias].GetDbItem().ConnectionString = Config.ReportConnection;
                    }
                    r.Params["IDPAGO"].Value = factura.Id.ToString();

                    PrintOutPDF pdfFile = new PrintOutPDF();
                    pdfFile.FileName = factura.Id.PdfFileName(Config.PrintOutDirectory);
                    pdfFile.Print(r.MetaFile);
                }
                catch (Exception e) {
                    return(new FacturaPagoImprimirResponse()
                    {
                        Success = false,
                        ResponseStatus = new ResponseStatus()
                        {
                            ErrorCode = "ErrorImpresion",
                            Message = e.Message
                        }
                    });
                }
            }

            return(new FacturaPagoImprimirResponse()
            {
                Success = true
            });
        }
Example #6
0
        protected override object Run(FacturaPagoInsert request)
        {
            var tp = DbFactory.TipoPago(request.IdTipoPago);

            request.FechaPago        = DateTime.Today;
            request.FechaTerminacion =
                request.FechaInicio.FechaTerminacion(request.Cantidad * tp.Dias);

            request.IdUsuarioRegistra = Int16.Parse(Session.UserId);

            request.IdFormaPago = (request.IdFormaPago == default(Int16))
                                ? (System.Int16) 1
                                :request.IdFormaPago;

            request.ValorUnitario = tp.Valor;
            request.ValorTotal    = tp.Valor * request.Cantidad;
            request.Activa        = true;

            DbFactory.Exec(dbCmd =>
                           dbCmd.Insert(request));


            // imprimir
            string printMessage;
            bool   printSuccess;
            string mailMessage;
            bool   mailSuccess;

            try{
                Report r = new Report();
                r.LoadFromFile(Path.Combine(Config.MetaFilesDirectory, "factura.rep"));
                foreach (DataInfo di in r.DataInfo)
                {
                    r.DataInfo[di.Alias].GetDbItem().ConnectionString = Config.ReportConnection;
                }
                r.Params["IDPAGO"].Value = request.Id.ToString();

                PrintOutPDF pdfFile = new PrintOutPDF();
                pdfFile.FileName = request.Id.PdfFileName(Config.PrintOutDirectory);
                pdfFile.Print(r.MetaFile);
                printMessage = "OK";
                printSuccess = true;

                Persona p = DbFactory.Persona(request.IdPersona);
                if (p.Email.IsValidEmail())
                {
                    try{
                        Mail = new Mailer(Config);
                        Mail.Message.Subject    = string.Format("{0} Factura {1}", Config.GymName, request.Numero);
                        Mail.Message.IsBodyHtml = true;
                        Mail.Message.Body       = "Cordial saludo.<br />Adjuntamos su factura de pago";
                        Mail.Message.To.Add(p.Email);
                        Mail.Message.Attachments.Add(new Attachment(pdfFile.FileName, MediaTypeNames.Application.Pdf));
                        Mail.Send();
                        mailMessage = "OK";
                        mailSuccess = true;
                    }
                    catch (Exception e) {
                        mailMessage = e.Message;
                        mailSuccess = false;
                    }
                }
                else
                {
                    mailMessage = string.Format("Correo no Valido : '{0}'", p.Email);
                    mailSuccess = false;
                }
            }
            catch (Exception e) {
                printMessage = e.Message;
                printSuccess = false;
                mailMessage  = "Factura NO generada";
                mailSuccess  = false;
            }

            return(new FacturaPagoInsertResponse()
            {
                Factura = request as Pago,
                Success = true,
                PrintSuccess = printSuccess,
                PrintMessage = printMessage,
                MailMessage = mailMessage,
                MailSuccess = mailSuccess,
            });
        }
Example #7
0
        private void bsfirst_Click(object sender, EventArgs e)
        {
            if (sender == BExit)
            {
                if (WindowForm != null)
                {
                    WindowForm.Close();
                }
                else
                {
                    SendToBack();
                }
                if (OnClose != null)
                {
                    OnClose(this, new EventArgs());
                }
                return;
            }
            if (sender == bsfirst)
            {
                fmetapr.Page = 0;
                return;
            }
            if (sender == bsprior)
            {
                fmetapr.PriorPage();
                return;
            }
            if (sender == bsnext)
            {
                fmetapr.NextPage();
                return;
            }
            if (sender == bslast)
            {
                fmetapr.LastPage();
                return;
            }
            if (sender == bssearch)
            {
                FindNext();
                return;
            }
            if (sender == BScaleFull)
            {
                fmetapr.AutoScale = AutoScaleType.Real;
//                BScaleFull.Checked = true;
//                BScaleEntire.Pushed = false;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == this.BPageSetup)
            {
                try
                {
                    if (fmetapr.OnPageSetup())
                    {
                        if (fmetapr.MetaFile.Empty)
                        {
                            DisableButtons();
                        }
                        else
                        {
                            EnableButtons();
                        }
                    }
                }
                catch
                {
                    DisableButtons();
                    throw;
                }
                return;
            }
            if (sender == this.BParameters)
            {
                try
                {
                    if (fmetapr.OnReportParams())
                    {
                        if (fmetapr.MetaFile.Empty)
                        {
                            DisableButtons();
                        }
                        else
                        {
                            EnableButtons();
                        }
                    }
                }
                catch
                {
                    DisableButtons();
                    throw;
                }
                return;
            }
            if (sender == BScaleWide)
            {
                fmetapr.AutoScale = AutoScaleType.Wide;
//                BScaleFull.Checked = false;
//                BScaleEntire.Pushed = false;
//                BScaleWide.Checked = true;
                return;
            }
            if (sender == BScaleEntire)
            {
                fmetapr.AutoScale = AutoScaleType.EntirePage;
//                BScaleFull.Checked = false;
//                BScaleEntire.Pushed = true;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == BZoomMinus)
            {
                fmetapr.PreviewScale = fmetapr.PreviewScale - 0.1F;
//                BScaleFull.Checked = false;
//                BScaleEntire.Pushed = false;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == BZoomPlus)
            {
                fmetapr.PreviewScale = fmetapr.PreviewScale + 0.1F;
//                BScaleFull.Checked = false;
//                BScaleEntire.Checked = false;
//                BScaleWide.Checked = false;
                return;
            }
            if (sender == BPrint)
            {
                PrintOutWinForms prw = new PrintOutWinForms();
                //				prw.Preview=true;
                if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                    (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                {
                    fmetapr.MetaFile.Clear();
                    fmetapr.MetaFile.BeginPrint(prw);
                }
                prw.ShowPrintDialog = true;
                prw.Print(fmetapr.MetaFile);
                return;
            }
            if (sender == BSave)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    switch (saveFileDialog1.FilterIndex)
                    {
                    case 1:
                    case 2:
                    case 3:
                        PrintOutPDF prpdf = new PrintOutPDF();
                        if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                            (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                        {
                            fmetapr.MetaFile.Clear();
                            fmetapr.MetaFile.BeginPrint(prpdf);
                        }
                        prpdf.Compressed = (saveFileDialog1.FilterIndex == 0);
                        if (saveFileDialog1.FilterIndex != 0)
                        {
                            string nfilename  = saveFileDialog1.FileName;
                            string nextension = System.IO.Path.GetExtension(nfilename).ToUpper();
                            if (nextension != ".PDF")
                            {
                                nfilename = nfilename + ".pdf";
                            }
                            prpdf.FileName = nfilename;
                            prpdf.Print(fmetapr.MetaFile);
                        }
                        else
                        {
                            fmetapr.MetaFile.SaveToFile(saveFileDialog1.FileName, true);
                        }
                        break;

                    case 4:
                    case 5:
                        PrintOutExcel prex = new PrintOutExcel();
                        prex.OneSheet = (saveFileDialog1.FilterIndex == 5);
                        prex.FileName = saveFileDialog1.FileName;

                        if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                            (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                        {
                            fmetapr.MetaFile.Clear();
                            fmetapr.MetaFile.BeginPrint(prex);
                        }
                        prex.Print(fmetapr.MetaFile);
                        break;

                    case 6:
                    case 7:
                        string nresult = PrintOutCSV.ExportToCSV(fmetapr.MetaFile, true, 0, 0, System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ListSeparator, '\"', 5);
                        using (System.IO.FileStream nfstream = new System.IO.FileStream(saveFileDialog1.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                        {
                            if (saveFileDialog1.FilterIndex == 6)
                            {
                                StreamUtil.WriteStringToUTF8Stream(nresult, nfstream);
                            }
                            else
                            {
                                StreamUtil.WriteStringToStream(nresult, nfstream, Encoding.GetEncoding(1252));
                            }
                        }
                        break;
                    }
                }
                return;
            }
            if (sender == BMail)
            {
                // Update mail params
                if (fmetapr.OnMail != null)
                {
                    SendMailEventArgs margs = new SendMailEventArgs();
                    //                    string file_name;
                    string      filename;
                    PrintOutPDF prpdf = new PrintOutPDF();
                    if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                        (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                    {
                        fmetapr.MetaFile.Clear();
                        fmetapr.MetaFile.BeginPrint(prpdf);
                    }
                    filename = System.IO.Path.GetTempFileName();
                    try
                    {
                        filename         = System.IO.Path.ChangeExtension(filename, ".pdf");
                        prpdf.Compressed = true;
                        //prpdf.FileName = filename;
                        prpdf.FileName = "";
                        margs.Filename = filename;
                        prpdf.Print(fmetapr.MetaFile);
                        margs.Filename = filename;
                        margs.Content  = ((System.IO.MemoryStream)prpdf.PDFStream).ToArray();
                        StreamUtil.MemoryStreamToFile((System.IO.MemoryStream)prpdf.PDFStream, filename);
                        fmetapr.OnMail(this, margs);
                    }
                    finally
                    {
                        if (System.IO.File.Exists(filename))
                        {
                            System.IO.File.Delete(filename);
                        }
                    }
                }
                return;
            }
        }
Example #8
0
        private void BToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            if (e.Button == BExit)
            {
                Close();
            }
            if (sender == bsfirst)
            {
                fmetapr.Page = 0;
                return;
            }
            if (sender == bsprior)
            {
                fmetapr.PriorPage();
                return;
            }
            if (sender == bsnext)
            {
                fmetapr.NextPage();
                return;
            }
            if (sender == bslast)
            {
                fmetapr.LastPage();
                return;
            }
            if (sender == bssearch)
            {
                FindNext();
                return;
            }
            if (e.Button == BScaleFull)
            {
                fmetapr.AutoScale   = AutoScaleType.Real;
                BScaleFull.Pushed   = true;
                BScaleEntire.Pushed = false;
                BScaleWide.Pushed   = false;
                return;
            }
            if (e.Button == this.BPageSetup)
            {
                if (fmetapr.OnPageSetup())
                {
                }
                return;
            }
            if (e.Button == this.BParameters)
            {
                if (fmetapr.OnReportParams())
                {
                }
                return;
            }
            if (e.Button == BScaleWide)
            {
                fmetapr.AutoScale   = AutoScaleType.Wide;
                BScaleFull.Pushed   = false;
                BScaleEntire.Pushed = false;
                BScaleWide.Pushed   = true;
                return;
            }
            if (e.Button == BScaleEntire)
            {
                fmetapr.AutoScale   = AutoScaleType.EntirePage;
                BScaleFull.Pushed   = false;
                BScaleEntire.Pushed = true;
                BScaleWide.Pushed   = false;
                return;
            }
            if (e.Button == BZoomMinus)
            {
                fmetapr.PreviewScale = fmetapr.PreviewScale - 0.1F;
                BScaleFull.Pushed    = false;
                BScaleEntire.Pushed  = false;
                BScaleWide.Pushed    = false;
                return;
            }
            if (e.Button == BZoomPlus)
            {
                fmetapr.PreviewScale = fmetapr.PreviewScale + 0.1F;
                BScaleFull.Pushed    = false;
                BScaleEntire.Pushed  = false;
                BScaleWide.Pushed    = false;
                return;
            }
            if (e.Button == BPrint)
            {
                PrintOutWinForms prw = new PrintOutWinForms();
                //				prw.Preview=true;
                if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                    (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                {
                    fmetapr.MetaFile.Clear();
                    fmetapr.MetaFile.BeginPrint(prw);
                }
                prw.ShowPrintDialog = true;
                prw.Print(fmetapr.MetaFile);
                return;
            }
            if (e.Button == BSave)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    PrintOutPDF prpdf = new PrintOutPDF();
                    if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                        (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                    {
                        fmetapr.MetaFile.Clear();
                        fmetapr.MetaFile.BeginPrint(prpdf);
                    }
                    prpdf.Compressed = (saveFileDialog1.FilterIndex == 0);
                    prpdf.FileName   = saveFileDialog1.FileName;
                    prpdf.Print(fmetapr.MetaFile);
                }
                return;
            }
            if (e.Button == BMail)
            {
                // Update mail params
                if (fmetapr.OnMail != null)
                {
//                    string file_name;
                    string      filename;
                    PrintOutPDF prpdf = new PrintOutPDF();
                    if ((fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Recalculate) ||
                        (fmetapr.MetaFile.PrinterFonts == PrinterFontsType.Always))
                    {
                        fmetapr.MetaFile.Clear();
                        fmetapr.MetaFile.BeginPrint(prpdf);
                    }
                    filename = System.IO.Path.GetTempFileName();
                    try
                    {
                        prpdf.Compressed = true;
                        prpdf.FileName   = filename;
                        prpdf.Print(fmetapr.MetaFile);
                        fmetapr.OnMail(filename);
                    }
                    finally
                    {
                        System.IO.File.Delete(prpdf.FileName);
                    }
                }
                return;
            }
        }
Example #9
0
        public static void Main(string[] args)
        {
            string printername = "";

            AssemblyResolver.HandleUnresolvedAssemblies();

#if REPMAN_DOTNET2
            // Bug in .Net 1.x, don't enable, but you can use a .manifest file
#if FORMS
            Application.EnableVisualStyles();
#endif
#endif
            bool dothrow = false;



            Report rp = new Report();
            try
            {
                bool   asyncexecution  = true;
                bool   stdin           = false;
                bool   pdf             = false;
                bool   metafile        = false;
                bool   showprintdialog = false;
                string filename        = "";
                string pdffilename     = "";
                string fieldsfilename  = "";
                bool   deletereport    = false;
                bool   showprogress    = false;
                bool   preview         = false;
                bool   showparams      = false;
                bool   compressedpdf   = true;
                bool   systempreview   = false;
                bool   showdata        = false;
                bool   showfields      = false;
                bool   testconnection  = false;
                string connectionname  = "";
                bool   doprint         = true;
                bool   evaluatetext    = false;
                bool   syntaxcheck     = false;
                bool   doread          = true;
                string evaltext        = "";
                string dataset         = "";
                SortedList <string, string> ParamValues = new SortedList <string, string>();
#if REPMAN_DOTNET2
                bool   showproviders     = false;
                string providersfilename = "";
#endif
                try
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i].Trim().Length > 0)
                        {
                            switch (args[i].ToUpper())
                            {
                            case "-STDIN":
                                stdin = true;
                                break;

                            case "-PREVIEW":
                                preview = true;
                                break;

                            case "-SHOWPARAMS":
                                showparams = true;
                                break;

                            case "-SYNCEXECUTION":
                                asyncexecution = false;
                                break;

                            case "-SYSTEMPREVIEW":
                                systempreview = true;
                                break;

                            case "-U":
                                compressedpdf = false;
                                break;

                            case "-THROW":
                                dothrow = true;
                                break;

                            case "-PDF":
                                pdf = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    pdffilename = args[i];
                                }
                                break;

                            case "-M":
                                metafile = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    pdffilename = args[i];
                                }
                                break;

                            case "-SHOWDATA":
                                showdata = true;
                                doprint  = false;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    dataset = args[i];
                                }
                                break;

                            case "-TESTCONNECTION":
                                doprint        = false;
                                testconnection = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    connectionname = args[i];
                                }
                                break;

                            case "-EVAL":
                                doprint      = false;
                                evaluatetext = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    evaltext = args[i];
                                }
                                break;

                            case "-SYNTAX":
                                doprint     = false;
                                syntaxcheck = true;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    evaltext = args[i];
                                }
                                break;

                            case "-SHOWFIELDS":
                                showfields = true;
                                doprint    = false;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    dataset = args[i];
                                }
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    fieldsfilename = args[i];
                                }
                                break;

                            case "-GETPROVIDERS":
                                showproviders = true;
                                doprint       = false;
                                doread        = false;
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    providersfilename = args[i];
                                }
                                break;

                            case "-GETPRINTERS":
                                System.Text.StringBuilder nprinters = new System.Text.StringBuilder();
                                nprinters.AppendLine("Installed printers:");
                                foreach (string pname in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                                {
                                    nprinters.AppendLine(pname);
                                }
#if FORMS
                                MessageBox.Show(nprinters.ToString());
#else
                                System.Console.WriteLine(nprinters.ToString());
#endif
                                break;

                            case "-PRINTERNAME":
                                if (args.GetUpperBound(0) > i)
                                {
                                    i++;
                                    printername = args[i];
                                }
                                else
                                {
                                    throw new Exception("A printer name must be provided after -printername");
                                }
                                break;

                            case "-SHOWPROGRESS":
                                showprogress = true;
                                break;

                            case "-DELETEREPORT":
                                deletereport = true;
                                break;

                            case "-PRINTDIALOG":
                                showprintdialog = true;
                                break;

                            default:
                                // Get parameter names and values
                                string argname = args[i];
                                if (argname[0] == '-')
                                {
                                    bool correctparam = false;
                                    if (argname.Length > 7)
                                    {
                                        if (argname.Substring(0, 6).ToUpper() == "-PARAM")
                                        {
                                            argname = argname.Substring(6, argname.Length - 6);
                                            int indexequ = argname.IndexOf('=');
                                            if (indexequ < 0)
                                            {
                                                throw new Exception("Invalid syntax in -param, -paramPARAMNAME=value syntax must be used");
                                            }
                                            string paramvalue = argname.Substring(indexequ + 1, argname.Length - indexequ - 1);
                                            argname = argname.Substring(0, indexequ);
                                            ParamValues.Add(argname, paramvalue);
                                            System.Console.WriteLine("Decoded parameter: " + argname + " value " + paramvalue);
                                            correctparam = true;
                                        }
                                    }
                                    if (!correctparam)
                                    {
                                        throw new Exception("Invalid argument:" + args[i]);
                                    }
                                }
                                else
                                {
                                    if (filename.Length > 0)
                                    {
                                        filename = args[i];
                                    }
                                    else
                                    {
                                        filename = args[i];
                                    }
                                }
                                break;
                            }
                        }
                    }
                    AddCustomFactories();

#if REPMAN_DOTNET2
                    if (showproviders)
                    {
                        string messageproviders = "";

/*#if REPMAN_MONO
 *                                              if (providersfilename.Length == 0)
 *                                              {
 *                                                      foreach (Provider p in ProviderFactory.Providers)
 *                                                      {
 *                                                              if (messageproviders.Length!=0)
 *                                                                      messageproviders=messageproviders+(char)13+(char)10;
 *                                                              messageproviders=messageproviders+p.Name;
 *
 *                                                      }
 *                                                      MessageBox.Show(messageproviders,"Data providers");
 *                                              }
 *                                              else
 *                                              {
 *                                                      FileStream providersstream = new FileStream(providersfilename,System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.None);
 *                                                      try
 *                                                      {
 *                                                              foreach (Provider p2 in ProviderFactory.Providers)
 *                                                              {
 *                                                                      StreamUtil.SWriteLine(providersstream,p2.Name);
 *                                                              }
 *                                                      }
 *                                                      finally
 *                                                      {
 *                                                              providersstream.Close();
 *                                                      }
 *
 *                                              }
 #else*/
                        int       indexp;
                        DataTable atable = DbProviderFactories.GetFactoryClasses();
                        if (providersfilename.Length == 0)
                        {
                            bool firebirdfound = false;
                            bool mysqlfound    = false;
                            bool sqlitefound   = false;
                            for (indexp = 0; indexp < atable.Rows.Count; indexp++)
                            {
                                if (messageproviders.Length != 0)
                                {
                                    messageproviders = messageproviders + (char)13 + (char)10;
                                }
                                string nprovider = atable.Rows[indexp][2].ToString();
                                if (nprovider == DatabaseInfo.FIREBIRD_PROVIDER)
                                {
                                    firebirdfound = true;
                                }
                                if (nprovider == DatabaseInfo.MYSQL_PROVIDER)
                                {
                                    mysqlfound = true;
                                }
                                if (nprovider == DatabaseInfo.SQLITE_PROVIDER)
                                {
                                    sqlitefound = true;
                                }
                                messageproviders = messageproviders + atable.Rows[indexp][2].ToString();
                            }
                            if (!firebirdfound)
                            {
                                messageproviders = DatabaseInfo.FIREBIRD_PROVIDER + (char)13 + (char)10 + messageproviders;
                            }
                            if (!mysqlfound)
                            {
                                messageproviders = DatabaseInfo.MYSQL_PROVIDER + (char)13 + (char)10 + messageproviders;
                            }
                            if (!sqlitefound)
                            {
                                messageproviders = DatabaseInfo.SQLITE_PROVIDER + (char)13 + (char)10 + messageproviders;
                            }
#if FORMS
                            MessageBox.Show(messageproviders, "Data providers");
#else
                            System.Console.WriteLine("Data providers");
                            System.Console.WriteLine(messageproviders);
#endif
                        }
                        else
                        {
                            FileStream providersstream = new FileStream(providersfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);
                            try
                            {
                                bool    firebirdfound = false;
                                bool    mysqlfound    = false;
                                bool    sqlitefound   = false;
                                Strings nstrings      = new Strings();
                                for (indexp = 0; indexp < atable.Rows.Count; indexp++)
                                {
                                    string nprovider = atable.Rows[indexp][2].ToString();
                                    if (nprovider == DatabaseInfo.FIREBIRD_PROVIDER)
                                    {
                                        firebirdfound = true;
                                    }
                                    if (nprovider == DatabaseInfo.MYSQL_PROVIDER)
                                    {
                                        mysqlfound = true;
                                    }
                                    if (nprovider == DatabaseInfo.SQLITE_PROVIDER)
                                    {
                                        sqlitefound = true;
                                    }
                                    nstrings.Add(nprovider);
                                }
                                if (!firebirdfound)
                                {
                                    nstrings.Insert(0, DatabaseInfo.FIREBIRD_PROVIDER);
                                }
                                if (!mysqlfound)
                                {
                                    nstrings.Insert(0, DatabaseInfo.MYSQL_PROVIDER);
                                }
                                if (!sqlitefound)
                                {
                                    nstrings.Insert(0, DatabaseInfo.SQLITE_PROVIDER);
                                }

                                foreach (string nstring in nstrings)
                                {
                                    StreamUtil.SWriteLine(providersstream, nstring);
                                }
                            }
                            finally
                            {
                                providersstream.Close();
                            }
                        }
//#endif
                    }
#endif
                    if (doread)
                    {
                        if (stdin)
                        {
                            Stream astream = System.Console.OpenStandardInput();
                            rp.LoadFromStream(astream, 8192);
                        }
                        else
                        {
                            if (filename.Length == 0)
                            {
                                throw new Exception("You must provide a report filename");
                            }
                            rp.LoadFromFile(filename);
                        }

                        foreach (string nparamname in ParamValues.Keys)
                        {
                            string nvalue = ParamValues[nparamname];
                            if (rp.Params.IndexOf(nparamname) < 0)
                            {
                                System.Console.WriteLine("Warning: parameter not found created: " + nparamname);
                                Reportman.Reporting.Param xparam = new Reportman.Reporting.Param(rp);
                                xparam.Alias   = nparamname;
                                xparam.Visible = false;
                                rp.Params.Add(xparam);
                                //throw new Exception("Parameter " + nparamname + " not found");
                            }
                            rp.Params[nparamname].Value = nvalue;
                        }
                    }
                    if (showdata)
                    {
                        rp.PrintOnlyIfDataAvailable = false;
                        PrintOutPDF printpdf3 = new PrintOutPDF();
                        rp.BeginPrint(printpdf3);
#if FORMS
                        DataShow.ShowData(rp, dataset);
#else
                        rp.DataInfo[dataset].Connect();
                        ReportDataset ndataset = rp.DataInfo[dataset].Data;
                        foreach (DataColumn ncol in ndataset.Columns)
                        {
                            string nstring = ncol.ColumnName.PadLeft(30);
                            if (nstring.Length > 30)
                            {
                                nstring = nstring.Substring(0, 30);
                            }
                            System.Console.Write(nstring);
                        }
                        System.Console.WriteLine();
                        while (!ndataset.Eof)
                        {
                            foreach (DataColumn ncol in ndataset.Columns)
                            {
                                string nstring = ndataset.CurrentRow[ncol.ColumnName].ToString().PadLeft(30);
                                if (nstring.Length > 30)
                                {
                                    nstring = nstring.Substring(0, 30);
                                }
                                System.Console.Write(nstring);
                            }
                            System.Console.WriteLine();
                            ndataset.Next();
                        }
#endif
                    }
                    if (testconnection)
                    {
                        int conindex = rp.DatabaseInfo.IndexOf(connectionname);
                        if (conindex < 0)
                        {
                            throw new Exception("Connection name not found:" + connectionname);
                        }
                        rp.DatabaseInfo[conindex].Connect();
#if FORMS
                        MessageBox.Show("Connexion successfull:" + connectionname);
#else
                        System.Console.WriteLine("Connexion successfull:" + connectionname);
#endif
                    }
                    if (showfields)
                    {
                        int index = rp.DataInfo.IndexOf(dataset);
                        if (index < 0)
                        {
                            throw new Exception("Dataset not found:" + dataset);
                        }
                        rp.DataInfo[index].Connect();
                        FileStream fstream = new FileStream(fieldsfilename,
                                                            System.IO.FileMode.Create, System.IO.FileAccess.Write,
                                                            System.IO.FileShare.None);
                        try
                        {
                            rp.DataInfo[index].GetFieldsInfo(fstream);
                        }
                        finally
                        {
                            fstream.Close();
                        }
                    }
                    if ((evaluatetext) || (syntaxcheck))
                    {
                        rp.PrintOnlyIfDataAvailable = false;
                        PrintOutPDF printpdf2 = new PrintOutPDF();
                        rp.BeginPrint(printpdf2);
                        if (evaluatetext)
                        {
                            try
                            {
                                Variant aresult = rp.Evaluator.EvaluateText(evaltext);
#if FORMS
                                MessageBox.Show("Result:" + aresult.ToString());
#else
                                System.Console.WriteLine("Result:" + aresult.ToString());
#endif
                            }

                            catch (EvalException e)
                            {
#if FORMS
                                MessageBox.Show("Error Line: " + e.SourceLine.ToString() +
                                                " Error position:" + e.SourcePos.ToString() + " - " + e.Message);
#else
                                System.Console.WriteLine("Error Line: " + e.SourceLine.ToString() +
                                                         " Error position:" + e.SourcePos.ToString() + " - " + e.Message);
#endif
                            }
                            catch (Exception E)
                            {
#if FORMS
                                MessageBox.Show("Error: " + E.Message);
#else
                                System.Console.WriteLine("Error: " + E.Message);
#endif
                            }
                        }
                        else
                        {
                            try
                            {
                                rp.Evaluator.CheckSyntax(evaltext);
#if FORMS
                                MessageBox.Show("Syntax check ok");
#else
                                System.Console.WriteLine("Syntax check ok");
#endif
                            }
                            catch (Exception E)
                            {
#if FORMS
                                MessageBox.Show("Error: " + E.Message);
#else
                                System.Console.WriteLine("Error: " + E.Message);
#endif
                            }
                        }
                    }
                    // Ask for parameters?
                    if (doprint)
                    {
                        if (showparams)
                        {
#if FORMS
                            doprint = ParamsForm.ShowParams(rp);
#else
                            throw new Exception("Show params not supported in console mode");
#endif
                        }
                    }
                    if (doprint)
                    {
                        if (showprogress)
#if FORMS
                        {
                            ReportProgressForm fprogres = new ReportProgressForm();
                            fprogres.SetMetaFile(rp.MetaFile);
                            fprogres.Show();
                        }
#else
                        { throw new Exception("Show progress not supported in console mode"); }
#endif
                        if (pdf)
                        {
                            rp.AsyncExecution = false;
                            PrintOutPDF printpdf = new PrintOutPDF();
                            printpdf.FileName   = pdffilename;
                            printpdf.Compressed = compressedpdf;
                            printpdf.Print(rp.MetaFile);
                        }
                        else
                        if (metafile)
                        {
                            rp.AsyncExecution = false;
                            rp.TwoPass        = true;
                            PrintOutPDF printpdf = new PrintOutPDF();
                            printpdf.FileName   = "";
                            printpdf.Compressed = compressedpdf;
                            printpdf.Print(rp.MetaFile);
                            rp.MetaFile.SaveToFile(pdffilename, compressedpdf);
                        }
                        else
                        {
                            rp.AsyncExecution = asyncexecution;
#if FORMS
                            PrintOutReportWinForms prw = new PrintOutReportWinForms(rp);
                            prw.Preview         = preview;
                            prw.ShowInTaskbar   = true;
                            prw.SystemPreview   = systempreview;
                            prw.ShowPrintDialog = showprintdialog;
                            prw.Print(rp.MetaFile);
#else
                            PrintOutPrint prw = new PrintOutPrint();
                            if (printername.Length > 0)
                            {
                                PrintOutNet.DefaultPrinterName = printername;
                            }

                            prw.Print(rp.MetaFile);
#endif

                            //                                PrintOutWinForms prw = new PrintOutWinForms();
                            //							prw.OptimizeWMF = WMFOptimization.Gdiplus;
                        }
                    }
                }
                finally
                {
                    if (deletereport)
                    {
                        if (filename.Length > 0)
                        {
                            System.IO.File.Delete(filename);
                        }
                    }
                }
            }
            catch (Exception E)
            {
                if (!dothrow)
                {
                    int    i;
                    string amessage = E.Message + (char)13 + (char)10;
                    for (i = 0; i < args.Length; i++)
                    {
                        amessage = amessage + (char)13 + (char)10 + "Arg" + i.ToString() + ":" + args[i];
                    }
                    Strings astrings = GetParams();
                    for (i = 0; i < astrings.Count; i++)
                    {
                        amessage = amessage + (char)13 + (char)10 + astrings[i];
                    }

#if FORMS
                    MessageBox.Show(amessage, "Error");
#else
                    System.Console.WriteLine(amessage);
#endif
                    System.Console.WriteLine(E.StackTrace);
                }
                else
                {
                    PrintParams();
                    throw;
                }
                //				Variant.WriteStringToUTF8Stream(amessage,System.Console.OpenStandardError());
            }
        }