| | |
| | | using System; |
| | | using Magicodes.ExporterAndImporter.Excel.Utility; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_IPackInfoRepository; |
| | | using WIDESEAWCS_Model.Models.PackInfo; |
| | | using WIDESEAWCS_PackInfoRepository; |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using WIDESEAWCS_Common.Utilities; |
| | | |
| | | namespace WIDESEAWCS_PackInfoService |
| | | { |
| | |
| | | public Dt_PackaxisService(IDt_PackaxisRepository BaseDal) : base(BaseDal) |
| | | { |
| | | } |
| | | public override WebResponseContent Import(List<IFormFile> files) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | // 1. éªè¯æä»¶ |
| | | if (files == null || files.Count == 0) |
| | | return new WebResponseContent { Status = false, Message = "è¯·éæ©ä¸ä¼ çæä»¶" }; |
| | | |
| | | var formFile = files[0]; |
| | | |
| | | // 2. åå¤ç®å½ï¼ä½¿ç¨Path.Combineï¼ |
| | | var dicPath = Path.Combine( |
| | | AppDomain.CurrentDomain.BaseDirectory, |
| | | "ExcelImport", |
| | | DateTime.Now.ToString("yyyyMMdd"), |
| | | typeof(Dt_Packaxis).Name); |
| | | |
| | | Directory.CreateDirectory(dicPath); |
| | | // 3. ä¿åä¸ä¼ æä»¶ |
| | | var fileName = $"{Guid.NewGuid()}_{formFile.FileName}"; |
| | | var fullPath = Path.Combine(dicPath, fileName); |
| | | |
| | | using (var stream = new FileStream(fullPath, FileMode.Create)) |
| | | { |
| | | formFile.CopyToAsync(stream); |
| | | } |
| | | |
| | | // 4. 导å
¥Excelæ°æ® |
| | | DataTable dtExcel = new DataTable(); |
| | | using (ImportExcelHelper excelHelper = new ImportExcelHelper(fullPath)) |
| | | { |
| | | dtExcel = excelHelper.ExcelToDataTable(); |
| | | |
| | | } |
| | | List<Dt_Packaxis> addAxis = new List<Dt_Packaxis>(); |
| | | List<Dt_Packaxis> updateAxis = new List<Dt_Packaxis>(); |
| | | if (dtExcel == null || dtExcel.Rows.Count == 0) |
| | | { |
| | | return content.Error("æªæ¾å°æ°æ®è¯·æ£æ¥Excelè¡¨æ ¼æ°æ®æ ¼å¼æ¯å¦æ£ç¡®ï¼"); |
| | | } |
| | | for (int i = 0; i < dtExcel.Rows.Count; i++) |
| | | { |
| | | DataRow row = dtExcel.Rows[i]; |
| | | string id = row["id"]?.ToString() ?? string.Empty; |
| | | string DeviceCode = row["DeviceCode"]?.ToString() ?? string.Empty; |
| | | string StationCode = row["StationCode"]?.ToString() ?? string.Empty; |
| | | string PackType = row["PackType"]?.ToString() ?? string.Empty; |
| | | string PackNum = row["PackNum"]?.ToString() ?? string.Empty; |
| | | string AxisX = row["AxisX"]?.ToString() ?? string.Empty; |
| | | string AxisXCount = row["AxisXCount"]?.ToString() ?? string.Empty; |
| | | string AxisXSpacing = row["AxisXSpacing"]?.ToString() ?? string.Empty; |
| | | string AxisY = row["AxisY"]?.ToString() ?? string.Empty; |
| | | string AxisYCount = row["AxisYCount"]?.ToString() ?? string.Empty; |
| | | string AxisYSpacing = row["AxisYSpacing"]?.ToString() ?? string.Empty; |
| | | string AxisZ = row["AxisZ"]?.ToString() ?? string.Empty; |
| | | string AxisZCount = row["AxisZCount"]?.ToString() ?? string.Empty; |
| | | string AxisZSpacing = row["AxisZSpacing"]?.ToString() ?? string.Empty; |
| | | var axis = BaseDal.QueryFirst(x => x.DeviceCode == DeviceCode && x.StationCode == Convert.ToInt32(StationCode) && x.PackType == PackType); |
| | | if(axis == null) |
| | | { |
| | | Dt_Packaxis packaxis = new Dt_Packaxis() |
| | | { |
| | | DeviceCode = DeviceCode, |
| | | StationCode = Convert.ToInt32(StationCode), |
| | | PackType = PackType, |
| | | PackNum = Convert.ToInt32(PackNum), |
| | | AxisX = Convert.ToInt32(AxisX), |
| | | AxisXCount = Convert.ToInt32(AxisXCount), |
| | | AxisXSpacing = Convert.ToInt32(AxisXSpacing), |
| | | AxisY = Convert.ToInt32(AxisY), |
| | | AxisYCount = Convert.ToInt32(AxisYCount), |
| | | AxisYSpacing = Convert.ToInt32(AxisYSpacing), |
| | | AxisZ = Convert.ToInt32(AxisZ), |
| | | AxisZCount = Convert.ToInt32(AxisZCount), |
| | | AxisZSpacing = Convert.ToInt32(AxisZSpacing), |
| | | Creater = App.User.UserId > 0 ? App.User.UserName : "System", |
| | | CreateDate = DateTime.Now |
| | | }; |
| | | addAxis.Add(packaxis); |
| | | } |
| | | else |
| | | { |
| | | axis.DeviceCode = DeviceCode; |
| | | axis.StationCode = Convert.ToInt32(StationCode); |
| | | axis.PackType = PackType; |
| | | axis.PackNum = Convert.ToInt32(PackNum); |
| | | axis.AxisX = Convert.ToInt32(AxisX); |
| | | axis.AxisXCount = Convert.ToInt32(AxisXCount); |
| | | axis.AxisXSpacing = Convert.ToInt32(AxisXSpacing); |
| | | axis.AxisY = Convert.ToInt32(AxisY); |
| | | axis.AxisYCount = Convert.ToInt32(AxisYCount); |
| | | axis.AxisYSpacing = Convert.ToInt32(AxisYSpacing); |
| | | axis.AxisZ = Convert.ToInt32(AxisZ); |
| | | axis.AxisZCount = Convert.ToInt32(AxisZCount); |
| | | axis.AxisZSpacing = Convert.ToInt32(AxisZSpacing); |
| | | axis.Modifier = App.User.UserId > 0 ? App.User.UserName : "System"; |
| | | axis.ModifyDate = DateTime.Now; |
| | | updateAxis.Add(axis); |
| | | } |
| | | } |
| | | BaseDal.AddData(addAxis); |
| | | BaseDal.UpdateData(updateAxis); |
| | | |
| | | content = WebResponseContent.Instance.OK("导å
¥æåï¼"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | return content; |
| | | } |
| | | } |
| | | } |