private void grdReminder_CellClick(object sender, CellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.CellName != CellName("Preview")) { return; } grdReminder.CommitEdit(); try { string serverPath = GetServerPath(); var summary = grdReminder.Rows[e.RowIndex].DataBoundItem as ReminderSummary; if (UseDestinationSummarized) { var option = new DestinationSearch(); option.CompanyId = CompanyId; option.CustomerId = summary.CustomerId; var taskDestination = GetDestinationsAsync(option); ProgressDialog.Start(ParentForm, taskDestination, false, SessionKey); var destinations = taskDestination.Result; var destinationIds = new List <ReminderSummary>(); var inputCode = string.Empty; var cell = grdReminder.Rows[e.RowIndex].Cells[CellName(nameof(Web.Models.ReminderSummary.DestinationCode))]; if (IsCellEmpty(cell)) { summary.DestinationIdInput = null; } else { inputCode = cell.Value.ToString().PadLeft(2, '0'); if (!destinations.Any(x => x.Code == inputCode)) { ShowWarningDialog(MsgWngMasterNotExist, "送付先", inputCode); return; } summary.DestinationIdInput = destinations.FirstOrDefault(x => x.Code == inputCode).Id; } var qry = from row in grdReminder.Rows where (string)(row.Cells[CellName(nameof(Web.Models.ReminderSummary.CustomerCode))].Value) == summary.CustomerCode select row; foreach (var row in qry) { var bsd = row.DataBoundItem as ReminderSummary; var code = Convert.ToString(row.Cells[CellName(nameof(Web.Models.ReminderSummary.DestinationCode))].Value); if (code == inputCode) { if (bsd.DestinationId.HasValue) { destinationIds.Add(bsd); } else { summary.NoDestination = true; } } } summary.CompanyId = CompanyId; summary.CustomerIds = new int[] { summary.CustomerId }; summary.DestinationIds = destinationIds.Select(x => x.DestinationId.Value).Distinct().ToArray(); } var summaryList = new List <ReminderSummary>(); summaryList.Add(summary); var task = UseDestinationSummarized ? GetReminderBillingForSummaryPrintByDestinationCodeAsync(summaryList) : GetReminderBillingForSummaryPrintAsync(ReminderSummary.Select(x => x.CustomerId).ToArray()); ProgressDialog.Start(ParentForm, task, false, SessionKey); if (!task.Result.ProcessResult.Result) { ShowWarningDialog(MsgErrCreateReportError); return; } var reminderBillings = task.Result.ReminderBilling; var template = ReminderTemplateSetting.First(x => x.Id == summary.TemplateId); PdfSetting = GetPdfOutputSetting(); var report = UtilReminder.CreateReminderReport(reminderBillings, ReminderCommonSetting, ReminderSummarySetting, template, Company, ColumnNameSettingInfo, DateTime.Now, PdfSetting); ShowDialogPreview(ParentForm, report, serverPath); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); ShowWarningDialog(MsgErrCreateReportError); } }
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); } }