shanji 3 years ago
parent
commit
813b88047d
  1. 1
      BBWY.Client/BBWY.Client.csproj
  2. 200
      BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs

1
BBWY.Client/BBWY.Client.csproj

@ -28,6 +28,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />

200
BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs

@ -7,6 +7,8 @@ using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -320,7 +322,7 @@ namespace BBWY.Client.ViewModels
OnlyException = false; OnlyException = false;
} }
private (string ErrorMessage, string FileName, IList<string> Lines) ImportAuditFile(AuditFileType auditFileType) private (string ErrorMessage, string FileName, DataTable DataTable) ImportAuditFile(AuditFileType auditFileType)
{ {
var ofd = new OpenFileDialog() { Filter = "CSV Files (*.csv)|*.csv" }; var ofd = new OpenFileDialog() { Filter = "CSV Files (*.csv)|*.csv" };
if (ofd.ShowDialog() != true) if (ofd.ShowDialog() != true)
@ -331,9 +333,19 @@ namespace BBWY.Client.ViewModels
return ("文件已存在", string.Empty, null); return ("文件已存在", string.Empty, null);
try 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 }); AuditFileList.Add(new AuditFile() { FileName = fileName, AuditFileType = auditFileType });
return (string.Empty, fileName, lines); return (string.Empty, fileName, dt);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -352,7 +364,7 @@ namespace BBWY.Client.ViewModels
MessageBox.Show(importResult.ErrorMessage, "导入支付宝账单"); MessageBox.Show(importResult.ErrorMessage, "导入支付宝账单");
return; return;
} }
if (importResult.Lines == null || importResult.Lines.Count() == 0) if (importResult.DataTable == null || importResult.DataTable.Rows.Count == 0)
return; return;
//忽略前5行 //忽略前5行
/* /*
@ -362,8 +374,8 @@ namespace BBWY.Client.ViewModels
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
+ - + -
*/ */
for (var i = 0; i < 5; i++) //for (var i = 0; i < 5; i++)
importResult.Lines.RemoveAt(0); // importResult.DataTable.RemoveAt(0);
//忽略后4行 //忽略后4行
/* /*
@ -372,44 +384,44 @@ namespace BBWY.Client.ViewModels
#8543889.26 #8543889.26
#[20220501 10:13:45] #[20220501 10:13:45]
*/ */
for (var i = 0; i < 4; i++) //for (var i = 0; i < 4; i++)
{ //{
importResult.Lines.RemoveAt(importResult.Lines.Count() - 1); // importResult.Lines.RemoveAt(importResult.Lines.Count() - 1);
} //}
var payBillNo = ""; var payBillNo = "";
try try
{ {
foreach (var line in importResult.Lines) //foreach (var line in importResult.Lines)
{ //{
var array = line.CSVstrToArry(); // var array = line.CSVstrToArry();
var sourceMerchantOrderNo = array[2].FormatString(); // var sourceMerchantOrderNo = array[2].FormatString();
if (!string.IsNullOrEmpty(sourceMerchantOrderNo) && sourceMerchantOrderNo.StartsWith("XP")) // if (!string.IsNullOrEmpty(sourceMerchantOrderNo) && sourceMerchantOrderNo.StartsWith("XP"))
continue; //暂时不支持此类商户单号 // continue; //暂时不支持此类商户单号
var expenditureAmount = decimal.Parse(array[7].FormatString()); // var expenditureAmount = decimal.Parse(array[7].FormatString());
if (expenditureAmount == 0) //支出为0的账单不参与审计 // if (expenditureAmount == 0) //支出为0的账单不参与审计
continue; // continue;
payBillNo = array[0].FormatString(); // payBillNo = array[0].FormatString();
if (AuditPayBillList.Any(p => p.PayBillNo == payBillNo)) // if (AuditPayBillList.Any(p => p.PayBillNo == payBillNo))
continue; // continue;
var payBill = new AuditPayBill() // var payBill = new AuditPayBill()
{ // {
BelongFileName = importResult.FileName, // BelongFileName = importResult.FileName,
PayBillNo = payBillNo, // PayBillNo = payBillNo,
PayBillType = PayBillType.AliPay, // PayBillType = PayBillType.AliPay,
SourceMerchantOrderNo = sourceMerchantOrderNo, // SourceMerchantOrderNo = sourceMerchantOrderNo,
ProductName = array[3].FormatString(), // ProductName = array[3].FormatString(),
PayTime = DateTime.Parse(array[4].FormatString()), // PayTime = DateTime.Parse(array[4].FormatString()),
OppositeAccount = array[5].FormatString(), // OppositeAccount = array[5].FormatString(),
ExpenditureAmount = Math.Abs(expenditureAmount) // ExpenditureAmount = Math.Abs(expenditureAmount)
}; // };
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo; // payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo;
if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP")) // if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP"))
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8); // payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8);
AuditPayBillList.Add(payBill); // AuditPayBillList.Add(payBill);
} //}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -428,40 +440,40 @@ namespace BBWY.Client.ViewModels
MessageBox.Show(importResult.ErrorMessage, "导入1688采购单"); MessageBox.Show(importResult.ErrorMessage, "导入1688采购单");
return; return;
} }
if (importResult.Lines == null || importResult.Lines.Count() == 0) if (importResult.DataTable == null || importResult.DataTable.Rows.Count == 0)
return; return;
//去掉列名 //去掉列名
importResult.Lines.RemoveAt(0); //importResult.Lines.RemoveAt(0);
var purchaseOrderId = ""; var purchaseOrderId = "";
try try
{ {
foreach (var line in importResult.Lines) //foreach (var line in importResult.DataTable)
{ //{
var array = line.CSVstrToArry(); // var array = line.CSVstrToArry();
purchaseOrderId = array[0].FormatString(); // purchaseOrderId = array[0].FormatString();
if (string.IsNullOrEmpty(purchaseOrderId) || AuditPurchaseOrderList.Any(p => p.PurchaseOrderId == purchaseOrderId)) // if (string.IsNullOrEmpty(purchaseOrderId) || AuditPurchaseOrderList.Any(p => p.PurchaseOrderId == purchaseOrderId))
continue; // continue;
var purchaseOrder = new AuditPurchaseOrder() // var purchaseOrder = new AuditPurchaseOrder()
{ // {
PurchaseOrderId = purchaseOrderId, // PurchaseOrderId = purchaseOrderId,
Platform = Platform., // Platform = Platform.阿里巴巴,
BelongFileName = importResult.FileName, // BelongFileName = importResult.FileName,
ProductAmount = decimal.Parse(array[5].FormatString()), // ProductAmount = decimal.Parse(array[5].FormatString()),
Freight = decimal.Parse(array[6].FormatString()), // Freight = decimal.Parse(array[6].FormatString()),
PayAmount = decimal.Parse(array[8].FormatString()), // PayAmount = decimal.Parse(array[8].FormatString()),
CreateTime = DateTime.Parse(array[10].FormatString()), // CreateTime = DateTime.Parse(array[10].FormatString()),
ContactName = array[13].FormatString(), // ContactName = array[13].FormatString(),
Address = array[14].FormatString(), // Address = array[14].FormatString(),
Phone = array[17].FormatString(), // Phone = array[17].FormatString(),
Quantity = int.Parse(array[20].FormatString()) // Quantity = int.Parse(array[20].FormatString())
}; // };
if (!string.IsNullOrEmpty(array[11])) // if (!string.IsNullOrEmpty(array[11]))
purchaseOrder.PayTime = DateTime.Parse(array[11].FormatString()); // purchaseOrder.PayTime = DateTime.Parse(array[11].FormatString());
AuditPurchaseOrderList.Add(purchaseOrder); // AuditPurchaseOrderList.Add(purchaseOrder);
} //}
Console.WriteLine(AuditPurchaseOrderList.Count()); //Console.WriteLine(AuditPurchaseOrderList.Count());
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -481,38 +493,38 @@ namespace BBWY.Client.ViewModels
MessageBox.Show(importResult.ErrorMessage, "导入京东销售订单"); MessageBox.Show(importResult.ErrorMessage, "导入京东销售订单");
return; return;
} }
if (importResult.Lines == null || importResult.Lines.Count() == 0) //if (importResult.Lines == null || importResult.Lines.Count() == 0)
return; // return;
//去掉列名 //去掉列名
importResult.Lines.RemoveAt(0); //importResult.Lines.RemoveAt(0);
var orderId = ""; var orderId = "";
try try
{ {
foreach (var line in importResult.Lines) //foreach (var line in importResult.Lines)
{ //{
var array = line.CSVstrToArry(); // var array = line.CSVstrToArry();
orderId = array[0].FormatString(); // orderId = array[0].FormatString();
if (string.IsNullOrEmpty(orderId) || AuditShopOrderList.Any(p => p.OrderId == orderId)) // if (string.IsNullOrEmpty(orderId) || AuditShopOrderList.Any(p => p.OrderId == orderId))
continue; // continue;
var order = new AuditShopOrder() // var order = new AuditShopOrder()
{ // {
OrderId = orderId, // OrderId = orderId,
Platform = Platform., // Platform = Platform.京东,
BelongFileName = importResult.FileName, // BelongFileName = importResult.FileName,
Quantity = int.Parse(array[3].FormatString()), // Quantity = int.Parse(array[3].FormatString()),
CreateTime = DateTime.Parse(array[5].FormatString()), // CreateTime = DateTime.Parse(array[5].FormatString()),
PayAmount = decimal.Parse(array[10].FormatString()), // PayAmount = decimal.Parse(array[10].FormatString()),
ContactName = array[14].FormatString(), // ContactName = array[14].FormatString(),
Address = array[15].FormatString(), // Address = array[15].FormatString(),
Phone = array[16].FormatString(), // Phone = array[16].FormatString(),
ProductName = array[2].FormatString(), // ProductName = array[2].FormatString(),
VenderRemark = array[27].FormatString() // VenderRemark = array[27].FormatString()
}; // };
AuditShopOrderList.Add(order); // AuditShopOrderList.Add(order);
if (!string.IsNullOrEmpty(array[30])) // if (!string.IsNullOrEmpty(array[30]))
order.PayTime = DateTime.Parse(array[30].FormatString()); // order.PayTime = DateTime.Parse(array[30].FormatString());
} //}
} }
catch (Exception ex) catch (Exception ex)
{ {

Loading…
Cancel
Save