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.

809 lines
41 KiB

11 months 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. using System.Data.Common;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using Newtonsoft.Json.Linq;
  12. using Newtonsoft.Json;
  13. using NFine.Domain._03_Entity.WMS;
  14. namespace NFine.Application.WMS
  15. {
  16. public class HomeWorkApp : RepositoryFactory<ICSVendor>
  17. {
  18. public string SetData_PR(String savePath, string Year)
  19. {
  20. //数据获取
  21. try
  22. {
  23. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  24. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  25. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  26. SqlConnection conn = SqlHelper.GetDataCenterConn();
  27. DataTable data = FileToExcel.ExcelToTable(savePath);
  28. int index = 1;
  29. int countLot = 1;
  30. string msg = "";
  31. string StorageCode = "";
  32. DateTime time = DateTime.Now;
  33. string Tday = time.ToString("yyyyMMdd");
  34. string sql = string.Empty;
  35. sql = string.Format(@"select InvCode FROM dbo.ICSInventory where WorkPoint ='{0}' ", WorkPoint);
  36. sql += string.Format(@"select LocationCode ,WarehouseCode FROM dbo.ICSLocation a
  37. inner join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where b.Enable='1' and a.WorkPoint ='{0}' ", WorkPoint);
  38. 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);
  39. 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 ");
  40. sql += string.Format(@"SELECT top 0 ID,LotNo,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSWareHouseLotInfo ");
  41. 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 ");
  42. 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);
  43. sql += string.Format(@"SELECT top 0 LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSInventoryLotDetail");
  44. DataSet ds = SqlHelper.GetDataSetBySql(sql);
  45. DataSet dsSave = new DataSet();
  46. dsSave.Tables.Add(ds.Tables[3].Copy());
  47. dsSave.Tables.Add( ds.Tables[4].Copy());
  48. dsSave.Tables.Add( ds.Tables[5].Copy());
  49. dsSave.Tables.Add(ds.Tables[6].Clone());
  50. dsSave.Tables.Add(ds.Tables[7].Copy());
  51. dsSave.Tables[0].TableName="ICSInventoryLot";
  52. dsSave.Tables[1].TableName = "ICSWareHouseLotInfo";
  53. dsSave.Tables[2].TableName = "ICSWareHouseLotInfoLog";
  54. dsSave.Tables[3].TableName = "ICSExtension";
  55. dsSave.Tables[4].TableName = "ICSInventoryLotDetail";
  56. string LotNO = "";
  57. Int64 Lot_NO = 0;
  58. DataTable dts = ds.Tables[2];
  59. if (dts != null && dts.Rows.Count > 0)
  60. {
  61. string lot = dts.Rows[0]["LOTNO"].ToString();
  62. if(!string.IsNullOrWhiteSpace(lot))
  63. Lot_NO = Convert.ToInt64(lot.Substring(lot.Length - 5));
  64. }
  65. if (data != null && data.Rows.Count > 0)
  66. {
  67. foreach (DataRow dr in data.Rows)
  68. {
  69. index++;
  70. string OldLotNo = dr["条码"].ToString();
  71. string ItemCode = dr["物料编码"].ToString();
  72. string StackCode = dr["库位"].ToString();
  73. string Date = dr["入库日期"].ToString();
  74. string VENCODE = dr["供应商"].ToString();
  75. string ProductDate = dr["生产日期"].ToString();
  76. //decimal MinQty = Convert.ToDecimal(dr["最小包装数量"].ToString());
  77. decimal Amount = 0;
  78. if (data.Columns.Contains("辅计量数量"))
  79. {
  80. Amount = string.IsNullOrWhiteSpace(dr["辅计量数量"].ToString())?0:Convert.ToDecimal(dr["辅计量数量"].ToString());
  81. }
  82. string ProjectCode = string.Empty;
  83. string BatchCode = string.Empty;
  84. string Version = string.Empty;
  85. string Brand = string.Empty;
  86. string cFree1 = string.Empty;
  87. string cFree2 = string.Empty;
  88. string cFree3 = string.Empty;
  89. string cFree4 = string.Empty;
  90. string cFree5 = string.Empty;
  91. string cFree6 = string.Empty;
  92. string cFree7 = string.Empty;
  93. string cFree8 = string.Empty;
  94. string cFree9 = string.Empty;
  95. string cFree10 = string.Empty;
  96. if (data.Columns.Contains("项目号"))
  97. {
  98. ProjectCode = dr["项目号"].ToString();
  99. }
  100. if (data.Columns.Contains("批次"))
  101. {
  102. BatchCode= dr["批次"].ToString();
  103. }
  104. if (data.Columns.Contains("版本"))
  105. {
  106. Version = dr["版本"].ToString();
  107. }
  108. if (data.Columns.Contains("厂牌"))
  109. {
  110. Brand = dr["厂牌"].ToString();
  111. }
  112. if (data.Columns.Contains("自由项1"))
  113. {
  114. cFree1 = dr["自由项1"].ToString();
  115. }
  116. if (data.Columns.Contains("自由项2"))
  117. {
  118. cFree2 = dr["自由项2"].ToString();
  119. }
  120. if (data.Columns.Contains("自由项3"))
  121. {
  122. cFree3 = dr["自由项3"].ToString();
  123. }
  124. if (data.Columns.Contains("自由项4"))
  125. {
  126. cFree4 = dr["自由项4"].ToString();
  127. }
  128. if (data.Columns.Contains("自由项5"))
  129. {
  130. cFree5 = dr["自由项5"].ToString();
  131. }
  132. if (data.Columns.Contains("自由项6"))
  133. {
  134. cFree6 = dr["自由项6"].ToString();
  135. }
  136. if (data.Columns.Contains("自由项7"))
  137. {
  138. cFree7 = dr["自由项7"].ToString();
  139. }
  140. if (data.Columns.Contains("自由项8"))
  141. {
  142. cFree8 = dr["自由项8"].ToString();
  143. }
  144. if (data.Columns.Contains("自由项9"))
  145. {
  146. cFree9 = dr["自由项9"].ToString();
  147. }
  148. if (data.Columns.Contains("自由项10"))
  149. {
  150. cFree10 = dr["自由项10"].ToString();
  151. }
  152. string Colspan = ProjectCode + "~" + BatchCode + "~" + Version + "~" + Brand + "~" + cFree1 + "~" + cFree2 + "~" + cFree3 + "~" + cFree4 + "~" + cFree5 + "~" + cFree6 + "~" + cFree7 + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  153. DateTime dataTime;
  154. if (Date == "")
  155. {
  156. dataTime = DateTime.Now;
  157. }
  158. else
  159. {
  160. dataTime = Convert.ToDateTime(Date);
  161. }
  162. decimal QTY = 0;
  163. bool result = decimal.TryParse(dr["库位数量"].ToString(), out QTY);
  164. if (!result)
  165. {
  166. throw new Exception("第 " + index + " 行,库位数量:" + dr["库位数量"].ToString() + " 格式不正确!");
  167. }
  168. if (decimal.Parse(dr["库位数量"].ToString()) < 0)
  169. {
  170. throw new Exception("第 " + index + " 行,库位数量:" + dr["库位数量"].ToString() + " 数量不正确,为负值!");
  171. }
  172. if (string.IsNullOrWhiteSpace(dr["生产日期"].ToString()))
  173. {
  174. throw new Exception("第 " + index + " 行,生产日期不能为空!");
  175. }
  176. if (decimal.Parse(dr["最小包装数量"].ToString()) < 0)
  177. {
  178. throw new Exception("第 " + index + " 行,最小包装数量:" + dr["最小包装数量"].ToString() + " 数量不正确,为负值!");
  179. }
  180. int count = 0;
  181. string ZBCount = (Math.Ceiling(Convert.ToDecimal(dr["库位数量"].ToString()) / Convert.ToDecimal(dr["最小包装数量"].ToString()))).ToString();
  182. bool resultCount = int.TryParse(ZBCount, out count);
  183. if (!resultCount)
  184. {
  185. throw new Exception("第 " + index + " 行,整盘数:" + dr["整盘数"].ToString() + " 格式不正确!");
  186. }
  187. var itemdrs = ds.Tables[0].Select(string.Format("InvCode='{0}'", ItemCode));
  188. if (itemdrs == null || itemdrs.Length <= 0)
  189. {
  190. throw new Exception("第 " + index + " 行,物料编码:" + ItemCode + " 不存在!");
  191. }
  192. var itemdrs2 = ds.Tables[1].Select(string.Format("LocationCode='{0}'", StackCode));
  193. if (itemdrs2 == null || itemdrs2.Length <= 0)
  194. {
  195. throw new Exception("第 " + index + " 行,库位:" + StackCode + " 不存在!");
  196. }
  197. else
  198. {
  199. StorageCode = itemdrs2[0]["WarehouseCode"].ToString();
  200. }
  201. var ID = "";
  202. var Extension = ds.Tables[6].Select(string.Format("Colspan='{0}'", Colspan));
  203. if (Extension == null || Extension.Length <= 0)
  204. {
  205. DataRow drExtension = dsSave.Tables[3].NewRow();
  206. ID = GetNewid();
  207. drExtension["ID"] = ID;
  208. drExtension["Colspan"] = Colspan;
  209. drExtension["ProjectCode"] = ProjectCode;
  210. drExtension["BatchCode"] = BatchCode;
  211. drExtension["Version"] = Version;
  212. drExtension["Brand"] = Brand;
  213. drExtension["cFree1"] = cFree1;
  214. drExtension["cFree2"] = cFree2;
  215. drExtension["cFree3"] = cFree3;
  216. drExtension["cFree4"] = cFree4;
  217. drExtension["cFree5"] = cFree5;
  218. drExtension["cFree6"] = cFree6;
  219. drExtension["cFree7"] = cFree7;
  220. drExtension["cFree8"] = cFree8;
  221. drExtension["cFree9"] = cFree9;
  222. drExtension["cFree10"] = cFree10;
  223. drExtension["MUSER"] = MUSER;
  224. drExtension["MUSERName"] = MUSERNAME;
  225. drExtension["MTIME"] = DateTime.Now;
  226. drExtension["WorkPoint"] = WorkPoint;
  227. dsSave.Tables[3].Rows.Add(drExtension);
  228. DataRow drNew = ds.Tables[6].NewRow();
  229. drNew.ItemArray = drExtension.ItemArray;
  230. ds.Tables[6].Rows.Add(drNew);
  231. }
  232. else
  233. {
  234. ID = Extension[0]["ID"].ToString();
  235. }
  236. // var Quantity= Convert.ToDecimal(dr["库位数量"].ToString());
  237. var logID = GetNewid();
  238. for (int i = count; i > 0; i--)
  239. {
  240. var Quantity = Convert.ToDecimal(dr["最小包装数量"].ToString());
  241. if (OldLotNo != ""&& Quantity!= Convert.ToDecimal(dr["库位数量"].ToString()))
  242. {
  243. throw new Exception("第 " + index + " 行,条码:" + OldLotNo + " 所填写的最小包装量与库位数量不一致!");
  244. }
  245. if (OldLotNo!="")
  246. {
  247. LotNO = OldLotNo.ToUpper();
  248. }
  249. else
  250. {
  251. LotNO = Tday + (Lot_NO + countLot++).ToString().PadLeft(5, '0');
  252. }
  253. if (count == i)
  254. {
  255. Quantity= Convert.ToDecimal(dr["库位数量"].ToString())- (Convert.ToDecimal(dr["最小包装数量"].ToString())*(Convert.ToDecimal(count) - 1));
  256. }
  257. #region 条码
  258. DataRow drInventory = dsSave.Tables[0].NewRow();
  259. drInventory["ID"] = GetNewid();
  260. drInventory["LotNo"] = LotNO;
  261. drInventory["InvCode"] = ItemCode;
  262. drInventory["ProductDate"] = ProductDate;
  263. //drInventory["ProductDate"] = dataTime;
  264. drInventory["ExpirationDate"] = Convert.ToDateTime("2999-12-31");
  265. drInventory["Quantity"] = Quantity;
  266. drInventory["Amount"] = Amount;
  267. drInventory["Type"] = "0";
  268. drInventory["ExtensionID"] = ID;
  269. drInventory["MUSER"] = MUSER;
  270. drInventory["MUSERName"] = MUSERNAME;
  271. drInventory["MTIME"] = DateTime.Now;
  272. drInventory["WorkPoint"] = WorkPoint;
  273. dsSave.Tables[0].Rows.Add(drInventory);
  274. #endregion
  275. #region 条码关联单据
  276. DataRow drInventoryLotDetail = dsSave.Tables[4].NewRow();
  277. drInventoryLotDetail["LotNo"] = LotNO;
  278. drInventoryLotDetail["TransCode"] = "";
  279. drInventoryLotDetail["TransSequence"] = "";
  280. drInventoryLotDetail["MUSER"] = MUSER;
  281. drInventoryLotDetail["MUSERName"] = MUSERNAME;
  282. drInventoryLotDetail["MTIME"] = DateTime.Now;
  283. drInventoryLotDetail["WorkPoint"] = WorkPoint;
  284. dsSave.Tables[4].Rows.Add(drInventoryLotDetail);
  285. #endregion
  286. #region 库存
  287. DataRow drHouseInfo = dsSave.Tables[1].NewRow();
  288. drHouseInfo["ID"] = GetNewid();
  289. drHouseInfo["LotNo"] = LotNO;
  290. drHouseInfo["WarehouseCode"] = StorageCode;
  291. drHouseInfo["LocationCode"] = StackCode;
  292. drHouseInfo["InvCode"] = ItemCode;
  293. drHouseInfo["Quantity"] = Quantity;
  294. drHouseInfo["InDate"] = dataTime;
  295. drHouseInfo["LockQuantity"] = 0;
  296. drHouseInfo["MUSER"] = MUSER;
  297. drHouseInfo["MUSERName"] = MUSERNAME;
  298. drHouseInfo["MTIME"] = DateTime.Now;
  299. drHouseInfo["WorkPoint"] = WorkPoint;
  300. dsSave.Tables[1].Rows.Add(drHouseInfo);
  301. #endregion
  302. #region 记录表
  303. DataRow drHouseLog = dsSave.Tables[2].NewRow();
  304. drHouseLog["ID"] = GetNewid();
  305. drHouseLog["Identification"] = logID;
  306. drHouseLog["LotNo"] = LotNO;
  307. drHouseLog["InvCode"] = ItemCode;
  308. drHouseLog["ToWarehouseCode"] = StorageCode;
  309. drHouseLog["ToLocationCode"] = StackCode;
  310. drHouseLog["Quantity"] = Quantity;
  311. drHouseLog["Lock"] = 0;
  312. drHouseLog["TransType"] = "1";
  313. drHouseLog["BusinessCode"] = "39";
  314. drHouseLog["ERPUpload"] = 0;
  315. drHouseLog["MUSER"] = MUSER;
  316. drHouseLog["MUSERName"] = MUSERNAME;
  317. drHouseLog["MTIME"] = DateTime.Now;
  318. drHouseLog["WorkPoint"] = WorkPoint;
  319. dsSave.Tables[2].Rows.Add(drHouseLog);
  320. #endregion
  321. }
  322. }
  323. SqlHelper.ExecuteDataSet(dsSave);
  324. }
  325. else
  326. {
  327. return "无有效的导入数据。";
  328. }
  329. return "true";
  330. }
  331. catch (Exception ex)
  332. {
  333. return ex.Message;
  334. }
  335. }
  336. public string GetNewid()
  337. {
  338. string sql = "select newid() AS ID";
  339. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  340. }
  341. /// <summary>
  342. /// 获取仓库信息
  343. /// </summary>
  344. /// <param name="jqgridparam"></param>
  345. /// <param name="queryJson"></param>
  346. /// <returns></returns>
  347. public DataTable GetICSWarehouse(ref Pagination jqgridparam, string queryJson)
  348. {
  349. DataTable dt = new DataTable();
  350. var queryParam = queryJson.ToJObject();
  351. List<DbParameter> parameter = new List<DbParameter>();
  352. string sql = @" SELECT WarehouseCode,WarehouseName,WorkPoint FROM dbo.ICSWarehouse";
  353. sql += " WHERE 1=1 and WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location+"'";
  354. sql = string.Format(sql);
  355. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  356. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  357. }
  358. public DataTable ICSWarehouseExportAll(string keyvalue)
  359. {
  360. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  361. DataTable dt = new DataTable();
  362. string[] PrintParas = keyvalue.TrimEnd(',').Split(',');
  363. List<ICSWarehouse> list = new List<ICSWarehouse>();
  364. foreach (var p in PrintParas)
  365. {
  366. ICSWarehouse DetailList = new ICSWarehouse();
  367. DetailList.WHCode = p.ToString();
  368. DetailList.WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  369. list.Add(DetailList);
  370. }
  371. string json = JsonConvert.SerializeObject(list);
  372. string msg = "";
  373. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "CurrentStock/Get";
  374. string result = DeciliterApp.HttpPost(APIURL, json);
  375. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  376. string MessAge = Obj["Message"].ToString();
  377. string Success = Obj["Success"].ToString();
  378. if (Success.ToUpper() == "FALSE")
  379. {
  380. throw new Exception(MessAge);
  381. }
  382. string Data = Obj["Data"].ToString();
  383. if (string.IsNullOrWhiteSpace(Data))
  384. {
  385. throw new Exception("获取现存量失败!");
  386. }
  387. var dataSet = JsonConvert.DeserializeObject<DataSet>(Data);
  388. dt = dataSet.Tables[0];
  389. string sqls = @"SELECT ColCode,ColName,Enable
  390. from ICSExtensionEnable where WorkPoint='" + WorkPoint + "'";
  391. DataTable dtExtension = SqlHelper.GetDataTableBySql(sqls);
  392. foreach (DataRow drE in dtExtension.Rows)
  393. {
  394. if (dt.Columns.Contains(drE["ColCode"].ToString()))
  395. {
  396. if (!Convert.ToBoolean(drE["Enable"]))
  397. {
  398. dt.Columns.Remove(drE["ColCode"].ToString());
  399. }
  400. else if (Convert.ToBoolean(drE["Enable"]))
  401. {
  402. dt.Columns[drE["ColCode"].ToString()].ColumnName = drE["ColName"].ToString();
  403. }
  404. }
  405. }
  406. return dt;
  407. }
  408. public string DeleteInitialImport(string keyValue)
  409. {
  410. //站点信息
  411. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  412. string msg = "";
  413. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  414. string sql = string.Empty;
  415. sql += string.Format(@"DELETE FROM dbo.ICSInventoryLot WHERE LotNo IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  416. sql += string.Format(@"DELETE FROM dbo.ICSInventoryLotDetail WHERE LotNo IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  417. sql += string.Format(@"DELETE FROM dbo.ICSWareHouseLotInfo WHERE LotNo IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  418. sql += string.Format(@"update ICSWareHouseLotInfoLog set TransType='16' ,MTIME=getdate() where LotNo IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  419. try
  420. {
  421. SqlHelper.CmdExecuteNonQueryLi(sql);
  422. }
  423. catch (Exception ex)
  424. {
  425. throw new Exception(ex.Message);
  426. }
  427. return msg;
  428. }
  429. public string LotNoSetData_PR(String savePath, string Year)
  430. {
  431. //数据获取
  432. try
  433. {
  434. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  435. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  436. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  437. SqlConnection conn = SqlHelper.GetDataCenterConn();
  438. DataTable data = FileToExcel.ExcelToTable(savePath);
  439. int index = 1;
  440. int countLot = 1;
  441. string msg = "";
  442. string StorageCode = "";
  443. DateTime time = DateTime.Now;
  444. string Tday = time.ToString("yyyyMMdd");
  445. string sql = string.Empty;
  446. sql = string.Format(@"select InvCode FROM dbo.ICSInventory where WorkPoint ='{0}' ", WorkPoint);
  447. sql += string.Format(@"select LocationCode ,WarehouseCode FROM dbo.ICSLocation a
  448. inner join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where b.Enable='1' and a.WorkPoint ='{0}' ", WorkPoint);
  449. 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);
  450. 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 ");
  451. sql += string.Format(@"SELECT top 0 ID,LotNo,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSWareHouseLotInfo ");
  452. 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 ");
  453. 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);
  454. sql += string.Format(@"SELECT top 0 LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1 FROM ICSInventoryLotDetail");
  455. DataSet ds = SqlHelper.GetDataSetBySql(sql);
  456. DataSet dsSave = new DataSet();
  457. dsSave.Tables.Add(ds.Tables[3].Copy());
  458. dsSave.Tables.Add(ds.Tables[4].Copy());
  459. dsSave.Tables.Add(ds.Tables[5].Copy());
  460. dsSave.Tables.Add(ds.Tables[6].Clone());
  461. dsSave.Tables.Add(ds.Tables[7].Copy());
  462. dsSave.Tables[0].TableName = "ICSInventoryLot";
  463. dsSave.Tables[1].TableName = "ICSWareHouseLotInfo";
  464. dsSave.Tables[2].TableName = "ICSWareHouseLotInfoLog";
  465. dsSave.Tables[3].TableName = "ICSExtension";
  466. dsSave.Tables[4].TableName = "ICSInventoryLotDetail";
  467. // string LotNO = "";
  468. //string Lot_NO = "";
  469. DataTable dts = ds.Tables[2];
  470. //if (dts != null && dts.Rows.Count > 0)
  471. //{
  472. // string lot = dts.Rows[0]["LOTNO"].ToString();
  473. // if (!string.IsNullOrWhiteSpace(lot))
  474. // Lot_NO = Convert.ToInt64(lot.Substring(lot.Length - 5));
  475. //}
  476. if (data != null && data.Rows.Count > 0)
  477. {
  478. foreach (DataRow dr in data.Rows)
  479. {
  480. index++;
  481. string ItemCode = dr["物料编码"].ToString();
  482. string StackCode = dr["库位"].ToString();
  483. string Date = dr["入库日期"].ToString();
  484. string VENCODE = dr["供应商"].ToString();
  485. string LotNO = dr["条码"].ToString();
  486. decimal Amount = 0;
  487. if (data.Columns.Contains("辅计量数量"))
  488. {
  489. Amount = string.IsNullOrWhiteSpace(dr["辅计量数量"].ToString()) ? 0 : Convert.ToDecimal(dr["辅计量数量"].ToString());
  490. }
  491. string ProjectCode = string.Empty;
  492. string BatchCode = string.Empty;
  493. string Version = string.Empty;
  494. string Brand = string.Empty;
  495. string cFree1 = string.Empty;
  496. string cFree2 = string.Empty;
  497. string cFree3 = string.Empty;
  498. string cFree4 = string.Empty;
  499. string cFree5 = string.Empty;
  500. string cFree6 = string.Empty;
  501. string cFree7 = string.Empty;
  502. string cFree8 = string.Empty;
  503. string cFree9 = string.Empty;
  504. string cFree10 = string.Empty;
  505. if (data.Columns.Contains("项目号"))
  506. {
  507. ProjectCode = dr["项目号"].ToString();
  508. }
  509. if (data.Columns.Contains("批次"))
  510. {
  511. BatchCode = dr["批次"].ToString();
  512. }
  513. if (data.Columns.Contains("版本"))
  514. {
  515. Version = dr["版本"].ToString();
  516. }
  517. if (data.Columns.Contains("厂牌"))
  518. {
  519. Brand = dr["厂牌"].ToString();
  520. }
  521. if (data.Columns.Contains("自由项1"))
  522. {
  523. cFree1 = dr["自由项1"].ToString();
  524. }
  525. if (data.Columns.Contains("自由项2"))
  526. {
  527. cFree2 = dr["自由项2"].ToString();
  528. }
  529. if (data.Columns.Contains("自由项3"))
  530. {
  531. cFree3 = dr["自由项3"].ToString();
  532. }
  533. if (data.Columns.Contains("自由项4"))
  534. {
  535. cFree4 = dr["自由项4"].ToString();
  536. }
  537. if (data.Columns.Contains("自由项5"))
  538. {
  539. cFree5 = dr["自由项5"].ToString();
  540. }
  541. if (data.Columns.Contains("自由项6"))
  542. {
  543. cFree6 = dr["自由项6"].ToString();
  544. }
  545. if (data.Columns.Contains("自由项7"))
  546. {
  547. cFree7 = dr["自由项7"].ToString();
  548. }
  549. if (data.Columns.Contains("自由项8"))
  550. {
  551. cFree8 = dr["自由项8"].ToString();
  552. }
  553. if (data.Columns.Contains("自由项9"))
  554. {
  555. cFree9 = dr["自由项9"].ToString();
  556. }
  557. if (data.Columns.Contains("自由项10"))
  558. {
  559. cFree10 = dr["自由项10"].ToString();
  560. }
  561. string Colspan = ProjectCode + "~" + BatchCode + "~" + Version + "~" + Brand + "~" + cFree1 + "~" + cFree2 + "~" + cFree3 + "~" + cFree4 + "~" + cFree5 + "~" + cFree6 + "~" + cFree7 + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  562. DateTime dataTime;
  563. if (Date == "")
  564. {
  565. dataTime = DateTime.Now;
  566. }
  567. else
  568. {
  569. dataTime = Convert.ToDateTime(Date);
  570. }
  571. decimal QTY = 0;
  572. bool result = decimal.TryParse(dr["库位数量或最小包装数量"].ToString(), out QTY);
  573. if (!result)
  574. {
  575. throw new Exception("第 " + index + " 行,库位数量或最小包装数量:" + dr["库位数量或最小包装数量"].ToString() + " 格式不正确!");
  576. }
  577. if (decimal.Parse(dr["库位数量或最小包装数量"].ToString()) < 0)
  578. {
  579. throw new Exception("第 " + index + " 行,库位数量或最小包装数量:" + dr["库位数量或最小包装数量"].ToString() + " 数量不正确,为负值!");
  580. }
  581. int count = 0;
  582. bool resultCount = int.TryParse(dr["整盘数"].ToString(), out count);
  583. if (!resultCount)
  584. {
  585. throw new Exception("第 " + index + " 行,整盘数:" + dr["整盘数"].ToString() + " 格式不正确!");
  586. }
  587. var itemdrs = ds.Tables[0].Select(string.Format("InvCode='{0}'", ItemCode));
  588. if (itemdrs == null || itemdrs.Length <= 0)
  589. {
  590. throw new Exception("第 " + index + " 行,物料编码:" + ItemCode + " 不存在!");
  591. }
  592. var itemdrs2 = ds.Tables[1].Select(string.Format("LocationCode='{0}'", StackCode));
  593. if (itemdrs2 == null || itemdrs2.Length <= 0)
  594. {
  595. throw new Exception("第 " + index + " 行,库位:" + StackCode + " 不存在!");
  596. }
  597. else
  598. {
  599. StorageCode = itemdrs2[0]["WarehouseCode"].ToString();
  600. }
  601. var ID = "";
  602. var Extension = ds.Tables[6].Select(string.Format("Colspan='{0}'", Colspan));
  603. if (Extension == null || Extension.Length <= 0)
  604. {
  605. DataRow drExtension = dsSave.Tables[3].NewRow();
  606. ID = GetNewid();
  607. drExtension["ID"] = ID;
  608. drExtension["Colspan"] = Colspan;
  609. drExtension["ProjectCode"] = ProjectCode;
  610. drExtension["BatchCode"] = BatchCode;
  611. drExtension["Version"] = Version;
  612. drExtension["Brand"] = Brand;
  613. drExtension["cFree1"] = cFree1;
  614. drExtension["cFree2"] = cFree2;
  615. drExtension["cFree3"] = cFree3;
  616. drExtension["cFree4"] = cFree4;
  617. drExtension["cFree5"] = cFree5;
  618. drExtension["cFree6"] = cFree6;
  619. drExtension["cFree7"] = cFree7;
  620. drExtension["cFree8"] = cFree8;
  621. drExtension["cFree9"] = cFree9;
  622. drExtension["cFree10"] = cFree10;
  623. drExtension["MUSER"] = MUSER;
  624. drExtension["MUSERName"] = MUSERNAME;
  625. drExtension["MTIME"] = DateTime.Now;
  626. drExtension["WorkPoint"] = WorkPoint;
  627. dsSave.Tables[3].Rows.Add(drExtension);
  628. DataRow drNew = ds.Tables[6].NewRow();
  629. drNew.ItemArray = drExtension.ItemArray;
  630. ds.Tables[6].Rows.Add(drNew);
  631. }
  632. else
  633. {
  634. ID = Extension[0]["ID"].ToString();
  635. }
  636. var Quantity = Convert.ToDecimal(dr["库位数量或最小包装数量"].ToString());
  637. var logID = GetNewid();
  638. for (int i = count; i > 0; i--)
  639. {
  640. //LotNO = Lot_NO;
  641. #region 条码
  642. DataRow drInventory = dsSave.Tables[0].NewRow();
  643. drInventory["ID"] = GetNewid();
  644. drInventory["LotNo"] = LotNO;
  645. drInventory["InvCode"] = ItemCode;
  646. drInventory["ProductDate"] = dataTime;
  647. drInventory["ExpirationDate"] = Convert.ToDateTime("2999-12-31");
  648. drInventory["Quantity"] = Quantity;
  649. drInventory["Amount"] = Amount;
  650. drInventory["Type"] = "0";
  651. drInventory["ExtensionID"] = ID;
  652. drInventory["MUSER"] = MUSER;
  653. drInventory["MUSERName"] = MUSERNAME;
  654. drInventory["MTIME"] = DateTime.Now;
  655. drInventory["WorkPoint"] = WorkPoint;
  656. dsSave.Tables[0].Rows.Add(drInventory);
  657. #endregion
  658. #region 条码关联单据
  659. DataRow drInventoryLotDetail = dsSave.Tables[4].NewRow();
  660. drInventoryLotDetail["LotNo"] = LotNO;
  661. drInventoryLotDetail["TransCode"] = "";
  662. drInventoryLotDetail["TransSequence"] = "";
  663. drInventoryLotDetail["MUSER"] = MUSER;
  664. drInventoryLotDetail["MUSERName"] = MUSERNAME;
  665. drInventoryLotDetail["MTIME"] = DateTime.Now;
  666. drInventoryLotDetail["WorkPoint"] = WorkPoint;
  667. dsSave.Tables[4].Rows.Add(drInventoryLotDetail);
  668. #endregion
  669. #region 库存
  670. DataRow drHouseInfo = dsSave.Tables[1].NewRow();
  671. drHouseInfo["ID"] = GetNewid();
  672. drHouseInfo["LotNo"] = LotNO;
  673. drHouseInfo["WarehouseCode"] = StorageCode;
  674. drHouseInfo["LocationCode"] = StackCode;
  675. drHouseInfo["InvCode"] = ItemCode;
  676. drHouseInfo["Quantity"] = Quantity;
  677. drHouseInfo["InDate"] = dataTime;
  678. drHouseInfo["LockQuantity"] = 0;
  679. drHouseInfo["MUSER"] = MUSER;
  680. drHouseInfo["MUSERName"] = MUSERNAME;
  681. drHouseInfo["MTIME"] = DateTime.Now;
  682. drHouseInfo["WorkPoint"] = WorkPoint;
  683. dsSave.Tables[1].Rows.Add(drHouseInfo);
  684. #endregion
  685. #region 记录表
  686. DataRow drHouseLog = dsSave.Tables[2].NewRow();
  687. drHouseLog["ID"] = GetNewid();
  688. drHouseLog["Identification"] = logID;
  689. drHouseLog["LotNo"] = LotNO;
  690. drHouseLog["InvCode"] = ItemCode;
  691. drHouseLog["ToWarehouseCode"] = StorageCode;
  692. drHouseLog["ToLocationCode"] = StackCode;
  693. drHouseLog["Quantity"] = Quantity;
  694. drHouseLog["Lock"] = 0;
  695. drHouseLog["TransType"] = "1";
  696. drHouseLog["BusinessCode"] = "39";
  697. drHouseLog["ERPUpload"] = 0;
  698. drHouseLog["MUSER"] = MUSER;
  699. drHouseLog["MUSERName"] = MUSERNAME;
  700. drHouseLog["MTIME"] = DateTime.Now;
  701. drHouseLog["WorkPoint"] = WorkPoint;
  702. dsSave.Tables[2].Rows.Add(drHouseLog);
  703. #endregion
  704. }
  705. }
  706. SqlHelper.ExecuteDataSet(dsSave);
  707. }
  708. else
  709. {
  710. return "无有效的导入数据。";
  711. }
  712. return "true";
  713. }
  714. catch (Exception ex)
  715. {
  716. return ex.Message;
  717. }
  718. }
  719. }
  720. }