public void SetUp() { var importBook = new ImportBook { Id = 123 }; var importBookResource = new ImportBookResource { Id = 123, ParcelNumber = 4, SupplierId = 2, DateCreated = new DateTime().ToString("o"), CarrierId = 4, Weight = 00.70m, Comments = "Rsn 1234 raised as BRG, but Customs charged duty incorrectly." }; this.ImportBooksFacadeService.Update(Arg.Any <int>(), Arg.Any <ImportBookResource>()) .Returns(new SuccessResult <ImportBook>(importBook)); this.Response = this.Browser.Put( "/logistics/import-books/123", with => { with.Header("Accept", "application/json"); with.JsonBody(importBookResource); }).Result; }
public void TestImport() { var sheet1 = new ImportSheet <ImportStudent> { UniqueValidationPrompt = "零花钱不可重复", HeaderRowIndex = 0, SheetIndex = 0, ValidateHandler = (list) => { foreach (ImportStudent model in list) { if (model.IsValidated && model.Name == "name0") { model.SetError(nameof(model.Name), "名字不可为0"); } if (model.IsValidated && model.Money < 0.5) { model.SetError(nameof(model.Money), "零花钱不可小于0.5"); } } } }; var sheet2 = new ImportSheet <ImportGrade> { HeaderRowIndex = 0, SheetIndex = 1 }; var sheet3 = new ImportSheet <ImportSchool> { HeaderRowIndex = 1, SheetIndex = 2, ValidateHandler = (list) => { foreach (var model in list) { if (model.Price > 0.5) { model.SetError(nameof(model.Price), "学费不可大于0.5"); } } } }; var import = new DefaultExcelImporter(); using var inputStrem = new FileStream("D://export.xlsx", FileMode.OpenOrCreate, FileAccess.Read); using var outStrem = new FileStream("D://error.xlsx", FileMode.Create, FileAccess.Write); var bookmodel = new ImportBook(); bookmodel.SetSheetModels(sheet1, sheet2, sheet3); var ret = import.ImportExcel(inputStrem, ExtEnum.XLSX, bookmodel, outStrem); var success = ret.ImportSuccess; var summaryErrorMsg = ret.GetSummaryErrorMessage(); var notDisplayMsg = ret.GetNotDisplayErrorMessage(); Output.WriteLine($"success:{success}"); Output.WriteLine("summaryErrorMsg------------"); Output.WriteLine(summaryErrorMsg); Output.WriteLine("notDisplayMsg------------"); Output.WriteLine(notDisplayMsg); }
public void TestImport() { var sheet1 = new BookSheet <ImportStudent> { UniqueValidationPrompt = "零花钱不可重复", HeaderRowIndex = 0, SheetIndex = 0, ValidateHandler = (list) => { foreach (ImportStudent model in list) { if (model.IsValidated && model.Name == "name0") { model.SetError(nameof(model.Name), "名字不可为0"); } if (model.IsValidated && model.Money < 0.5) { model.SetError(nameof(model.Money), "零花钱不可小于0.5"); } } } }; var sheet2 = new BookSheet <ImportGrade> { HeaderRowIndex = 0, SheetIndex = 1 }; var sheet3 = new BookSheet <ImportSchool> { HeaderRowIndex = 1, SheetIndex = 2, ValidateHandler = (list) => { foreach (var model in list) { if (model.Price > 0.5) { model.SetError(nameof(model.Price), "学费不可大于0.5"); } } } }; var bookmodel = new ImportBook().SetSheets(sheet1, sheet2, sheet3); using var inputStream = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Excels//Export.xlsx"), FileMode.OpenOrCreate, FileAccess.Read); using var outStream = new FileStream("D://Export_Error.xlsx", FileMode.Create, FileAccess.Write); var importResult = _importer.ImportExcel(inputStream, ExtEnum.Xlsx, bookmodel, outStream); var success = importResult.ImportSuccess; var summaryErrorMsg = importResult.GetSummaryErrorMessage(); var notDisplayMsg = importResult.GetNotDisplayErrorMessage(); var sheet1Data = importResult.Sheets[0].GetData <ImportStudent>(); Output.WriteLine($"success:{success}"); Output.WriteLine("summaryErrorMsg------------"); Output.WriteLine(summaryErrorMsg); Output.WriteLine("notDisplayMsg------------"); Output.WriteLine(notDisplayMsg); }
public void SetUp() { var importBook = new ImportBook { Id = 123 }; this.ImportBooksFacadeService.GetById(123).Returns(new SuccessResult <ImportBook>(importBook)); this.Response = this.Browser.Get( "/logistics/import-books/123", with => { with.Header("Accept", "application/json"); }).Result; }
public void SetUp() { var firstInvoiceDetail = new ImportBookInvoiceDetail { ImportBookId = this.impbookId, InvoiceNumber = "123", LineNumber = 1, InvoiceValue = 12.5m }; var secondInvoiceDetail = new ImportBookInvoiceDetail { ImportBookId = this.impbookId, InvoiceNumber = "1234", LineNumber = 2, InvoiceValue = 155.2m }; this.impbook = new ImportBook { Id = this.impbookId, DateCreated = DateTime.Now.AddDays(-5), SupplierId = 555, CarrierId = 678, TransportId = 1, TransactionId = 44, TotalImportValue = 123.4m, InvoiceDetails = new List <ImportBookInvoiceDetail> { firstInvoiceDetail, secondInvoiceDetail }, OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry>() }; var newImportBook = new ImportBook { Id = this.impbookId, DateCreated = DateTime.Now.AddDays(-5), SupplierId = 555, CarrierId = 678, TransactionId = 44, TotalImportValue = 123.4m, InvoiceDetails = new List <ImportBookInvoiceDetail> { firstInvoiceDetail }, OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry>() }; this.Sut.Update(this.impbook, newImportBook); }
/// <summary> /// 导入Excel /// </summary> /// <param name="fileStream">excel文件流</param> /// <param name="ext">excel后缀</param> /// <param name="importBook">导入模型</param> /// <param name="outPutErrorStream">错误输出流</param> /// <returns>导入结果</returns> public ImportResult ImportExcel(Stream fileStream, ExtEnum ext, ImportBook importBook, Stream outPutErrorStream = null) { var ret = new ImportResult(); var sheets = importBook.Sheets.Select(m => this.CreateResultSheetInstance(m.GetType().GenericTypeArguments[0], m)).ToArray(); ret.SetSheets(sheets); IWorkbook workbook; try { workbook = WorkbookGenerator.GetIWorkbook(fileStream, ext); } catch (Exception ex) { ret.SetBookFormatErrorMessage(ex.Message, ex); return(ret); } var errorStyleGenerator = new ImporterErrorStyleGenerator(workbook, importBook.DataErrorForegroundColor, importBook.RepeatedErrorForegroundColor, importBook.DefaultForegroundColor); for (var i = 0; i < workbook.NumberOfSheets; i++) { var sheet = workbook.GetSheetAt(i); var sheetModel = ret.Sheets.FirstOrDefault(m => m.SheetIndex == i || m.SheetName == sheet.SheetName); if (sheetModel == null) { continue; } sheetModel.SheetIndex = i; sheetModel.SheetName = sheet.SheetName; this.ParseSheetToModel(sheet, sheetModel); if (outPutErrorStream != null) { errorStyleGenerator.InitStyle(sheet, sheetModel.HeaderRowIndex); errorStyleGenerator.SetErrorStyle(sheet, sheetModel); } } if (outPutErrorStream != null) { workbook.Write(outPutErrorStream); } return(ret); }
private void ExtractDetails( ICollection <CalculationValueModel> values, ImportBook impbook, ImportBookOrderDetail orderDetail) { values.Add( new CalculationValueModel { RowId = $"{impbook.Id.ToString()}/{orderDetail.LineNumber}", ColumnId = "RsnNo", TextDisplay = orderDetail.RsnNumber?.ToString(), RowTitle = impbook.Id.ToString() }); values.Add( new CalculationValueModel { RowId = $"{impbook.Id.ToString()}/{orderDetail.LineNumber}", ColumnId = "Currency", TextDisplay = impbook.Currency, RowTitle = impbook.Id.ToString() }); values.Add( new CalculationValueModel { RowId = $"{impbook.Id.ToString()}/{orderDetail.LineNumber}", ColumnId = "CustomsEntryCodeDate", TextDisplay = impbook.CustomsEntryCodeDate?.ToString("o"), RowTitle = impbook.Id.ToString() }); values.Add( new CalculationValueModel { RowId = $"{impbook.Id.ToString()}/{orderDetail.LineNumber}", ColumnId = "TariffCode", TextDisplay = orderDetail.TariffCode, RowTitle = impbook.Id.ToString() }); }
public void TestImport() { var sheet = new BookSheet <ImportBalanceOfPayment> { UniqueValidationPrompt = "年月不可重复", HeaderRowIndex = 0, SheetIndex = 0 }; var bookmodel = new ImportBook().SetSheets(sheet); var inputFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Excels//Simple.xlsx"); using var inputStream = new FileStream(inputFilePath, FileMode.OpenOrCreate, FileAccess.Read); using var outStream = new FileStream("D://Simple_Error.xlsx", FileMode.Create, FileAccess.Write); var importResult = _importer.ImportExcel(inputStream, inputFilePath.GetExt(), bookmodel, outStream); var success = importResult.ImportSuccess; var summaryErrorMsg = importResult.GetSummaryErrorMessage(); var importData = importResult.Sheets[0].GetData <ImportBalanceOfPayment>(); Output.WriteLine($"success:{success}"); Output.WriteLine(summaryErrorMsg); }
public void SetUp() { this.from = new ImportBook { Id = this.impbookId, DateCreated = this.now.AddDays(-5), ParcelNumber = null, SupplierId = 555, ForeignCurrency = string.Empty, Currency = "GBP", CarrierId = 678, OldArrivalPort = "Glasscow", FlightNumber = string.Empty, TransportId = 1, TransportBillNumber = string.Empty, TransactionId = 44, DeliveryTermCode = string.Empty, ArrivalPort = "LAX", LineVatTotal = null, Hwb = "what is hwb", SupplierCostCurrency = "bacon", TransNature = "air", ArrivalDate = null, FreightCharges = null, HandlingCharge = null, ClearanceCharge = null, Cartage = null, Duty = null, Vat = null, Misc = null, CarriersInvTotal = null, CarriersVatTotal = null, TotalImportValue = 123.4m, Pieces = null, Weight = null, CustomsEntryCode = "code RED", CustomsEntryCodeDate = null, LinnDuty = null, LinnVat = null, IprCpcNumber = null, EecgNumber = null, DateCancelled = null, CancelledBy = null, CancelledReason = null, CarrierInvNumber = null, CarrierInvDate = null, CountryOfOrigin = string.Empty, FcName = string.Empty, VaxRef = string.Empty, Storage = null, NumCartons = null, NumPallets = null, Comments = string.Empty, ExchangeRate = null, ExchangeCurrency = string.Empty, BaseCurrency = string.Empty, PeriodNumber = null, CreatedBy = null, PortCode = string.Empty, CustomsEntryCodePrefix = "AA", InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry>() }; this.resource = new ImportBookResource() { Id = this.impbookId, DateCreated = this.now.AddDays(2).ToString("o"), ParcelNumber = 1, SupplierId = 556, ForeignCurrency = "YN", Currency = "GBD", CarrierId = 678, OldArrivalPort = "Glesga", FlightNumber = "sk123", TransportId = 2, TransportBillNumber = "1212", TransactionId = 45, DeliveryTermCode = "dli", ArrivalPort = "LAZ", LineVatTotal = 12, Hwb = "hwbbb", SupplierCostCurrency = "egg", TransNature = "sea", ArrivalDate = this.now.AddDays(3).ToString("o"), FreightCharges = 11.1m, HandlingCharge = 11.1m, ClearanceCharge = 11.1m, Cartage = 11.1m, Duty = 11.1m, Vat = 11.1m, Misc = 11.1m, CarriersInvTotal = 11.1m, CarriersVatTotal = 11.1m, TotalImportValue = 133.4m, Pieces = 1, Weight = 11.1m, CustomsEntryCode = "code green", CustomsEntryCodeDate = this.now.AddDays(2).ToString("o"), LinnDuty = 12, LinnVat = 11.1m, IprCpcNumber = 1, EecgNumber = 1, DateCancelled = this.now.AddDays(5).ToString("o"), CancelledBy = 33105, CancelledReason = "cancel", CarrierInvNumber = "inv123", CarrierInvDate = this.now.AddDays(3).ToString("o"), CountryOfOrigin = "DE", FcName = "FC1", VaxRef = "VAX123", Storage = 11.1m, NumCartons = 1, NumPallets = 1, Comments = "now closed", ExchangeRate = 11.1m, ExchangeCurrency = "BB", BaseCurrency = "AA", PeriodNumber = 47, CreatedBy = 33105, PortCode = "g74", CustomsEntryCodePrefix = "AA", ImportBookInvoiceDetails = new List <ImportBookInvoiceDetailResource> { new ImportBookInvoiceDetailResource { ImportBookId = this.impbookId, InvoiceNumber = "123", LineNumber = 1, InvoiceValue = 12.5m }, new ImportBookInvoiceDetailResource { ImportBookId = this.impbookId, InvoiceNumber = "1234", LineNumber = 2, InvoiceValue = 155.2m } }, ImportBookOrderDetails = new List <ImportBookOrderDetailResource> { new ImportBookOrderDetailResource { ImportBookId = this.impbookId, LineNumber = 2, OrderNumber = 13, RsnNumber = 2, OrderDescription = "palpatine final order", Qty = 1, DutyValue = 21.12m, FreightValue = 22.12m, VatValue = 3.12m, OrderValue = 44.1m, Weight = 55.2m, LoanNumber = null, LineType = "TYpe B", CpcNumber = null, TariffCode = "121213", InsNumber = null, VatRate = null }, new ImportBookOrderDetailResource { ImportBookId = this.impbookId, LineNumber = 1, OrderNumber = 111, RsnNumber = 222, OrderDescription = "kylo ren first order", Qty = 3, DutyValue = 91.12m, FreightValue = 92.12m, VatValue = 93.12m, OrderValue = 944.1m, Weight = 955.2m, LoanNumber = 999, LineType = "Type C", CpcNumber = 91, TariffCode = "121213", InsNumber = 92, VatRate = 93 } }, ImportBookPostEntries = new List <ImportBookPostEntryResource> { new ImportBookPostEntryResource { ImportBookId = this.impbookId, LineNumber = 1, EntryCodePrefix = "PR", EntryCode = "code blu", EntryDate = null, Reference = "refer fence", Duty = null, Vat = null }, new ImportBookPostEntryResource { ImportBookId = this.impbookId, LineNumber = 2, EntryCodePrefix = "DL", EntryCode = "code blanc", EntryDate = this.now.AddDays(-6) .ToString("o"), Reference = "hocus pocus", Duty = 33, Vat = 44 } } }; this.ImportBookRepository.FindById(Arg.Any <int>()).Returns(this.from); this.result = this.Sut.Update(this.impbookId, this.resource); }
public void SetUp() { this.impbook = new ImportBook { Id = this.impbookId, DateCreated = this.now.AddDays(-5), ParcelNumber = null, SupplierId = 555, ForeignCurrency = string.Empty, Currency = "GBP", CarrierId = 678, OldArrivalPort = "Glasscow", FlightNumber = string.Empty, TransportId = 1, TransportBillNumber = string.Empty, TransactionId = 44, DeliveryTermCode = string.Empty, ArrivalPort = "LAX", LineVatTotal = null, Hwb = "what is hwb", SupplierCostCurrency = "bacon", TransNature = "air", ArrivalDate = null, FreightCharges = null, HandlingCharge = null, ClearanceCharge = null, Cartage = null, Duty = null, Vat = null, Misc = null, CarriersInvTotal = null, CarriersVatTotal = null, TotalImportValue = 123.4m, Pieces = null, Weight = null, CustomsEntryCode = "code RED", CustomsEntryCodeDate = null, LinnDuty = null, LinnVat = null, IprCpcNumber = null, EecgNumber = null, DateCancelled = null, CancelledBy = null, CancelledReason = null, CarrierInvNumber = null, CarrierInvDate = null, CountryOfOrigin = string.Empty, FcName = string.Empty, VaxRef = string.Empty, Storage = null, NumCartons = null, NumPallets = null, Comments = string.Empty, ExchangeRate = null, ExchangeCurrency = string.Empty, BaseCurrency = string.Empty, PeriodNumber = null, CreatedBy = null, PortCode = string.Empty, CustomsEntryCodePrefix = "AA", InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry>() }; this.newImpBook = new ImportBook { Id = this.impbookId, DateCreated = this.now.AddDays(2), ParcelNumber = 1, SupplierId = 556, ForeignCurrency = "YN", Currency = "GBD", CarrierId = 678, OldArrivalPort = "Glesga", FlightNumber = "sk123", TransportId = 2, TransportBillNumber = "1212", TransactionId = 45, DeliveryTermCode = "dli", ArrivalPort = "LAZ", LineVatTotal = 12, Hwb = "hwbbb", SupplierCostCurrency = "egg", TransNature = "sea", ArrivalDate = this.now.AddDays(3), FreightCharges = 11.1m, HandlingCharge = 11.1m, ClearanceCharge = 11.1m, Cartage = 11.1m, Duty = 11.1m, Vat = 11.1m, Misc = 11.1m, CarriersInvTotal = 11.1m, CarriersVatTotal = 11.1m, TotalImportValue = 133.4m, Pieces = 1, Weight = 11.1m, CustomsEntryCode = "code green", CustomsEntryCodeDate = this.now.AddDays(2), LinnDuty = 12, LinnVat = 11.1m, IprCpcNumber = 1, EecgNumber = 1, DateCancelled = this.now.AddDays(5), CancelledBy = 33105, CancelledReason = "cancel", CarrierInvNumber = "inv123", CarrierInvDate = this.now.AddDays(3), CountryOfOrigin = "DE", FcName = "FC1", VaxRef = "VAX123", Storage = 11.1m, NumCartons = 1, NumPallets = 1, Comments = "now closed", ExchangeRate = 11.1m, ExchangeCurrency = "BB", BaseCurrency = "AA", PeriodNumber = 47, CreatedBy = 33105, PortCode = "g74", CustomsEntryCodePrefix = "AA", InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry>() }; this.Sut.Update(this.impbook, this.newImpBook); }
public void SetUp() { var firstOrderDetail = new ImportBookOrderDetail { ImportBookId = this.impbookId, LineNumber = 1, OrderNumber = null, RsnNumber = null, OrderDescription = "kylo ren first order", Qty = 1, DutyValue = 21.12m, FreightValue = 22.12m, VatValue = 3.12m, OrderValue = 44.1m, Weight = 55.2m, LoanNumber = null, LineType = "typea", CpcNumber = null, TariffCode = "121213", InsNumber = null, VatRate = null }; var secondOrderDetail = new ImportBookOrderDetail { ImportBookId = this.impbookId, LineNumber = 2, OrderNumber = 13, RsnNumber = 2, OrderDescription = "palpatine final order", Qty = 1, DutyValue = 21.12m, FreightValue = 22.12m, VatValue = 3.12m, OrderValue = 44.1m, Weight = 55.2m, LoanNumber = null, LineType = "TYpe B", CpcNumber = null, TariffCode = "121213", InsNumber = null, VatRate = null }; var updatedFirstOrderDetail = new ImportBookOrderDetail { ImportBookId = this.impbookId, LineNumber = 1, OrderNumber = 111, RsnNumber = 222, OrderDescription = "kylo ren first order", Qty = 3, DutyValue = 91.12m, FreightValue = 92.12m, VatValue = 93.12m, OrderValue = 944.1m, Weight = 955.2m, LoanNumber = 999, LineType = "Type C", CpcNumber = 91, TariffCode = "121213", InsNumber = 92, VatRate = 93 }; this.impbook = new ImportBook { Id = this.impbookId, DateCreated = DateTime.Now.AddDays(-5), SupplierId = 555, CarrierId = 678, TransportId = 1, TransactionId = 44, TotalImportValue = 123.4m, InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail> { firstOrderDetail }, PostEntries = new List <ImportBookPostEntry>() }; var newImportBook = new ImportBook { Id = this.impbookId, DateCreated = DateTime.Now.AddDays(-5), SupplierId = 555, CarrierId = 678, TransactionId = 44, TotalImportValue = 123.4m, InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail> { updatedFirstOrderDetail, secondOrderDetail }, PostEntries = new List <ImportBookPostEntry>() }; this.Sut.Update(this.impbook, newImportBook); }
public void SetUp() { var firstPostEntry = new ImportBookPostEntry() { ImportBookId = this.impbookId, LineNumber = 1, EntryCodePrefix = "PR", EntryCode = "code blu", EntryDate = null, Reference = "refer fence", Duty = null, Vat = null }; var secondPostEntry = new ImportBookPostEntry() { ImportBookId = this.impbookId, LineNumber = 2, EntryCodePrefix = "DL", EntryCode = "code blanc", EntryDate = this.now.AddDays(-6), Reference = "hocus pocus", Duty = 33, Vat = 44 }; var updatedFirstPostEntry = new ImportBookPostEntry() { ImportBookId = this.impbookId, LineNumber = 1, EntryCodePrefix = "PRE", EntryCode = "code vert", EntryDate = this.now.AddDays(-5), Reference = "refer fence", Duty = 111, Vat = 222 }; this.impbook = new ImportBook { Id = this.impbookId, DateCreated = DateTime.Now.AddDays(-5), SupplierId = 555, CarrierId = 678, TransportId = 1, TransactionId = 44, TotalImportValue = 123.4m, InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry> { firstPostEntry } }; var newImportBook = new ImportBook { Id = this.impbookId, DateCreated = DateTime.Now.AddDays(-5), SupplierId = 555, CarrierId = 678, TransactionId = 44, TotalImportValue = 123.4m, InvoiceDetails = new List <ImportBookInvoiceDetail>(), OrderDetails = new List <ImportBookOrderDetail>(), PostEntries = new List <ImportBookPostEntry> { updatedFirstPostEntry, secondPostEntry } }; this.Sut.Update(this.impbook, newImportBook); }