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

359 lines
18 KiB

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