Esempio n. 1
0
        private async Task PrintDestinationSummarized(string path)
        {
            try
            {
                var reminderOutputed = new List <ReminderOutputed>();
                var updateResult     = new CountResult();

                var option = new DestinationSearch();
                option.CompanyId = CompanyId;

                var destinations = await GetDestinationsAsync(option);

                foreach (var summary in ReminderSummary)
                {
                    if (summary.DestinationCode == null || string.IsNullOrEmpty(summary.DestinationCode))
                    {
                        summary.NoDestination      = true;
                        summary.DestinationIdInput = null;
                        continue;
                    }

                    var destination = destinations.FirstOrDefault(x => x.CustomerId == summary.CustomerId && x.Code == summary.DestinationCode);
                    if (destination == null)
                    {
                        ShowWarningDialog(MsgWngMasterNotExist, "送付先", summary.DestinationCode);
                        return;
                    }
                    summary.DestinationIdInput = destination.Id;
                }

                var summaryList  = new List <ReminderSummary>();
                var gDestination = ReminderSummary.GroupBy(x => new { x.CustomerCode, x.DestinationCode }).Select(x => x);

                foreach (var grs in gDestination)
                {
                    var summary        = grs.First();
                    var destinationIds = new List <ReminderSummary>();
                    foreach (var item in ReminderSummary.Where(x => x.CustomerId == summary.CustomerId && x.DestinationCode == summary.DestinationCode))
                    {
                        if (item.DestinationId == null)
                        {
                            summary.NoDestination = true;
                        }
                        else
                        {
                            destinationIds.Add(item);
                        }
                    }
                    summary.CompanyId      = CompanyId;
                    summary.CustomerIds    = new int[] { summary.CustomerId };
                    summary.DestinationIds = destinationIds.Select(x => x.DestinationId.Value).Distinct().ToArray();
                    summaryList.Add(summary);
                }

                var reminderBillingResult = await GetReminderBillingForSummaryPrintByDestinationCodeAsync(summaryList);

                var reminderBilling = reminderBillingResult.ReminderBilling;

                var outputNo = 1;

                var countResult = await GetMaxOutputNoAsync();

                if (countResult.ProcessResult.Result)
                {
                    outputNo = countResult.Count + 1;
                }

                var            reportList = new List <ReminderReport>();
                var            now        = DateTime.Now;
                ReminderReport allReport  = null;

                foreach (var gdr in gDestination)
                {
                    var r = gdr.First();

                    var template = ReminderTemplateSetting.First(x => x.Id == r.TemplateId);
                    var source   = reminderBilling.Where(x => x.CustomerId == r.CustomerId && x.DestinationId == r.DestinationIdInput);

                    foreach (var b in source)
                    {
                        var output = new ReminderOutputed();
                        output.OutputNo           = outputNo;
                        output.BillingId          = b.Id;
                        output.ReminderId         = b.ReminderId;
                        output.RemainAmount       = b.RemainAmount;
                        output.BillingAmount      = b.BillingAmount;
                        output.ReminderTemplateId = r.TemplateId;
                        output.OutputAt           = now;
                        output.DestinationId      = r.DestinationIdInput;
                        reminderOutputed.Add(output);

                        b.OutputNo = outputNo;
                    }

                    var report = UtilReminder.CreateReminderReport(source,
                                                                   ReminderCommonSetting,
                                                                   ReminderSummarySetting,
                                                                   template,
                                                                   Company,
                                                                   ColumnNameSettingInfo,
                                                                   now,
                                                                   PdfSetting);

                    if (PdfSetting.IsAllInOne)
                    {
                        if (allReport == null)
                        {
                            allReport = report;
                        }
                        else
                        {
                            allReport.Document.Pages.AddRange((PagesCollection)report.Document.Pages.Clone());
                        }
                    }
                    else
                    {
                        reportList.Add(report);
                    }

                    outputNo++;
                }

                if (PdfSetting.IsAllInOne)
                {
                    Action <Form> outputHandler = owner =>
                    {
                        var taskOutput = SaveOutputAtReminderSummaryAsync(reminderOutputed.ToArray(), ReminderSummary.ToArray());
                        ProgressDialog.Start(owner, taskOutput, false, SessionKey);
                        updateResult = taskOutput.Result;
                    };
                    updateResult = null;
                    ShowDialogPreview(ParentForm, allReport, GetServerPath(), outputHandler);
                }
                else
                {
                    var exporter = new PdfReportExporter();
                    var fileList = new List <string>();
                    foreach (var rpt in reportList)
                    {
                        var filePath = Util.GetUniqueFileName(Path.Combine(path, $"{rpt.Name}.pdf"));
                        exporter.PdfExport(rpt, filePath);
                        if (PdfSetting.UseZip)
                        {
                            fileList.Add(filePath);
                        }
                    }
                    if (PdfSetting.UseZip)
                    {
                        Util.ArchivesAsZip(fileList, path, $"督促状{now.ToString("yyyyMMdd")}", PdfSetting.MaximumByte);
                    }
                    updateResult = await SaveOutputAtReminderSummaryAsync(reminderOutputed.ToArray(), ReminderSummary.ToArray());
                }

                if (PdfSetting.IsAllInOne && updateResult == null)
                {
                    return;
                }
                else if (!updateResult.ProcessResult.Result || updateResult.Count <= 0)
                {
                    ShowWarningDialog(MsgErrExportError);
                }
                else
                {
                    ParentForm.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrExportError);
            }
        }
        private void Reoutput()
        {
            ClearStatusMessage();
            if (!ValidateInputValueForPrint())
            {
                return;
            }

            try
            {
                string serverPath = GetServerPath();

                var reminderOutputed = new ReminderOutputed();
                reminderOutputed.OutputNos = grdReminder.Rows.Select(x => x.DataBoundItem as ReminderOutputed)
                                             .Where(x => x.Checked)
                                             .Select(x => x.OutputNo).Distinct().ToArray();
                reminderOutputed.DestinationIds = grdReminder.Rows.Select(x => x.DataBoundItem as ReminderOutputed)
                                                  .Where(x => x.Checked && x.DestinationId != null)
                                                  .Select(x => x.DestinationId.Value).Distinct().ToArray();

                var path       = string.Empty;
                var pdfSetting = GetPdfOutputSetting();
                if (!pdfSetting.IsAllInOne)
                {
                    var selectedPath    = string.Empty;
                    var rootBrowserPath = new List <string>();
                    if (!LimitAccessFolder
                        ? !ShowFolderBrowserDialog(serverPath, out selectedPath)
                        : !ShowRootFolderBrowserDialog(ApplicationControl.RootPath, out rootBrowserPath, Constants.FolderBrowserType.SelectFolder))
                    {
                        DispStatusMessage(MsgInfProcessCanceled);
                        return;
                    }
                    path = (!LimitAccessFolder ? selectedPath : rootBrowserPath.First());
                }

                if (!reminderOutputed.OutputNos.Any())
                {
                    ShowWarningDialog(MsgWngPrintDataNotExist, "再出力");
                    return;
                }

                if (!pdfSetting.IsAllInOne && !ShowConfirmDialog(MsgQstConfirmOutput))
                {
                    DispStatusMessage(MsgInfProcessCanceled);
                    return;
                }

                var reportList = new List <ReminderReport>();
                var isCanceled = true;
                var task       = ServiceProxyFactory.LifeTime(async factory =>
                {
                    List <ReminderBilling> reminderBilling          = null;
                    List <ReminderTemplateSetting> templateSettings = null;

                    var reminderClient = factory.Create <ReminderServiceClient>();
                    var reminderResult = (!UseDestinationSummarized)
                        ? await reminderClient.GetReminderBillingForReprintAsync(SessionKey, CompanyId, reminderOutputed)
                        : await reminderClient.GetReminderBillingForReprintByDestinationAsync(SessionKey, CompanyId, reminderOutputed);
                    if (reminderResult.ProcessResult.Result)
                    {
                        reminderBilling = reminderResult.ReminderBilling;
                    }

                    var templateSettingClient = factory.Create <ReminderSettingServiceClient>();
                    var templateSettingResult = await templateSettingClient.GetReminderTemplateSettingsAsync(SessionKey, CompanyId);
                    if (templateSettingResult.ProcessResult.Result)
                    {
                        templateSettings = templateSettingResult.ReminderTemplateSettings;
                    }

                    var now = DateTime.Now;
                    ReminderReport allReport = null;

                    foreach (var r in grdReminder.Rows.Select(x => x.DataBoundItem as ReminderOutputed).Where(x => x.Checked))
                    {
                        var reminderReport = UtilReminder.CreateReminderReport(reminderBilling.Where(x => x.OutputNo == r.OutputNo),
                                                                               ReminderCommonSetting,
                                                                               ReminderSummarySetting,
                                                                               templateSettings.First(x => x.Id == r.ReminderTemplateId),
                                                                               Company,
                                                                               ColumnNameSettingInfo,
                                                                               now,
                                                                               pdfSetting);


                        if (pdfSetting.IsAllInOne)
                        {
                            if (allReport == null)
                            {
                                allReport = reminderReport;
                            }
                            else
                            {
                                allReport.Document.Pages.AddRange((PagesCollection)reminderReport.Document.Pages.Clone());
                            }
                        }
                        else
                        {
                            if (r.DestinationId != null)
                            {
                                reportList.Add(reminderReport);
                            }
                            else
                            {
                                reportList.Add(reminderReport);
                            }
                        }
                    }

                    if (pdfSetting.IsAllInOne)
                    {
                        Action <Form> outputHandler = owner => isCanceled = false;
                        ShowDialogPreview(ParentForm, allReport, GetServerPath(), outputHandler);
                    }
                    else
                    {
                        var exporter = new PdfReportExporter();
                        var fileList = new List <string>();
                        foreach (var rpt in reportList)
                        {
                            var filePath = Util.GetUniqueFileName(Path.Combine(path, $"{rpt.Name}.pdf"));
                            exporter.PdfExport(rpt, filePath);
                            if (pdfSetting.UseZip)
                            {
                                fileList.Add(filePath);
                            }
                        }
                        if (pdfSetting.UseZip)
                        {
                            Util.ArchivesAsZip(fileList, path, $"督促状{now.ToString("yyyyMMdd")}", pdfSetting.MaximumByte);
                        }
                    }
                });

                var result = ProgressDialog.Start(ParentForm, task, false, SessionKey);
                if (pdfSetting.IsAllInOne && isCanceled)
                {
                    return;
                }
                else if (result == DialogResult.OK)
                {
                    DispStatusMessage(MsgInfFinishedSuccessReOutputProcess);
                }
                else
                {
                    ShowWarningDialog(MsgErrCreateReportError);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrCreateReportError);
            }
        }
