Beispiel #1
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;
            }
        }
        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;
            }
        }
Beispiel #3
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;
            }
        }