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.

548 lines
31 KiB

3 weeks ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using NFine.Code;
  6. using NFine.Repository;
  7. using System.Data.Common;
  8. using NFine.Domain._03_Entity.SRM;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Linq;
  11. namespace NFine.Application.WMS
  12. {
  13. public class ICSOperationApp : RepositoryFactory<ICSVendor>
  14. {
  15. /// 主表查询
  16. public DataTable SearchICSOperation(string queryJson, ref Pagination jqgridparam)
  17. {
  18. DataTable dt = new DataTable();
  19. var queryParam = queryJson.ToJObject();
  20. List<DbParameter> parameter = new List<DbParameter>();
  21. string sql = @" select a.ID ,a.OperationCode ,a.WHCode ,c.WarehouseName,
  22. case when a.Status ='1' then '' when a.Status ='2' then '' else '' end as Status
  23. ,a.Type ,b.Name ,a.Memo ,a.CreatePerson ,a.CreateDateTime ,a.MUSER ,a.MUSERName ,a.MTIME ,a.WorkPoint ,b.EATTRIBUTE1 as CRType,
  24. a.EATTRIBUTE1 ,a.EATTRIBUTE2 ,a.EATTRIBUTE3 ,a.EATTRIBUTE4 ,a.EATTRIBUTE5 ,a.EATTRIBUTE6 ,a.EATTRIBUTE7 ,a.EATTRIBUTE8 ,a.EATTRIBUTE9 ,a.EATTRIBUTE10
  25. from dbo.ICSOperation a
  26. left join ICSType b on a.Type=b.Code and b.TableCode='ICSOperation' and b.ColumnCode='Type' and a.WorkPoint=b.WorkPoint
  27. left join dbo.ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=b.WorkPoint";
  28. //sql = string.Format(sql);
  29. //DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  30. if (!string.IsNullOrWhiteSpace(queryJson))
  31. {
  32. if (!string.IsNullOrWhiteSpace(queryParam["Code"].ToString()))
  33. {
  34. sql += " and a.ApplyCode like '%" + queryParam["Code"].ToString() + "%' ";
  35. }
  36. if (!string.IsNullOrWhiteSpace(queryParam["UserCode"].ToString()))
  37. {
  38. sql += " and a.MUSER like '%" + queryParam["UserCode"].ToString() + "%' ";
  39. }
  40. //if (!string.IsNullOrWhiteSpace(queryParam["selShow"].ToString()))
  41. //{
  42. // string POStatus = queryParam["selShow"].ToString();
  43. // if (POStatus == "1")
  44. // {
  45. // sql += " and a.Status='1' ";
  46. // }
  47. // else if (POStatus == "2")
  48. // {
  49. // sql += " and a.Status='2' ";
  50. // }
  51. // else if (POStatus == "3")
  52. // {
  53. // sql += " and a.Status='3' ";
  54. // }
  55. // else
  56. // {
  57. // }
  58. //}
  59. }
  60. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  61. }
  62. //子表查询
  63. public DataTable SearchICSOperationDetail(string Code, ref Pagination jqgridparam)
  64. {
  65. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  66. DataTable dt = new DataTable();
  67. List<DbParameter> parameter = new List<DbParameter>();
  68. string sql = @" select a.ID ,a.OperationCode ,a.Sequence ,a.InvCode ,a.Quantity ,a.Amount , a.OperationQuantity ,a.ExtensionID ,a.MUSER ,a.MUSERName ,a.MTIME , a.WorkPoint ,
  69. a.EATTRIBUTE1 ,a.EATTRIBUTE2 , a.EATTRIBUTE3 , a.EATTRIBUTE4 ,a.EATTRIBUTE5 ,a.EATTRIBUTE6 , a.EATTRIBUTE7 ,a.EATTRIBUTE8 ,a.EATTRIBUTE9 , a.EATTRIBUTE10 ,
  70. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  71. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  72. from ICSOperationDetail a
  73. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  74. WHERE a.OperationCode='" + Code + "' ";
  75. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  76. }
  77. public DataTable GetIcsApplyDetail(string invcode, string Code, string Invstd, ref Pagination jqgridparam)
  78. {
  79. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  80. List<DbParameter> parameter = new List<DbParameter>();
  81. DataTable table = new DataTable();
  82. string wherestr = "";
  83. if (!string.IsNullOrEmpty(invcode))
  84. {
  85. wherestr += " and a.InvCode like '%" + invcode + "%'";
  86. }
  87. //if (!string.IsNullOrEmpty(Code))
  88. //{
  89. // wherestr += " and c.MOCode like '%" + Code + "%'";
  90. //}
  91. if (!string.IsNullOrEmpty(Invstd))
  92. {
  93. wherestr += " and b.InvStd like '%" + Invstd + "%'";
  94. }
  95. //if (!string.IsNullOrEmpty(EATTRIBUTE2))
  96. //{
  97. // wherestr += " and a.EATTRIBUTE2 like '%" + EATTRIBUTE2 + "%'";
  98. //}
  99. string sql = @"select a.ID, a.ApplyCode,a.Sequence,a.Quantity ,a.Amount, a.InvCode,b.InvName,b.InvDesc,b.InvUnit,b.InvStd ,
  100. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  101. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  102. from dbo.ICSApplyDetail a
  103. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  104. left join dbo.ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  105. where a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  106. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  107. }
  108. public DataTable GetICSOperationDetail(string OperationCode, ref Pagination jqgridparam)
  109. {
  110. List<DbParameter> parameter = new List<DbParameter>();
  111. string sql = @"SELECT
  112. a.ID,
  113. a.ID as ZID,
  114. a.OperationCode,
  115. a.SourceDetailID as SQID,
  116. a.InvCode,
  117. a.Quantity,
  118. a.Amount,
  119. b.InvName,
  120. b.InvStd,
  121. b.InvUnit,
  122. a.OperationQuantity,
  123. a.ExtensionID
  124. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  125. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  126. FROM
  127. ICSOperationDetail a
  128. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  129. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  130. where a.OperationCode='" + OperationCode + "'";
  131. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  132. //DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  133. //return table;
  134. }
  135. public string SaveICSOperation(string ICSASN)
  136. {
  137. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  138. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  139. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  140. string msg = "";
  141. string SeachCode;
  142. string sql = string.Empty;
  143. string Colspan = "";
  144. string str1 = "";
  145. List<string> ExtensionIDList = new List<string>();
  146. //获取单号
  147. SeachCode = @"DECLARE @MaxNO INT,@date varchar(20)='WK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  148. SELECT @MaxNO=SUBSTRING(MAX(OperationCode),LEN(@date)+1,LEN(MAX(OperationCode))-LEN(@date))+1 FROM ICSOperation
  149. WHERE SUBSTRING(OperationCode, 1, LEN(@date))=@date
  150. IF @MaxNO IS NULL
  151. BEGIN
  152. SELECT @date+'0001' AS Code
  153. END
  154. ELSE
  155. BEGIN
  156. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  157. END ";
  158. object Code = SqlHelper.ExecuteScalar(SeachCode);
  159. JArray res = (JArray)JsonConvert.DeserializeObject(ICSASN);
  160. foreach (var item in res)
  161. {
  162. JObject jo = (JObject)item;
  163. //创建主表
  164. sql += @"insert into ICSOperation( ID,OperationCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint)
  165. VALUES (NEWID(),'{0}','{1}','1','{2}','{3}','{4}',getdate(),'{4}','{5}',getdate(),'{6}')";
  166. sql = string.Format(sql, Code, jo["WHCode"].ToString(), jo["Type"].ToString(), jo["Memo"].ToString(), MUSER, MUSERNAME, WorkPoint);
  167. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["Detail"].ToString());
  168. foreach (var detail in resdetail)
  169. {
  170. JObject det = (JObject)detail;
  171. Colspan = det["ProjectCode"].ToString() + "~" + det["BatchCode"].ToString() + "~" + det["Version"].ToString() + "~" + det["Brand"].ToString() + "~" + det["cFree1"].ToString() + "~" + det["cFree2"].ToString() + "~" + det["cFree3"].ToString() + "~" + det["cFree4"].ToString() + "~" + det["cFree5"].ToString() + "~" + det["cFree6"].ToString() + "~" + det["cFree7"].ToString() + "~" + det["cFree8"].ToString() + "~" + det["cFree9"].ToString() + "~" + det["cFree10"].ToString();
  172. string sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  173. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  174. bool flag = true;
  175. foreach (var itemE in ExtensionIDList)
  176. {
  177. if (itemE == Colspan + WorkPoint)
  178. {
  179. flag = false;
  180. }
  181. }
  182. if (ExtensionID == null && flag == true)
  183. {
  184. str1 = Guid.NewGuid().ToString();
  185. sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  186. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  187. str1, Colspan, det["ProjectCode"].ToString(), det["BatchCode"].ToString(), det["Version"].ToString(), det["Brand"].ToString(), det["cFree1"].ToString(), det["cFree2"].ToString(), det["cFree3"].ToString(), det["cFree4"].ToString(), det["cFree5"].ToString(), det["cFree6"].ToString(), det["cFree7"].ToString(), det["cFree8"].ToString(), det["cFree9"].ToString(), det["cFree10"].ToString(),
  188. MUSER, MUSERNAME, WorkPoint);
  189. }
  190. else if (ExtensionID != null)
  191. {
  192. str1 = ExtensionID.ToString();
  193. }
  194. ExtensionIDList.Add(Colspan + WorkPoint);
  195. sql += @"insert into ICSOperationDetail( ID,OperationCode,Sequence,InvCode,Quantity,Amount,OperationQuantity,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint,SourceDetailID)
  196. VALUES (NEWID(),'{0}','{1}','{2}','{3}','{4}','0','{5}','{6}','{7}',getdate(),'{8}','{9}')";
  197. sql = string.Format(sql, Code, det["Sequence"].ToString(), det["InvCode"].ToString(), det["Quantity"].ToString(),
  198. det["Amount"].ToString(), str1, MUSER, MUSERNAME, WorkPoint, det["SQID"].ToString());
  199. }
  200. }
  201. try
  202. {
  203. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  204. {
  205. }
  206. else
  207. {
  208. msg = "新增失败";
  209. }
  210. }
  211. catch (Exception ex)
  212. {
  213. msg = ex.Message;
  214. }
  215. return msg;
  216. }
  217. public string UpdateICSOperation(string ICSASN)
  218. {
  219. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  220. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  221. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  222. string msg = "";
  223. string sql = string.Empty;
  224. string Colspan = "";
  225. string str1 = "";
  226. string idss = "";
  227. string Code = "";
  228. List<string> ExtensionIDList = new List<string>();
  229. JArray res = (JArray)JsonConvert.DeserializeObject(ICSASN);
  230. foreach (var item in res)
  231. {
  232. JObject jo = (JObject)item;
  233. //创建主表
  234. sql += @"update ICSOperation set WHCode='{0}' ,Memo='{1}' ,MUSER='{2}',MUSERName='{3}',MTIME=getdate() where OperationCode='{4}'";
  235. sql = string.Format(sql, jo["WHCode"].ToString(), jo["Memo"].ToString(), MUSER, MUSERNAME, jo["Code"].ToString());
  236. Code = jo["Code"].ToString();
  237. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["Detail"].ToString());
  238. foreach (var detail in resdetail)
  239. {
  240. JObject det = (JObject)detail;
  241. Colspan = det["ProjectCode"].ToString() + "~" + det["BatchCode"].ToString() + "~" + det["Version"].ToString() + "~" + det["Brand"].ToString() + "~" + det["cFree1"].ToString() + "~" + det["cFree2"].ToString() + "~" + det["cFree3"].ToString() + "~" + det["cFree4"].ToString() + "~" + det["cFree5"].ToString() + "~" + det["cFree6"].ToString() + "~" + det["cFree7"].ToString() + "~" + det["cFree8"].ToString() + "~" + det["cFree9"].ToString() + "~" + det["cFree10"].ToString();
  242. string sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  243. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  244. bool flag = true;
  245. foreach (var itemE in ExtensionIDList)
  246. {
  247. if (itemE == Colspan + WorkPoint)
  248. {
  249. flag = false;
  250. }
  251. }
  252. if (ExtensionID == null && flag == true)
  253. {
  254. str1 = Guid.NewGuid().ToString();
  255. sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  256. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  257. str1, Colspan, det["ProjectCode"].ToString(), det["BatchCode"].ToString(), det["Version"].ToString(), det["Brand"].ToString(), det["cFree1"].ToString(), det["cFree2"].ToString(), det["cFree3"].ToString(), det["cFree4"].ToString(), det["cFree5"].ToString(), det["cFree6"].ToString(), det["cFree7"].ToString(), det["cFree8"].ToString(), det["cFree9"].ToString(), det["cFree10"].ToString(),
  258. MUSER, MUSERNAME, WorkPoint);
  259. }
  260. else if (ExtensionID != null)
  261. {
  262. str1 = ExtensionID.ToString();
  263. }
  264. ExtensionIDList.Add(Colspan + WorkPoint);
  265. if (string.IsNullOrWhiteSpace(det["ZID"].ToString()))
  266. {
  267. string DetailID = Guid.NewGuid().ToString();
  268. sql += @"insert into ICSOperationDetail( ID,OperationCode,Sequence,InvCode,Quantity,Amount,OperationQuantity,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint,SourceDetailID)
  269. VALUES ('{9}','{0}','{1}','{2}','{3}','{4}','0','{5}','{6}','{7}',getdate(),'{8}','{9}')";
  270. sql = string.Format(sql, jo["Code"].ToString(), det["Sequence"].ToString(), det["InvCode"].ToString(), det["Quantity"].ToString(),
  271. det["Amount"].ToString(), str1, MUSER, MUSERNAME, WorkPoint, DetailID, det["SQID"].ToString());
  272. idss += "'" + DetailID + "',";
  273. }
  274. else
  275. {
  276. //子表修改
  277. sql += @"update ICSOperationDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',MUSER='{3}',MUSERName='{4}',MTIME=getdate() where ID='{5}' and WorkPoint='{6}'";
  278. sql = string.Format(sql, det["InvCode"].ToString(), det["Quantity"].ToString(), det["Amount"].ToString(), MUSER, MUSERNAME, det["ZID"].ToString(), WorkPoint);
  279. idss += "'" + det["ZID"].ToString() + "',";
  280. }
  281. }
  282. }
  283. sql += @"DELETE from ICSOperationDetail where OperationCode ='{0}' and id not in ({1})";
  284. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  285. try
  286. {
  287. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  288. {
  289. }
  290. else
  291. {
  292. msg = "修改失败";
  293. }
  294. }
  295. catch (Exception ex)
  296. {
  297. msg = ex.Message;
  298. }
  299. return msg;
  300. }
  301. public string AuditICSOperation(string keyValue)
  302. {
  303. //站点信息
  304. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  305. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  306. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  307. string msg = "";
  308. JArray res = (JArray)JsonConvert.DeserializeObject(keyValue);
  309. string sql = string.Empty;
  310. string ProductDate = DateTime.Now.ToString();
  311. string Identification = Guid.NewGuid().ToString();
  312. try
  313. {
  314. foreach (var item in res)
  315. {
  316. JObject jo = (JObject)item;
  317. string sqlSeachDetail = @" select * from ICSOperationDetail where OperationCode='" + jo["Code"].ToString() + "' ";
  318. DataTable dt = Repository().FindTableBySql(sqlSeachDetail);
  319. //判断是出还是入(1:入/2:出)
  320. if (jo["Type"].ToString()=="1")
  321. {
  322. string SqlForSys_SRM_ItemsDetail = @"select F_ItemCode from Sys_SRM_ItemsDetail where F_ItemId='14361ce1-c5e3-4e85-a253-51aa3cdde3e6' and F_EnabledMark='1'";
  323. object F_ItemCode = SqlHelper.ExecuteScalar(SqlForSys_SRM_ItemsDetail);
  324. string SqlForLocation = @"select top 1 a.LocationCode from dbo.ICSLocation a
  325. inner join dbo.ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
  326. where b.WarehouseCode='"+ jo["WHCode"].ToString() + "' and a.WorkPoint='"+ WorkPoint + "' order by a.LocationCode asc";
  327. object LocationCode = SqlHelper.ExecuteScalar(SqlForLocation);
  328. //查询作业单子行
  329. for (int i = 0; i < dt.Rows.Count; i++)
  330. {
  331. string Sequence = dt.Rows[i]["Sequence"].ToString();
  332. //批次维度(现条码维度)
  333. if (F_ItemCode.ToString() == "ControlMode01")
  334. {
  335. string Pre = jo["Code"].ToString() + (Convert.ToInt32(Sequence)).ToString("D3");
  336. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  337. //新增条码
  338. sql += @"insert into ICSInventoryLot
  339. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount,ExtensionID)
  340. select
  341. newid(),'{0}',a.InvCode,'{1}',
  342. case when b.EffectiveEnable='1' then cast('{1}' as datetime)+cast(b.EffectiveDays as datetime) else '2999-12-31 00:00:00.000' end ,
  343. a.Quantity,'20','{2}','{3}', getdate(),'{4}',a.Amount,a.ExtensionID
  344. from ICSOperationDetail a
  345. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  346. where a.OperationCode='{5}' and a.Sequence='{6}' and a.WorkPoint='{4}'";
  347. sql = string.Format(sql, LotNo, ProductDate, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  348. //新增条码关联
  349. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID)
  350. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}' )",
  351. LotNo, jo["Code"].ToString(), Sequence, MUSER, MUSERNAME, WorkPoint, dt.Rows[i]["ID"].ToString());
  352. //新增出入库记录
  353. sql += string.Format(@"INSERT into ICSWareHouseLotInfoLog
  354. (ID,Identification,TransID,TransCode,TransSequence,LotNo,InvCode,ToWarehouseCode,ToLocationCode,Quantity,Lock,TransType,BusinessCode,
  355. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  356. select newid(),'{0}',a.ID,a.OperationCode,a.Sequence, '{1}',a.InvCode,'{2}','{3}',a.Quantity,'0' ,'2','71','{4}','{5}',getdate(),'{6}',''
  357. from ICSOperationDetail a
  358. where a.OperationCode='{7}' and a.Sequence='{8}' and a.WorkPoint='{6}'",
  359. Identification, LotNo, jo["WHCode"].ToString(), LocationCode, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  360. //新增库存
  361. sql += string.Format(@"INSERT into ICSWareHouseLotInfo(ID,LotNo,WarehouseCode,LocationCode ,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint)
  362. select newid(),'{0}','{1}','{2}',a.InvCode,a.Quantity,'{3}','0','{4}','{5}',getdate(),'{6}'
  363. from ICSOperationDetail a
  364. where a.OperationCode='{7}' and a.Sequence='{8}' and a.WorkPoint='{6}'",
  365. LotNo, jo["WHCode"].ToString(), LocationCode, ProductDate, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  366. }
  367. //料品+仓库维度
  368. else
  369. {
  370. string LotNo = jo["WHCode"].ToString()+ dt.Rows[i]["InvCode"].ToString();
  371. string SqlForLot = @"select * from dbo.ICSInventoryLot where LotNo='"+ LotNo + "' and WorkPoint='"+WorkPoint+"'";
  372. DataTable Lotdt = Repository().FindTableBySql(SqlForLot);
  373. //条码存在直接变更库存
  374. if (Lotdt.Rows.Count>0)
  375. {
  376. //新增出入库记录
  377. sql += string.Format(@"INSERT into ICSWareHouseLotInfoLog
  378. (ID,Identification,TransID,TransCode,TransSequence,LotNo,InvCode,ToWarehouseCode,ToLocationCode,Quantity,Lock,TransType,BusinessCode,
  379. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  380. select newid(),'{0}',a.ID,a.OperationCode,a.Sequence, '{1}',a.InvCode,'{2}','{3}',a.Quantity,'0' ,'2','71','{4}','{5}',getdate(),'{6}',''
  381. from ICSOperationDetail a
  382. where a.OperationCode='{7}' and a.Sequence='{8}' and a.WorkPoint='{6}'",
  383. Identification, LotNo, jo["WHCode"].ToString(), LocationCode, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  384. //修改库存
  385. sql += string.Format(@"update dbo.ICSWareHouseLotInfo set Quantity=Quantity+'{0}' where LotNo='{1}' and WorkPoint='{2}'",
  386. dt.Rows[i]["Quantity"].ToString(), LotNo, WorkPoint);
  387. }
  388. else
  389. {
  390. //新增条码
  391. sql += @"insert into ICSInventoryLot
  392. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount,ExtensionID)
  393. select
  394. newid(),'{0}',a.InvCode,'{1}',
  395. case when b.EffectiveEnable='1' then cast('{1}' as datetime)+cast(b.EffectiveDays as datetime) else '2999-12-31 00:00:00.000' end ,
  396. a.Quantity,'20','{2}','{3}', getdate(),'{4}',a.Amount,a.ExtensionID
  397. from ICSOperationDetail a
  398. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  399. where a.OperationCode='{5}' and a.Sequence='{6}' and a.WorkPoint='{4}'";
  400. sql = string.Format(sql, LotNo, ProductDate, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  401. //新增条码关联
  402. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID)
  403. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}' )",
  404. LotNo, jo["Code"].ToString(), Sequence, MUSER, MUSERNAME, WorkPoint, dt.Rows[i]["ID"].ToString());
  405. //新增出入库记录
  406. sql += string.Format(@"INSERT into ICSWareHouseLotInfoLog
  407. (ID,Identification,TransID,TransCode,TransSequence,LotNo,InvCode,ToWarehouseCode,ToLocationCode,Quantity,Lock,TransType,BusinessCode,
  408. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  409. select newid(),'{0}',a.ID,a.OperationCode,a.Sequence, '{1}',a.InvCode,'{2}','{3}',a.Quantity,'0' ,'2','71','{4}','{5}',getdate(),'{6}',''
  410. from ICSOperationDetail a
  411. where a.OperationCode='{7}' and a.Sequence='{8}' and a.WorkPoint='{6}'",
  412. Identification, LotNo, jo["WHCode"].ToString(), LocationCode, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  413. //新增库存
  414. sql += string.Format(@"INSERT into ICSWareHouseLotInfo(ID,LotNo,WarehouseCode,LocationCode ,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint)
  415. select newid(),'{0}','{1}','{2}',a.InvCode,a.Quantity,'{3}','0','{4}','{5}',getdate(),'{6}'
  416. from ICSOperationDetail a
  417. where a.OperationCode='{7}' and a.Sequence='{8}' and a.WorkPoint='{6}'",
  418. LotNo, jo["WHCode"].ToString(), LocationCode, ProductDate, MUSER, MUSERNAME, WorkPoint, jo["Code"].ToString(), Sequence);
  419. }
  420. }
  421. }
  422. }
  423. //出
  424. else
  425. {
  426. decimal LotQTY = 0;
  427. string SeachCode = $"'\'\'{ jo["Code"].ToString()}\'\''";
  428. string sqlLot = @"EXEC ICSDistributionLot {0},'{1}'";
  429. sqlLot = string.Format(sqlLot, SeachCode, WorkPoint);
  430. var dataset = Repository().FindDataSetBySql(sqlLot);
  431. DataTable Lottable = dataset.Tables[0];
  432. DataRow[] dssLot = Lottable.Select("LotNO<>''");
  433. if (dssLot.Length == 0)
  434. {
  435. throw new Exception($"库存不足!");
  436. }
  437. foreach (var itemLot in dssLot)
  438. {
  439. //新增出入库记录
  440. sql += string.Format(@"INSERT into ICSWareHouseLotInfoLog
  441. (ID,Identification,TransID,TransCode,TransSequence,LotNo,InvCode,ToWarehouseCode,ToLocationCode,Quantity,Lock,TransType,BusinessCode,
  442. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  443. select newid(),'{0}',a.ID,a.OperationCode,a.Sequence, '{1}',a.InvCode,'{2}','{3}',a.Quantity,'0' ,'2','71','{4}','{5}',getdate(),'{6}',''
  444. from ICSOperationDetail a
  445. where a.OperationCode='{7}' and a.Sequence='{8}' and a.WorkPoint='{6}'",
  446. Identification, item["LotNO"].ToString(), item["WarehouseCode"].ToString(), item["LocationCode"].ToString() , MUSER, MUSERNAME, WorkPoint, item["Code"].ToString(), item["Sequence"].ToString() );
  447. //改库存
  448. sql+= string.Format(@"update dbo.ICSWareHouseLotInfo set Quantity=Quantity-'{0}' where LotNo='{1}' and WorkPoint='{2}'",
  449. item["QTY"].ToString(), item["LotNO"].ToString() ,WorkPoint);
  450. LotQTY= LotQTY + item["QTY"].ToDecimal();
  451. }
  452. string sqlForNum = @"select sum(Quantity) from ICSOperationDetail where OperationCode='"+ jo["Code"].ToString() + "' and WorkPoint='"+ WorkPoint + "'";
  453. object DocumentNum = SqlHelper.ExecuteScalar(sqlForNum);
  454. if (LotQTY!= DocumentNum.ToDecimal())
  455. {
  456. throw new Exception($"库存不足!");
  457. }
  458. }
  459. sql += @"update ICSOperationDetail set OperationQuantity=Quantity where OperationCode='" + jo["Code"].ToString() + "'";
  460. sql += @"update ICSOperation set Status='2' where OperationCode='" + jo["Code"].ToString() + "'";
  461. }
  462. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  463. {
  464. }
  465. }
  466. catch (Exception ex)
  467. {
  468. msg = ex.Message;
  469. }
  470. return msg;
  471. }
  472. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  473. {
  474. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  475. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  476. return SqlHelper.ExecuteScalar(sql).ToString();
  477. }
  478. }
  479. }