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 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 grdReminder_CellClick(object sender, CellEventArgs e) { if (e.CellName != CellName("Preview")) { return; } var data = grdReminder.Rows[e.RowIndex].DataBoundItem as ReminderOutputed; if (data == null) { return; } try { data.OutputNos = new int[] { data.OutputNo }; if (UseDestinationSummarized && data.DestinationId.HasValue) { data.DestinationIds = new int[] { data.DestinationId.Value } } ; string serverPath = GetServerPath(); var task = ServiceProxyFactory.LifeTime(async factory => { List <ReminderBilling> reminderBilling = null; List <ReminderTemplateSetting> templateSettings = null; var reminderClient = factory.Create <ReminderServiceClient>(); var reminderResult = (UseDestinationSummarized && data.DestinationId.HasValue) ? await reminderClient.GetReminderBillingForReprintByDestinationAsync(SessionKey, CompanyId, data) : await reminderClient.GetReminderBillingForReprintAsync(SessionKey, CompanyId, data); if (!reminderResult.ProcessResult.Result) { ShowWarningDialog(MsgErrCreateReportError); return; } reminderBilling = reminderResult.ReminderBilling; var templateSettingClient = factory.Create <ReminderSettingServiceClient>(); var templateSettingResult = await templateSettingClient.GetReminderTemplateSettingsAsync(SessionKey, CompanyId); if (templateSettingResult.ProcessResult.Result) { templateSettings = templateSettingResult.ReminderTemplateSettings; } var pdfSetting = GetPdfOutputSetting(); var reminderReport = UtilReminder.CreateReminderReport(reminderBilling, ReminderCommonSetting, ReminderSummarySetting, templateSettings.First(x => x.Id == data.ReminderTemplateId), Company, ColumnNameSettingInfo, DateTime.Now, pdfSetting); ShowDialogPreview(ParentForm, reminderReport, 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); } }
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); } }