From c3b60d865c3457c35054446e81b352e93e00a696 Mon Sep 17 00:00:00 2001
From: xiaojiao <xiaojiao@kaokeziliao.com>
Date: 星期一, 12 一月 2026 18:31:11 +0800
Subject: [PATCH] 更改了大部分功能和逻辑
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA.Core/Utilities/EPPlusHelper.cs | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 166 insertions(+), 11 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Core/Utilities/EPPlusHelper.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Core/Utilities/EPPlusHelper.cs"
index 5e945ca..4e32e19 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Core/Utilities/EPPlusHelper.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Core/Utilities/EPPlusHelper.cs"
@@ -1,8 +1,12 @@
-锘縰sing OfficeOpenXml;
+锘縰sing 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;
@@ -11,12 +15,74 @@
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鐨凲uery鏂规硶锛岃嚜鍔ㄦ槧灏勫埌User瀹炰綋鍒楄〃
+ // Query<T> 鏄疍apper鏍稿績鏂规硶锛孴鏄綘瑕佹槧灏勭殑瀹炰綋绫诲瀷
+ 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>
@@ -34,8 +100,58 @@
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)
+ {
+ // 璇存槑搴撳瓨涓湁 閭e氨淇敼浠栫殑閲嶉噺
+ 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("鏈鍏ユ暟鎹�");
@@ -451,6 +567,23 @@
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>
@@ -473,16 +606,38 @@
{
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;
--
Gitblit v1.9.3