纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
15 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using NFine.Domain._03_Entity.WMS;
  18. using System.IO;
  19. namespace NFine.Application.WMS
  20. {
  21. public class HomeWorkApp : RepositoryFactory<ICSVendor>
  22. {
  23. public string SetData_PR(String savePath, string Year)
  24. {
  25. //数据获取
  26. try
  27. {
  28. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  29. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  30. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  31. SqlConnection conn = SqlHelper.GetDataCenterConn();
  32. DataTable data = FileToExcel.ExcelToTable(savePath);
  33. int index = 1;
  34. int countLot = 1;
  35. string msg = "";
  36. string StorageCode = "";
  37. DateTime time = DateTime.Now;
  38. string Tday = time.ToString("yyyyMMdd");
  39. string sql = string.Empty;
  40. sql = string.Format(@"select InvCode FROM dbo.ICSInventory where WorkPoint ='{0}' ", WorkPoint);
  41. sql += string.Format(@"select LocationCode ,WarehouseCode FROM dbo.ICSLocation a
  42. inner join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where b.Enable='1' and a.WorkPoint ='{0}' ", WorkPoint);
  43. sql += string.Format(@"SELECT MAX(A.LotNO) AS LOTNO FROM ICSInventoryLot A WHERE A.LotNO LIKE '{0}%' and A.WorkPoint='{1}' AND LEN(a.LotNO) = 13", Tday, WorkPoint);
  44. sql += string.Format(@"SELECT top 0 ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,AmountRate,ExtensionID,Type,PrintTimes,LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSInventoryLot ");
  45. sql += string.Format(@"SELECT top 0 ID,LotNo,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSWareHouseLotInfo ");
  46. sql += string.Format(@"SELECT top 0 ID,Identification,TransCode,TransSequence,LotNo,InvCode,FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSWareHouseLotInfoLog ");
  47. sql += string.Format(@"SELECT ID,Colspan,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,MTIME,MUSER,MUSERName,WorkPoint,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5 FROM ICSExtension where WorkPoint='{0}' ", WorkPoint);
  48. sql += string.Format(@"SELECT top 0 LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSInventoryLotDetail");
  49. DataSet ds = SqlHelper.GetDataSetBySql(sql);
  50. DataSet dsSave = new DataSet();
  51. dsSave.Tables.Add(ds.Tables[3].Copy());
  52. dsSave.Tables.Add( ds.Tables[4].Copy());
  53. dsSave.Tables.Add( ds.Tables[5].Copy());
  54. dsSave.Tables.Add(ds.Tables[6].Clone());
  55. dsSave.Tables.Add(ds.Tables[7].Copy());
  56. dsSave.Tables[0].TableName="ICSInventoryLot";
  57. dsSave.Tables[1].TableName = "ICSWareHouseLotInfo";
  58. dsSave.Tables[2].TableName = "ICSWareHouseLotInfoLog";
  59. dsSave.Tables[3].TableName = "ICSExtension";
  60. dsSave.Tables[4].TableName = "ICSInventoryLotDetail";
  61. string LotNO = "";
  62. Int64 Lot_NO = 0;
  63. DataTable dts = ds.Tables[2];
  64. if (dts != null && dts.Rows.Count > 0)
  65. {
  66. string lot = dts.Rows[0]["LOTNO"].ToString();
  67. if(!string.IsNullOrWhiteSpace(lot))
  68. Lot_NO = Convert.ToInt64(lot.Substring(lot.Length - 5));
  69. }
  70. if (data != null && data.Rows.Count > 0)
  71. {
  72. foreach (DataRow dr in data.Rows)
  73. {
  74. index++;
  75. string ItemCode = dr["物料编码"].ToString();
  76. string StackCode = dr["库位"].ToString();
  77. string Date = dr["入库日期"].ToString();
  78. string VENCODE = dr["供应商"].ToString();
  79. string ProjectCode= dr["项目号"].ToString();
  80. string BatchCode = dr["批次"].ToString();
  81. string Version = dr["版本"].ToString();
  82. string Brand = dr["厂牌"].ToString();
  83. string cFree1 = dr["自由项1"].ToString();
  84. string cFree2 = dr["自由项2"].ToString();
  85. string cFree3 = dr["自由项3"].ToString();
  86. string cFree4 = dr["自由项4"].ToString();
  87. string cFree5 = dr["自由项5"].ToString();
  88. string cFree6 = dr["自由项6"].ToString();
  89. string cFree7 = dr["自由项7"].ToString();
  90. string cFree8 = dr["自由项8"].ToString();
  91. string cFree9 = dr["自由项9"].ToString();
  92. string cFree10 = dr["自由项10"].ToString();
  93. string Colspan = ProjectCode + BatchCode + Version + Brand + cFree1 + cFree2 + cFree3 + cFree4 + cFree5 + cFree6 + cFree7 + cFree8 + cFree9 + cFree10;
  94. DateTime dataTime;
  95. if (Date == "")
  96. {
  97. dataTime = DateTime.Now;
  98. }
  99. else
  100. {
  101. dataTime = Convert.ToDateTime(Date);
  102. }
  103. decimal QTY = 0;
  104. bool result = decimal.TryParse(dr["库位数量或最小包装数量"].ToString(), out QTY);
  105. if (!result)
  106. {
  107. throw new Exception("第 " + index + " 行,库位数量或最小包装数量:" + dr["库位数量或最小包装数量"].ToString() + " 格式不正确!");
  108. }
  109. if (decimal.Parse(dr["库位数量或最小包装数量"].ToString()) < 0)
  110. {
  111. throw new Exception("第 " + index + " 行,库位数量或最小包装数量:" + dr["库位数量或最小包装数量"].ToString() + " 数量不正确,为负值!");
  112. }
  113. int count = 0;
  114. bool resultCount = int.TryParse(dr["整盘数"].ToString(), out count);
  115. if (!resultCount)
  116. {
  117. throw new Exception("第 " + index + " 行,整盘数:" + dr["整盘数"].ToString() + " 格式不正确!");
  118. }
  119. var itemdrs = ds.Tables[0].Select(string.Format("InvCode='{0}'", ItemCode));
  120. if (itemdrs == null || itemdrs.Length <= 0)
  121. {
  122. throw new Exception("第 " + index + " 行,物料编码:" + ItemCode + " 不存在!");
  123. }
  124. var itemdrs2 = ds.Tables[1].Select(string.Format("LocationCode='{0}'", StackCode));
  125. if (itemdrs2 == null || itemdrs2.Length <= 0)
  126. {
  127. throw new Exception("第 " + index + " 行,库位:" + StackCode + " 不存在!");
  128. }
  129. else
  130. {
  131. StorageCode = itemdrs2[0]["WarehouseCode"].ToString();
  132. }
  133. var ID = "";
  134. var Extension = ds.Tables[6].Select(string.Format("Colspan='{0}'", Colspan));
  135. if (Extension == null || Extension.Length <= 0)
  136. {
  137. DataRow drExtension = dsSave.Tables[3].NewRow();
  138. ID = GetNewid();
  139. drExtension["ID"] = ID;
  140. drExtension["Colspan"] = Colspan;
  141. drExtension["ProjectCode"] = ProjectCode;
  142. drExtension["BatchCode"] = BatchCode;
  143. drExtension["Version"] = Version;
  144. drExtension["Brand"] = Brand;
  145. drExtension["cFree1"] = cFree1;
  146. drExtension["cFree2"] = cFree2;
  147. drExtension["cFree3"] = cFree3;
  148. drExtension["cFree4"] = cFree4;
  149. drExtension["cFree5"] = cFree5;
  150. drExtension["cFree6"] = cFree6;
  151. drExtension["cFree7"] = cFree7;
  152. drExtension["cFree8"] = cFree8;
  153. drExtension["cFree9"] = cFree9;
  154. drExtension["cFree10"] = cFree10;
  155. drExtension["MUSER"] = MUSER;
  156. drExtension["MUSERName"] = MUSERNAME;
  157. drExtension["MTIME"] = DateTime.Now;
  158. drExtension["WorkPoint"] = WorkPoint;
  159. dsSave.Tables[3].Rows.Add(drExtension);
  160. }
  161. else
  162. {
  163. ID = Extension[0]["ID"].ToString();
  164. }
  165. var Quantity= Convert.ToDecimal(dr["库位数量或最小包装数量"].ToString());
  166. var logID = GetNewid();
  167. for (int i = count; i > 0; i--)
  168. {
  169. LotNO = Tday + (Lot_NO + countLot++).ToString().PadLeft(5, '0');
  170. #region 条码
  171. DataRow drInventory = dsSave.Tables[0].NewRow();
  172. drInventory["ID"] = GetNewid();
  173. drInventory["LotNo"] = LotNO;
  174. drInventory["InvCode"] = ItemCode;
  175. drInventory["ProductDate"] = dataTime;
  176. drInventory["ExpirationDate"] = Convert.ToDateTime("2999-12-31");
  177. drInventory["Quantity"] = Quantity;
  178. drInventory["AmountRate"] = "1";
  179. drInventory["Type"] = "11";
  180. drInventory["ExtensionID"] = ID;
  181. drInventory["MUSER"] = MUSER;
  182. drInventory["MUSERName"] = MUSERNAME;
  183. drInventory["MTIME"] = DateTime.Now;
  184. drInventory["WorkPoint"] = WorkPoint;
  185. dsSave.Tables[0].Rows.Add(drInventory);
  186. #endregion
  187. #region 条码关联单据
  188. DataRow drInventoryLotDetail = dsSave.Tables[4].NewRow();
  189. drInventoryLotDetail["LotNo"] = LotNO;
  190. drInventoryLotDetail["TransCode"] = "";
  191. drInventoryLotDetail["TransSequence"] = "";
  192. drInventoryLotDetail["MUSER"] = MUSER;
  193. drInventoryLotDetail["MUSERName"] = MUSERNAME;
  194. drInventoryLotDetail["MTIME"] = DateTime.Now;
  195. drInventoryLotDetail["WorkPoint"] = WorkPoint;
  196. dsSave.Tables[4].Rows.Add(drInventoryLotDetail);
  197. #endregion
  198. #region 库存
  199. DataRow drHouseInfo = dsSave.Tables[1].NewRow();
  200. drHouseInfo["ID"] = GetNewid();
  201. drHouseInfo["LotNo"] = LotNO;
  202. drHouseInfo["WarehouseCode"] = StorageCode;
  203. drHouseInfo["LocationCode"] = StackCode;
  204. drHouseInfo["InvCode"] = ItemCode;
  205. drHouseInfo["Quantity"] = Quantity;
  206. drHouseInfo["InDate"] = dataTime;
  207. drHouseInfo["LockQuantity"] = 0;
  208. drHouseInfo["MUSER"] = MUSER;
  209. drHouseInfo["MUSERName"] = MUSERNAME;
  210. drHouseInfo["MTIME"] = DateTime.Now;
  211. drHouseInfo["WorkPoint"] = WorkPoint;
  212. dsSave.Tables[1].Rows.Add(drHouseInfo);
  213. #endregion
  214. #region 记录表
  215. DataRow drHouseLog = dsSave.Tables[2].NewRow();
  216. drHouseLog["ID"] = GetNewid();
  217. drHouseLog["Identification"] = logID;
  218. drHouseLog["LotNo"] = LotNO;
  219. drHouseLog["InvCode"] = ItemCode;
  220. drHouseLog["ToWarehouseCode"] = StorageCode;
  221. drHouseLog["ToLocationCode"] = StackCode;
  222. drHouseLog["Quantity"] = Quantity;
  223. drHouseLog["Lock"] = 0;
  224. drHouseLog["TransType"] = "1";
  225. drHouseLog["BusinessCode"] = "39";
  226. drHouseLog["ERPUpload"] = 0;
  227. drHouseLog["MUSER"] = MUSER;
  228. drHouseLog["MUSERName"] = MUSERNAME;
  229. drHouseLog["MTIME"] = DateTime.Now;
  230. drHouseLog["WorkPoint"] = WorkPoint;
  231. dsSave.Tables[2].Rows.Add(drHouseLog);
  232. #endregion
  233. }
  234. }
  235. SqlHelper.ExecuteDataSet(dsSave);
  236. }
  237. else
  238. {
  239. return "无有效的导入数据。";
  240. }
  241. return "true";
  242. }
  243. catch (Exception ex)
  244. {
  245. return ex.Message;
  246. }
  247. }
  248. public string GetNewid()
  249. {
  250. string sql = "select newid() AS ID";
  251. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  252. }
  253. }
  254. }