|
@@ -1,6 +1,7 @@
|
|
|
using Comal.Classes;
|
|
|
using ControlzEx.Standard;
|
|
|
using CsvHelper;
|
|
|
+using CsvHelper.Configuration;
|
|
|
using CsvHelper.Configuration.Attributes;
|
|
|
using FastReport.Utils;
|
|
|
using InABox.Core;
|
|
@@ -8,6 +9,7 @@ using InABox.Core.Postable;
|
|
|
using InABox.Poster.Timberline;
|
|
|
using InABox.Scripting;
|
|
|
using Microsoft.Win32;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Globalization;
|
|
@@ -15,6 +17,7 @@ using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
|
|
namespace PRS.Shared
|
|
@@ -438,18 +441,99 @@ public class Module
|
|
|
|
|
|
if (dlg.ShowDialog() == true)
|
|
|
{
|
|
|
- using var writer = new StreamWriter(dlg.FileName);
|
|
|
- using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
|
|
|
- foreach(var apif in result.Exports)
|
|
|
+ using (var writer = new StreamWriter(dlg.FileName))
|
|
|
{
|
|
|
- csv.WriteRecord(apif);
|
|
|
- csv.NextRecord();
|
|
|
- foreach(var apdf in apif.Distributions)
|
|
|
+ using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
|
|
|
+ foreach (var apif in result.Exports)
|
|
|
{
|
|
|
- csv.WriteRecord(apdf);
|
|
|
+ csv.WriteRecord(apif);
|
|
|
csv.NextRecord();
|
|
|
+ foreach (var apdf in apif.Distributions)
|
|
|
+ {
|
|
|
+ csv.WriteRecord(apdf);
|
|
|
+ csv.NextRecord();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /*while (true)
|
|
|
+ {
|
|
|
+ var logDlg = new OpenFileDialog
|
|
|
+ {
|
|
|
+ InitialDirectory = Path.GetDirectoryName(dlg.FileName),
|
|
|
+ FileName = "JCREJECT.JCC",
|
|
|
+ Filter = "Rejected Item Files (*.jcc) | *.jcc;*.JCC | All Files (*.*) | *.*",
|
|
|
+ Title = "Please select JCREJECT.JCC"
|
|
|
+ };
|
|
|
+ if (logDlg.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ var rejectedHeaders = new List<BillTimberlineHeader?>();
|
|
|
+ var rejectedLines = new List<BillTimberlineDistribution?>();
|
|
|
+ BillTimberlineHeader? lastHeader = null;
|
|
|
+ using (var reader = new StreamReader(logDlg.FileName))
|
|
|
+ {
|
|
|
+ using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
|
|
|
+ {
|
|
|
+ HasHeaderRecord = false
|
|
|
+ });
|
|
|
+
|
|
|
+ var i = 1;
|
|
|
+ while (csv.Read())
|
|
|
+ {
|
|
|
+ var id = csv.GetField(0);
|
|
|
+ if (id == "APIF")
|
|
|
+ {
|
|
|
+ var header = csv.GetRecord<BillTimberlineHeader>();
|
|
|
+ if (header is not null)
|
|
|
+ {
|
|
|
+ var entry = result.Items.FirstOrDefault(x => x.Item2?.Invoice.Equals(header.Invoice) == true);
|
|
|
+ if (entry is not null)
|
|
|
+ {
|
|
|
+ (entry.Item1 as IPostable).FailPost("");
|
|
|
+ }
|
|
|
+ lastHeader = header;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Error, "", "Bill Timberline export: Unable to parse header from CSV line in rejection file.");
|
|
|
+ MessageBox.Show($"Invalid line {i} in file; skipping.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (id == "APDF")
|
|
|
+ {
|
|
|
+ var line = csv.GetRecord<BillTimberlineDistribution>();
|
|
|
+ if (line is not null)
|
|
|
+ {
|
|
|
+ var entry = result.Items.FirstOrDefault(x => x.Item2?.Invoice.Equals(line.Invoice) == true);
|
|
|
+ if (entry is not null)
|
|
|
+ {
|
|
|
+ (entry.Item1 as IPostable).FailPost("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Error, "", "Bill Timberline export: Unable to parse line from CSV line in rejection file.");
|
|
|
+ MessageBox.Show("Invalid line in file; skipping.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (MessageBox.Show("Do you wish to cancel the export?", "Cancel Export?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ throw new PostCancelledException();
|
|
|
+ }
|
|
|
+ else if (MessageBox.Show("Did everything post successfully?", "Successful?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
else
|