コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AllLetters">HTML text (could be several pages)</param>
        /// <param name="APathForImagesBase">Could be null if I'm not printing images!</param>
        public void PreviewOrPrint(String AllLetters, String APathForImagesBase)
        {
            System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            bool printerInstalled = printDocument.PrinterSettings.IsValid;

            if (!printerInstalled)
            {
                MessageBox.Show(Catalog.GetString("There is no printer, so printing is not possible"));
                return;
            }

            FGfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter);
            try
            {
                TPrinterHtml htmlPrinter = new TPrinterHtml(AllLetters,
                                                            APathForImagesBase,
                                                            FGfxPrinter);
                FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea);
                this.ppvLetters.InvalidatePreview();
                this.ppvLetters.Document       = FGfxPrinter.Document;
                this.ppvLetters.Zoom           = 1;
                FGfxPrinter.Document.EndPrint += new PrintEventHandler(this.EndPrint);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Use a .NET PrintPreview Dialog to print (or not print) this (possibly multi-page) HTML document.
        /// </summary>
        /// <param name="HtmlPages"></param>
        public static void PreviewOrPrint(String HtmlPages)
        {
            System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            bool printerInstalled = printDocument.PrinterSettings.IsValid;

            if (!printerInstalled)
            {
                MessageBox.Show(Catalog.GetString("There is no printer, so printing is not possible"));
                return;
            }

            TGfxPrinter  GfxPrinter  = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter);
            TPrinterHtml htmlPrinter = new TPrinterHtml(HtmlPages,
                                                        TAppSettingsManager.GetValue("Formletters.Path"),
                                                        GfxPrinter);

            GfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea);

            CoolPrintPreviewDialog PrintDlg = new CoolPrintPreviewDialog();

            PrintDlg.Document   = GfxPrinter.Document;
            PrintDlg.ClientSize = new System.Drawing.Size(500, 720);
            try
            {
                PrintDlg.ShowDialog();
            }
            catch (Exception)  // if the user presses Cancel, an exception may be raised!
            {
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: lulzzz/openpetra
        void TbbImportReportBinaryFileClick(object sender, EventArgs e)
        {
            OpenFileDialog DialogOpen = new OpenFileDialog();

            // see file in sub directory test data.
            // create file with method TResultList.WriteBinaryFile
            DialogOpen.Filter           = "Binary Report File (*.bin)|*.bin";
            DialogOpen.RestoreDirectory = true;
            DialogOpen.Title            = "Open Binary Report File";

            if (DialogOpen.ShowDialog() == DialogResult.OK)
            {
                TResultList    Results = new TResultList();
                TParameterList Parameters;
                Results.ReadBinaryFile(DialogOpen.FileName, out Parameters);

                PrintDocument doc = new PrintDocument();

                TPetraIdentity PetraIdentity = new TPetraIdentity(
                    "TESTUSER", "", "", "", "", DateTime.MinValue,
                    DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false, false, false);

                UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null);

                FGfxPrinter = new TGfxPrinter(doc, TGfxPrinter.ePrinterBehaviour.eReport);
                new TReportPrinterLayout(Results, Parameters, FGfxPrinter, true);
                printPreviewControl1.Document = doc;
                doc.EndPrint += new PrintEventHandler(this.PrintDocument_EndPrint);
                printPreviewControl1.InvalidatePreview();
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: lulzzz/openpetra
        void TbbPreviewClick(object sender, EventArgs e)
        {
            PrintDocument doc = new PrintDocument();

            FGfxPrinter = new TGfxPrinter(doc, TGfxPrinter.ePrinterBehaviour.eFormLetter);
            TPrinterHtml htmlPrinter = new TPrinterHtml(txtHTMLText.Text,
                                                        String.Empty,
                                                        FGfxPrinter);

            FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea);

            doc.EndPrint += new PrintEventHandler(this.PrintDocument_EndPrint);

            printPreviewControl1.Document = doc;
            printPreviewControl1.InvalidatePreview();

            printPreviewControl1.Rows = 1;
        }
コード例 #5
0
ファイル: PrintPreview.cs プロジェクト: jsuen123/openpetragit
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="ACallerForm"></param>
        /// <param name="caption">caption of the dialog</param>
        /// <param name="duration"></param>
        /// <param name="results"></param>
        /// <param name="parameters"></param>
        /// <param name="AWrapColumn">True: Wrap the text in the column. False: Cut the text that is too long for the column</param>
        /// <param name="ACalculator"></param>
        public TFrmPrintPreview(Form ACallerForm, String caption, TimeSpan duration, TResultList results,
                                TParameterList parameters, bool AWrapColumn, TRptCalculator ACalculator)
            : base()
        {
            FPetraUtilsObject = new Ict.Petra.Client.CommonForms.TFrmPetraUtils(ACallerForm, this, stbMain);
            FCalculator       = ACalculator;

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            #region CATALOGI18N

            // this code has been inserted by GenerateI18N, all changes in this region will be overwritten by GenerateI18N
            this.mniFile.Text                = Catalog.GetString("&File");
            this.mniFileClose.Text           = Catalog.GetString("&Close");
            this.mniFileClose.ToolTipText    = Catalog.GetString("Close the preview");
            this.mniHelp.Text                = Catalog.GetString("&Help");
            this.mniHelpPetraHelp.Text       = Catalog.GetString("&Petra Help");
            this.mniHelpBugReport.Text       = Catalog.GetString("Bug &Report");
            this.mniHelpAboutPetra.Text      = Catalog.GetString("&About OpenPetra...");
            this.mniHelpDevelopmentTeam.Text = Catalog.GetString("&The Development Team...");
            this.stbMain.Text                = Catalog.GetString("Status Bar");
            this.stpInfo.Text                = Catalog.GetString("Ready");
            this.tbbClose.Text               = Catalog.GetString("Close");
            this.tbbClose.ToolTipText        = Catalog.GetString("Closes this window");
            this.Text                           = Catalog.GetString("Print Preview");
            this.tbpText.Text                   = Catalog.GetString("Text Preview");
            this.txtOutput.Text                 = Catalog.GetString("Text Output");
            this.tbpPreview.Text                = Catalog.GetString("Print Preview");
            this.lblNoPrinter.Text              = Catalog.GetString("Unfortunately this function is disabled. Please" + " install a printer to use this page.");
            this.CbB_Zoom.Text                  = Catalog.GetString("Select Zoom");
            this.Btn_PreviousPage.Text          = Catalog.GetString("Previous Page");
            this.Btn_NextPage.Text              = Catalog.GetString("Next Page");
            this.tbpGridView.Text               = Catalog.GetString("Detail Reports");
            this.tbtPrint.Text                  = Catalog.GetString("Print");
            this.tbtPrint.ToolTipText           = Catalog.GetString("Print the report");
            this.tbtExportCSV.Text              = Catalog.GetString("Export to CSV");
            this.tbtExportCSV.ToolTipText       = Catalog.GetString("Export to CSV text file");
            this.tbtExportExcelFile.Text        = Catalog.GetString("Export to Excel");
            this.tbtExportExcelFile.ToolTipText = Catalog.GetString("Export to Excel xlsx file or directly into Excel, if" + " it is available");
            this.tbtExportText.Text             = Catalog.GetString("Save as Text file");
            this.tbtExportText.ToolTipText      = Catalog.GetString("Save as a text file (e.g. for email)");
            this.tbtSendEmail.Text              = Catalog.GetString("Send Email");
            this.tbtSendEmail.ToolTipText       = Catalog.GetString("Send the Report as an Email with Excel attachment");
            this.tbtGenerateChart.Text          = Catalog.GetString("Generate Chart");
            this.tbtGenerateChart.ToolTipText   = Catalog.GetString(
                "Generates a chart in Excel (only ava" + "ilable yet for few reports at the moment)");
            this.Text = Catalog.GetString("Print Preview");
            #endregion

            System.Windows.Forms.TabPage SelectedTab;

            this.Text             = this.Text + ": " + caption;
            this.ReportName       = caption;
            this.Results          = results;
            this.Parameters       = parameters;
            FTxtPrinter           = new TTxtPrinter();
            this.ReportTxtPrinter = new TReportPrinterLayout(Results, Parameters, FTxtPrinter, AWrapColumn);
            ReportTxtPrinter.PrintReport();

            this.txtOutput.Lines = FTxtPrinter.GetArrayOfString();
            FPrinterInstalled    = this.PrintDocument.PrinterSettings.IsValid;

            FWrapColumn = AWrapColumn;

            if (FPrinterInstalled)
            {
                this.tabPreview.SelectedTab = tbpPreview;
                FGfxPrinter = new TGfxPrinter(this.PrintDocument, TGfxPrinter.ePrinterBehaviour.eReport);

                // TReportPrinterLayout ReportGfxPrinter
                new TReportPrinterLayout(Results, Parameters, FGfxPrinter, AWrapColumn);

                this.PrintPreviewControl.Document     = FGfxPrinter.Document;
                this.PrintPreviewControl.Zoom         = 1; // show 100% by default
                this.PrintPreviewControl.UseAntiAlias = true;
                this.lblNoPrinter.Visible             = false;
            }
            else
            {
                // PrintPreviewControl.CalculatePageInfo will throw InvalidPrinterException
                this.tabPreview.SelectedTab      = tbpText;
                this.PrintPreviewControl.Visible = false;
                this.CbB_Zoom.Enabled            = false;
                this.Btn_PreviousPage.Enabled    = false;
                this.Btn_NextPage.Enabled        = false;
            }

            this.PrintChartProcedure         = null;
            this.PrintChartProcedureValid    = false;
            sgGridView.SortableHeaders       = false;
            sgGridView.SelectionMode         = SourceGrid.GridSelectionMode.Cell;
            this.sgGridView.DoubleClickCell += new TDoubleClickCellEventHandler(this.SgGridView_DoubleClickCell);
            FGridPreview = new TGridPreview(this, FPetraUtilsObject, @PreviewDetailReport, Results, Parameters);

            if (!FGridPreview.PopulateResultGrid(sgGridView))
            {
                SelectedTab = tabPreview.SelectedTab;
                this.tabPreview.TabPages.Clear();
                this.tabPreview.TabPages.AddRange(new TabPage[] { this.tbpText, this.tbpPreview });
                tabPreview.SelectedTab = SelectedTab;
            }
            else
            {
                FGridPreview.PopulateGridContextMenu(ContextMenu1);
            }

            stpInfo.Text = string.Empty;
            stbMain.ShowMessage(String.Format(Catalog.GetString("It took {0} to calculate the report"), FormatDuration(duration)));
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="APaymentNum"></param>
        /// <param name="ALedgerNumber"></param>
        public void PrintRemittanceAdvice(Int32 APaymentNum, Int32 ALedgerNumber)
        {
            FLedgerNumber = ALedgerNumber;

            txtPaymentNum.NumberValueInt = APaymentNum;
            AccountsPayableTDS PaymentDetails = TRemote.MFinance.AP.WebConnectors.LoadAPPayment(ALedgerNumber, APaymentNum);

            if (PaymentDetails.AApPayment.Rows.Count == 0) // unable to load this payment..
            {
                lblLoadStatus.Text = String.Format(Catalog.GetString("Error - can't load Payment number {0}."), APaymentNum);
                return;
            }

            SortedList <string, List <string> > FormValues = new SortedList <string, List <string> >();

            //
            // load my own country code, so I don't print it on letters to my own country.
            //
            string LocalCountryCode = TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetCountryCodeFromSiteLedger();

            //
            // These are the fields that I will pull out of the TDS...
            //
            FormValues.Add("SupplierName", new List <string>());
            FormValues.Add("SupplierAddress", new List <string>());
            FormValues.Add("PaymentDate", new List <string>());
            FormValues.Add("OurReference", new List <string>());
            FormValues.Add("InvoiceDate", new List <string>());
            FormValues.Add("InvoiceNumber", new List <string>());
            FormValues.Add("InvoiceAmount", new List <string>());
            FormValues.Add("TotalPayment", new List <string>());

            FormValues["SupplierName"].Add(PaymentDetails.PPartner[0].PartnerShortName);

            if (PaymentDetails.PLocation[0].CountryCode == LocalCountryCode)
            {
                PaymentDetails.PLocation[0].CountryCode = ""; // Don't print country code it it's the same as my own.
            }

            FormValues["SupplierAddress"].Add(Calculations.DetermineLocationString(PaymentDetails.PLocation[0],
                                                                                   Calculations.TPartnerLocationFormatEnum.plfHtmlLineBreak));

            String DatePattern = Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern;

            DatePattern = "dd MMMM yyyy"; // The long pattern above is no good in UK, although it might be OK in other cultures...

            FormValues["PaymentDate"].Add(PaymentDetails.AApPayment[0].PaymentDate.Value.ToString(DatePattern));
            FormValues["OurReference"].Add(PaymentDetails.AApSupplier[0].OurReference);

            foreach (AApDocumentRow Row in PaymentDetails.AApDocument.Rows)
            {
                FormValues["InvoiceDate"].Add(Row.DateIssued.ToString(DatePattern));
                FormValues["InvoiceNumber"].Add(Row.DocumentCode);
                FormValues["InvoiceAmount"].Add(Row.TotalAmount.ToString("n2") + " " + PaymentDetails.AApSupplier[0].CurrencyCode);
            }

            FormValues["TotalPayment"].Add(PaymentDetails.AApPayment[0].Amount.ToString("n2") + " " + PaymentDetails.AApSupplier[0].CurrencyCode);

            String TemplateFilename = TAppSettingsManager.GetValue("Formletters.Path") + "\\ApRemittanceAdvice.html";

            if (!File.Exists(TemplateFilename))
            {
                lblLoadStatus.Text = String.Format(Catalog.GetString("Error - unable to load HTML template from {0}"), TemplateFilename);
                return;
            }

            FHtmlDoc = TFormLettersTools.PrintSimpleHTMLLetter(TemplateFilename, FormValues);

            System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            bool printerInstalled = printDocument.PrinterSettings.IsValid;

            if (!printerInstalled)
            {
                lblLoadStatus.Text = Catalog.GetString("There is no printer, so printing is not possible");
                return;
            }

            FGfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter);
            try
            {
                TPrinterHtml htmlPrinter = new TPrinterHtml(FHtmlDoc,
                                                            TAppSettingsManager.GetValue("Formletters.Path"),
                                                            FGfxPrinter);
                FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea);
                this.ppvLetters.InvalidatePreview();
                this.ppvLetters.Document = FGfxPrinter.Document;
                this.ppvLetters.Zoom     = 1;
                // GfxPrinter.Document.EndPrint += new PrintEventHandler(this.EndPrint);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            btnPDF.Visible  = true;
            btnCopy.Visible = true;

            lblLoadStatus.Text = "";
        }