Commit b4161960 by 陶然

优化

parent 7a4865d5
......@@ -54,7 +54,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RestfulPayment.cs" />
<Compile Include="RestfulReadExcel.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Kivii.Biz.Finances\Src\Kivii.Biz.Finances.V4.5.csproj">
......@@ -64,6 +64,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Content\Templates\Finances.Payment.Receipt.xlsx" />
<EmbeddedResource Include="Content\Templates\Finances.InvoiceTitle.xlsx" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -129,4 +129,67 @@ namespace Kivii.Finances.Addons
return rtns;
}
}
[Api(Description = "读取Excel发票抬头")]
[RequiresAnyRole(SystemRoles.Everyone)]
public class InvoiceTitleReadExcel : RestfulExecution<InvoiceTitle>
{
public override object OnExecution(IRequest req, IResponse res)
{
(Request.Files.Count() < 1 || Request.Files == null).ThrowIfTrue("未找到excel文件!");
var httpFile = Request.Files[0];
ExcelPackage package = new ExcelPackage(Request.Files[0].InputStream);
(package.Workbook.Worksheets.Count == 0).ThrowIfTrue("未找到Sheet!");
var rtns = new ReadExcelResponse<InvoiceTitle>();
rtns.Results = new List<InvoiceTitle>();
try
{
var sheet = package.Workbook.Worksheets[1];
var end = sheet.Dimension.End.Row;
for (int i = 2; i <= end; i++)
{
#region 格式化Excel中每行数据,必填项若不符合验证条件就抛出异常
var eCompanyName = sheet.Cells[i, 2].Value;
if (eCompanyName == null)
{
throw new Exception($"Excel第{i}行第2列不可为空,请传入不重复的名称!");
}
var companyName = eCompanyName.ToString();
var eTaxNumber = sheet.Cells[i, 3].Value;
if (eTaxNumber == null)
{
throw new Exception($"Excel第{i}行第3列不可为空,请传入不重复的税号!");
}
var taxNumber = eTaxNumber.ToString();
var eCompanyAddress = sheet.Cells[i, 4].Value;
var companyAddress = eCompanyAddress == null ? string.Empty : eCompanyAddress.ToString();
var ePhone = sheet.Cells[i, 5].Value;
var phone = ePhone == null ? string.Empty : ePhone.ToString();
var eBankName = sheet.Cells[i, 6].Value;
var bankName = eBankName == null ? string.Empty : eBankName.ToString();
var eBankAccount = sheet.Cells[i, 7].Value;
var bankAccount = eBankAccount == null ? string.Empty : eBankAccount.ToString();
#endregion
var invoiceTitle = new InvoiceTitle();
invoiceTitle.CompanyName = companyName;
invoiceTitle.TaxNumber = taxNumber;
invoiceTitle.CompanyAddress = companyAddress;
invoiceTitle.Phone = phone;
invoiceTitle.BankName = bankName;
invoiceTitle.BankAccount = bankAccount;
if (!rtns.Results.Exists(o => o.CompanyName == invoiceTitle.CompanyName)) rtns.Results.Add(invoiceTitle);
}
}
catch (Exception ex)
{
throw ex;
}
rtns.Total = rtns.Results.Count;
rtns.success = true;
return rtns;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment