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.

931 lines
50 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Text;
  6. using NFine.Code;
  7. using NFine.Repository;
  8. using System.Data.Common;
  9. using NFine.Domain._03_Entity.SRM;
  10. using Newtonsoft.Json;
  11. using System.Configuration;
  12. using System.Net;
  13. using System.IO;
  14. using Newtonsoft.Json.Linq;
  15. namespace NFine.Application.OMAY
  16. {
  17. public class ICSMoCreateLotApp : RepositoryFactory<ICSVendor>
  18. {
  19. //奥美工单生成条码主表查询
  20. public DataTable GetGridJsonChengPing(string queryJson, ref Pagination jqgridparam)
  21. {
  22. DataTable dt = new DataTable();
  23. var queryParam = queryJson.ToJObject();
  24. List<DbParameter> parameter = new List<DbParameter>();
  25. object Figure = GetDecimalDigits();
  26. #region [SQL]
  27. string sql = @" select distinct a.ID, a.MODetailID,a.MOCode,a.Sequence, CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity ,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,a.StartDate
  28. ,a.DueDate,a.MOStatus,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY ,CAST( a.Quantity AS DECIMAL(18,{0})) -CAST(a.RCVQuantity AS DECIMAL(18,{0})) as ERPNum,a.MOMemo
  29. ,case when a.EATTRIBUTE1='1' then 1 else 0 end MoTypeValue
  30. ,case when a.EATTRIBUTE1='1' then '' else '' end MoType
  31. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  32. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  33. a.EATTRIBUTE9,a.EATTRIBUTE10
  34. from ICSMO a
  35. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  36. left join (
  37. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  38. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='3'
  39. where isnull(ee.EATTRIBUTE1,'')=''
  40. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  41. )c
  42. on a.MOCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  43. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint ";
  44. sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  45. sql = string.Format(sql, Figure);
  46. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  47. #endregion
  48. if (!string.IsNullOrWhiteSpace(queryJson))
  49. {
  50. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  51. {
  52. sql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  53. }
  54. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  55. {
  56. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  57. }
  58. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  59. {
  60. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  61. }
  62. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  63. {
  64. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  65. }
  66. if (!string.IsNullOrWhiteSpace(queryParam["SelGDLX"].ToString()))
  67. {
  68. sql += " and a.MOType like '%" + queryParam["SelGDLX"].ToString() + "%' ";
  69. }
  70. if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
  71. {
  72. string POStatus = queryParam["POStatus"].ToString();
  73. if (POStatus == "0")
  74. {
  75. //sql += " and a.Quantity=ISNULL(c.LotQty,0)";
  76. }
  77. else if (POStatus == "1")
  78. {
  79. sql += " and ISNULL(c.LOTQTY,0)>=a.Quantity";
  80. }
  81. else
  82. {
  83. sql += " and ISNULL(c.LOTQTY,0)<a.Quantity";
  84. }
  85. }
  86. }
  87. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  88. {
  89. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  90. }
  91. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  92. {
  93. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  94. }
  95. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  96. }
  97. //生成条码子表查询
  98. public DataTable GetSubGridJson(string ApplyNegCode, string Sequence, string Type, ref Pagination jqgridparam)
  99. {
  100. DataTable dt = new DataTable();
  101. object Figure = GetDecimalDigits();
  102. List<DbParameter> parameter = new List<DbParameter>();
  103. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  104. string sql = @" select c.TransCode,c.TransSequence ,a.ID,a.LotNo, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity ,a.MUSERName,a.MTIME
  105. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  106. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,
  107. case when isnull(d.ID,'')='' then '' else '' end as isStorage,
  108. case when g.InvIQC='1'and isnull(e.ID,'')='' then '' else '' end as isInspection,
  109. case when g.InvIQC='1' then '是' else '否' end as isExemption,a.Amount,
  110. convert(varchar(20),a.ProductDate,23) as ProductDate,convert(varchar(20),a.ExpirationDate,23) as ExpirationDate ,g.EffectiveDays
  111. from ICSInventoryLot a
  112. left join (select count(LotNo) LotNoCount,LotNo,WorkPoint from ICSWareHouseLotInfo
  113. group by LotNo,WorkPoint)b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  114. left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  115. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  116. left join dbo.ICSWareHouseLotInfo d on a.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint
  117. left join ICSInspection e on a.LotNo=e.LotNo and e.Enable='1' and a.WorkPoint=e.WorkPoint
  118. left join ICSInventory g on a.InvCode=g.InvCode and a.WorkPoint=g.WorkPoint
  119. WHERE isnull(a.EATTRIBUTE1,'')='' and a.Type='" + Type + "' and c.TransCode='" + ApplyNegCode + "' and c.TransSequence='" + Sequence + "' and a.WorkPoint in ('" + WorkPoint + "')";
  120. sql = string.Format(sql, Figure);
  121. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  122. }
  123. //获取小数点数位
  124. public object GetDecimalDigits()
  125. {
  126. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  127. try
  128. {
  129. string sql = string.Empty;
  130. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  131. object Figure = SqlHelper.ExecuteScalar(sql);
  132. return Figure;
  133. }
  134. catch (Exception ex)
  135. {
  136. throw new Exception(ex.Message.ToString());
  137. }
  138. }
  139. //工单生成条码获取物料数量信息
  140. public DataTable GetSubGridJsonChengPingByCreate(string MOCode, string Sequence, string WorkPoint, string MoTypeValue)
  141. {
  142. DataTable dt = new DataTable();
  143. object Figure = GetDecimalDigits();
  144. List<DbParameter> parameter = new List<DbParameter>();
  145. string sql = string.Empty;
  146. if (MoTypeValue=="0")
  147. {
  148. sql = @"select
  149. d.Enable, a.InvCode,b.ClassCode,b.InvName,b.InvStd,b.InvUnit,a.Quantity as Quantity,
  150. cast( isnull(h.BL,0)*a.Quantity AS DECIMAL(18,4)) as AbsolveQty,
  151. cast( isnull(h.BL,0)*a.Amount AS DECIMAL(18,4)) as AbsolveAmount,
  152. cast( isnull(c.LOTQTY,0) as DECIMAL(18,4)) as CreatedQty,
  153. CAST( ((isnull(h.BL,0)*a.Quantity) -(isnull(c.LOTQTY,0))) as DECIMAL(18,4)) as thisCreateQty,
  154. cast( a.Amount as DECIMAL(18,4)) as Amount,
  155. isnull(b.EffectiveEnable,0) as EffectiveEnable,
  156. cast( isnull(b.EffectiveDays,0) as DECIMAL(18,4)) as EffectiveDays
  157. ,e.ProjectCode,e.BatchCode,e.Version,e.Brand,e.cFree1,e.cFree2,e.cFree3,e.cFree4,e.cFree5,e.cFree6,e.cFree7,e.cFree8,e.cFree9,e.cFree10
  158. from ICSMO a
  159. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  160. left join (
  161. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  162. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='3'
  163. where isnull(a.EATTRIBUTE1,'')=''
  164. group by b.TransCode,b.TransSequence
  165. ) c on a.MOCode=c.TransCode and a.Sequence=c.TransSequence
  166. left join (
  167. select b.TransCode,PARSENAME(REPLACE(b.TransSequence, '~', '.'), 2) as TransSequence ,sum(isnull(Quantity,0)) FCPQTY from ICSInventoryLot a
  168. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='18'
  169. where isnull(a.EATTRIBUTE1,'')=''
  170. group by b.TransCode,PARSENAME(REPLACE(b.TransSequence, '~', '.'), 2)
  171. ) f on a.MOCode=f.TransCode and a.Sequence=f.TransSequence
  172. left join
  173. (
  174. select case when Flag>0 then ( case when PSLNUM>MLNUM then MLNUM else PSLNUM end) else PSLNUM end as BL ,MODetailID from (
  175. select a.MODetailID,
  176. case when isnull(sum(a.PSLYL),0)=0 then 0 else sum(a.PSLLSS)/sum(a.PSLYL)* max(isnull(F_Define1,0)/100.0) end as PSLNUM,
  177. case when isnull(sum(a.MLYL),0)=0 then 0 else sum(a.MLLSS)/sum(a.MLYL)*max(isnull(F_Define1,0)/100.0) end as MLNUM,
  178. sum(Flag) as Flag
  179. from (
  180. select a.MODetailID ,
  181. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.Quantity else 0 end PSLYL,
  182. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.IssueQuantity else 0 end PSLLSS,
  183. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.Quantity else 0 end MLYL,
  184. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.IssueQuantity else 0 end MLLSS,
  185. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then 1 else 0 end Flag
  186. from dbo.ICSMOPick a
  187. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  188. where a.EATTRIBUTE1<>'1')a
  189. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  190. group by MODetailID )a) h on a.MODetailID=h.MODetailID
  191. left join ICSConfiguration d on d.Code='CompleteVerification001' and a.WorkPoint =d.WorkPoint
  192. left join ICSExtension e on a.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  193. WHERE 1 =1 and a.MOStatus<>'3' ";
  194. }
  195. else
  196. {
  197. sql = @"select
  198. d.Enable, a.InvCode,b.ClassCode,b.InvName,b.InvStd,b.InvUnit,a.Quantity as Quantity,
  199. cast( isnull(h.BL,0)*a.Quantity AS DECIMAL(18,4)) as AbsolveQty,
  200. cast( isnull(h.BL,0)*a.Amount AS DECIMAL(18,4)) as AbsolveAmount,
  201. cast( isnull(c.LOTQTY,0) as DECIMAL(18,4)) as CreatedQty,
  202. CAST( ((isnull(h.BL,0)*a.Quantity) -(isnull(c.LOTQTY,0))) as DECIMAL(18,4)) as thisCreateQty,
  203. cast( a.Amount as DECIMAL(18,4)) as Amount,
  204. isnull(b.EffectiveEnable,0) as EffectiveEnable,
  205. cast( isnull(b.EffectiveDays,0) as DECIMAL(18,4)) as EffectiveDays
  206. ,e.ProjectCode,e.BatchCode,e.Version,e.Brand,e.cFree1,e.cFree2,e.cFree3,e.cFree4,e.cFree5,e.cFree6,e.cFree7,e.cFree8,e.cFree9,e.cFree10
  207. from ICSMO a
  208. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  209. left join (
  210. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  211. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='3'
  212. where isnull(a.EATTRIBUTE1,'')=''
  213. group by b.TransCode,b.TransSequence
  214. ) c on a.MOCode=c.TransCode and a.Sequence=c.TransSequence
  215. left join (
  216. select b.TransCode,PARSENAME(REPLACE(b.TransSequence, '~', '.'), 2) as TransSequence ,sum(isnull(Quantity,0)) FCPQTY from ICSInventoryLot a
  217. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='18'
  218. where isnull(a.EATTRIBUTE1,'')=''
  219. group by b.TransCode,PARSENAME(REPLACE(b.TransSequence, '~', '.'), 2)
  220. ) f on a.MOCode=f.TransCode and a.Sequence=f.TransSequence
  221. left join
  222. (
  223. select MinBL as BL ,MODetailID from (
  224. select a.MODetailID,
  225. min(ALLBL)*max(isnull(F_Define1,0)/100.0) as MinBL
  226. from (
  227. select a.MODetailID ,
  228. case when a.Quantity =0 then 0 when a.IssueQuantity=0 then 0 else a.IssueQuantity/a.Quantity end as ALLBL
  229. from dbo.ICSMOPick a
  230. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  231. where a.EATTRIBUTE1<>'1' and a.IssueQuantity>0 )a
  232. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  233. group by MODetailID )a) h on a.MODetailID=h.MODetailID
  234. left join ICSConfiguration d on d.Code='CompleteVerification001' and a.WorkPoint =d.WorkPoint
  235. left join ICSExtension e on a.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  236. WHERE 1 =1 and a.MOStatus<>'3' and a.EATTRIBUTE1='1' ";
  237. }
  238. sql += " and a.MOCode = '" + MOCode + "' and a.Sequence = '" + Sequence + "' and a.WorkPoint='" + WorkPoint + "'";
  239. sql = string.Format(sql, Figure);
  240. return Repository().FindTableBySql(sql.ToString());
  241. }
  242. //查询超生比例
  243. public DataTable GetScale()
  244. {
  245. DataTable dt = new DataTable();
  246. List<DbParameter> parameter = new List<DbParameter>();
  247. string sql = @" SELECT Top 1 a.F_Define1 as Prorate
  248. FROM [dbo].[Sys_SRM_ItemsDetail] a
  249. LEFT JOIN [dbo].[Sys_SRM_Items] b ON a.F_ItemId=b.F_Id AND b.F_EnabledMark='1'
  250. WHERE b.F_EnCode='CS0001' ORDER BY a.F_ItemCode";
  251. return Repository().FindTableBySql(sql.ToString());
  252. }
  253. //调用接口来显示本次可生产数量
  254. public object GetAbsolveQty(string MOCode, string Sequence,string Qty)
  255. {
  256. decimal AvailQty = 0;
  257. decimal AllQty = 0;
  258. string msg = "";
  259. string sql = @"select
  260. a.WorkPoint as WorkPoint,
  261. a.MODetailID as DetailID,
  262. '' as Type,
  263. cast( isnull(c.LOTQTY,0) as DECIMAL(18,4)) as InQty,
  264. " + Qty + @" as Qty,
  265. flag.F_Define1 as Prorate
  266. from ICSMO a
  267. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  268. left join (
  269. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  270. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='3'
  271. where isnull(a.EATTRIBUTE1,'')=''
  272. group by b.TransCode,b.TransSequence
  273. ) c on a.MOCode=c.TransCode and a.Sequence=c.TransSequence
  274. left join (
  275. select b.TransCode,PARSENAME(REPLACE(b.TransSequence, '~', '.'), 2) as TransSequence ,sum(isnull(Quantity,0)) FCPQTY from ICSInventoryLot a
  276. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='18'
  277. where isnull(a.EATTRIBUTE1,'')=''
  278. group by b.TransCode,PARSENAME(REPLACE(b.TransSequence, '~', '.'), 2)
  279. ) f on a.MOCode=f.TransCode and a.Sequence=f.TransSequence
  280. left join ICSConfiguration d on d.Code='CompleteVerification001' and a.WorkPoint =d.WorkPoint
  281. left join ICSExtension e on a.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  282. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  283. WHERE 1 =1 and a.MOStatus<>'3'
  284. and a.MOCode='" + MOCode + "' and a.Sequence='" + Sequence + "'";
  285. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  286. string Inputstr = JsonConvert.SerializeObject(dt);
  287. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "Completeamnew/Approve";
  288. string result = HttpPost(APIURL, Inputstr);
  289. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  290. string MessAge = Obj["Message"].ToString();
  291. string Success = Obj["Success"].ToString();
  292. if (Success.ToUpper() == "FALSE")
  293. {
  294. msg = MessAge;
  295. }
  296. else
  297. {
  298. if (msg == "")
  299. {
  300. JObject dataObj = JObject.Parse(Obj["Data"].ToString());
  301. AvailQty = decimal.Parse(dataObj["AvailQty"].ToString());
  302. AllQty = decimal.Parse(dataObj["AllQty"].ToString());
  303. //JArray res = (JArray)JsonConvert.DeserializeObject(Obj["Data"].ToString());
  304. //foreach (var item in res)
  305. //{
  306. // JObject jo = (JObject)item;
  307. // //var aa= jo["min_lotqty"].ToString();
  308. // Num = Convert.ToDecimal(jo["AllQty"].ToString());
  309. //}
  310. }
  311. }
  312. var Header = new
  313. {
  314. msg = msg,
  315. AvailQty = AvailQty,
  316. AllQty= AllQty,
  317. };
  318. return Header;
  319. }
  320. //接口api解析
  321. public static string HttpPost(string url, string body)
  322. {
  323. try
  324. {
  325. Encoding encoding = Encoding.UTF8;
  326. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  327. request.Method = "POST";
  328. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  329. request.ContentType = "application/json; charset=utf-8";
  330. byte[] buffer = encoding.GetBytes(body);
  331. request.ContentLength = buffer.Length;
  332. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  333. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  334. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  335. {
  336. return reader.ReadToEnd();
  337. }
  338. }
  339. catch (WebException ex)
  340. {
  341. throw new Exception(ex.Message);
  342. }
  343. }
  344. //工单生成条码
  345. public int SubmitFormChengPing(string MOCode, string Sequence, string keyValue, string WorkPoint,string AMEnable)
  346. {
  347. var queryParam = keyValue.ToJObject();
  348. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  349. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  350. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  351. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  352. decimal LOTQTY = minPackQty;
  353. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  354. //string VenCode = GetVendorCode(ApplyNegCode, Sequence, WorkPoint);
  355. string Pre = "CP" + MOCode + (Convert.ToInt32(Sequence)).ToString("D4");
  356. string sql = string.Empty;
  357. //string VendorLot = queryParam["VendorLot"].ToString();
  358. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  359. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  360. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  361. string InvCode = queryParam["ClassCode"].ToString();
  362. string sqls = string.Empty;
  363. string Colspan = "";
  364. string str1 = "";
  365. string LotNo=string.Empty;
  366. List<string> ExtensionIDList = new List<string>();
  367. for (int i = 0; i < createPageCount; i++)
  368. {
  369. if (i + 1 == createPageCount)
  370. {
  371. if (minPackQty * createPageCount > thisCreateQty)
  372. {
  373. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  374. }
  375. }
  376. Colspan = queryParam["ProjectCode"].ToString() + "~" + queryParam["BatchCode"].ToString() + "~" + queryParam["Version"].ToString() + "~" + queryParam["Brand"].ToString() + "~" + queryParam["cFree1"].ToString() + "~" + queryParam["cFree2"].ToString() + "~" + queryParam["cFree3"].ToString() + "~" + queryParam["cFree4"].ToString() + "~" + queryParam["cFree5"].ToString() + "~" + queryParam["cFree6"].ToString() + "~" + queryParam["cFree7"].ToString() + "~" + queryParam["cFree8"].ToString() + "~" + queryParam["cFree9"].ToString() + "~" + queryParam["cFree10"].ToString();
  377. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  378. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  379. bool flag = true;
  380. foreach (var item in ExtensionIDList)
  381. {
  382. if (item == Colspan + WorkPoint)
  383. {
  384. flag = false;
  385. }
  386. }
  387. if (ExtensionID == null && flag == true)
  388. {
  389. str1 = Guid.NewGuid().ToString();
  390. 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)
  391. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  392. str1, Colspan, queryParam["ProjectCode"].ToString(), queryParam["BatchCode"].ToString(), queryParam["Version"].ToString(), queryParam["Brand"].ToString(), queryParam["cFree1"].ToString(), queryParam["cFree2"].ToString(), queryParam["cFree3"].ToString(), queryParam["cFree4"].ToString(), queryParam["cFree5"].ToString(), queryParam["cFree6"].ToString(), queryParam["cFree7"].ToString(), queryParam["cFree8"].ToString(), queryParam["cFree9"].ToString(), queryParam["cFree10"].ToString(),
  393. MUSER, MUSERNAME, WorkPoints);
  394. }
  395. else if (ExtensionID != null)
  396. {
  397. str1 = ExtensionID.ToString();
  398. }
  399. ExtensionIDList.Add(Colspan + WorkPoint);
  400. //传过来的参数判断是否是奥美的项目奥美项目执行独有生成条码规则
  401. if (AMEnable == "true")
  402. {
  403. LotNo = SqlHelper.GetLOTNumber(InvCode, WorkPoint);
  404. }
  405. else
  406. {
  407. LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  408. }
  409. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  410. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  411. LotNo, MOCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  412. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  413. //{
  414. sql += string.Format(@"insert into ICSInventoryLot
  415. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount
  416. ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  417. select
  418. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','3','{3}','{4}', getdate(),'{5}','{9}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'
  419. from ICSMO where MOCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  420. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, MOCode, Sequence, str1, Convert.ToDecimal(queryParam["Amount"].ToString()) / minPackQty * LOTQTY, queryParam["ExpirationDate"].ToString()
  421. , queryParam["EATTRIBUTE1"].ToString(), queryParam["EATTRIBUTE2"].ToString(), queryParam["EATTRIBUTE3"].ToString(), queryParam["EATTRIBUTE4"].ToString(), queryParam["EATTRIBUTE5"].ToString(),
  422. queryParam["EATTRIBUTE6"].ToString(), queryParam["EATTRIBUTE7"].ToString(), queryParam["EATTRIBUTE8"].ToString(), queryParam["EATTRIBUTE9"].ToString(), queryParam["EATTRIBUTE10"].ToString());
  423. sql += "\r\n";
  424. //}
  425. }
  426. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  427. return count;
  428. }
  429. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  430. {
  431. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  432. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  433. //return Repository().FindTableBySql(sql.ToString());
  434. return SqlHelper.ExecuteScalar(sql).ToString();
  435. //return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
  436. }
  437. //副产品
  438. public DataTable GetGridJsonFCP(string queryJson, ref Pagination jqgridparam)
  439. {
  440. DataTable dt = new DataTable();
  441. var queryParam = queryJson.ToJObject();
  442. List<DbParameter> parameter = new List<DbParameter>();
  443. object Figure = GetDecimalDigits();
  444. #region [SQL]
  445. string sql = @"select a.ID,d.MOCode,d.Sequence+'~'+ a.Sequence as Sequence,a.PickID,a.InvCode as ZInvCode,d.InvCode as MInvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
  446. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,a.MODetailID,
  447. CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.IssueQuantity AS DECIMAL(18,{0})) as IssueQuantity ,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  448. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  449. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  450. a.EATTRIBUTE9,a.EATTRIBUTE10
  451. from ICSMOPick a
  452. inner join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint and d.MOStatus<>'3'
  453. inner join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  454. left join (
  455. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  456. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='18'
  457. where isnull(ee.EATTRIBUTE1,'')=''
  458. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  459. )c
  460. on d.MOCode=c.TransCode and d.Sequence+'~'+a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  461. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  462. where a.EATTRIBUTE1='1' and SUBSTRING(b.ClassCode, 1, 2) not IN ('05') ";
  463. sql = string.Format(sql, Figure);
  464. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  465. #endregion
  466. if (!string.IsNullOrWhiteSpace(queryJson))
  467. {
  468. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  469. {
  470. sql += " and d.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  471. }
  472. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  473. {
  474. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  475. }
  476. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  477. {
  478. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  479. }
  480. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  481. {
  482. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  483. }
  484. if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
  485. {
  486. string POStatus = queryParam["POStatus"].ToString();
  487. if (POStatus == "0")
  488. {
  489. //sql += " and a.Quantity=ISNULL(c.LotQty,0)";
  490. }
  491. else if (POStatus == "1")
  492. {
  493. sql += " and ISNULL(c.LOTQTY,0)>=a.Quantity";
  494. }
  495. else
  496. {
  497. sql += " and ISNULL(c.LOTQTY,0)<a.Quantity";
  498. }
  499. }
  500. }
  501. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  502. {
  503. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  504. }
  505. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  506. {
  507. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  508. }
  509. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  510. }
  511. //副产品生成条码获取物料数量信息
  512. public DataTable GetSubGridJsonFCPCreate(string FCPMOCode, string Sequence, string WorkPoint)
  513. {
  514. DataTable dt = new DataTable();
  515. object Figure = GetDecimalDigits();
  516. List<DbParameter> parameter = new List<DbParameter>();
  517. string sql = @"
  518. select
  519. a.InvCode,b.InvName,b.ClassCode,b.InvStd,b.InvUnit, a.Quantity as Quantity,
  520. cast( isnull(h.BL,0)*a.Quantity AS DECIMAL(18,4)) as AbsolveQty,
  521. cast( isnull(h.BL,0)*a.Amount AS DECIMAL(18,4)) as AbsolveAmount,
  522. cast( isnull(c.LOTQTY,0)+isnull(f.GDQTY,0) as DECIMAL(18,4)) as CreatedQty,
  523. CAST( ((isnull(h.BL,0)*a.Amount) -(isnull(c.LOTQTY,0)+isnull(f.GDQTY,0))) as DECIMAL(18,4)) as thisCreateQty,
  524. cast( a.Amount as DECIMAL(18,4)) as Amount,
  525. isnull(b.EffectiveEnable,0) as EffectiveEnable,
  526. cast( isnull(b.EffectiveDays,0) as DECIMAL(18,4)) as EffectiveDays
  527. ,e.ProjectCode,e.BatchCode,e.Version,e.Brand,e.cFree1,e.cFree2,e.cFree3,e.cFree4,e.cFree5,e.cFree6,e.cFree7,e.cFree8,e.cFree9,e.cFree10
  528. from ICSMOPick a
  529. left join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint and d.MOStatus<>'3'
  530. --
  531. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  532. left join (
  533. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  534. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='18'
  535. where isnull(a.EATTRIBUTE1,'')=''
  536. group by b.TransCode,b.TransSequence
  537. ) c on d.MOCode=c.TransCode and d.Sequence+'~'+a.Sequence=c.TransSequence
  538. --
  539. left join (
  540. select b.TransCode,b.TransSequence ,sum(isnull(Quantity,0)) GDQTY from ICSInventoryLot a
  541. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='3'
  542. where isnull(a.EATTRIBUTE1,'')=''
  543. group by b.TransCode,b.TransSequence
  544. ) f on d.MOCode=f.TransCode and d.Sequence=f.TransSequence
  545. left join
  546. (select case when Flag>0 then ( case when PSLNUM>MLNUM then MLNUM else PSLNUM end) else PSLNUM end as BL ,MODetailID from (
  547. select a.MODetailID,
  548. case when isnull(sum(a.PSLYL),0)=0 then 0 else sum(a.PSLLSS)/sum(a.PSLYL)* max(isnull(F_Define1,0)/100.0) end as PSLNUM,
  549. case when isnull(sum(a.MLYL),0)=0 then 0 else sum(a.MLLSS)/sum(a.MLYL)*max(isnull(F_Define1,0)/100.0) end as MLNUM,
  550. sum(Flag) as Flag
  551. from (
  552. select a.MODetailID ,
  553. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.Quantity else 0 end PSLYL,
  554. case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.IssueQuantity else 0 end PSLLSS,
  555. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.Quantity else 0 end MLYL,
  556. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.IssueQuantity else 0 end MLLSS,
  557. case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then 1 else 0 end Flag
  558. from dbo.ICSMOPick a
  559. inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  560. where a.EATTRIBUTE1 <> '1')a
  561. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  562. group by MODetailID )a) h on a.MODetailID=h.MODetailID
  563. left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  564. WHERE 1=1
  565. and d.MOCode='" + FCPMOCode + "' and d.Sequence+'~'+a.Sequence='" + Sequence + "'";
  566. sql += " and a.WorkPoint='" + WorkPoint + "'";
  567. sql = string.Format(sql, Figure);
  568. return Repository().FindTableBySql(sql.ToString());
  569. }
  570. //副产品调用接口获取可生成数量
  571. public object GetFCPAbsolveQty(string MOCode, string Sequence, string Qty)
  572. {
  573. decimal AvailQty = 0;
  574. decimal AllQty = 0;
  575. string msg = "";
  576. string sql = @"
  577. select
  578. a.WorkPoint as WorkPoint,
  579. a.MODetailID as DetailID,
  580. '' as Type,
  581. cast( isnull(c.LOTQTY,0) as DECIMAL(18,4)) as InQty,
  582. " + Qty + @" as Qty,
  583. flag.F_Define1 as Prorate
  584. from ICSMOPick a
  585. left join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint and d.MOStatus<>'3'
  586. --
  587. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  588. left join (
  589. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  590. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='18'
  591. where isnull(a.EATTRIBUTE1,'')=''
  592. group by b.TransCode,b.TransSequence
  593. ) c on d.MOCode=c.TransCode and d.Sequence+'~'+a.Sequence=c.TransSequence
  594. --
  595. left join (
  596. select b.TransCode,b.TransSequence ,sum(isnull(Quantity,0)) GDQTY from ICSInventoryLot a
  597. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='3'
  598. where isnull(a.EATTRIBUTE1,'')=''
  599. group by b.TransCode,b.TransSequence
  600. ) f on d.MOCode=f.TransCode and d.Sequence=f.TransSequence
  601. left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  602. left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
  603. WHERE 1=1
  604. and d.MOCode='" + MOCode + "' and d.Sequence+'~'+a.Sequence='" + Sequence + "'";
  605. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  606. string Inputstr = JsonConvert.SerializeObject(dt);
  607. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "Completeamnew05/Approve";
  608. string result = HttpPost(APIURL, Inputstr);
  609. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  610. string MessAge = Obj["Message"].ToString();
  611. string Success = Obj["Success"].ToString();
  612. if (Success.ToUpper() == "FALSE")
  613. {
  614. msg = MessAge;
  615. }
  616. else
  617. {
  618. if (msg == "")
  619. {
  620. JObject dataObj = JObject.Parse(Obj["Data"].ToString());
  621. AvailQty = decimal.Parse(dataObj["AvailQty"].ToString());
  622. AllQty = decimal.Parse(dataObj["AllQty"].ToString());
  623. }
  624. }
  625. var Header = new
  626. {
  627. msg = msg,
  628. AvailQty = AvailQty,
  629. AllQty = AllQty,
  630. };
  631. return Header;
  632. }
  633. //联副产品
  634. public int SubmitFormFCP(string FCPMOCode, string Sequence, string keyValue, string WorkPoint,string AMEnable)
  635. {
  636. var queryParam = keyValue.ToJObject();
  637. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  638. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  639. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  640. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  641. decimal LOTQTY = minPackQty;
  642. string Sequences = Sequence.Replace("~", "");
  643. string Pre = "FCP" + FCPMOCode + (Convert.ToInt32(Sequences)).ToString("D4");
  644. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  645. string sql = string.Empty;
  646. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  647. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  648. string InvCode = queryParam["ClassCode"].ToString();
  649. string sqls = string.Empty;
  650. string Colspan = "";
  651. string str1 = "";
  652. string LotNo = string.Empty;
  653. List<string> ExtensionIDList = new List<string>();
  654. for (int i = 0; i < createPageCount; i++)
  655. {
  656. if (i + 1 == createPageCount)
  657. {
  658. if (minPackQty * createPageCount > thisCreateQty)
  659. {
  660. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  661. }
  662. }
  663. Colspan = queryParam["ProjectCode"].ToString() + "~" + queryParam["BatchCode"].ToString() + "~" + queryParam["Version"].ToString() + "~" + queryParam["Brand"].ToString() + "~" + queryParam["cFree1"].ToString() + "~" + queryParam["cFree2"].ToString() + "~" + queryParam["cFree3"].ToString() + "~" + queryParam["cFree4"].ToString() + "~" + queryParam["cFree5"].ToString() + "~" + queryParam["cFree6"].ToString() + "~" + queryParam["cFree7"].ToString() + "~" + queryParam["cFree8"].ToString() + "~" + queryParam["cFree9"].ToString() + "~" + queryParam["cFree10"].ToString();
  664. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  665. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  666. bool flag = true;
  667. foreach (var item in ExtensionIDList)
  668. {
  669. if (item == Colspan + WorkPoint)
  670. {
  671. flag = false;
  672. }
  673. }
  674. if (ExtensionID == null && flag == true)
  675. {
  676. str1 = Guid.NewGuid().ToString();
  677. 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)
  678. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  679. str1, Colspan, queryParam["ProjectCode"].ToString(), queryParam["BatchCode"].ToString(), queryParam["Version"].ToString(), queryParam["Brand"].ToString(), queryParam["cFree1"].ToString(), queryParam["cFree2"].ToString(), queryParam["cFree3"].ToString(), queryParam["cFree4"].ToString(), queryParam["cFree5"].ToString(), queryParam["cFree6"].ToString(), queryParam["cFree7"].ToString(), queryParam["cFree8"].ToString(), queryParam["cFree9"].ToString(), queryParam["cFree10"].ToString(),
  680. MUSER, MUSERNAME, WorkPoints);
  681. }
  682. else if (ExtensionID != null)
  683. {
  684. str1 = ExtensionID.ToString();
  685. }
  686. ExtensionIDList.Add(Colspan + WorkPoint);
  687. //传过来的参数判断是否是奥美的项目奥美项目执行独有生成条码规则
  688. if (AMEnable == "true")
  689. {
  690. LotNo = SqlHelper.GetLOTNumber(InvCode, WorkPoint);
  691. }
  692. else
  693. {
  694. LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  695. }
  696. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  697. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  698. LotNo, FCPMOCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  699. sql += string.Format(@"insert into ICSInventoryLot
  700. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  701. select
  702. newid(),'{0}',a.InvCode,'{1}','{10}','{2}','{8}','18','{3}','{4}', getdate(),'{5}','{9}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'
  703. from ICSMOPick a left join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint and d.MOStatus<>'3' where d.MOCode='{6}' and d.Sequence+'~'+a.Sequence='{7}' and a.WorkPoint='{5}' ",
  704. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, FCPMOCode, Sequence, str1, Convert.ToDecimal(queryParam["Amount"].ToString()) / minPackQty * LOTQTY, queryParam["ExpirationDate"].ToString()
  705. , queryParam["EATTRIBUTE1"].ToString(), queryParam["EATTRIBUTE2"].ToString(), queryParam["EATTRIBUTE3"].ToString(), queryParam["EATTRIBUTE4"].ToString(), queryParam["EATTRIBUTE5"].ToString(),
  706. queryParam["EATTRIBUTE6"].ToString(), queryParam["EATTRIBUTE7"].ToString(), queryParam["EATTRIBUTE8"].ToString(), queryParam["EATTRIBUTE9"].ToString(), queryParam["EATTRIBUTE10"].ToString());
  707. sql += "\r\n";
  708. }
  709. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  710. return count;
  711. }
  712. public DataTable GetByproductGridJson(string queryJson, ref Pagination jqgridparam)
  713. {
  714. DataTable dt = new DataTable();
  715. var queryParam = queryJson.ToJObject();
  716. List<DbParameter> parameter = new List<DbParameter>();
  717. #region [SQL]
  718. string sql = @" select a.ID,a.LotNo,a.InvCode,c.InvName,c.InvStd,a.Quantity,a.MUSERName,b.MTIME as WMTIME,a.MTIME
  719. from dbo.ICSInventoryLot a
  720. left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  721. inner join dbo.ICSInventory c on a.InvCode=c.InvCode
  722. where a.Type='19'";
  723. // sql += " WHERE 1=1";
  724. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  725. #endregion
  726. if (!string.IsNullOrWhiteSpace(queryJson))
  727. {
  728. if (!string.IsNullOrWhiteSpace(queryParam["MTDOCCode"].ToString()))
  729. {
  730. sql += " and a.MTDOCCode like '%" + queryParam["MTDOCCode"].ToString() + "%' ";
  731. }
  732. }
  733. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  734. {
  735. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  736. }
  737. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  738. //{
  739. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  740. //}
  741. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  742. }
  743. public DataTable GetInvCode()
  744. {
  745. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  746. string sql = @"
  747. select '' as Code,'' as InvCode
  748. union all
  749. SELECT InvCode as Code ,InvCode as InvCode FROM dbo.ICSInventory WITH (NOLOCK) WHERE 1=1 and SUBSTRING(ClassCode, 1, 2) IN ('05') ";
  750. sql += " and WorkPoint='" + WorkPoint + "'";
  751. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  752. return dt;
  753. }
  754. public DataTable SeachAmountEnablebyInvCode(string InvCode)
  755. {
  756. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  757. DataTable dt = new DataTable();
  758. List<DbParameter> parameter = new List<DbParameter>();
  759. string sql = @"
  760. select isnull(AmountEnable,0) as AmountEnable ,ClassCode,isnull(EATTRIBUTE1,'') as EATTRIBUTE1 from dbo.ICSInventory where InvCode='" + InvCode + "' and WorkPoint='" + WorkPoint + "'";
  761. return Repository().FindTableBySql(sql.ToString());
  762. }
  763. public int SubmitFormFCPNoCode (string keyValue, string WorkPoint, string AMEnable)
  764. {
  765. var queryParam = keyValue.ToJObject();
  766. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  767. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  768. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  769. string InvCode = queryParam["InvCode"].ToString();
  770. decimal LOTQTY = minPackQty;
  771. //string Sequences = Sequence.Replace("~", "");
  772. //string Pre = "FCP" + FCPMOCode + (Convert.ToInt32(Sequences)).ToString("D4");
  773. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  774. string sql = string.Empty;
  775. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  776. // string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  777. string ClassCode = queryParam["ClassCode"].ToString();
  778. string sqls = string.Empty;
  779. string Colspan = "";
  780. string str1 = "";
  781. string LotNo = string.Empty;
  782. List<string> ExtensionIDList = new List<string>();
  783. for (int i = 0; i < createPageCount; i++)
  784. {
  785. //if (i + 1 == createPageCount)
  786. //{
  787. // if (minPackQty * createPageCount > thisCreateQty)
  788. // {
  789. // LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  790. // }
  791. //}
  792. Colspan = queryParam["ProjectCode"].ToString() + "~" + queryParam["BatchCode"].ToString() + "~" + queryParam["Version"].ToString() + "~" + queryParam["Brand"].ToString() + "~" + queryParam["cFree1"].ToString() + "~" + queryParam["cFree2"].ToString() + "~" + queryParam["cFree3"].ToString() + "~" + queryParam["cFree4"].ToString() + "~" + queryParam["cFree5"].ToString() + "~" + queryParam["cFree6"].ToString() + "~" + queryParam["cFree7"].ToString() + "~" + queryParam["cFree8"].ToString() + "~" + queryParam["cFree9"].ToString() + "~" + queryParam["cFree10"].ToString();
  793. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  794. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  795. bool flag = true;
  796. foreach (var item in ExtensionIDList)
  797. {
  798. if (item == Colspan + WorkPoint)
  799. {
  800. flag = false;
  801. }
  802. }
  803. if (ExtensionID == null && flag == true)
  804. {
  805. str1 = Guid.NewGuid().ToString();
  806. 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)
  807. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  808. str1, Colspan, queryParam["ProjectCode"].ToString(), queryParam["BatchCode"].ToString(), queryParam["Version"].ToString(), queryParam["Brand"].ToString(), queryParam["cFree1"].ToString(), queryParam["cFree2"].ToString(), queryParam["cFree3"].ToString(), queryParam["cFree4"].ToString(), queryParam["cFree5"].ToString(), queryParam["cFree6"].ToString(), queryParam["cFree7"].ToString(), queryParam["cFree8"].ToString(), queryParam["cFree9"].ToString(), queryParam["cFree10"].ToString(),
  809. MUSER, MUSERNAME, WorkPoints);
  810. }
  811. else if (ExtensionID != null)
  812. {
  813. str1 = ExtensionID.ToString();
  814. }
  815. ExtensionIDList.Add(Colspan + WorkPoint);
  816. //传过来的参数判断是否是奥美的项目奥美项目执行独有生成条码规则
  817. if (AMEnable == "true")
  818. {
  819. LotNo = SqlHelper.GetLOTNumber(ClassCode, WorkPoint);
  820. }
  821. sql += string.Format(@"insert into ICSInventoryLot (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  822. values(newid(),'{0}','{1}',getdate(),'{2}','{3}','{4}','19','{5}','{6}',getdate(),'{7}','{8}','','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}')",
  823. LotNo, InvCode, queryParam["ExpirationDate"].ToString(), LOTQTY, str1, MUSER, MUSERNAME, WorkPoints, queryParam["Amount"].ToString(),
  824. queryParam["EATTRIBUTE2"].ToString(), queryParam["EATTRIBUTE3"].ToString(), queryParam["EATTRIBUTE4"].ToString(), queryParam["EATTRIBUTE5"].ToString(),
  825. queryParam["EATTRIBUTE6"].ToString(), queryParam["EATTRIBUTE7"].ToString(), queryParam["EATTRIBUTE8"].ToString(), queryParam["EATTRIBUTE9"].ToString(), queryParam["EATTRIBUTE10"].ToString());
  826. sql += "\r\n";
  827. }
  828. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  829. return count;
  830. }
  831. }
  832. }