From f92c866451641efe1e7d62267a3a97c72b571cde Mon Sep 17 00:00:00 2001 From: qian Date: Thu, 25 Jul 2024 10:16:35 +0800 Subject: [PATCH] =?UTF-8?q?datatable=E5=92=8Clist=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/OdbcApiQadController.cs | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/UniApiGroup/Controller/OdbcApiQadController.cs b/UniApiGroup/Controller/OdbcApiQadController.cs index de3016a..d0f513a 100644 --- a/UniApiGroup/Controller/OdbcApiQadController.cs +++ b/UniApiGroup/Controller/OdbcApiQadController.cs @@ -31,6 +31,8 @@ using static CK.SCP.UniApi.Controller.NetPriceController; using System.Xml.Linq; using System.Security.Principal; using System.Diagnostics; +using Z.BulkOperations.Internal.InformationSchema; +using System.Collections; namespace CK.SCP.GrupUniApi.Controller { @@ -1648,8 +1650,8 @@ namespace CK.SCP.GrupUniApi.Controller hisList = idb.xxDiMaxes_Order.Where(q => q.CREATEDDATE > time).ToList(); // 读取一年内 所有审批完的一般材料订单 DataTable b = GetGeneralMaterialOrder(); - List orderlist = ChangKeTec.Utils.ListHelper.DataTableToList(b); - Listmaxes_Orders = ChangKeTec.Utils.ListHelper.DataTableToList(b); + List orderlist = GetTableToList(b); + Listmaxes_Orders = GetTableToList(b); // 取历史表不存在的数据 var expectedList = maxes_Orders.Where(x=> !hisList.Any(e=>e.DI_BATCHNO == x.DI_BATCHNO && e.PURDOCNO == x.PURDOCNO && e.PURDOCITEMNO ==x.PURDOCITEMNO)).ToList(); if (expectedList.Count() == 0) @@ -1917,5 +1919,52 @@ namespace CK.SCP.GrupUniApi.Controller } } } + + + + + /// + /// 转换 + /// + /// 集合 + /// + public static List GetTableToList(this DataTable dt) + { + var list = new List(); + var plist = new List(typeof(T).GetProperties()); + foreach (DataRow item in dt.Rows) + { + T s = Activator.CreateInstance(); + for (int i = 0; i < dt.Columns.Count; i++) + { + PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName); + if (info != null) + { + try + { + if (!Convert.IsDBNull(item[i])) + { + object v = null; + if (info.PropertyType.ToString().Contains("System.Nullable")) + { + v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType)); + } + else + { + v = Convert.ChangeType(item[i], info.PropertyType); + } + info.SetValue(s, v, null); + } + } + catch (Exception ex) + { + throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message); + } + } + } + list.Add(s); + } + return list; + } } }