Exemple #1
0
        public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            SiharaiYoteiHyou_Report rpt = new SiharaiYoteiHyou_Report();

            rpt.Site = this.Site;
            return(rpt);
        }
Exemple #2
0
        /// <summary>
        /// <Remark>PDF出力F11</Remark>
        /// <Remark>印刷する処理F12</Remark>
        /// </summary>
        protected override void PrintSec()
        {
            // レコード定義を行う
            try
            {
                //DataTable table = CheckData(1);
                //if (table == null)
                //{
                //    return;
                //}
                DialogResult            ret;
                SiharaiYoteiHyou_Report Report = new SiharaiYoteiHyou_Report();

                switch (PrintMode)
                {
                case EPrintMode.DIRECT:
                    dtResult = CheckData(1);
                    if (dtResult == null)
                    {
                        return;
                    }

                    if (StartUpKBN == "1")
                    {
                        ret = DialogResult.No;
                    }
                    else
                    {
                        //Q202 印刷します。”はい”でプレビュー、”いいえ”で直接プリンターから印刷します。
                        ret = bbl.ShowMessage("Q201");
                        if (ret == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    Report.PrintOptions.PaperSize        = CrystalDecisions.Shared.PaperSize.PaperA4;
                    Report.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;

                    // 印字データをセット
                    Report.SetDataSource(dtResult);
                    Report.Refresh();
                    Report.SetParameterValue("StoreCD", comboStore.SelectedValue.ToString() + "  " + comboStore.Text);
                    Report.SetParameterValue("DateFrom", txtPaymentDueDateFrom.Text);
                    Report.SetParameterValue("DateTo", txtPaymentDueDateTo.Text);
                    Report.SetParameterValue("PrintDate", System.DateTime.Now.ToString("yyyy/MM/dd") + " " + System.DateTime.Now.ToString("hh:mm"));

                    if (ret == DialogResult.Yes)
                    {
                        //プレビュー
                        var previewForm = new Viewer();
                        previewForm.CrystalReportViewer1.ShowPrintButton = true;
                        previewForm.CrystalReportViewer1.ReportSource    = Report;
                        previewForm.ShowDialog();
                    }
                    else
                    {
                        //int marginLeft = 360;
                        CrystalDecisions.Shared.PageMargins margin = Report.PrintOptions.PageMargins;
                        margin.leftMargin   = DefaultMargin.Left;     // mmの指定をtwip単位に変換する
                        margin.topMargin    = DefaultMargin.Top;
                        margin.bottomMargin = DefaultMargin.Bottom;   //mmToTwip(marginLeft);
                        margin.rightMargin  = DefaultMargin.Right;
                        Report.PrintOptions.ApplyPageMargins(margin); /// Error Now
                        // プリンタに印刷
                        System.Drawing.Printing.PageSettings ps;
                        try
                        {
                            System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();

                            CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();

                            System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();



                            Report.PrintOptions.PrinterName = "\\\\dataserver\\Canon LBP2900";
                            System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);

                            Report.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;

                            Report.PrintOptions.PrinterDuplex = PrinterDuplex.Simplex;

                            Report.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
                            // Print the report. Set the startPageN and endPageN
                            // parameters to 0 to print all pages.
                            //Report.PrintToPrinter(1, false, 0, 0);
                        }
                        catch (Exception ex)
                        {
                        }
                    }

                    break;

                case EPrintMode.CSV:
                    dtCSV = CheckData(2);
                    if (dtCSV == null)
                    {
                        return;
                    }
                    try
                    {
                        DialogResult DResult;
                        DResult = bbl.ShowMessage("Q203");
                        if (DResult == DialogResult.Yes)
                        {
                            ////LoacalDirectory
                            string folderPath = "C:\\CSV\\";
                            if (!Directory.Exists(folderPath))
                            {
                                Directory.CreateDirectory(folderPath);
                            }
                            SaveFileDialog savedialog = new SaveFileDialog();
                            savedialog.Filter           = "CSV|*.csv";
                            savedialog.Title            = "Save";
                            savedialog.FileName         = "支払予定表";
                            savedialog.InitialDirectory = folderPath;
                            savedialog.RestoreDirectory = true;
                            if (savedialog.ShowDialog() == DialogResult.OK)
                            {
                                if (Path.GetExtension(savedialog.FileName).Contains("csv"))
                                {
                                    CsvWriter csvwriter = new CsvWriter();
                                    csvwriter.WriteCsv(dtCSV, savedialog.FileName, Encoding.GetEncoding(932));
                                }
                                Process.Start(Path.GetDirectoryName(savedialog.FileName));
                                shyhbl.ShowMessage("I203");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    break;

                case EPrintMode.PDF:

                    dtResult = CheckData(1);
                    if (dtResult == null)
                    {
                        return;
                    }

                    if (bbl.ShowMessage("Q204") != DialogResult.Yes)
                    {
                        return;
                    }
                    string filePath = "";
                    if (!ShowSaveFileDialog(InProgramNM, out filePath))
                    {
                        return;
                    }

                    // 印字データをセット
                    Report.SetDataSource(dtResult);
                    Report.Refresh();
                    Report.SetParameterValue("StoreCD", comboStore.SelectedValue.ToString() + "  " + comboStore.Text);
                    Report.SetParameterValue("DateFrom", txtPaymentDueDateFrom.Text);
                    Report.SetParameterValue("DateTo", txtPaymentDueDateTo.Text);
                    Report.SetParameterValue("PrintDate", System.DateTime.Now.ToString("yyyy/MM/dd") + " " + System.DateTime.Now.ToString("hh:mm"));

                    bool result = OutputPDF(filePath, Report);

                    //PDF出力が完了しました。
                    bbl.ShowMessage("I202");
                    break;
                }

                //プログラム実行履歴
                InsertLog(Get_L_Log_Entity());

                //ClearDetail();
            }
            finally
            {
            }
        }