| | |
| | | using OfficeOpenXml; |
| | | using Microsoft.Extensions.Configuration; |
| | | using OfficeOpenXml; |
| | | using OfficeOpenXml.Style; |
| | | using Renci.SshNet; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel.DataAnnotations; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using System.Drawing; |
| | | using System.IO; |
| | | using System.Linq; |
| | |
| | | using WIDESEA.Core.DBManager; |
| | | using WIDESEA.Core.Extensions; |
| | | using WIDESEA.Core.Infrastructure; |
| | | using WIDESEA.Core.ManageUser; |
| | | using WIDESEA.Entity.DomainModels; |
| | | |
| | | using static Dapper.SqlMapper; |
| | | //using WIDESEA.Services.Repositories; |
| | | namespace WIDESEA.Core.Utilities |
| | | { |
| | | public class EPPlusHelper |
| | | { |
| | | // å
¨å±é
ç½®å¯¹è±¡ï¼æ¨è注å
¥ï¼æ¤å¤ä¸ºç®åç´æ¥è¯»åï¼ |
| | | private static readonly IConfiguration _configuration; |
| | | |
| | | // éææé 彿°ï¼åå§åé
置读å |
| | | static EPPlusHelper() |
| | | { |
| | | // æå»ºé
置读åå¨ï¼è¯»åappsettings.json |
| | | _configuration = new ConfigurationBuilder() |
| | | .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) // 设置é
ç½®æä»¶æå¨ç®å½ |
| | | .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) // å¿
é¡»åå¨ï¼æ¯æçéè½½ |
| | | .Build(); |
| | | } |
| | | public static List<Dt_EmptyPallet> GetAllUsers() |
| | | { |
| | | //string _connectionString = "Server=.;Database=BJ_ZCWIDESEA_ZCJWMS;User Id=sa;Password=123;TrustServerCertificate=True;"; |
| | | string _connectionString = _configuration["Connection:DbConnectionString"]; |
| | | // 1. ç¼åSQLè¯å¥ |
| | | |
| | | string sql = "SELECT * FROM Dt_EmptyPallet;"; |
| | | |
| | | // 2. åå»ºæ°æ®åºè¿æ¥å¹¶æ§è¡æ¥è¯¢ |
| | | using (SqlConnection connection = new SqlConnection(_connectionString)) |
| | | { |
| | | // 3. è°ç¨DapperçQueryæ¹æ³ï¼èªå¨æ å°å°Userå®ä½å表 |
| | | // Query<T> æ¯Dapperæ ¸å¿æ¹æ³ï¼Tæ¯ä½ è¦æ å°çå®ä½ç±»å |
| | | List<Dt_EmptyPallet> users = connection.Query<Dt_EmptyPallet>(sql).ToList(); |
| | | return users; |
| | | } // usingåç»æä¼èªå¨éæ¾è¿æ¥ï¼æ éæå¨Close |
| | | } |
| | | |
| | | public static void UpdateEmptyPallet(int EmptyPallet_id, string EmptyPallet_palletweight) |
| | | { |
| | | // 读åè¿æ¥å符串 |
| | | string _connectionString = _configuration["Connection:DbConnectionString"]; |
| | | |
| | | // æ ¸å¿ä¿®æ¹ï¼ä½¿ç¨åæ°åSQLï¼ç»å¯¹ä¸è¦æ¼æ¥å符串 |
| | | string sql = "UPDATE Dt_EmptyPallet SET EmptyPallet_palletweight = @EmptyPallet_palletweight WHERE EmptyPallet_id = @EmptyPallet_id;"; |
| | | |
| | | using (SqlConnection connection = new SqlConnection(_connectionString)) |
| | | { |
| | | // æ§è¡æ´æ°å¹¶æ¥æ¶åå½±åè¡æ° |
| | | int affectedRows = connection.Execute(sql, new |
| | | { |
| | | EmptyPallet_id = EmptyPallet_id, |
| | | EmptyPallet_palletweight = EmptyPallet_palletweight |
| | | }); |
| | | |
| | | // å¯éï¼æå°ç»æï¼æ¹ä¾¿ææ¥ |
| | | if (affectedRows == 0) |
| | | { |
| | | Console.WriteLine($"ä¿®æ¹å¤±è´¥ï¼æªæ¾å°EmptyPallet_id={EmptyPallet_id}çè®°å½ï¼æåæ®µå¼æªåå"); |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine($"ä¿®æ¹æåï¼å
±æ´æ°{affectedRows}æ¡è®°å½"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 导å
¥æ¨¡æ¿(ä»
éæ¡æ¶å¯¼åºæ¨¡æ¿ä½¿ç¨)(202.05.07) |
| | | /// </summary> |
| | |
| | | if (!file.Exists) return responseContent.Error("æªæ¾å°ä¸ä¼ çæä»¶,è¯·éæ°ä¸ä¼ "); |
| | | |
| | | List<T> entities = new List<T>(); |
| | | |
| | | List<Dt_EmptyPallet> TempList = GetAllUsers(); |
| | | |
| | | using (ExcelPackage package = new ExcelPackage(file)) |
| | | { |
| | | ExcelWorksheet sheet2 = package.Workbook.Worksheets.FirstOrDefault(); |
| | | if (typeof(T).Name == "Dt_EmptyPallet") |
| | | { |
| | | for (int m = sheet2.Dimension.Start.Row + 1, n = sheet2.Dimension.End.Row; m <= n; m++) |
| | | { |
| | | T entity = Activator.CreateInstance<T>(); |
| | | string barcode = ""; |
| | | string weight = ""; |
| | | for (int j = 1, k = 2; j <= k; j++) |
| | | { |
| | | if (j == 1) |
| | | { |
| | | barcode = sheet2.Cells[m, j].Value?.ToString(); |
| | | } |
| | | else |
| | | { |
| | | weight = sheet2.Cells[m, j].Value?.ToString(); |
| | | } |
| | | } |
| | | if (barcode == "" || barcode == null || weight == "" || weight == null) |
| | | { |
| | | continue; |
| | | } |
| | | Dt_EmptyPallet Temps = TempList.Where(x => x.EmptyPallet_name == barcode).FirstOrDefault(); |
| | | if (Temps != null) |
| | | { |
| | | // 说æåºå䏿 é£å°±ä¿®æ¹ä»çéé |
| | | UpdateEmptyPallet(Temps.EmptyPallet_id, weight); |
| | | continue; |
| | | } |
| | | //var emptyPalletRepo = Dt_EmptyPalletRepository.Instance; |
| | | // UserContext.Current.UserTrueName; |
| | | Dt_EmptyPallet dt_Empty = new Dt_EmptyPallet(); |
| | | dt_Empty.EmptyPallet_name = barcode; |
| | | dt_Empty.EmptyPallet_palletweight = weight; |
| | | dt_Empty.EmptyPallet_creator = UserContext.Current.UserTrueName; |
| | | dt_Empty.EmptyPallet_createtime = DateTime.Now; |
| | | dt_Empty.EmptyPallet_modifier = UserContext.Current.UserTrueName; |
| | | dt_Empty.EmptyPallet_modifiertime = DateTime.Now; |
| | | //Dt_EmptyPalletRepository.Instance.Add(dt_Empty, true); |
| | | dt_Empty.SetCreateDefaultVal(); |
| | | entities.Add((T)(object)dt_Empty); |
| | | } |
| | | return responseContent.OK("ä¸ä¼ æå", entities); |
| | | } |
| | | |
| | | |
| | | if (package.Workbook.Worksheets.Count == 0 || |
| | | package.Workbook.Worksheets.FirstOrDefault().Dimension.End.Row <= 1) |
| | | return responseContent.Error("æªå¯¼å
¥æ°æ®"); |
| | |
| | | return fullPath; |
| | | } |
| | | |
| | | public static Dictionary<string, string> TempDict = new Dictionary<string, string>(); |
| | | // å®ä¹è·ååæ®µä¿¡æ¯çæ¹æ³ |
| | | public static void GetEntityFieldInfo<T>() where T : class |
| | | { |
| | | // è·åå®ä½ç±»çææå±æ§ |
| | | PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); |
| | | foreach (var prop in properties) |
| | | { |
| | | // 1. è·ååæ®µåç§°ï¼å±æ§åï¼ |
| | | string fieldName = prop.Name; |
| | | // 2. è·åDisplayç¹æ§çNameå¼ï¼æ³¨éï¼ |
| | | var displayAttr = prop.GetCustomAttribute<DisplayAttribute>(); |
| | | string comment = displayAttr?.Name ?? "æ æ³¨é"; |
| | | TempDict[fieldName] = comment; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å导åºçåçæ°æ®ä¿¡æ¯ |
| | | /// </summary> |
| | |
| | | { |
| | | query = query.Where(x => x.IsDisplay == 1); |
| | | } |
| | | List<CellOptions> cellOptions = query.OrderByDescending(r => r.OrderNo).Select(c => new CellOptions() |
| | | List<CellOptions> cellOptions = new List<CellOptions>(); |
| | | if (tableName == "Dt_EmptyPallet") |
| | | { |
| | | ColumnName = c.ColumnName, |
| | | ColumnCNName = c.ColumnCnName, |
| | | DropNo = c.DropNo, |
| | | Requierd = c.IsNull > 0 ? false : true, |
| | | ColumnWidth = c.ColumnWidth ?? 90, |
| | | EditType = c.EditType, |
| | | SearchType = c.SearchType |
| | | }).ToList(); |
| | | GetEntityFieldInfo<Dt_EmptyPallet>(); |
| | | foreach (KeyValuePair<string, string> kvp in TempDict) |
| | | { |
| | | cellOptions.Add(new CellOptions() |
| | | { |
| | | ColumnName = kvp.Key, |
| | | ColumnCNName = kvp.Value, |
| | | DropNo = null, |
| | | Requierd = false, |
| | | ColumnWidth = 120, |
| | | EditType = null, |
| | | SearchType = null |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | cellOptions = query.OrderByDescending(r => r.OrderNo).Select(c => new CellOptions() |
| | | { |
| | | ColumnName = c.ColumnName, |
| | | ColumnCNName = c.ColumnCnName, |
| | | DropNo = c.DropNo, |
| | | Requierd = c.IsNull > 0 ? false : true, |
| | | ColumnWidth = c.ColumnWidth ?? 90, |
| | | EditType = c.EditType, |
| | | SearchType = c.SearchType |
| | | }).ToList(); |
| | | } |
| | | |
| | | |
| | | if (temlate) return cellOptions; |
| | | |