Esempio n. 3
0
        private async Task PrintSummarized(string path)
        {
            try
            {
                var reminderOutputed = new List <ReminderOutputed>();
                var updateResult     = new CountResult();


                List <ReminderBilling> reminderBilling = null;
                var outputNo = 1;

                var reminderResult = await GetReminderBillingForSummaryPrintAsync(ReminderSummary.Select(x => x.CustomerId).ToArray());

                reminderBilling = reminderResult.ReminderBilling;
                var countResult = await GetMaxOutputNoAsync();

                if (countResult.ProcessResult.Result)
                {
                    outputNo = countResult.Count + 1;
                }

                var            reportList = new List <ReminderReport>();
                var            now        = DateTime.Now;
                ReminderReport allReport  = null;

                foreach (var r in ReminderSummary)
                {
                    var template = ReminderTemplateSetting.First(x => x.Id == r.TemplateId);
                    var source   = reminderBilling.Where(x => x.CustomerId == r.CustomerId);

                    foreach (var b in source)
                    {
                        var output = new ReminderOutputed();
                        output.OutputNo           = outputNo;
                        output.BillingId          = b.Id;
                        output.ReminderId         = b.ReminderId;
                        output.RemainAmount       = b.RemainAmount;
                        output.BillingAmount      = b.BillingAmount;
                        output.ReminderTemplateId = r.TemplateId;
                        output.OutputAt           = now;
                        reminderOutputed.Add(output);

                        b.OutputNo = outputNo;
                    }

                    var report = UtilReminder.CreateReminderReport(source,
                                                                   ReminderCommonSetting,
                                                                   ReminderSummarySetting,
                                                                   template,
                                                                   Company,
                                                                   ColumnNameSettingInfo,
                                                                   now,
                                                                   PdfSetting);

                    if (PdfSetting.IsAllInOne)
                    {
                        if (allReport == null)
                        {
                            allReport = report;
                        }
                        else
                        {
                            allReport.Document.Pages.AddRange((PagesCollection)report.Document.Pages.Clone());
                        }
                    }
                    else
                    {
                        reportList.Add(report);
                    }

                    outputNo++;
                }

                if (PdfSetting.IsAllInOne)
                {
                    Action <Form> outputHandler = owner =>
                    {
                        var taskOutput = SaveOutputAtReminderSummaryAsync(reminderOutputed.ToArray(), ReminderSummary.ToArray());
                        ProgressDialog.Start(owner, taskOutput, false, SessionKey);
                        updateResult = taskOutput.Result;
                    };
                    updateResult = null;
                    ShowDialogPreview(ParentForm, allReport, GetServerPath(), outputHandler);
                }
                else
                {
                    var exporter = new PdfReportExporter();
                    var fileList = new List <string>();
                    foreach (var rpt in reportList)
                    {
                        var filePath = Util.GetUniqueFileName(Path.Combine(path, $"{rpt.Name}.pdf"));
                        exporter.PdfExport(rpt, filePath);
                        if (PdfSetting.UseZip)
                        {
                            fileList.Add(filePath);
                        }
                    }
                    if (PdfSetting.UseZip)
                    {
                        Util.ArchivesAsZip(fileList, path, $"督促状{now.ToString("yyyyMMdd")}", PdfSetting.MaximumByte);
                    }
                    updateResult = await SaveOutputAtReminderSummaryAsync(reminderOutputed.ToArray(), ReminderSummary.ToArray());
                }

                if (PdfSetting.IsAllInOne && updateResult == null)
                {
                    return;
                }
                else if (!updateResult.ProcessResult.Result || updateResult.Count <= 0)
                {
                    ShowWarningDialog(MsgErrExportError);
                }
                else
                {
                    ParentForm.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrExportError);
            }
        }
