纽威
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.

348 lines
17 KiB

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