From 0fb0f17319ecf71d66b96a6acfd07f754be9443e Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 24 十月 2024 13:44:38 +0800
Subject: [PATCH] WCS添加穿梭车信息表,修改任务信息表
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/ExportHelper.cs | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/ExportHelper.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/ExportHelper.cs"
new file mode 100644
index 0000000..6e9a8fc
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/ExportHelper.cs"
@@ -0,0 +1,106 @@
+锘縰sing Magicodes.ExporterAndImporter.Core;
+using Magicodes.ExporterAndImporter.Excel;
+using Magicodes.IE.Core;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEA_Core.Helper
+{
+ public static class ExportHelper
+ {
+ public static Type CreateDynamicClass(this PropertyInfo[] propertyInfos)
+ {
+ string className = "DynamicClass";
+ AssemblyName assemblyName = new AssemblyName("WIDESEA_Model.Models");
+ AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);//瀹氫箟鍏锋湁鎸囧畾鍚嶇О鍜岃闂潈闄愮殑鍔ㄦ�佺▼搴忛泦
+ ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MainModule");//鍦ㄦ绋嬪簭闆嗕腑瀹氫箟鍛藉悕鐨勬殏鏃跺姩鎬佹ā鍧�
+ TypeBuilder typeBuilder = moduleBuilder.DefineType(className, TypeAttributes.Public);//TypeBuilder:鍦ㄨ繍琛屾椂瀹氫箟骞跺垱寤虹被鐨勬柊瀹炰緥
+
+ Type attributeType1 = typeof(ExcelExporterAttribute);
+ MethodInfo [] methodInfos = attributeType1.GetMethods(BindingFlags.Public);
+ ConstructorInfo[] constructorInfos2 = attributeType1.GetConstructors();
+ ConstructorInfo constructorInfo2 = constructorInfos2[0];
+ CustomAttributeBuilder customAttributeBuilder2 = new CustomAttributeBuilder(constructorInfo2, new object[] { });
+
+ typeBuilder.SetCustomAttribute(customAttributeBuilder2);
+
+ foreach (var property in propertyInfos)
+ {
+ string propertyName = property.Name;
+ Type propertyType = property.PropertyType;
+
+ FieldBuilder fieldBuilder = typeBuilder.DefineField("_" + propertyName, propertyType, FieldAttributes.Private);
+ PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null);
+
+ SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>();
+ if (sugarColumn != null)
+ {
+ Type attributeType = typeof(ExporterHeaderAttribute);
+ ConstructorInfo[] constructorInfos = attributeType.GetConstructors();
+ ConstructorInfo constructorInfo = constructorInfos[0];
+ CustomAttributeBuilder customAttributeBuilder = new CustomAttributeBuilder(constructorInfo, new object[] { sugarColumn.ColumnDescription, 11f, null, false, true, true, 0, KnownColor.Empty });
+ propertyBuilder.SetCustomAttribute(customAttributeBuilder);
+ }
+
+ MethodAttributes getSetAttributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
+
+ MethodBuilder getMethodBuilder = typeBuilder.DefineMethod("get_" + propertyName, getSetAttributes, propertyType, Type.EmptyTypes);
+ ILGenerator getIL = getMethodBuilder.GetILGenerator();
+ getIL.Emit(OpCodes.Ldarg_0);
+ getIL.Emit(OpCodes.Ldfld, fieldBuilder);
+ getIL.Emit(OpCodes.Ret);
+
+ MethodBuilder setMethodBuilder = typeBuilder.DefineMethod("set_" + propertyName, getSetAttributes, null, new Type[] { propertyType });
+ ILGenerator setIL = setMethodBuilder.GetILGenerator();
+ setIL.Emit(OpCodes.Ldarg_0);
+ setIL.Emit(OpCodes.Ldarg_1);
+ setIL.Emit(OpCodes.Stfld, fieldBuilder);
+ setIL.Emit(OpCodes.Ret);
+
+ propertyBuilder.SetGetMethod(getMethodBuilder);
+ propertyBuilder.SetSetMethod(setMethodBuilder);
+
+
+ }
+
+ Type generatedType = typeBuilder.CreateType();
+ return generatedType;
+ }
+
+ public static void SetProperty(object instance, string propertyName, object value)
+ {
+ Type type = instance.GetType();
+ PropertyInfo propertyInfo = type.GetProperty(propertyName);
+ propertyInfo.SetValue(instance, value);
+ }
+
+ public static object GetProperty(object instance, string propertyName)
+ {
+ Type type = instance.GetType();
+ PropertyInfo propertyInfo = type.GetProperty(propertyName);
+ return propertyInfo.GetValue(instance);
+ }
+
+ public static void SetValue<T>(object instance, T value)
+ {
+ Type type = instance.GetType();
+
+ PropertyInfo[] propertyInfos = typeof(T).GetProperties();
+ for (int j = 0; j < propertyInfos.Length; j++)
+ {
+ PropertyInfo propertyInfo = type.GetProperty(propertyInfos[j].Name);
+ object obj = propertyInfos[j].GetValue(value);
+ propertyInfo.SetValue(instance, obj);
+ ExporterHeaderAttribute exporterHeaderAttribute = propertyInfo.GetCustomAttribute<ExporterHeaderAttribute>();
+ }
+
+ }
+
+ }
+}
--
Gitblit v1.9.3