Esempio n. 4
0
        void buttonExport_Click(object sender, EventArgs e)
        {
            Save();
            //ActiveView(OutputView.ProgressView);

            string strUrl = String.Empty;
            string strPath = this.report.GetOutputPath(this.report.Format.ExportFormat);

            strUrl = report.GetOutputUrl(this.report.Format.ExportFormat);

            this.report.FilePath = strPath;

            IReportExport exporter = null;
            if (this.report.Format.ExportFormat == ReportFormat.ExportType.Excel)
            {
                exporter = new ExcelReportExporter(this.report, ExportMode.Export, false);
                exporter.FileName = this.report.FilePath;
            }
            else
            {
                exporter = new PdfReportExporter(this.report, ExportMode.Export, false);
            }

            exporter.Export();

            Control container = this.report.MultiView;
            CheckBox cbxSendMail = (CheckBox)container.FindControl(CHECKBOX_SEND_MAIL);
            if (cbxSendMail.Checked)
            {
                ShowModelPopup(ModelPopupView.DownloadView);
                ActiveView(OutputView.SendMailView);
                InitialSendMailView(this.report);

                MemoryStream ms = new MemoryStream(File.ReadAllBytes(this.report.FilePath));
                this.report.MailSetting.Attachments.Add(new Attachment(ms, Path.GetFileName(this.report.FilePath)));
            }
            else
            {
                AspNetScriptsProvider.DownLoadFile(this.report);
            }
        }