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

356 lines
18 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
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. string originalCode = dr["原条码"].ToString();
  69. decimal Amount = 0;
  70. if (data.Columns.Contains("辅计量数量"))
  71. {
  72. Amount = string.IsNullOrWhiteSpace(dr["辅计量数量"].ToString())?0:Convert.ToDecimal(dr["辅计量数量"].ToString());
  73. }
  74. string ProjectCode = string.Empty;
  75. string BatchCode = string.Empty;
  76. string Version = string.Empty;
  77. string Brand = string.Empty;
  78. string cFree1 = string.Empty;
  79. string cFree2 = string.Empty;
  80. string cFree3 = string.Empty;
  81. string cFree4 = string.Empty;
  82. string cFree5 = string.Empty;
  83. string cFree6 = string.Empty;
  84. string cFree7 = string.Empty;
  85. string cFree8 = string.Empty;
  86. string cFree9 = string.Empty;
  87. string cFree10 = string.Empty;
  88. if (data.Columns.Contains("销售凭证"))
  89. {
  90. ProjectCode = dr["销售凭证"].ToString();
  91. }
  92. if (data.Columns.Contains("序列号"))
  93. {
  94. BatchCode= dr["序列号"].ToString();
  95. }
  96. if (data.Columns.Contains("版本"))
  97. {
  98. Version = dr["版本"].ToString();
  99. }
  100. if (data.Columns.Contains("销售凭证项号"))
  101. {
  102. Brand = dr["销售凭证项号"].ToString();
  103. }
  104. if (data.Columns.Contains("自由项1"))
  105. {
  106. cFree1 = dr["自由项1"].ToString();
  107. }
  108. if (data.Columns.Contains("自由项2"))
  109. {
  110. cFree2 = dr["自由项2"].ToString();
  111. }
  112. if (data.Columns.Contains("自由项3"))
  113. {
  114. cFree3 = dr["自由项3"].ToString();
  115. }
  116. if (data.Columns.Contains("自由项4"))
  117. {
  118. cFree4 = dr["自由项4"].ToString();
  119. }
  120. if (data.Columns.Contains("自由项5"))
  121. {
  122. cFree5 = dr["自由项5"].ToString();
  123. }
  124. if (data.Columns.Contains("自由项6"))
  125. {
  126. cFree6 = dr["自由项6"].ToString();
  127. }
  128. if (data.Columns.Contains("自由项7"))
  129. {
  130. cFree7 = dr["自由项7"].ToString();
  131. }
  132. if (data.Columns.Contains("自由项8"))
  133. {
  134. cFree8 = dr["自由项8"].ToString();
  135. }
  136. if (data.Columns.Contains("自由项9"))
  137. {
  138. cFree9 = dr["自由项9"].ToString();
  139. }
  140. if (data.Columns.Contains("自由项10"))
  141. {
  142. cFree10 = dr["自由项10"].ToString();
  143. }
  144. string Colspan = ProjectCode + "~" + BatchCode + "~" + Version + "~" + Brand + "~" + cFree1 + "~" + cFree2 + "~" + cFree3 + "~" + cFree4 + "~" + cFree5 + "~" + cFree6 + "~" + cFree7 + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  145. DateTime dataTime;
  146. if (Date == "")
  147. {
  148. dataTime = DateTime.Now;
  149. }
  150. else
  151. {
  152. dataTime = Convert.ToDateTime(Date);
  153. }
  154. decimal QTY = 0;
  155. bool result = decimal.TryParse(dr["库位数量或最小包装数量"].ToString(), out QTY);
  156. if (!result)
  157. {
  158. throw new Exception("第 " + index + " 行,库位数量或最小包装数量:" + dr["库位数量或最小包装数量"].ToString() + " 格式不正确!");
  159. }
  160. if (decimal.Parse(dr["库位数量或最小包装数量"].ToString()) < 0)
  161. {
  162. throw new Exception("第 " + index + " 行,库位数量或最小包装数量:" + dr["库位数量或最小包装数量"].ToString() + " 数量不正确,为负值!");
  163. }
  164. int count = 0;
  165. bool resultCount = int.TryParse(dr["整盘数"].ToString(), out count);
  166. if (!resultCount)
  167. {
  168. throw new Exception("第 " + index + " 行,整盘数:" + dr["整盘数"].ToString() + " 格式不正确!");
  169. }
  170. var itemdrs = ds.Tables[0].Select(string.Format("InvCode='{0}'", ItemCode));
  171. if (itemdrs == null || itemdrs.Length <= 0)
  172. {
  173. throw new Exception("第 " + index + " 行,物料编码:" + ItemCode + " 不存在!");
  174. }
  175. var itemdrs2 = ds.Tables[1].Select(string.Format("LocationCode='{0}'", StackCode));
  176. if (itemdrs2 == null || itemdrs2.Length <= 0)
  177. {
  178. throw new Exception("第 " + index + " 行,库位:" + StackCode + " 不存在!");
  179. }
  180. else
  181. {
  182. StorageCode = itemdrs2[0]["WarehouseCode"].ToString();
  183. }
  184. var ID = "";
  185. var Extension = ds.Tables[6].Select(string.Format("Colspan='{0}'", Colspan));
  186. if (Extension == null || Extension.Length <= 0)
  187. {
  188. DataRow drExtension = dsSave.Tables[3].NewRow();
  189. ID = GetNewid();
  190. drExtension["ID"] = ID;
  191. drExtension["Colspan"] = Colspan;
  192. drExtension["ProjectCode"] = ProjectCode;
  193. drExtension["BatchCode"] = BatchCode;
  194. drExtension["Version"] = Version;
  195. drExtension["Brand"] = Brand;
  196. drExtension["cFree1"] = cFree1;
  197. drExtension["cFree2"] = cFree2;
  198. drExtension["cFree3"] = cFree3;
  199. drExtension["cFree4"] = cFree4;
  200. drExtension["cFree5"] = cFree5;
  201. drExtension["cFree6"] = cFree6;
  202. drExtension["cFree7"] = cFree7;
  203. drExtension["cFree8"] = cFree8;
  204. drExtension["cFree9"] = cFree9;
  205. drExtension["cFree10"] = cFree10;
  206. drExtension["MUSER"] = MUSER;
  207. drExtension["MUSERName"] = MUSERNAME;
  208. drExtension["MTIME"] = DateTime.Now;
  209. drExtension["WorkPoint"] = WorkPoint;
  210. dsSave.Tables[3].Rows.Add(drExtension);
  211. DataRow drNew = ds.Tables[6].NewRow();
  212. drNew.ItemArray = drExtension.ItemArray;
  213. ds.Tables[6].Rows.Add(drNew);
  214. }
  215. else
  216. {
  217. ID = Extension[0]["ID"].ToString();
  218. }
  219. var Quantity= Convert.ToDecimal(dr["库位数量或最小包装数量"].ToString());
  220. var logID = GetNewid();
  221. for (int i = count; i > 0; i--)
  222. {
  223. if (originalCode != null&& originalCode!="")
  224. {
  225. LotNO = originalCode.ToString();
  226. }
  227. else
  228. {
  229. LotNO = Tday + (Lot_NO + countLot++).ToString().PadLeft(5, '0');
  230. }
  231. #region 条码
  232. DataRow drInventory = dsSave.Tables[0].NewRow();
  233. drInventory["ID"] = GetNewid();
  234. drInventory["LotNo"] = LotNO;
  235. drInventory["InvCode"] = ItemCode;
  236. drInventory["ProductDate"] = dataTime;
  237. drInventory["ExpirationDate"] = Convert.ToDateTime("2999-12-31");
  238. drInventory["Quantity"] = Quantity;
  239. drInventory["Amount"] = Amount;
  240. drInventory["Type"] = "0";
  241. drInventory["ExtensionID"] = ID;
  242. drInventory["MUSER"] = MUSER;
  243. drInventory["MUSERName"] = MUSERNAME;
  244. drInventory["MTIME"] = DateTime.Now;
  245. drInventory["WorkPoint"] = WorkPoint;
  246. dsSave.Tables[0].Rows.Add(drInventory);
  247. #endregion
  248. #region 条码关联单据
  249. DataRow drInventoryLotDetail = dsSave.Tables[4].NewRow();
  250. drInventoryLotDetail["LotNo"] = LotNO;
  251. drInventoryLotDetail["TransCode"] = "";
  252. drInventoryLotDetail["TransSequence"] = "";
  253. drInventoryLotDetail["MUSER"] = MUSER;
  254. drInventoryLotDetail["MUSERName"] = MUSERNAME;
  255. drInventoryLotDetail["MTIME"] = DateTime.Now;
  256. drInventoryLotDetail["WorkPoint"] = WorkPoint;
  257. dsSave.Tables[4].Rows.Add(drInventoryLotDetail);
  258. #endregion
  259. #region 库存
  260. DataRow drHouseInfo = dsSave.Tables[1].NewRow();
  261. drHouseInfo["ID"] = GetNewid();
  262. drHouseInfo["LotNo"] = LotNO;
  263. drHouseInfo["WarehouseCode"] = StorageCode;
  264. drHouseInfo["LocationCode"] = StackCode;
  265. drHouseInfo["InvCode"] = ItemCode;
  266. drHouseInfo["Quantity"] = Quantity;
  267. drHouseInfo["InDate"] = dataTime;
  268. drHouseInfo["LockQuantity"] = 0;
  269. drHouseInfo["MUSER"] = MUSER;
  270. drHouseInfo["MUSERName"] = MUSERNAME;
  271. drHouseInfo["MTIME"] = DateTime.Now;
  272. drHouseInfo["WorkPoint"] = WorkPoint;
  273. dsSave.Tables[1].Rows.Add(drHouseInfo);
  274. #endregion
  275. #region 记录表
  276. DataRow drHouseLog = dsSave.Tables[2].NewRow();
  277. drHouseLog["ID"] = GetNewid();
  278. drHouseLog["Identification"] = logID;
  279. drHouseLog["LotNo"] = LotNO;
  280. drHouseLog["InvCode"] = ItemCode;
  281. drHouseLog["ToWarehouseCode"] = StorageCode;
  282. drHouseLog["ToLocationCode"] = StackCode;
  283. drHouseLog["Quantity"] = Quantity;
  284. drHouseLog["Lock"] = 0;
  285. drHouseLog["TransType"] = "1";
  286. drHouseLog["BusinessCode"] = "39";
  287. drHouseLog["ERPUpload"] = 0;
  288. drHouseLog["MUSER"] = MUSER;
  289. drHouseLog["MUSERName"] = MUSERNAME;
  290. drHouseLog["MTIME"] = DateTime.Now;
  291. drHouseLog["WorkPoint"] = WorkPoint;
  292. dsSave.Tables[2].Rows.Add(drHouseLog);
  293. #endregion
  294. }
  295. }
  296. SqlHelper.ExecuteDataSet(dsSave);
  297. }
  298. else
  299. {
  300. return "无有效的导入数据。";
  301. }
  302. return "true";
  303. }
  304. catch (Exception ex)
  305. {
  306. return ex.Message;
  307. }
  308. }
  309. public string GetNewid()
  310. {
  311. string sql = "select newid() AS ID";
  312. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  313. }
  314. }
  315. }