| | |
| | | using AutoMapper; |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using MailKit.Search; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using Org.BouncyCastle.Asn1.X509; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.Attributes; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_ITaskInfoRepository; |
| | | using WIDESEA_Model.Models; |
| | | using OrderByType = SqlSugar.OrderByType; |
| | | |
| | | namespace WIDESEA_InboundService |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | //ä¸è½½æ¨¡ç |
| | | public virtual WebResponseContent DownLoadTemplate() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | IExporter exporter = new ExcelExporter(); |
| | | Inbounddaoc inbounddaoc = new Inbounddaoc(); |
| | | byte[] data = exporter.ExportHeaderAsByteArray(inbounddaoc).Result; |
| | | string fileName = ""; |
| | | fileName ="模æ¿.xlsx"; |
| | | string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprotTemplate"; |
| | | FileHelper.WriteFile(savePath, fileName, data); |
| | | |
| | | content = WebResponseContent.Instance.OK(data: savePath + "\\" + fileName); |
| | | return content; |
| | | } |
| | | |
| | | //导å
¥ |
| | | public virtual WebResponseContent Import(List<IFormFile> files) |
| | | { |
| | | try |
| | | { |
| | | if (files == null || files.Count == 0) |
| | | return new WebResponseContent { Status = true, Message = "è¯·éæ©ä¸ä¼ çæä»¶" }; |
| | | |
| | | Microsoft.AspNetCore.Http.IFormFile formFile = files[0]; |
| | | |
| | | // 使ç¨Path.Combineï¼é¿å
硬ç¼ç è·¯å¾åé符 |
| | | string dicPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExcelImport", DateTime.Now.ToString("yyyyMMdd")); |
| | | if (!Directory.Exists(dicPath)) |
| | | Directory.CreateDirectory(dicPath); |
| | | |
| | | string fileName = $"{Guid.NewGuid()}_{formFile.FileName}"; |
| | | string fullPath = Path.Combine(dicPath, fileName); |
| | | |
| | | // 使ç¨FileStreamä¿åæä»¶ |
| | | using (FileStream stream = new FileStream(fullPath, FileMode.Create)) |
| | | { |
| | | formFile.CopyTo(stream); |
| | | } |
| | | |
| | | // åå§åExcel导å
¥å·¥å
· |
| | | ExcelImporter importer = new ExcelImporter(); |
| | | |
| | | // 导å
¥Excelæ°æ® |
| | | ImportResult<Inbounddaoc> importResult = importer.Import<Inbounddaoc>(fullPath, "").Result; |
| | | |
| | | |
| | | if (importResult.HasError) |
| | | { |
| | | return WebResponseContent.Instance.Error(importResult.TemplateErrors.Serialize()); |
| | | } |
| | | // å设BaseDalæ¯æ°æ®è®¿é®å±ï¼è¿è¡æ°æ®åå¨ |
| | | List<Dt_InboundOrder> dt_Inbounds = new List<Dt_InboundOrder>(); |
| | | |
| | | |
| | | |
| | | foreach (var item in importResult.Data) |
| | | { |
| | | int Startingcolumn = 0; |
| | | int Terminationcolumn = 0; |
| | | if (item.OrderType == "æå") |
| | | { |
| | | if (item.UpperOrderNo.Contains("åæ")) |
| | | { |
| | | Startingcolumn = 14; |
| | | Terminationcolumn = 37; |
| | | } |
| | | } |
| | | |
| | | Dt_InboundOrder dt_2 = new Dt_InboundOrder() |
| | | { |
| | | OrderName = item.OrderName, |
| | | UpperOrderNo = item.UpperOrderNo, |
| | | OrderType = item.OrderType == "åææ" ? (int)InventoryMaterialType.åææ : (int)InventoryMaterialType.æå, |
| | | OrderNo = item.OrderNo, |
| | | CreateType = (int)CreateType.daoru, |
| | | Creater = "导å
¥", |
| | | CreateDate = DateTime.Now, |
| | | Startingcolumn= Startingcolumn, |
| | | Terminationcolumn= Terminationcolumn |
| | | }; |
| | | dt_Inbounds.Add(dt_2); |
| | | } |
| | | BaseDal.AddData(dt_Inbounds); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // æè·å¼å¸¸å¹¶è¿åéè¯¯æ¶æ¯ |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public class Inbounddaoc |
| | | { |
| | | [ImporterHeader(Name = "ç©æå·")] |
| | | [ExporterHeader(DisplayName = "ç©æå·")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "ç©æå·", ColumnName = "ç©æå·")] |
| | | public string OrderName { get; set; } |
| | | |
| | | [ImporterHeader(Name = "ç©æåç§°")] |
| | | [ExporterHeader(DisplayName = "ç©æåç§°")] |
| | | [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "ç©æåç§°", ColumnName = "ç©æåç§°")] |
| | | public string UpperOrderNo { get; set; } |
| | | |
| | | [ImporterHeader(Name = "ç±»å")] |
| | | [ExporterHeader(DisplayName = "ç±»å")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "ç±»å", ColumnName = "ç±»å")] |
| | | public string OrderType { get; set; } |
| | | |
| | | [ImporterHeader(Name = "ç©æè¯¦æ
")] |
| | | [ExporterHeader(DisplayName = "ç©æè¯¦æ
")] |
| | | [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "ç©æè¯¦æ
", ColumnName = "ç©æè¯¦æ
")] |
| | | public string OrderNo { get; set; } |
| | | } |
| | | } |
| | | } |