コード例 #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);
            }
        }
コード例 #2
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);
            }
        }