diff --git a/BBWY.Client/BBWY.Client.csproj b/BBWY.Client/BBWY.Client.csproj index dae9b45d..a7a24613 100644 --- a/BBWY.Client/BBWY.Client.csproj +++ b/BBWY.Client/BBWY.Client.csproj @@ -28,6 +28,7 @@ + diff --git a/BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs b/BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs index af6d353b..32e82095 100644 --- a/BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs +++ b/BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs @@ -7,6 +7,8 @@ using Microsoft.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Data; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -320,7 +322,7 @@ namespace BBWY.Client.ViewModels OnlyException = false; } - private (string ErrorMessage, string FileName, IList Lines) ImportAuditFile(AuditFileType auditFileType) + private (string ErrorMessage, string FileName, DataTable DataTable) ImportAuditFile(AuditFileType auditFileType) { var ofd = new OpenFileDialog() { Filter = "CSV Files (*.csv)|*.csv" }; if (ofd.ShowDialog() != true) @@ -331,9 +333,19 @@ namespace BBWY.Client.ViewModels return ("文件已存在", string.Empty, null); try { - var lines = File.ReadAllLines(filePath, Encoding.GetEncoding("GB2312")).ToList(); + var dt = new DataTable(); + using (var reader = File.OpenText(filePath)) + { + using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture)) + using (var dataReader = new CsvHelper.CsvDataReader(csv)) + { + dt.Load(dataReader); + } + } + + //var lines = File.ReadAllLines(filePath, Encoding.GetEncoding("GB2312")).ToList(); AuditFileList.Add(new AuditFile() { FileName = fileName, AuditFileType = auditFileType }); - return (string.Empty, fileName, lines); + return (string.Empty, fileName, dt); } catch (Exception ex) { @@ -352,7 +364,7 @@ namespace BBWY.Client.ViewModels MessageBox.Show(importResult.ErrorMessage, "导入支付宝账单"); return; } - if (importResult.Lines == null || importResult.Lines.Count() == 0) + if (importResult.DataTable == null || importResult.DataTable.Rows.Count == 0) return; //忽略前5行 /* @@ -362,8 +374,8 @@ namespace BBWY.Client.ViewModels #-----------------------------------------账务明细列表---------------------------------------- 账务流水号 业务流水号 商户订单号 商品名称 发生时间 对方账号 收入金额(+元) 支出金额(-元) 账户余额(元) 交易渠道 业务类型 备注 */ - for (var i = 0; i < 5; i++) - importResult.Lines.RemoveAt(0); + //for (var i = 0; i < 5; i++) + // importResult.DataTable.RemoveAt(0); //忽略后4行 /* @@ -372,44 +384,44 @@ namespace BBWY.Client.ViewModels #收入合计:85笔,共43889.26元 #导出时间:[2022年05月01日 10:13:45] */ - for (var i = 0; i < 4; i++) - { - importResult.Lines.RemoveAt(importResult.Lines.Count() - 1); - } + //for (var i = 0; i < 4; i++) + //{ + // importResult.Lines.RemoveAt(importResult.Lines.Count() - 1); + //} var payBillNo = ""; try { - foreach (var line in importResult.Lines) - { - var array = line.CSVstrToArry(); - var sourceMerchantOrderNo = array[2].FormatString(); - if (!string.IsNullOrEmpty(sourceMerchantOrderNo) && sourceMerchantOrderNo.StartsWith("XP")) - continue; //暂时不支持此类商户单号 - - var expenditureAmount = decimal.Parse(array[7].FormatString()); - if (expenditureAmount == 0) //支出为0的账单不参与审计 - continue; - payBillNo = array[0].FormatString(); - if (AuditPayBillList.Any(p => p.PayBillNo == payBillNo)) - continue; - var payBill = new AuditPayBill() - { - BelongFileName = importResult.FileName, - PayBillNo = payBillNo, - PayBillType = PayBillType.AliPay, - SourceMerchantOrderNo = sourceMerchantOrderNo, - ProductName = array[3].FormatString(), - PayTime = DateTime.Parse(array[4].FormatString()), - OppositeAccount = array[5].FormatString(), - ExpenditureAmount = Math.Abs(expenditureAmount) - }; - payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo; - if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP")) - payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8); - - AuditPayBillList.Add(payBill); - } + //foreach (var line in importResult.Lines) + //{ + // var array = line.CSVstrToArry(); + // var sourceMerchantOrderNo = array[2].FormatString(); + // if (!string.IsNullOrEmpty(sourceMerchantOrderNo) && sourceMerchantOrderNo.StartsWith("XP")) + // continue; //暂时不支持此类商户单号 + + // var expenditureAmount = decimal.Parse(array[7].FormatString()); + // if (expenditureAmount == 0) //支出为0的账单不参与审计 + // continue; + // payBillNo = array[0].FormatString(); + // if (AuditPayBillList.Any(p => p.PayBillNo == payBillNo)) + // continue; + // var payBill = new AuditPayBill() + // { + // BelongFileName = importResult.FileName, + // PayBillNo = payBillNo, + // PayBillType = PayBillType.AliPay, + // SourceMerchantOrderNo = sourceMerchantOrderNo, + // ProductName = array[3].FormatString(), + // PayTime = DateTime.Parse(array[4].FormatString()), + // OppositeAccount = array[5].FormatString(), + // ExpenditureAmount = Math.Abs(expenditureAmount) + // }; + // payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo; + // if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP")) + // payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8); + + // AuditPayBillList.Add(payBill); + //} } catch (Exception ex) { @@ -428,40 +440,40 @@ namespace BBWY.Client.ViewModels MessageBox.Show(importResult.ErrorMessage, "导入1688采购单"); return; } - if (importResult.Lines == null || importResult.Lines.Count() == 0) + if (importResult.DataTable == null || importResult.DataTable.Rows.Count == 0) return; //去掉列名 - importResult.Lines.RemoveAt(0); + //importResult.Lines.RemoveAt(0); var purchaseOrderId = ""; try { - foreach (var line in importResult.Lines) - { - var array = line.CSVstrToArry(); - purchaseOrderId = array[0].FormatString(); - if (string.IsNullOrEmpty(purchaseOrderId) || AuditPurchaseOrderList.Any(p => p.PurchaseOrderId == purchaseOrderId)) - continue; - var purchaseOrder = new AuditPurchaseOrder() - { - PurchaseOrderId = purchaseOrderId, - Platform = Platform.阿里巴巴, - BelongFileName = importResult.FileName, - ProductAmount = decimal.Parse(array[5].FormatString()), - Freight = decimal.Parse(array[6].FormatString()), - PayAmount = decimal.Parse(array[8].FormatString()), - CreateTime = DateTime.Parse(array[10].FormatString()), - ContactName = array[13].FormatString(), - Address = array[14].FormatString(), - Phone = array[17].FormatString(), - Quantity = int.Parse(array[20].FormatString()) - }; - if (!string.IsNullOrEmpty(array[11])) - purchaseOrder.PayTime = DateTime.Parse(array[11].FormatString()); - AuditPurchaseOrderList.Add(purchaseOrder); - } - Console.WriteLine(AuditPurchaseOrderList.Count()); + //foreach (var line in importResult.DataTable) + //{ + // var array = line.CSVstrToArry(); + // purchaseOrderId = array[0].FormatString(); + // if (string.IsNullOrEmpty(purchaseOrderId) || AuditPurchaseOrderList.Any(p => p.PurchaseOrderId == purchaseOrderId)) + // continue; + // var purchaseOrder = new AuditPurchaseOrder() + // { + // PurchaseOrderId = purchaseOrderId, + // Platform = Platform.阿里巴巴, + // BelongFileName = importResult.FileName, + // ProductAmount = decimal.Parse(array[5].FormatString()), + // Freight = decimal.Parse(array[6].FormatString()), + // PayAmount = decimal.Parse(array[8].FormatString()), + // CreateTime = DateTime.Parse(array[10].FormatString()), + // ContactName = array[13].FormatString(), + // Address = array[14].FormatString(), + // Phone = array[17].FormatString(), + // Quantity = int.Parse(array[20].FormatString()) + // }; + // if (!string.IsNullOrEmpty(array[11])) + // purchaseOrder.PayTime = DateTime.Parse(array[11].FormatString()); + // AuditPurchaseOrderList.Add(purchaseOrder); + //} + //Console.WriteLine(AuditPurchaseOrderList.Count()); } catch (Exception ex) { @@ -481,38 +493,38 @@ namespace BBWY.Client.ViewModels MessageBox.Show(importResult.ErrorMessage, "导入京东销售订单"); return; } - if (importResult.Lines == null || importResult.Lines.Count() == 0) - return; + //if (importResult.Lines == null || importResult.Lines.Count() == 0) + // return; //去掉列名 - importResult.Lines.RemoveAt(0); + //importResult.Lines.RemoveAt(0); var orderId = ""; try { - foreach (var line in importResult.Lines) - { - var array = line.CSVstrToArry(); - orderId = array[0].FormatString(); - if (string.IsNullOrEmpty(orderId) || AuditShopOrderList.Any(p => p.OrderId == orderId)) - continue; - var order = new AuditShopOrder() - { - OrderId = orderId, - Platform = Platform.京东, - BelongFileName = importResult.FileName, - Quantity = int.Parse(array[3].FormatString()), - CreateTime = DateTime.Parse(array[5].FormatString()), - PayAmount = decimal.Parse(array[10].FormatString()), - ContactName = array[14].FormatString(), - Address = array[15].FormatString(), - Phone = array[16].FormatString(), - ProductName = array[2].FormatString(), - VenderRemark = array[27].FormatString() - }; - AuditShopOrderList.Add(order); - if (!string.IsNullOrEmpty(array[30])) - order.PayTime = DateTime.Parse(array[30].FormatString()); - } + //foreach (var line in importResult.Lines) + //{ + // var array = line.CSVstrToArry(); + // orderId = array[0].FormatString(); + // if (string.IsNullOrEmpty(orderId) || AuditShopOrderList.Any(p => p.OrderId == orderId)) + // continue; + // var order = new AuditShopOrder() + // { + // OrderId = orderId, + // Platform = Platform.京东, + // BelongFileName = importResult.FileName, + // Quantity = int.Parse(array[3].FormatString()), + // CreateTime = DateTime.Parse(array[5].FormatString()), + // PayAmount = decimal.Parse(array[10].FormatString()), + // ContactName = array[14].FormatString(), + // Address = array[15].FormatString(), + // Phone = array[16].FormatString(), + // ProductName = array[2].FormatString(), + // VenderRemark = array[27].FormatString() + // }; + // AuditShopOrderList.Add(order); + // if (!string.IsNullOrEmpty(array[30])) + // order.PayTime = DateTime.Parse(array[30].FormatString()); + //} } catch (Exception ex) {