爱思开
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.

2875 lines
178 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years 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 System.Configuration;
  11. using Newtonsoft.Json.Linq;
  12. using NFine.Domain._03_Entity.WMS;
  13. using System.Text;
  14. using System.Net;
  15. using System.IO;
  16. using System.Data.SqlClient;
  17. using ICS.Data;
  18. namespace NFine.Application.WMS
  19. {
  20. public class WMSCreateItemLotApp : RepositoryFactory<ICSVendor>
  21. {
  22. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  23. {
  24. DataTable dt = new DataTable();
  25. var queryParam = queryJson.ToJObject();
  26. List<DbParameter> parameter = new List<DbParameter>();
  27. object Figure = GetDecimalDigits();
  28. #region [SQL]
  29. string sql = @"select a.ID,a.ApplyNegCode, cast(a.Sequence as int) as Sequence,a.SourceDetailID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit, CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity
  30. ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount , CAST(a.IssueNegQuantity AS DECIMAL(18,{0})) as IssueNegQuantity ,a.ExtensionID,a.MUSERName,a.MTIME , CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  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
  33. from ICSMOApplyNegDetail a
  34. left join ICSMOApplyNeg d on a.ApplyNegCode=d.ApplyNegCode and a.WorkPoint=d.WorkPoint
  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='1'
  39. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  40. )c
  41. on a.ApplyNegCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  42. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  43. where d.Type='1'";
  44. sql = string.Format(sql, Figure);
  45. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  46. #endregion
  47. if (!string.IsNullOrWhiteSpace(queryJson))
  48. {
  49. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  50. {
  51. sql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  52. }
  53. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  54. {
  55. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  56. }
  57. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  58. {
  59. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  60. }
  61. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  62. {
  63. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  64. }
  65. }
  66. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  67. {
  68. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  69. }
  70. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  71. {
  72. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  73. }
  74. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  75. }
  76. public DataTable GetSubGridJson(string ApplyNegCode, string Sequence, string Type, ref Pagination jqgridparam)
  77. {
  78. DataTable dt = new DataTable();
  79. object Figure = GetDecimalDigits();
  80. List<DbParameter> parameter = new List<DbParameter>();
  81. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  82. string sql = @" select c.TransCode,c.TransSequence ,a.ID,a.LotNo, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity ,a.MUSERName,a.MTIME
  83. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  84. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, CASE WHEN isnull(b.LotNoCount,0)>0 THEN '' ELSE '' END AS RKState
  85. from ICSInventoryLot a
  86. left join (select count(LotNo) LotNoCount,LotNo,WorkPoint from ICSWareHouseLotInfo
  87. group by LotNo,WorkPoint)b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  88. left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  89. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  90. WHERE a.Type='" + Type + "' and c.TransCode='" + ApplyNegCode + "' and c.TransSequence='" + Sequence + "' and a.WorkPoint in ('" + WorkPoint + "')";
  91. sql = string.Format(sql, Figure);
  92. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  93. }
  94. /// <summary>
  95. /// 点击生成条码
  96. /// </summary>
  97. public DataTable GetSubGridJsonByCreate(string ApplyNegCode, string Sequence, string WorkPoint)
  98. {
  99. DataTable dt = new DataTable();
  100. object Figure = GetDecimalDigits();
  101. List<DbParameter> parameter = new List<DbParameter>();
  102. string sql = @" select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity, CAST( a.Amount as DECIMAL(18,{0})) as Amount, CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty ,
  103. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  104. from ICSMOApplyNegDetail a
  105. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  106. left join (
  107. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  108. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='1'
  109. group by b.TransCode,b.TransSequence
  110. ) c on a.ApplyNegCode=c.TransCode and a.Sequence=c.TransSequence
  111. WHERE 1 =1
  112. and a.ApplyNegCode='" + ApplyNegCode + "' and a.Sequence='" + Sequence + "'";
  113. sql += " and a.WorkPoint='" + WorkPoint + "'";
  114. sql = string.Format(sql, Figure);
  115. return Repository().FindTableBySql(sql.ToString());
  116. }
  117. public DataTable GetVendorLotNo(string VenCode, string WorkPoint)
  118. {
  119. DataTable dt = new DataTable();
  120. //var queryParam = queryJson.ToJObject();
  121. List<DbParameter> parameter = new List<DbParameter>();
  122. string dtPre = DateTime.Now.ToString("yyyyMMdd");
  123. string sql = @"EXEC Addins_GetSerialCode '" + WorkPoint + "','ICSITEMLotNo','VendorLotNo','" + VenCode + dtPre + "',2";
  124. return Repository().FindTableBySql(sql.ToString());
  125. }
  126. /// <summary>
  127. /// 生产退料生成条码
  128. /// </summary>
  129. /// <param name="POCode"></param>
  130. /// <param name="PORow"></param>
  131. /// <param name="keyValue"></param>
  132. /// 已改
  133. /// <returns></returns>
  134. public int CreateItemLotNo(string ApplyNegCode, string Sequence, string keyValue, string WorkPoint)
  135. {
  136. var queryParam = keyValue.ToJObject();
  137. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  138. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  139. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  140. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  141. decimal LOTQTY = minPackQty;
  142. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  143. //string VenCode = GetVendorCode(ApplyNegCode, Sequence, WorkPoint);
  144. string Pre = "MDN" + ApplyNegCode + (Convert.ToInt32(Sequence)).ToString("D4");
  145. string sql = string.Empty;
  146. //string VendorLot = queryParam["VendorLot"].ToString();
  147. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  148. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  149. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  150. string sqls = string.Empty;
  151. string Colspan = "";
  152. 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();
  153. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  154. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  155. if (ExtensionID == null)
  156. {
  157. ExtensionID = Guid.NewGuid();
  158. 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)
  159. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  160. ExtensionID, 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(),
  161. MUSER, MUSERNAME, WorkPoints);
  162. }
  163. for (int i = 0; i < createPageCount; i++)
  164. {
  165. if (i + 1 == createPageCount)
  166. {
  167. if (minPackQty * createPageCount > thisCreateQty)
  168. {
  169. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  170. }
  171. }
  172. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  173. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  174. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  175. LotNo, ApplyNegCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  176. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  177. //{
  178. sql += string.Format(@"insert into ICSInventoryLot
  179. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  180. select
  181. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','1','{3}','{4}', getdate(),'{5}','{9}'
  182. from ICSMOApplyNegDetail where ApplyNegCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  183. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ApplyNegCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  184. sql += "\r\n";
  185. //}
  186. }
  187. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  188. return count;
  189. }
  190. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  191. {
  192. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  193. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  194. return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
  195. }
  196. /// <summary>
  197. /// 删除条码
  198. /// </summary>
  199. /// <param name="keyValue"></param>
  200. /// <returns></returns>
  201. public string DeleteItemLot(string keyValue)
  202. {
  203. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  204. string msg = string.Empty;
  205. string sql = string.Format(@"SELECT * FROM dbo.ICSInspection
  206. WHERE LotNo IN (SELECT LotNO FROM dbo.ICSInventoryLot WHERE ID IN ({0})) and WorkPoint in ('{1}')", keyValue.TrimEnd(','), WorkPoint);
  207. DataTable dtASN = SqlHelper.GetDataTableBySql(sql);
  208. if (dtASN != null && dtASN.Rows.Count > 0)
  209. {
  210. msg = "所选条码已生成检验单,无法删除!";
  211. }
  212. sql = string.Format(@"SELECT * FROM dbo.ICSWareHouseLotInfo WHERE LotNO IN
  213. (SELECT LotNO FROM dbo.ICSInventoryLot WHERE ID IN ({0})) and WorkPoint in ('{1}')", keyValue.TrimEnd(','), WorkPoint);
  214. DataTable dtCarton = SqlHelper.GetDataTableBySql(sql);
  215. if (dtCarton != null && dtCarton.Rows.Count > 0)
  216. {
  217. msg += "所选条码已入库,无法删除!";
  218. }
  219. if (string.IsNullOrEmpty(msg))
  220. {
  221. string sqls = string.Format("DELETE FROM ICSInventoryLotDetail WHERE LotNO IN (select LotNO from ICSInventoryLot where ID in ({0}) ) and WorkPoint in ('{1}')", keyValue.TrimEnd(','), WorkPoint);
  222. sqls += string.Format("DELETE FROM dbo.ICSInventoryLot WHERE ID IN ({0}) and WorkPoint in ('{1}')", keyValue.TrimEnd(','), WorkPoint);
  223. SqlHelper.CmdExecuteNonQueryLi(sqls);
  224. }
  225. return msg;
  226. }
  227. public DataTable GetGridJsonWeiWai(string queryJson, ref Pagination jqgridparam)
  228. {
  229. DataTable dt = new DataTable();
  230. var queryParam = queryJson.ToJObject();
  231. List<DbParameter> parameter = new List<DbParameter>();
  232. object Figure = GetDecimalDigits();
  233. #region [SQL]
  234. string sql = @"select a.ID,a.OApplyNegCode, cast(a.Sequence as int) as Sequence,a.SourceDetailID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit, CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity
  235. ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount , CAST(a.IssueNegQuantity AS DECIMAL(18,{0})) as IssueNegQuantity,a.ExtensionID,a.MUSERName,a.MTIME ,
  236. CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  237. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  238. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  239. from ICSOApplyNegDetail a
  240. left join ICSOApplyNeg d on a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
  241. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  242. left join (
  243. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  244. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='2'
  245. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  246. )c
  247. on a.OApplyNegCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  248. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  249. WHERE d.Type='1' ";
  250. sql = string.Format(sql, Figure);
  251. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  252. #endregion
  253. if (!string.IsNullOrWhiteSpace(queryJson))
  254. {
  255. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  256. {
  257. sql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  258. }
  259. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  260. {
  261. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  262. }
  263. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  264. {
  265. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  266. }
  267. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  268. {
  269. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  270. }
  271. }
  272. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  273. {
  274. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  275. }
  276. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  277. {
  278. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  279. }
  280. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  281. }
  282. public DataTable GetSubGridJsonWeiWai(string OApplyNegCode, string Sequence, ref Pagination jqgridparam)
  283. {
  284. DataTable dt = new DataTable();
  285. object Figure = GetDecimalDigits();
  286. //var queryParam = queryJson.ToJObject();
  287. List<DbParameter> parameter = new List<DbParameter>();
  288. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  289. string sql = @" select c.TransCode,c.TransSequence ,a.ID,a.LotNo,CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity from ICSInventoryLot a
  290. left join (select count(LotNo) LotNoCount,LotNo,WorkPoint from ICSWareHouseLotInfo
  291. group by LotNo,WorkPoint)b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  292. left join ICSInventoryLotDetail c on a.LotNo=c.LotNo
  293. WHERE c.TransCode='" + OApplyNegCode + "' and c.TransSequence='" + Sequence + "' and a.WorkPoint in (" + WorkPoint + ")";
  294. sql = string.Format(sql, Figure);
  295. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  296. }
  297. /// <summary>
  298. /// 点击委外退料生成条码
  299. /// </summary>
  300. public DataTable GetSubGridJsonWeiWaiByCreate(string OApplyNegCode, string Sequence, string WorkPoint)
  301. {
  302. DataTable dt = new DataTable();
  303. object Figure = GetDecimalDigits();
  304. List<DbParameter> parameter = new List<DbParameter>();
  305. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  306. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  307. from ICSOApplyNegDetail a
  308. left join ICSOApplyNeg d on a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
  309. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  310. left join (
  311. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  312. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='2'
  313. group by b.TransCode,b.TransSequence
  314. ) c on a.OApplyNegCode=c.TransCode and a.Sequence=c.TransSequence
  315. WHERE d.Type='1'
  316. and a.OApplyNegCode='" + OApplyNegCode + "' and a.Sequence='" + Sequence + "'";
  317. sql += " and a.WorkPoint='" + WorkPoint + "'";
  318. sql = string.Format(sql, Figure);
  319. return Repository().FindTableBySql(sql.ToString());
  320. }
  321. /// <summary>
  322. /// 委外退料生成条码
  323. /// </summary>
  324. /// <param name="POCode"></param>
  325. /// <param name="PORow"></param>
  326. /// <param name="keyValue"></param>
  327. /// 已改
  328. /// <returns></returns>
  329. public int SubmitFormWeiWai(string OApplyNegCode, string Sequence, string keyValue, string WorkPoint)
  330. {
  331. var queryParam = keyValue.ToJObject();
  332. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  333. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  334. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  335. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  336. decimal LOTQTY = minPackQty;
  337. string Pre = "OI" + OApplyNegCode + (Convert.ToInt32(Sequence)).ToString("D4");
  338. string sql = string.Empty;
  339. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  340. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  341. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  342. string sqls = string.Empty;
  343. string Colspan = "";
  344. 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();
  345. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  346. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  347. if (ExtensionID == null)
  348. {
  349. ExtensionID = Guid.NewGuid();
  350. 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)
  351. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  352. ExtensionID, 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(),
  353. MUSER, MUSERNAME, WorkPoints);
  354. }
  355. for (int i = 0; i < createPageCount; i++)
  356. {
  357. if (i + 1 == createPageCount)
  358. {
  359. if (minPackQty * createPageCount > thisCreateQty)
  360. {
  361. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  362. }
  363. }
  364. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  365. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  366. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  367. LotNo, OApplyNegCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  368. sql += string.Format(@"insert into ICSInventoryLot
  369. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  370. select
  371. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','2','{3}','{4}', getdate(),'{5}','{9}'
  372. from ICSOApplyNegDetail where OApplyNegCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  373. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, OApplyNegCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  374. sql += "\r\n";
  375. }
  376. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  377. return count;
  378. }
  379. public DataTable GetGridJsonChengPing(string queryJson, ref Pagination jqgridparam)
  380. {
  381. DataTable dt = new DataTable();
  382. var queryParam = queryJson.ToJObject();
  383. List<DbParameter> parameter = new List<DbParameter>();
  384. object Figure = GetDecimalDigits();
  385. #region [SQL]
  386. string sql = @" select a.ID,a.MOCode, cast(a.Sequence as int) as 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
  387. ,a.DueDate,a.MOStatus,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  388. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  389. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.CreateDateTime,a.ERPStatus
  390. from ICSMO a
  391. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  392. left join (
  393. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  394. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='3'
  395. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  396. )c
  397. on a.MOCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  398. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint ";
  399. sql += " WHERE 1=1";
  400. sql = string.Format(sql, Figure);
  401. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  402. #endregion
  403. if (!string.IsNullOrWhiteSpace(queryJson))
  404. {
  405. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  406. {
  407. sql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  408. }
  409. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  410. {
  411. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  412. }
  413. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  414. {
  415. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  416. }
  417. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  418. {
  419. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  420. }
  421. }
  422. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  423. {
  424. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  425. }
  426. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  427. {
  428. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  429. }
  430. //sql += " order by a.MOCode, cast(a.Sequence as int)";
  431. // sql += " order by a.MTIME desc ,a.MOCode asc,cast(a.Sequence as int) asc";
  432. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  433. }
  434. /// <summary>
  435. /// 点击成品生成条码(成品)
  436. /// </summary>
  437. public DataTable GetSubGridJsonChengPingByCreate(string MOCode, string Sequence, string WorkPoint)
  438. {
  439. DataTable dt = new DataTable();
  440. object Figure = GetDecimalDigits();
  441. List<DbParameter> parameter = new List<DbParameter>();
  442. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  443. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays ,
  444. d.ProjectCode,d.BatchCode,d.Version,d.Brand,d.cFree1,d.cFree2,d.cFree3,d.cFree4,d.cFree5,d.cFree6,d.cFree7,d.cFree8,d.cFree9,d.cFree10
  445. from ICSMO a
  446. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  447. left join (
  448. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  449. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='3'
  450. group by b.TransCode,b.TransSequence
  451. ) c on a.MOCode=c.TransCode and a.Sequence=c.TransSequence
  452. left join dbo.ICSExtension d on a.ExtensionID=d.ID and a.WorkPoint=d.WorkPoint
  453. WHERE 1 =1
  454. and a.MOCode='" + MOCode + "' and a.Sequence='" + Sequence + "'";
  455. sql += " and a.WorkPoint='" + WorkPoint + "'";
  456. sql = string.Format(sql, Figure);
  457. return Repository().FindTableBySql(sql.ToString());
  458. }
  459. /// <summary>
  460. /// 成品生成条码
  461. /// </summary>
  462. /// <param name="POCode"></param>
  463. /// <param name="PORow"></param>
  464. /// <param name="keyValue"></param>
  465. /// 已改
  466. /// <returns></returns>
  467. public int SubmitFormChengPing(string MOCode, string Sequence, string keyValue, string WorkPoint)
  468. {
  469. var queryParam = keyValue.ToJObject();
  470. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  471. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  472. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  473. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  474. decimal LOTQTY = minPackQty;
  475. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  476. //string VenCode = GetVendorCode(ApplyNegCode, Sequence, WorkPoint);
  477. string Pre = "CP" + MOCode + (Convert.ToInt32(Sequence)).ToString("D4");
  478. string sql = string.Empty;
  479. //string VendorLot = queryParam["VendorLot"].ToString();
  480. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  481. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  482. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  483. string sqls = string.Empty;
  484. string Colspan = "";
  485. 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();
  486. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  487. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  488. if (ExtensionID == null)
  489. {
  490. ExtensionID = Guid.NewGuid();
  491. 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)
  492. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  493. ExtensionID, 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(),
  494. MUSER, MUSERNAME, WorkPoints);
  495. }
  496. for (int i = 0; i < createPageCount; i++)
  497. {
  498. if (i + 1 == createPageCount)
  499. {
  500. if (minPackQty * createPageCount > thisCreateQty)
  501. {
  502. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  503. }
  504. }
  505. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  506. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  507. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  508. LotNo, MOCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  509. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  510. //{
  511. sql += string.Format(@"insert into ICSInventoryLot
  512. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  513. select
  514. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','3','{3}','{4}', getdate(),'{5}','{9}'
  515. from ICSMO where MOCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  516. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, MOCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  517. sql += "\r\n";
  518. //}
  519. }
  520. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  521. return count;
  522. }
  523. public DataTable GetGridJsonXiaoShou(string queryJson, ref Pagination jqgridparam)
  524. {
  525. DataTable dt = new DataTable();
  526. var queryParam = queryJson.ToJObject();
  527. List<DbParameter> parameter = new List<DbParameter>();
  528. object Figure = GetDecimalDigits();
  529. #region [SQL]
  530. string sql = @" select a.ID,a.SDNCode, cast(a.Sequence as int) as Sequence,a.SOCode,a.SOSequence,a.CusCode,a.CusName,a.Type,a.ArriveDate,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity
  531. ,cast(a.Amount as decimal(18,{0})) as Amount, CAST(a.SDNQuantity AS DECIMAL(18,{0})) as SDNQuantity ,a.Status,a.ExtensionID,a.CreatePerson,a.CreateDateTime ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  532. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  533. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  534. from ICSSDN a
  535. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  536. left join (
  537. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  538. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='4'
  539. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  540. )c
  541. on a.SDNCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  542. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  543. where a.Type='2'";
  544. sql = string.Format(sql, Figure);
  545. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  546. #endregion
  547. if (!string.IsNullOrWhiteSpace(queryJson))
  548. {
  549. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  550. {
  551. sql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  552. }
  553. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  554. {
  555. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  556. }
  557. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  558. {
  559. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  560. }
  561. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  562. {
  563. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  564. }
  565. }
  566. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  567. {
  568. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  569. }
  570. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  571. {
  572. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  573. }
  574. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  575. }
  576. /// <summary>
  577. /// 点击销售退货生成条码(销售退货)
  578. /// </summary>
  579. public DataTable GetSubGridJsonXiaoShouByCreate(string SDNCode, string Sequence, string WorkPoint)
  580. {
  581. DataTable dt = new DataTable();
  582. object Figure = GetDecimalDigits();
  583. List<DbParameter> parameter = new List<DbParameter>();
  584. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  585. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays ,
  586. d.ProjectCode,d.BatchCode,d.Version,d.Brand,d.cFree1,d.cFree2,d.cFree3,d.cFree4,d.cFree5,d.cFree6,d.cFree7,d.cFree8,d.cFree9,d.cFree10
  587. from ICSSDN a
  588. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  589. left join (
  590. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  591. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='4'
  592. group by b.TransCode,b.TransSequence
  593. ) c on a.SDNCode=c.TransCode and a.Sequence=c.TransSequence
  594. left join dbo.ICSExtension d on a.ExtensionID=d.ID and a.WorkPoint=d.WorkPoint
  595. WHERE 1 =1
  596. and a.Type='2' and a.SDNCode='" + SDNCode + "' and a.Sequence='" + Sequence + "'";
  597. sql += " and a.WorkPoint='" + WorkPoint + "'";
  598. sql = string.Format(sql, Figure);
  599. return Repository().FindTableBySql(sql.ToString());
  600. }
  601. /// <summary>
  602. /// 销售退货生成条码
  603. /// </summary>
  604. /// <param name="POCode"></param>
  605. /// <param name="PORow"></param>
  606. /// <param name="keyValue"></param>
  607. /// 已改
  608. /// <returns></returns>
  609. public int SubmitFormXiaoShou(string SDNCode, string Sequence, string keyValue, string WorkPoint)
  610. {
  611. var queryParam = keyValue.ToJObject();
  612. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  613. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  614. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  615. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  616. decimal LOTQTY = minPackQty;
  617. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  618. //string VenCode = GetVendorCode(ApplyNegCode, Sequence, WorkPoint);
  619. string Pre = "SR" + SDNCode + (Convert.ToInt32(Sequence)).ToString("D4");
  620. string sql = string.Empty;
  621. //string VendorLot = queryParam["VendorLot"].ToString();
  622. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  623. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  624. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  625. string sqls = string.Empty;
  626. string Colspan = "";
  627. 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();
  628. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  629. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  630. if (ExtensionID == null)
  631. {
  632. ExtensionID = Guid.NewGuid();
  633. 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)
  634. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  635. ExtensionID, 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(),
  636. MUSER, MUSERNAME, WorkPoints);
  637. }
  638. for (int i = 0; i < createPageCount; i++)
  639. {
  640. if (i + 1 == createPageCount)
  641. {
  642. if (minPackQty * createPageCount > thisCreateQty)
  643. {
  644. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  645. }
  646. }
  647. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  648. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  649. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}')",
  650. LotNo, SDNCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  651. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  652. //{
  653. sql += string.Format(@"
  654. insert into ICSInventoryLot
  655. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  656. select
  657. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','4','{3}','{4}', getdate(),'{5}','{9}'
  658. from ICSSDN where Type='2' and SDNCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  659. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, SDNCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  660. sql += "\r\n";
  661. //}
  662. }
  663. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  664. return count;
  665. }
  666. public DataTable GetGridJsonQiTa(string queryJson, ref Pagination jqgridparam)
  667. {
  668. DataTable dt = new DataTable();
  669. var queryParam = queryJson.ToJObject();
  670. List<DbParameter> parameter = new List<DbParameter>();
  671. object Figure = GetDecimalDigits();
  672. #region [SQL]
  673. string sql = @" select a.ID,a.InCode, cast(a.Sequence as int) as Sequence,a.WHCode,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,
  674. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST(a.Amount AS DECIMAL(18,{0})) as Amount, CAST(a.InQuantity AS DECIMAL(18,{0})) as InQuantity,a.CreatePerson,a.CreateDateTime,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  675. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  676. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  677. from ICSOtherIn a
  678. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  679. left join (
  680. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  681. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='5'
  682. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  683. )c
  684. on a.InCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  685. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  686. where a.Status='1'";
  687. sql = string.Format(sql, Figure);
  688. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  689. #endregion
  690. if (!string.IsNullOrWhiteSpace(queryJson))
  691. {
  692. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  693. {
  694. sql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' ";
  695. }
  696. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  697. {
  698. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  699. }
  700. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  701. {
  702. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  703. }
  704. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  705. {
  706. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  707. }
  708. }
  709. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  710. {
  711. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  712. }
  713. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  714. {
  715. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  716. }
  717. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  718. }
  719. /// <summary>
  720. /// 点击生成条码(其他入库)
  721. /// </summary>
  722. public DataTable GetSubGridJsonQiTaByCreate(string InCode, string Sequence, string WorkPoint)
  723. {
  724. DataTable dt = new DataTable();
  725. object Figure = GetDecimalDigits();
  726. List<DbParameter> parameter = new List<DbParameter>();
  727. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  728. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays ,
  729. d.ProjectCode,d.BatchCode,d.Version,d.Brand,d.cFree1,d.cFree2,d.cFree3,d.cFree4,d.cFree5,d.cFree6,d.cFree7,d.cFree8,d.cFree9,d.cFree10
  730. from ICSOtherIn a
  731. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  732. left join (
  733. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  734. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='5'
  735. group by b.TransCode,b.TransSequence
  736. ) c on a.InCode=c.TransCode and a.Sequence=c.TransSequence
  737. left join dbo.ICSExtension d on a.ExtensionID=d.ID and a.WorkPoint=d.WorkPoint
  738. WHERE 1 =1
  739. and a.InCode='" + InCode + "' and a.Sequence='" + Sequence + "'";
  740. sql += " and a.WorkPoint='" + WorkPoint + "'";
  741. sql = string.Format(sql, Figure);
  742. return Repository().FindTableBySql(sql.ToString());
  743. }
  744. /// <summary>
  745. /// 其他入库生成条码
  746. /// </summary>
  747. /// <param name="POCode"></param>
  748. /// <param name="PORow"></param>
  749. /// <param name="keyValue"></param>
  750. /// 已改
  751. /// <returns></returns>
  752. public int SubmitFormQiTa(string InCode, string Sequence, string keyValue, string WorkPoint)
  753. {
  754. var queryParam = keyValue.ToJObject();
  755. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  756. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  757. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  758. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  759. decimal LOTQTY = minPackQty;
  760. string Pre = "QT" + InCode + (Convert.ToInt32(Sequence)).ToString("D4");
  761. string sql = string.Empty;
  762. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  763. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  764. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  765. string sqls = string.Empty;
  766. string Colspan = "";
  767. 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();
  768. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  769. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  770. if (ExtensionID == null)
  771. {
  772. ExtensionID = Guid.NewGuid();
  773. 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)
  774. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  775. ExtensionID, 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(),
  776. MUSER, MUSERNAME, WorkPoints);
  777. }
  778. for (int i = 0; i < createPageCount; i++)
  779. {
  780. if (i + 1 == createPageCount)
  781. {
  782. if (minPackQty * createPageCount > thisCreateQty)
  783. {
  784. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  785. }
  786. }
  787. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  788. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  789. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  790. LotNo, InCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  791. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  792. //{
  793. sql += string.Format(@"
  794. insert into ICSInventoryLot
  795. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  796. select
  797. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','5','{3}','{4}', getdate(),'{5}','{9}'
  798. from ICSOtherIn where InCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  799. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, InCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  800. sql += "\r\n";
  801. //}
  802. }
  803. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  804. return count;
  805. }
  806. //归还
  807. public DataTable GetGridJsonGuiHuan(string queryJson, ref Pagination jqgridparam)
  808. {
  809. DataTable dt = new DataTable();
  810. var queryParam = queryJson.ToJObject();
  811. List<DbParameter> parameter = new List<DbParameter>();
  812. object Figure = GetDecimalDigits();
  813. #region [SQL]
  814. string sql = @"select a.ID,a.ReturnCode, cast(a.Sequence as int) as Sequence,a.WHCode,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount, CAST(a.ReturnQuantity AS DECIMAL(18,{0})) as ReturnQuantity,a.CreatePerson,a.CreateDateTime,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  815. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  816. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 from ICSReturn a
  817. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  818. left join (
  819. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  820. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='6'
  821. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  822. ) c on a.ReturnCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  823. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  824. where a.Status='2'";
  825. sql = string.Format(sql, Figure);
  826. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  827. #endregion
  828. if (!string.IsNullOrWhiteSpace(queryJson))
  829. {
  830. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  831. {
  832. sql += " and a.ReturnCode like '%" + queryParam["POCode"].ToString() + "%' ";
  833. }
  834. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  835. {
  836. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  837. }
  838. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  839. {
  840. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  841. }
  842. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  843. {
  844. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  845. }
  846. }
  847. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  848. {
  849. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  850. }
  851. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  852. {
  853. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  854. }
  855. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  856. }
  857. //审核到货单(采购订单需与审核到货单一起同步)
  858. public DataTable GetGridJsonSHDH(string queryJson, ref Pagination jqgridparam)
  859. {
  860. DataTable dt = new DataTable();
  861. var queryParam = queryJson.ToJObject();
  862. List<DbParameter> parameter = new List<DbParameter>();
  863. object Figure = GetDecimalDigits();
  864. #region [SQL]
  865. string sql = @"select a.ID, d.POCode,d.Sequence as POSequence,a.DNCode, cast(a.Sequence as int) as Sequence,a.VenCode,e.VenName,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,
  866. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity,CAST(a.UnitPrice AS DECIMAL(18,{0})) as UnitPrice,a.Currency,a.CreatePerson,a.CreateDateTime,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  867. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  868. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  869. from ICSDeliveryNotice a
  870. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  871. left join (
  872. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  873. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='7'
  874. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  875. ) c on a.DNCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  876. inner join ICSPurchaseOrder d on a.POID=d.POID and a.PODetailID=d.PODetailID and a.WorkPoint=d.WorkPoint
  877. left join ICSVendor e on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  878. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  879. where a.DNType='1' and a.Status='2' and a.ASNCode is null
  880. ";
  881. sql = string.Format(sql, Figure);
  882. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  883. #endregion
  884. if (!string.IsNullOrWhiteSpace(queryJson))
  885. {
  886. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  887. {
  888. sql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  889. }
  890. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  891. {
  892. sql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  893. }
  894. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  895. {
  896. sql += " and e.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  897. }
  898. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  899. {
  900. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  901. }
  902. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  903. {
  904. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  905. }
  906. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  907. {
  908. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  909. }
  910. }
  911. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  912. {
  913. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  914. }
  915. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  916. {
  917. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  918. }
  919. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  920. }
  921. //审核委外到货单
  922. public DataTable GetGridJsonWWSHDH(string queryJson, ref Pagination jqgridparam)
  923. {
  924. DataTable dt = new DataTable();
  925. var queryParam = queryJson.ToJObject();
  926. List<DbParameter> parameter = new List<DbParameter>();
  927. object Figure = GetDecimalDigits();
  928. #region [SQL]
  929. string sql = @"select a.ID, d.OOCode,d.Sequence as OOSequence,a.ODNCode, cast(a.Sequence as int) as Sequence,a.VenCode,e.VenName,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity,CAST(a.UnitPrice AS DECIMAL(18,{0})) as UnitPrice,a.Currency,a.CreatePerson,a.CreateDateTime,
  930. CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  931. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  932. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  933. from ICSODeliveryNotice a
  934. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  935. left join (
  936. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  937. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='8'
  938. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  939. ) c on a.ODNCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  940. inner join ICSOutsourcingOrder d on a.OOID=d.OOID and a.OODetailID=d.OODetailID and a.WorkPoint=d.WorkPoint
  941. left join ICSVendor e on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  942. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  943. where a.ODNType='1' and a.Status='2' and a.OASNCode is null";
  944. sql = string.Format(sql, Figure);
  945. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  946. #endregion
  947. if (!string.IsNullOrWhiteSpace(queryJson))
  948. {
  949. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  950. {
  951. sql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  952. }
  953. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  954. {
  955. sql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  956. }
  957. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  958. {
  959. sql += " and e.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  960. }
  961. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  962. {
  963. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  964. }
  965. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  966. {
  967. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  968. }
  969. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  970. {
  971. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  972. }
  973. }
  974. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  975. {
  976. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  977. }
  978. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  979. {
  980. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  981. }
  982. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  983. }
  984. //开立得成品入库单
  985. public DataTable GetGridJsonKLCPRK(string queryJson, ref Pagination jqgridparam)
  986. {
  987. DataTable dt = new DataTable();
  988. var queryParam = queryJson.ToJObject();
  989. List<DbParameter> parameter = new List<DbParameter>();
  990. object Figure = GetDecimalDigits();
  991. #region [SQL]
  992. string sql = @"
  993. select a.ID,a.RCVCode, cast(a.Sequence as int) as Sequence,a.WHCode,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,
  994. CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity ,a.CreatePerson,a.CreateDateTime,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  995. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  996. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  997. from ICSManufactureReceive a
  998. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  999. left join (
  1000. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  1001. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='9'
  1002. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  1003. ) c on a.RCVCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  1004. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1005. where a.Status='1' and a.Type='1'";
  1006. sql = string.Format(sql, Figure);
  1007. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1008. #endregion
  1009. if (!string.IsNullOrWhiteSpace(queryJson))
  1010. {
  1011. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1012. {
  1013. sql += " and a.RCVCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1014. }
  1015. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1016. {
  1017. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1018. }
  1019. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1020. {
  1021. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1022. }
  1023. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1024. {
  1025. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1026. }
  1027. }
  1028. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1029. {
  1030. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1031. }
  1032. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1033. {
  1034. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1035. }
  1036. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1037. }
  1038. /// <summary>
  1039. /// 点击审核委外到货单生成条码(审核委外到货单)
  1040. /// </summary>
  1041. public DataTable GetSubGridJsonWWSHDHByCreate(string ODNCode, string Sequence, string WorkPoint)
  1042. {
  1043. DataTable dt = new DataTable();
  1044. object Figure = GetDecimalDigits();
  1045. List<DbParameter> parameter = new List<DbParameter>();
  1046. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1047. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1048. from ICSODeliveryNotice a
  1049. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1050. left join (select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1051. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='8'
  1052. group by b.TransCode,b.TransSequence
  1053. ) c on a.ODNCode=c.TransCode and a.Sequence=c.TransSequence
  1054. WHERE 1 =1
  1055. and a.ODNCode='" + ODNCode + "' and a.Sequence='" + Sequence + "'";
  1056. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1057. sql = string.Format(sql, Figure);
  1058. return Repository().FindTableBySql(sql.ToString());
  1059. }
  1060. /// <summary>
  1061. /// 点击开立成品入库生成条码(开立成品入库单)
  1062. /// </summary>
  1063. /// //--
  1064. public DataTable GetSubGridJsonKLCPRKByCreate(string RCVCode, string Sequence, string WorkPoint)
  1065. {
  1066. DataTable dt = new DataTable();
  1067. object Figure = GetDecimalDigits();
  1068. List<DbParameter> parameter = new List<DbParameter>();
  1069. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1070. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1071. from ICSManufactureReceive a
  1072. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1073. left join (select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1074. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='9'
  1075. group by b.TransCode,b.TransSequence
  1076. ) c on a.RCVCode=c.TransCode and a.Sequence=c.TransSequence
  1077. WHERE 1 =1
  1078. and a.RCVCode='" + RCVCode + "' and a.Sequence='" + Sequence + "'";
  1079. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1080. sql = string.Format(sql, Figure);
  1081. return Repository().FindTableBySql(sql.ToString());
  1082. }
  1083. /// <summary>
  1084. /// 点击审核到货单生成条码(审核到货单)
  1085. /// </summary>
  1086. public DataTable GetSubGridJsonSHDHByCreate(string DNCode, string Sequence, string WorkPoint)
  1087. {
  1088. DataTable dt = new DataTable();
  1089. object Figure = GetDecimalDigits();
  1090. List<DbParameter> parameter = new List<DbParameter>();
  1091. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1092. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays ,
  1093. d.ProjectCode,d.BatchCode,d.Version,d.Brand,d.cFree1,d.cFree2,d.cFree3,d.cFree4,d.cFree5,d.cFree6,d.cFree7,d.cFree8,d.cFree9,d.cFree10
  1094. from ICSDeliveryNotice a
  1095. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1096. left join (select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1097. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='7'
  1098. group by b.TransCode,b.TransSequence
  1099. ) c on a.DNCode=c.TransCode and a.Sequence=c.TransSequence
  1100. left join dbo.ICSExtension d on a.ExtensionID=d.ID and a.WorkPoint=d.WorkPoint
  1101. WHERE 1 =1
  1102. and a.DNCode='" + DNCode + "' and a.Sequence='" + Sequence + "'";
  1103. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1104. sql = string.Format(sql, Figure);
  1105. return Repository().FindTableBySql(sql.ToString());
  1106. }
  1107. /// <summary>
  1108. /// 点击归还生成条码(归还)
  1109. /// </summary>
  1110. public DataTable GetSubGridJsonGuiHuanByCreate(string ReturnCode, string Sequence, string WorkPoint)
  1111. {
  1112. DataTable dt = new DataTable();
  1113. object Figure = GetDecimalDigits();
  1114. List<DbParameter> parameter = new List<DbParameter>();
  1115. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1116. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1117. from ICSReturn a
  1118. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1119. left join (select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1120. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='6'
  1121. group by b.TransCode,b.TransSequence
  1122. ) c on a.ReturnCode=c.TransCode and a.Sequence=c.TransSequence
  1123. WHERE 1 =1
  1124. and a.ReturnCode='" + ReturnCode + "' and a.Sequence='" + Sequence + "'";
  1125. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1126. sql = string.Format(sql, Figure);
  1127. return Repository().FindTableBySql(sql.ToString());
  1128. }
  1129. /// <summary>
  1130. /// 归还单生成条码
  1131. /// </summary>
  1132. /// <param name="POCode"></param>
  1133. /// <param name="PORow"></param>
  1134. /// <param name="keyValue"></param>
  1135. /// 已改
  1136. /// <returns></returns>
  1137. public int SubmitFormGuiHuan(string ReturnCode, string Sequence, string keyValue, string WorkPoint)
  1138. {
  1139. var queryParam = keyValue.ToJObject();
  1140. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1141. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1142. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1143. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1144. decimal LOTQTY = minPackQty;
  1145. string Pre = "GH" + ReturnCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1146. string sql = string.Empty;
  1147. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1148. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1149. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1150. string sqls = string.Empty;
  1151. string Colspan = "";
  1152. 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();
  1153. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1154. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1155. if (ExtensionID == null)
  1156. {
  1157. ExtensionID = Guid.NewGuid();
  1158. 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)
  1159. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1160. ExtensionID, 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(),
  1161. MUSER, MUSERNAME, WorkPoints);
  1162. }
  1163. for (int i = 0; i < createPageCount; i++)
  1164. {
  1165. if (i + 1 == createPageCount)
  1166. {
  1167. if (minPackQty * createPageCount > thisCreateQty)
  1168. {
  1169. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1170. }
  1171. }
  1172. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1173. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1174. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1175. LotNo, ReturnCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1176. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  1177. //{
  1178. sql += string.Format(@"
  1179. insert into ICSInventoryLot
  1180. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1181. select
  1182. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','6','{3}','{4}', getdate(),'{5}','{9}'
  1183. from ICSReturn where ReturnCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  1184. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ReturnCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1185. sql += "\r\n";
  1186. //}
  1187. }
  1188. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1189. return count;
  1190. }
  1191. /// <summary>
  1192. /// 审核到货单生成条码
  1193. /// </summary>
  1194. /// <param name="POCode"></param>
  1195. /// <param name="PORow"></param>
  1196. /// <param name="keyValue"></param>
  1197. /// 已改
  1198. /// <returns></returns>
  1199. public int SubmitFormSHDH(string DNCode, string Sequence, string keyValue, string WorkPoint)
  1200. {
  1201. var queryParam = keyValue.ToJObject();
  1202. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1203. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1204. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1205. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1206. decimal LOTQTY = minPackQty;
  1207. string Pre = "DN" + DNCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1208. string sql = string.Empty;
  1209. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1210. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1211. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1212. string sqls = string.Empty;
  1213. string Colspan = "";
  1214. 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();
  1215. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1216. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1217. if (ExtensionID == null)
  1218. {
  1219. ExtensionID = Guid.NewGuid();
  1220. 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)
  1221. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1222. ExtensionID, 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(),
  1223. MUSER, MUSERNAME, WorkPoints);
  1224. }
  1225. for (int i = 0; i < createPageCount; i++)
  1226. {
  1227. if (i + 1 == createPageCount)
  1228. {
  1229. if (minPackQty * createPageCount > thisCreateQty)
  1230. {
  1231. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1232. }
  1233. }
  1234. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1235. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1236. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1237. LotNo, DNCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1238. sql += string.Format(@"
  1239. insert into ICSInventoryLot
  1240. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1241. select
  1242. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','7','{3}','{4}', getdate(),'{5}','{9}'
  1243. from ICSDeliveryNotice where DNCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
  1244. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, DNCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1245. sql += "\r\n";
  1246. }
  1247. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1248. return count;
  1249. }
  1250. /// <summary>
  1251. /// 审核委外到货单生成条码
  1252. /// </summary>
  1253. /// <param name="POCode"></param>
  1254. /// <param name="PORow"></param>
  1255. /// <param name="keyValue"></param>
  1256. /// 已改
  1257. /// <returns></returns>
  1258. public int SubmitFormWWSHDH(string ODNCode, string Sequence, string keyValue, string WorkPoint)
  1259. {
  1260. var queryParam = keyValue.ToJObject();
  1261. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1262. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1263. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1264. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1265. decimal LOTQTY = minPackQty;
  1266. string Pre = "ODN" + ODNCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1267. string sql = string.Empty;
  1268. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1269. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1270. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1271. string sqls = string.Empty;
  1272. string Colspan = "";
  1273. 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();
  1274. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1275. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1276. if (ExtensionID == null)
  1277. {
  1278. ExtensionID = Guid.NewGuid();
  1279. 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)
  1280. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1281. ExtensionID, 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(),
  1282. MUSER, MUSERNAME, WorkPoints);
  1283. }
  1284. for (int i = 0; i < createPageCount; i++)
  1285. {
  1286. if (i + 1 == createPageCount)
  1287. {
  1288. if (minPackQty * createPageCount > thisCreateQty)
  1289. {
  1290. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1291. }
  1292. }
  1293. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1294. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1295. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1296. LotNo, ODNCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1297. sql += string.Format(@"
  1298. insert into ICSInventoryLot
  1299. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1300. select
  1301. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','8','{3}','{4}', getdate(),'{5}','{9}'
  1302. from ICSODeliveryNotice where ODNCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
  1303. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ODNCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1304. sql += "\r\n";
  1305. }
  1306. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1307. return count;
  1308. }
  1309. /// <summary>
  1310. /// 开立成品入库单
  1311. /// </summary>
  1312. /// <param name="POCode"></param>
  1313. /// <param name="PORow"></param>
  1314. /// <param name="keyValue"></param>
  1315. /// 已改
  1316. /// <returns></returns>
  1317. public int SubmitFormKLCPRK(string RCVCode, string Sequence, string keyValue, string WorkPoint)
  1318. {
  1319. var queryParam = keyValue.ToJObject();
  1320. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1321. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1322. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1323. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1324. decimal LOTQTY = minPackQty;
  1325. string Pre = "KCP" + RCVCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1326. string sql = string.Empty;
  1327. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1328. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1329. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1330. string sqls = string.Empty;
  1331. string Colspan = "";
  1332. 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();
  1333. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}'", Colspan);
  1334. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1335. if (ExtensionID == null)
  1336. {
  1337. ExtensionID = Guid.NewGuid();
  1338. 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)
  1339. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1340. ExtensionID, 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(),
  1341. MUSER, MUSERNAME, WorkPoints);
  1342. }
  1343. for (int i = 0; i < createPageCount; i++)
  1344. {
  1345. if (i + 1 == createPageCount)
  1346. {
  1347. if (minPackQty * createPageCount > thisCreateQty)
  1348. {
  1349. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1350. }
  1351. }
  1352. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1353. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1354. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1355. LotNo, RCVCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1356. sql += string.Format(@"
  1357. insert into ICSInventoryLot
  1358. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1359. select
  1360. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','9','{3}','{4}', getdate(),'{5}','{9}'
  1361. from ICSManufactureReceive where RCVCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
  1362. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, RCVCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1363. sql += "\r\n";
  1364. }
  1365. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1366. return count;
  1367. }
  1368. //委外拒收单
  1369. public DataTable GetGridJsonWWJSD(string queryJson, ref Pagination jqgridparam)
  1370. {
  1371. DataTable dt = new DataTable();
  1372. var queryParam = queryJson.ToJObject();
  1373. List<DbParameter> parameter = new List<DbParameter>();
  1374. object Figure = GetDecimalDigits();
  1375. #region [SQL]
  1376. string sql = @"select a.ID, a.ODNCode OOCode, cast(a.Sequence as int) as OOSequence,a.VenCode,e.VenName,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,
  1377. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity,CAST(a.UnitPrice AS DECIMAL(18,{0})) as UnitPrice,a.Currency,a.CreatePerson,a.CreateDateTime,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  1378. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1379. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1380. from ICSODeliveryNotice a
  1381. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1382. left join (
  1383. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  1384. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='11'
  1385. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  1386. ) c on a.ODNCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  1387. --inner join ICSOutsourcingOrder d on a.OOID=d.OOID and a.OODetailID=d.OODetailID and a.WorkPoint=d.WorkPoint
  1388. left join ICSVendor e on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  1389. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1390. where a.ODNType='3' and a.Status='2' and a.EATTRIBUTE1 is NOT null
  1391. ";
  1392. sql = string.Format(sql, Figure);
  1393. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1394. #endregion
  1395. if (!string.IsNullOrWhiteSpace(queryJson))
  1396. {
  1397. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1398. {
  1399. sql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1400. }
  1401. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  1402. {
  1403. sql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  1404. }
  1405. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  1406. {
  1407. sql += " and e.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  1408. }
  1409. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1410. {
  1411. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1412. }
  1413. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1414. {
  1415. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1416. }
  1417. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1418. {
  1419. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1420. }
  1421. }
  1422. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1423. {
  1424. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1425. }
  1426. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1427. {
  1428. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1429. }
  1430. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1431. }
  1432. //拒收单
  1433. public DataTable GetGridJsonJSD(string queryJson, ref Pagination jqgridparam)
  1434. {
  1435. DataTable dt = new DataTable();
  1436. var queryParam = queryJson.ToJObject();
  1437. List<DbParameter> parameter = new List<DbParameter>();
  1438. object Figure = GetDecimalDigits();
  1439. #region [SQL]
  1440. string sql = @"select a.ID,a.DNCode , cast(a.Sequence as int) as Sequence ,a.VenCode,e.VenName,a.InvCode, b.InvName,b.InvStd,b.InvDesc,b.InvUnit,
  1441. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity,CAST( a.UnitPrice AS DECIMAL(18,{0})) as UnitPrice,a.Currency,a.CreatePerson,a.CreateDateTime,
  1442. CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  1443. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1444. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1445. from ICSDeliveryNotice a
  1446. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1447. left join (
  1448. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  1449. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='10'
  1450. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  1451. ) c on a.DNCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  1452. --inner join ICSPurchaseOrder d on a.POID=d.POID and a.PODetailID=d.PODetailID and a.WorkPoint=d.WorkPoint
  1453. left join ICSVendor e on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  1454. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1455. where a.DNType='3' and a.Status='2' and a.EATTRIBUTE1 is NOT null
  1456. ";
  1457. sql = string.Format(sql, Figure);
  1458. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1459. #endregion
  1460. if (!string.IsNullOrWhiteSpace(queryJson))
  1461. {
  1462. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1463. {
  1464. sql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1465. }
  1466. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  1467. {
  1468. sql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  1469. }
  1470. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  1471. {
  1472. sql += " and e.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  1473. }
  1474. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1475. {
  1476. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1477. }
  1478. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1479. {
  1480. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1481. }
  1482. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1483. {
  1484. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1485. }
  1486. }
  1487. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1488. {
  1489. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1490. }
  1491. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1492. {
  1493. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1494. }
  1495. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1496. }
  1497. //领料申请退料
  1498. public DataTable GetGridJsonLLSQTL(string queryJson, ref Pagination jqgridparam)
  1499. {
  1500. DataTable dt = new DataTable();
  1501. var queryParam = queryJson.ToJObject();
  1502. List<DbParameter> parameter = new List<DbParameter>();
  1503. object Figure = GetDecimalDigits();
  1504. #region [SQL]
  1505. string sql = @"select a.ID,a.ApplyNegCode,cast(a.Sequence as int) as Sequence,a.SourceDetailID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
  1506. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.IssueNegQuantity AS DECIMAL(18,{0})) as IssueNegQuantity ,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  1507. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1508. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1509. from ICSMOApplyNegDetail a
  1510. left join ICSMOApplyNeg d on a.ApplyNegCode=d.ApplyNegCode and a.WorkPoint=d.WorkPoint
  1511. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1512. left join (
  1513. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  1514. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='12'
  1515. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  1516. )c
  1517. on a.ApplyNegCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  1518. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1519. WHERE d.Type='2'";
  1520. sql = string.Format(sql, Figure);
  1521. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1522. #endregion
  1523. if (!string.IsNullOrWhiteSpace(queryJson))
  1524. {
  1525. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1526. {
  1527. sql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1528. }
  1529. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1530. {
  1531. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1532. }
  1533. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1534. {
  1535. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1536. }
  1537. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1538. {
  1539. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1540. }
  1541. }
  1542. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1543. {
  1544. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1545. }
  1546. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1547. {
  1548. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1549. }
  1550. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1551. }
  1552. /// <summary>
  1553. /// 拒收生成条码
  1554. /// </summary>
  1555. /// <param name="POCode"></param>
  1556. /// <param name="PORow"></param>
  1557. /// <param name="keyValue"></param>
  1558. /// <returns></returns>
  1559. public int SubmitFormJSD(string DNCode, string Sequence, string keyValue, string WorkPoint)
  1560. {
  1561. var queryParam = keyValue.ToJObject();
  1562. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1563. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1564. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1565. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1566. decimal LOTQTY = minPackQty;
  1567. string Pre = "JS" + DNCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1568. string sql = string.Empty;
  1569. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1570. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1571. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1572. string sqls = string.Empty;
  1573. string Colspan = "";
  1574. 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();
  1575. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1576. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1577. if (ExtensionID == null)
  1578. {
  1579. ExtensionID = Guid.NewGuid();
  1580. 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)
  1581. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1582. ExtensionID, 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(),
  1583. MUSER, MUSERNAME, WorkPoints);
  1584. }
  1585. for (int i = 0; i < createPageCount; i++)
  1586. {
  1587. if (i + 1 == createPageCount)
  1588. {
  1589. if (minPackQty * createPageCount > thisCreateQty)
  1590. {
  1591. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1592. }
  1593. }
  1594. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1595. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1596. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1597. LotNo, DNCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1598. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  1599. //{
  1600. sql += string.Format(@"
  1601. insert into ICSInventoryLot
  1602. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1603. select
  1604. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','10','{3}','{4}', getdate(),'{5}','{9}'
  1605. from ICSDeliveryNotice where DNCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
  1606. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, DNCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1607. sql += "\r\n";
  1608. //}
  1609. }
  1610. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1611. return count;
  1612. }
  1613. /// <summary>
  1614. /// 委外拒收生成条码
  1615. /// </summary>
  1616. /// <param name="POCode"></param>
  1617. /// <param name="PORow"></param>
  1618. /// <param name="keyValue"></param>
  1619. /// <returns></returns>
  1620. public int SubmitFormWWJSD(string ODNCode, string Sequence, string keyValue, string WorkPoint)
  1621. {
  1622. var queryParam = keyValue.ToJObject();
  1623. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1624. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1625. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1626. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1627. decimal LOTQTY = minPackQty;
  1628. string Pre = "OJS" + ODNCode + Sequence;
  1629. string sql = string.Empty;
  1630. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1631. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1632. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1633. string sqls = string.Empty;
  1634. string Colspan = "";
  1635. 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();
  1636. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1637. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1638. if (ExtensionID == null)
  1639. {
  1640. ExtensionID = Guid.NewGuid();
  1641. 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)
  1642. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1643. ExtensionID, 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(),
  1644. MUSER, MUSERNAME, WorkPoints);
  1645. }
  1646. for (int i = 0; i < createPageCount; i++)
  1647. {
  1648. if (i + 1 == createPageCount)
  1649. {
  1650. if (minPackQty * createPageCount > thisCreateQty)
  1651. {
  1652. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1653. }
  1654. }
  1655. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1656. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1657. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1658. LotNo, ODNCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1659. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  1660. //{
  1661. sql += string.Format(@"
  1662. insert into ICSInventoryLot
  1663. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1664. select
  1665. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','11','{3}','{4}', getdate(),'{5}','{9}'
  1666. from ICSODeliveryNotice where ODNCode='{6}' and Sequence='{7}' and WorkPoint='{5}'",
  1667. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ODNCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1668. sql += "\r\n";
  1669. //}
  1670. }
  1671. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1672. return count;
  1673. }
  1674. /// <summary>
  1675. /// 点击审核到货单生成条码(审核到货单)
  1676. /// </summary>
  1677. public DataTable GetSubGridJsonJSDByCreate(string DNCode, string Sequence, string WorkPoint)
  1678. {
  1679. DataTable dt = new DataTable();
  1680. object Figure = GetDecimalDigits();
  1681. List<DbParameter> parameter = new List<DbParameter>();
  1682. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1683. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1684. from ICSDeliveryNotice a
  1685. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1686. left join (select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1687. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='10'
  1688. group by b.TransCode,b.TransSequence
  1689. ) c on a.DNCode=c.TransCode and a.Sequence=c.TransSequence
  1690. WHERE a.DNType='3'
  1691. and a.DNCode='" + DNCode + "' and a.Sequence='" + Sequence + "'";
  1692. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1693. sql = string.Format(sql, Figure);
  1694. return Repository().FindTableBySql(sql.ToString());
  1695. }
  1696. /// <summary>
  1697. /// 点击审核委外到货单生成条码(审核委外到货单)
  1698. /// </summary>
  1699. public DataTable GetSubGridJsonWWJSDByCreate(string ODNCode, string Sequence, string WorkPoint)
  1700. {
  1701. DataTable dt = new DataTable();
  1702. object Figure = GetDecimalDigits();
  1703. List<DbParameter> parameter = new List<DbParameter>();
  1704. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1705. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1706. from ICSODeliveryNotice a
  1707. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1708. left join (select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1709. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='11'
  1710. group by b.TransCode,b.TransSequence
  1711. ) c on a.ODNCode=c.TransCode and a.Sequence=c.TransSequence
  1712. WHERE a.ODNType='3'
  1713. and a.ODNCode='" + ODNCode + "' and a.Sequence='" + Sequence + "'";
  1714. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1715. sql = string.Format(sql, Figure);
  1716. return Repository().FindTableBySql(sql.ToString());
  1717. }
  1718. public DataTable GetSubGridJsonLLSQDByCreate(string ApplyNegCode, string Sequence, string WorkPoint)
  1719. {
  1720. DataTable dt = new DataTable();
  1721. object Figure = GetDecimalDigits();
  1722. List<DbParameter> parameter = new List<DbParameter>();
  1723. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1724. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1725. from ICSMOApplyNegDetail a
  1726. left join ICSMOApplyNeg d on a.ApplyNegCode=d.ApplyNegCode and a.WorkPoint=d.WorkPoint
  1727. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1728. left join (
  1729. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1730. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='12'
  1731. group by b.TransCode,b.TransSequence
  1732. ) c on a.ApplyNegCode=c.TransCode and a.Sequence=c.TransSequence
  1733. WHERE d.Type='2'
  1734. and a.ApplyNegCode='" + ApplyNegCode + "' and a.Sequence='" + Sequence + "'";
  1735. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1736. sql = string.Format(sql, Figure);
  1737. return Repository().FindTableBySql(sql.ToString());
  1738. }
  1739. //领料申请退料生成条码
  1740. public int SubmitFormLLSQTL(string ApplyNegCode, string Sequence, string keyValue, string WorkPoint)
  1741. {
  1742. var queryParam = keyValue.ToJObject();
  1743. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1744. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1745. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1746. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1747. decimal LOTQTY = minPackQty;
  1748. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1749. //string VenCode = GetVendorCode(ApplyNegCode, Sequence, WorkPoint);
  1750. string Pre = "MA" + ApplyNegCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1751. string sql = string.Empty;
  1752. //string VendorLot = queryParam["VendorLot"].ToString();
  1753. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1754. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1755. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1756. string sqls = string.Empty;
  1757. string Colspan = "";
  1758. 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();
  1759. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1760. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1761. if (ExtensionID == null)
  1762. {
  1763. ExtensionID = Guid.NewGuid();
  1764. 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)
  1765. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1766. ExtensionID, 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(),
  1767. MUSER, MUSERNAME, WorkPoints);
  1768. }
  1769. for (int i = 0; i < createPageCount; i++)
  1770. {
  1771. if (i + 1 == createPageCount)
  1772. {
  1773. if (minPackQty * createPageCount > thisCreateQty)
  1774. {
  1775. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1776. }
  1777. }
  1778. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1779. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1780. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1781. LotNo, ApplyNegCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1782. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  1783. //{
  1784. sql += string.Format(@"insert into ICSInventoryLot
  1785. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1786. select
  1787. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','12','{3}','{4}', getdate(),'{5}','{9}'
  1788. from ICSMOApplyNegDetail where ApplyNegCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  1789. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ApplyNegCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1790. sql += "\r\n";
  1791. //}
  1792. }
  1793. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1794. return count;
  1795. }
  1796. //材料出库退料
  1797. public DataTable GetGridJsonCLCK(string queryJson, ref Pagination jqgridparam)
  1798. {
  1799. DataTable dt = new DataTable();
  1800. var queryParam = queryJson.ToJObject();
  1801. List<DbParameter> parameter = new List<DbParameter>();
  1802. object Figure = GetDecimalDigits();
  1803. #region [SQL]
  1804. string sql = @"
  1805. select a.ID,a.ApplyNegCode,cast(a.Sequence as int) as Sequence,a.SourceDetailID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
  1806. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity
  1807. CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.IssueNegQuantity AS DECIMAL(18,{0})) as IssueNegQuantity ,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  1808. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1809. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1810. from ICSMOApplyNegDetail a
  1811. left join ICSMOApplyNeg d on a.ApplyNegCode=d.ApplyNegCode and a.WorkPoint=d.WorkPoint
  1812. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1813. left join (
  1814. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  1815. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='13'
  1816. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  1817. )c
  1818. on a.ApplyNegCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  1819. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1820. WHERE d.Type='3'";
  1821. sql = string.Format(sql, Figure);
  1822. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1823. #endregion
  1824. if (!string.IsNullOrWhiteSpace(queryJson))
  1825. {
  1826. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1827. {
  1828. sql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1829. }
  1830. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1831. {
  1832. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1833. }
  1834. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1835. {
  1836. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1837. }
  1838. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1839. {
  1840. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1841. }
  1842. }
  1843. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1844. {
  1845. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1846. }
  1847. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1848. {
  1849. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1850. }
  1851. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1852. }
  1853. //材料出库退料
  1854. public DataTable GetSubGridJsonCLCKByCreate(string ApplyNegCode, string Sequence, string WorkPoint)
  1855. {
  1856. DataTable dt = new DataTable();
  1857. object Figure = GetDecimalDigits();
  1858. List<DbParameter> parameter = new List<DbParameter>();
  1859. string sql = @"select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1860. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1861. from ICSMOApplyNegDetail a
  1862. left join ICSMOApplyNeg d on a.ApplyNegCode=d.ApplyNegCode and a.WorkPoint=d.WorkPoint
  1863. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1864. left join (
  1865. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1866. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='13'
  1867. group by b.TransCode,b.TransSequence
  1868. ) c on a.ApplyNegCode=c.TransCode and a.Sequence=c.TransSequence
  1869. WHERE d.Type='3'
  1870. and a.ApplyNegCode='" + ApplyNegCode + "' and a.Sequence='" + Sequence + "'";
  1871. sql += " and a.WorkPoint='" + WorkPoint + "'";
  1872. sql = string.Format(sql, Figure);
  1873. return Repository().FindTableBySql(sql.ToString());
  1874. }
  1875. //材料出库退料生成条码
  1876. public int SubmitFormCLCKT(string ApplyNegCode, string Sequence, string keyValue, string WorkPoint)
  1877. {
  1878. var queryParam = keyValue.ToJObject();
  1879. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  1880. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  1881. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  1882. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  1883. decimal LOTQTY = minPackQty;
  1884. string Pre = "MD" + ApplyNegCode + (Convert.ToInt32(Sequence)).ToString("D4");
  1885. string sql = string.Empty;
  1886. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1887. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1888. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  1889. string sqls = string.Empty;
  1890. string Colspan = "";
  1891. 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();
  1892. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  1893. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  1894. if (ExtensionID == null)
  1895. {
  1896. ExtensionID = Guid.NewGuid();
  1897. 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)
  1898. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  1899. ExtensionID, 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(),
  1900. MUSER, MUSERNAME, WorkPoints);
  1901. }
  1902. for (int i = 0; i < createPageCount; i++)
  1903. {
  1904. if (i + 1 == createPageCount)
  1905. {
  1906. if (minPackQty * createPageCount > thisCreateQty)
  1907. {
  1908. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  1909. }
  1910. }
  1911. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  1912. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1913. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  1914. LotNo, ApplyNegCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  1915. sql += string.Format(@"insert into ICSInventoryLot
  1916. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  1917. select
  1918. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','13','{3}','{4}', getdate(),'{5}','{9}'
  1919. from ICSMOApplyNegDetail where ApplyNegCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  1920. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, ApplyNegCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  1921. sql += "\r\n";
  1922. }
  1923. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  1924. return count;
  1925. }
  1926. public DataTable GetGridJsonWWLLTL(string queryJson, ref Pagination jqgridparam)
  1927. {
  1928. DataTable dt = new DataTable();
  1929. var queryParam = queryJson.ToJObject();
  1930. List<DbParameter> parameter = new List<DbParameter>();
  1931. object Figure = GetDecimalDigits();
  1932. #region [SQL]
  1933. string sql = @"select a.ID,a.OApplyNegCode,cast(a.Sequence as int) as Sequence,a.SourceDetailID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
  1934. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.IssueNegQuantity AS DECIMAL(18,{0})) as IssueNegQuantity ,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  1935. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1936. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1937. from ICSOApplyNegDetail a
  1938. left join ICSOApplyNeg d on a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
  1939. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1940. left join (
  1941. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  1942. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='14'
  1943. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  1944. )c
  1945. on a.OApplyNegCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  1946. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1947. WHERE d.Type='2'";
  1948. sql = string.Format(sql, Figure);
  1949. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1950. #endregion
  1951. if (!string.IsNullOrWhiteSpace(queryJson))
  1952. {
  1953. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1954. {
  1955. sql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1956. }
  1957. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1958. {
  1959. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1960. }
  1961. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1962. {
  1963. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1964. }
  1965. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1966. {
  1967. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1968. }
  1969. }
  1970. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1971. {
  1972. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1973. }
  1974. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1975. {
  1976. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1977. }
  1978. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1979. }
  1980. /// <summary>
  1981. /// 点击委外领料退料生成条码
  1982. /// </summary>
  1983. public DataTable GetSubGridJsonWWLLByCreate(string OApplyNegCode, string Sequence, string WorkPoint)
  1984. {
  1985. DataTable dt = new DataTable();
  1986. object Figure = GetDecimalDigits();
  1987. List<DbParameter> parameter = new List<DbParameter>();
  1988. string sql = @"
  1989. select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  1990. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  1991. from ICSOApplyNegDetail a
  1992. left join ICSOApplyNeg d on a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
  1993. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  1994. left join (
  1995. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  1996. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='14'
  1997. group by b.TransCode,b.TransSequence
  1998. ) c on a.OApplyNegCode=c.TransCode and a.Sequence=c.TransSequence
  1999. WHERE d.Type='2'
  2000. and a.OApplyNegCode='" + OApplyNegCode + "' and a.Sequence='" + Sequence + "'";
  2001. sql += " and a.WorkPoint='" + WorkPoint + "'";
  2002. sql = string.Format(sql, Figure);
  2003. return Repository().FindTableBySql(sql.ToString());
  2004. }
  2005. //委外领料申请退料
  2006. public int SubmitFormWWLL(string OApplyNegCode, string Sequence, string keyValue, string WorkPoint)
  2007. {
  2008. var queryParam = keyValue.ToJObject();
  2009. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  2010. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  2011. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  2012. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  2013. decimal LOTQTY = minPackQty;
  2014. string Pre = "OMA" + OApplyNegCode + (Convert.ToInt32(Sequence)).ToString("D4");
  2015. string sql = string.Empty;
  2016. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2017. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2018. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  2019. string sqls = string.Empty;
  2020. string Colspan = "";
  2021. 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();
  2022. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  2023. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  2024. if (ExtensionID == null)
  2025. {
  2026. ExtensionID = Guid.NewGuid();
  2027. 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)
  2028. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  2029. ExtensionID, 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(),
  2030. MUSER, MUSERNAME, WorkPoints);
  2031. }
  2032. for (int i = 0; i < createPageCount; i++)
  2033. {
  2034. if (i + 1 == createPageCount)
  2035. {
  2036. if (minPackQty * createPageCount > thisCreateQty)
  2037. {
  2038. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  2039. }
  2040. }
  2041. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  2042. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2043. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  2044. LotNo, OApplyNegCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  2045. sql += string.Format(@"insert into ICSInventoryLot
  2046. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  2047. select
  2048. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','14','{3}','{4}', getdate(),'{5}','{9}'
  2049. from ICSOApplyNegDetail where OApplyNegCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  2050. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, OApplyNegCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  2051. sql += "\r\n";
  2052. }
  2053. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  2054. return count;
  2055. }
  2056. //委外材料出库
  2057. public DataTable GetGridJsonWWCLCK(string queryJson, ref Pagination jqgridparam)
  2058. {
  2059. DataTable dt = new DataTable();
  2060. var queryParam = queryJson.ToJObject();
  2061. List<DbParameter> parameter = new List<DbParameter>();
  2062. object Figure = GetDecimalDigits();
  2063. #region [SQL]
  2064. string sql = @"select a.ID,a.OApplyNegCode,cast(a.Sequence as int) as Sequence,a.SourceDetailID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
  2065. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity ,CAST(a.Amount AS DECIMAL(18,{0})) as Amount,CAST(a.IssueNegQuantity AS DECIMAL(18,{0})) as IssueNegQuantity ,a.ExtensionID,a.MUSERName,a.MTIME ,CAST(c.LOTQTY AS DECIMAL(18,{0})) as LOTQTY
  2066. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2067. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2068. from ICSOApplyNegDetail a
  2069. left join ICSOApplyNeg d on a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
  2070. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2071. left join (
  2072. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  2073. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='15'
  2074. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  2075. )c
  2076. on a.OApplyNegCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  2077. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2078. WHERE d.Type='3'";
  2079. sql = string.Format(sql, Figure);
  2080. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  2081. #endregion
  2082. if (!string.IsNullOrWhiteSpace(queryJson))
  2083. {
  2084. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  2085. {
  2086. sql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  2087. }
  2088. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  2089. {
  2090. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  2091. }
  2092. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  2093. {
  2094. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  2095. }
  2096. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  2097. {
  2098. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  2099. }
  2100. }
  2101. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  2102. {
  2103. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  2104. }
  2105. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  2106. {
  2107. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  2108. }
  2109. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  2110. }
  2111. //委外材料出库
  2112. public DataTable GetSubGridJsonWWCLByCreate(string OApplyNegCode, string Sequence, string WorkPoint)
  2113. {
  2114. DataTable dt = new DataTable();
  2115. object Figure = GetDecimalDigits();
  2116. List<DbParameter> parameter = new List<DbParameter>();
  2117. string sql = @"
  2118. select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  2119. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  2120. from ICSOApplyNegDetail a
  2121. left join ICSOApplyNeg d on a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
  2122. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2123. left join (
  2124. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  2125. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='15'
  2126. group by b.TransCode,b.TransSequence
  2127. ) c on a.OApplyNegCode=c.TransCode and a.Sequence=c.TransSequence
  2128. WHERE d.Type='3'
  2129. and a.OApplyNegCode='" + OApplyNegCode + "' and a.Sequence='" + Sequence + "'";
  2130. sql += " and a.WorkPoint='" + WorkPoint + "'";
  2131. sql = string.Format(sql, Figure);
  2132. return Repository().FindTableBySql(sql.ToString());
  2133. }
  2134. //委外材料出库
  2135. public int SubmitFormWWCL(string OApplyNegCode, string Sequence, string keyValue, string WorkPoint)
  2136. {
  2137. var queryParam = keyValue.ToJObject();
  2138. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  2139. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  2140. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  2141. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  2142. decimal LOTQTY = minPackQty;
  2143. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2144. //string VenCode = GetVendorCode(ApplyNegCode, Sequence, WorkPoint);
  2145. string Pre = "OMD" + OApplyNegCode + (Convert.ToInt32(Sequence)).ToString("D4");
  2146. string sql = string.Empty;
  2147. //string VendorLot = queryParam["VendorLot"].ToString();
  2148. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2149. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2150. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  2151. string sqls = string.Empty;
  2152. string Colspan = "";
  2153. 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();
  2154. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  2155. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  2156. if (ExtensionID == null)
  2157. {
  2158. ExtensionID = Guid.NewGuid();
  2159. 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)
  2160. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  2161. ExtensionID, 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(),
  2162. MUSER, MUSERNAME, WorkPoints);
  2163. }
  2164. for (int i = 0; i < createPageCount; i++)
  2165. {
  2166. if (i + 1 == createPageCount)
  2167. {
  2168. if (minPackQty * createPageCount > thisCreateQty)
  2169. {
  2170. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  2171. }
  2172. }
  2173. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  2174. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2175. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  2176. LotNo, OApplyNegCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  2177. //if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  2178. //{
  2179. sql += string.Format(@"insert into ICSInventoryLot
  2180. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  2181. select
  2182. newid(),'{0}',InvCode,'{1}','{10}','{2}','{8}','15','{3}','{4}', getdate(),'{5}','{9}'
  2183. from ICSOApplyNegDetail where OApplyNegCode='{6}' and Sequence='{7}' and WorkPoint='{5}' ",
  2184. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, OApplyNegCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  2185. sql += "\r\n";
  2186. //}
  2187. }
  2188. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  2189. return count;
  2190. }
  2191. public DataTable SelectICSExtensionEnable(string BeginTime, string EndTime)
  2192. {
  2193. string sql = @"select ColCode from ICSExtensionEnable
  2194. where Enable=0
  2195. order by cast(EATTRIBUTE1 as int)";
  2196. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2197. return dt;
  2198. }
  2199. //返工工单
  2200. public DataTable GetGridJsonFGGD(string queryJson, ref Pagination jqgridparam)
  2201. {
  2202. DataTable dt = new DataTable();
  2203. var queryParam = queryJson.ToJObject();
  2204. List<DbParameter> parameter = new List<DbParameter>();
  2205. object Figure = GetDecimalDigits();
  2206. #region [SQL]
  2207. string sql = @"select a.ID,d.MOCode,d.Sequence+'-'+ a.Sequence as Sequence,a.PickID,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
  2208. CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity
  2209. 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
  2210. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2211. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2212. from ICSMOPick a
  2213. left join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint
  2214. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2215. left join (
  2216. select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
  2217. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='16'
  2218. group by mm.TransCode,mm.TransSequence,ee.WorkPoint
  2219. )c
  2220. on d.MOCode=c.TransCode and d.Sequence+'-'+a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  2221. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2222. where a.EATTRIBUTE1='1' and d.EATTRIBUTE1='1'";
  2223. sql = string.Format(sql, Figure);
  2224. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  2225. #endregion
  2226. if (!string.IsNullOrWhiteSpace(queryJson))
  2227. {
  2228. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  2229. {
  2230. sql += " and d.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  2231. }
  2232. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  2233. {
  2234. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  2235. }
  2236. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  2237. {
  2238. sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  2239. }
  2240. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  2241. {
  2242. sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  2243. }
  2244. }
  2245. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  2246. {
  2247. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  2248. }
  2249. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  2250. {
  2251. sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  2252. }
  2253. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  2254. }
  2255. public DataTable GetSubGridJsonFGGDCreate(string FGGDMOCode, string Sequence, string WorkPoint)
  2256. {
  2257. DataTable dt = new DataTable();
  2258. object Figure = GetDecimalDigits();
  2259. List<DbParameter> parameter = new List<DbParameter>();
  2260. string sql = @"
  2261. select a.InvCode,b.InvName,b.InvStd,b.InvUnit, CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity,CAST( a.Amount as DECIMAL(18,{0})) as Amount,CAST( isnull(c.LOTQTY,0) as DECIMAL(18,{0})) as CreatedQty,
  2262. CAST( (a.Quantity-ISNULL(c.LOTQTY,0)) as DECIMAL(18,{0})) as thisCreateQty,isnull(b.EffectiveEnable,0) as EffectiveEnable, CAST( isnull(b.EffectiveDays,0) as DECIMAL(18,{0})) as EffectiveDays
  2263. from ICSMOPick a
  2264. left join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint
  2265. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2266. left join (
  2267. select b.TransCode,b.TransSequence,sum(isnull(Quantity,0)) LOTQTY from ICSInventoryLot a
  2268. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.Type='16'
  2269. group by b.TransCode,b.TransSequence
  2270. ) c on d.MOCode=c.TransCode and d.Sequence+'-'+a.Sequence=c.TransSequence
  2271. WHERE 1=1
  2272. and d.MOCode='" + FGGDMOCode + "' and d.Sequence+'-'+a.Sequence='" + Sequence + "'";
  2273. sql += " and a.WorkPoint='" + WorkPoint + "'";
  2274. sql = string.Format(sql, Figure);
  2275. return Repository().FindTableBySql(sql.ToString());
  2276. }
  2277. //返工工单
  2278. public int SubmitFormFGGD(string FGGDMOCode, string Sequence, string keyValue, string WorkPoint)
  2279. {
  2280. var queryParam = keyValue.ToJObject();
  2281. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  2282. int createPageCount = Convert.ToInt32(queryParam["createPageCount"].ToString());
  2283. decimal minPackQty = Convert.ToDecimal(queryParam["minPackQty"].ToString());
  2284. decimal thisCreateQty = Convert.ToDecimal(queryParam["thisCreateQty"].ToString());
  2285. decimal LOTQTY = minPackQty;
  2286. string Pre = "FG" + FGGDMOCode + (Convert.ToInt32(Sequence)).ToString("D4");
  2287. string sql = string.Empty;
  2288. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2289. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2290. string PRODUCTDATE = queryParam["PRODUCTDATE"].ToString();
  2291. string sqls = string.Empty;
  2292. string Colspan = "";
  2293. 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();
  2294. sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoints);
  2295. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  2296. if (ExtensionID == null)
  2297. {
  2298. ExtensionID = Guid.NewGuid();
  2299. 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)
  2300. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  2301. ExtensionID, 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(),
  2302. MUSER, MUSERNAME, WorkPoints);
  2303. }
  2304. for (int i = 0; i < createPageCount; i++)
  2305. {
  2306. if (i + 1 == createPageCount)
  2307. {
  2308. if (minPackQty * createPageCount > thisCreateQty)
  2309. {
  2310. LOTQTY = thisCreateQty - (minPackQty * (createPageCount - 1));
  2311. }
  2312. }
  2313. string LotNo = GetSerialCode(WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  2314. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2315. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}' )",
  2316. LotNo, FGGDMOCode, Sequence, MUSER, MUSERNAME, WorkPoints);
  2317. sql += string.Format(@"insert into ICSInventoryLot
  2318. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  2319. select
  2320. newid(),'{0}',a.InvCode,'{1}','{10}','{2}','{8}','16','{3}','{4}', getdate(),'{5}','{9}'
  2321. from ICSMOPick a left join ICSMO d on a.MODetailID=d.MODetailID and a.WorkPoint=d.WorkPoint where d.MOCode='{6}' and d.Sequence+'-'+a.Sequence='{7}' and a.WorkPoint='{5}' ",
  2322. LotNo, PRODUCTDATE, LOTQTY, MUSER, MUSERNAME, WorkPoints, FGGDMOCode, Sequence, ExtensionID, Convert.ToDecimal( Convert.ToDecimal(queryParam["Amount"].ToString())/ minPackQty* LOTQTY)/ minPackQty* LOTQTY, queryParam["ExpirationDate"].ToString());
  2323. sql += "\r\n";
  2324. }
  2325. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  2326. return count;
  2327. }
  2328. public object GetDecimalDigits()
  2329. {
  2330. try
  2331. {
  2332. string sql = string.Empty;
  2333. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1'";
  2334. object Figure = SqlHelper.ExecuteScalar(sql);
  2335. return Figure;
  2336. }
  2337. catch (Exception ex)
  2338. {
  2339. throw new Exception(ex.Message.ToString());
  2340. }
  2341. }
  2342. public object GetBatchEnable(string InvCode)
  2343. {
  2344. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2345. string sql = @"select BatchEnable from ICSInventory where InvCode='{0}' and WorkPoint='{1}'";
  2346. sql = string.Format(sql, InvCode, WorkPoint);
  2347. object Enable= SqlHelper.ExecuteScalar(sql);
  2348. return Enable;
  2349. }
  2350. //工单生成条码 上传功能 倒冲U8
  2351. public string CallU8ManufactureReceiveDoc(string Code, string Sequence)
  2352. {
  2353. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  2354. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2355. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2356. var MTIME = System.DateTime.Now.ToString("s");
  2357. string msg = "";
  2358. string connstr = SqlHelper.DataCenterConnString;
  2359. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connstr);
  2360. conn.Open();
  2361. SqlTransaction sqlTran = conn.BeginTransaction();
  2362. SqlCommand cmd = new SqlCommand();
  2363. cmd.Transaction = sqlTran;
  2364. cmd.Connection = conn;
  2365. try
  2366. {
  2367. List<ICSManufactureReceiveDocASKDC> asn = new List<ICSManufactureReceiveDocASKDC>();
  2368. ICSManufactureReceiveDocASKDC ass = new ICSManufactureReceiveDocASKDC();
  2369. #region 根据工单号+行号取出批次数量
  2370. string sqlLotBC = @"select distinct f.BatchCode from ICSInventoryLot a
  2371. left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  2372. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2373. left join dbo.ICSBackflushBCLog d on d.TransCode=c.TransCode and d.TransSequence=c.TransSequence and f.BatchCode=d.BatchCode
  2374. where c.TransCode='{0}' and c.TransSequence='{1}' and a.WorkPoint='{2}' and isnull(d.ID,'')=''";
  2375. sqlLotBC = string.Format(sqlLotBC, Code, Sequence, WorkPoint);
  2376. DataTable dtLotBC = SqlCommandHelper.SQlReturnData(sqlLotBC, cmd);
  2377. if (dtLotBC.Rows.Count<=0)
  2378. {
  2379. throw new Exception("该工单,暂无可上传批次!");
  2380. }
  2381. // DataTable dtLotBC = Repository().FindTableBySql(sqlLotBC.ToString());
  2382. var BCNum = dtLotBC.Rows.Count;
  2383. var LotAllBC = "";
  2384. string sqlBKLog = "";
  2385. foreach (DataRow dr in dtLotBC.Rows)
  2386. {
  2387. LotAllBC += dr["BatchCode"].ToString() + "|";
  2388. sqlBKLog += @" Insert into ICSBackflushBCLog(ID, TransCode,TransSequence,BatchCode,MUSER,MUSERName,MTIME,WorkPoint)
  2389. Values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}')";
  2390. sqlBKLog = string.Format(sqlBKLog, Code, Sequence, dr["BatchCode"].ToString(), MUSER, MUSERNAME, MTIME, WorkPoint);
  2391. }
  2392. SqlCommandHelper.CmdExecuteNonQuery(sqlBKLog, cmd);
  2393. LotAllBC = "|" + LotAllBC.TrimEnd('|') + "|";
  2394. #endregion
  2395. #region 查询传给U8的表头信息
  2396. string sqlHead = @"select * from dbo.ICSMO a where a.MOCode='{0}' and a.Sequence='{1}' and a.WorkPoint='{2}'";
  2397. sqlHead = string.Format(sqlHead, Code, Sequence, WorkPoint);
  2398. DataTable dtHead = SqlCommandHelper.SQlReturnData(sqlHead, cmd);
  2399. // DataTable dtHead = Repository().FindTableBySql(sqlHead.ToString());
  2400. #endregion
  2401. #region 查询传给U8的表体信息
  2402. string sqlSubject = @"select b.Sequence as Seq,b.PickID,b.InvCode,b.WHCode,b.EATTRIBUTE2,b.EATTRIBUTE1,b.Amount ,c.ClassCode
  2403. from dbo.ICSMO a left join dbo.ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint and b.EATTRIBUTE1 <>'1'
  2404. inner join dbo.ICSInventory c on b.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2405. where a.MOCode='{0}' and a.Sequence='{1}' and a.WorkPoint='{2}'";
  2406. sqlSubject = string.Format(sqlSubject, Code, Sequence, WorkPoint);
  2407. DataTable dtSubject = SqlCommandHelper.SQlReturnData(sqlSubject, cmd);
  2408. if (dtSubject.Rows.Count <= 0)
  2409. {
  2410. throw new Exception("该工单下暂无可上传的子行!");
  2411. }
  2412. // DataTable dtSubject = Repository().FindTableBySql(sqlSubject.ToString());
  2413. var Identification = Guid.NewGuid().ToString();
  2414. foreach (DataRow item in dtSubject.Rows)
  2415. {
  2416. //根据物料汇总条码的批次
  2417. var OffspringBc = "";
  2418. string SqlBackflush = @"select a.LotNo,a.Quantity,c.BatchCode from dbo.ICSWareHouseLotInfo a
  2419. left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  2420. left join dbo.ICSExtension c on b.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
  2421. where a.InvCode='{0}' and a.WorkPoint='{1}' and a.WarehouseCode='{2}' and a.Quantity<>0 order by InDate asc";
  2422. SqlBackflush = string.Format(SqlBackflush, item["InvCode"].ToString(), WorkPoint, item["WHCode"].ToString());
  2423. DataTable DtBackflush = SqlCommandHelper.SQlReturnData(SqlBackflush, cmd);
  2424. //DataTable DtBackflush = Repository().FindTableBySql(SqlBackflush.ToString());
  2425. var InvAllNum = Convert.ToDecimal(item["EATTRIBUTE2"]) * BCNum;
  2426. //判断这个物料是不是10或者20开头 如是需wms库存中先扣除
  2427. if (item["InvCode"].ToString().StartsWith("10") || item["InvCode"].ToString().StartsWith("20"))
  2428. {
  2429. if (DtBackflush.Rows.Count <= 0)
  2430. {
  2431. throw new Exception("料号:" + item["InvCode"].ToString() + "库存数量不足,无法上传!");
  2432. }
  2433. string sqlBackKC = string.Empty;
  2434. //在这里做倒冲
  2435. // decimal AllThisMakeNum = 0;
  2436. foreach (DataRow itemDeatil in DtBackflush.Rows)
  2437. {
  2438. if (InvAllNum == 0)
  2439. {
  2440. break;
  2441. }
  2442. decimal ThisMakeNum = InvAllNum > Convert.ToDecimal(itemDeatil["Quantity"]) ? Convert.ToDecimal(itemDeatil["Quantity"]) : InvAllNum;
  2443. if (InvAllNum != 0)
  2444. {
  2445. sqlBackKC += @"update ICSWareHouseLotInfo set Quantity=Quantity-'{5}' where LotNo='{3}'
  2446. insert into ICSWareHouseLotInfolog
  2447. (ID,Identification,TransCode,TransSequence,LotNo,InvCode,FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,Memo,Lock,TransType,BusinessCode,ERPUpload,MUSER,MUSERName,MTIME,WorkPoint)
  2448. select
  2449. newid(),'{0}','{1}','{2}','{3}','{4}',WarehouseCode,LocationCode,'','','{5}','','0','12','30','1','{6}','{7}','{8}','{9}'
  2450. from ICSWareHouseLotInfo where LotNo='{3}' and WorkPoint='{9}'";
  2451. sqlBackKC = string.Format(sqlBackKC, Identification, Code, Sequence, itemDeatil["LotNo"].ToString(), item["InvCode"].ToString(), ThisMakeNum, MUSER, MUSERNAME, MTIME, WorkPoint);
  2452. InvAllNum = InvAllNum - ThisMakeNum;
  2453. //AllThisMakeNum += ThisMakeNum;
  2454. //if (InvAllNum- AllThisMakeNum<0)
  2455. //{
  2456. // throw new Exception("料号:" + item["InvCode"].ToString() + "库存数量不足,无法上传!");
  2457. //}
  2458. //OffspringBc += item["BatchCode"].ToString() + "|";
  2459. }
  2460. ICSManufactureReceiveDocASKDCS DetailList = new ICSManufactureReceiveDocASKDCS();
  2461. DetailList.Seq = item["Seq"].ToString();
  2462. DetailList.PickID = item["PickID"].ToString();
  2463. DetailList.InvCode = item["InvCode"].ToString();
  2464. DetailList.WHCode = item["WHCode"].ToString();
  2465. DetailList.Quantity = ThisMakeNum;
  2466. DetailList.Amount = Convert.ToDecimal(item["Amount"]);
  2467. DetailList.ProjectCode = "";
  2468. DetailList.Brand = "";
  2469. DetailList.BatchCode = itemDeatil["BatchCode"].ToString();
  2470. DetailList.cFree1 = "";
  2471. DetailList.cFree2 = "";
  2472. DetailList.cFree3 = "";
  2473. DetailList.cFree4 = "";
  2474. DetailList.cFree5 = "";
  2475. DetailList.cFree6 = "";
  2476. DetailList.cFree7 = "";
  2477. DetailList.cFree8 = "";
  2478. DetailList.cFree9 = "";
  2479. DetailList.cFree10 = "";
  2480. ass.details.Add(DetailList);
  2481. }
  2482. if (InvAllNum > 0)
  2483. {
  2484. throw new Exception("料号:" + item["InvCode"].ToString() + "库存数量不足,无法上传!");
  2485. }
  2486. SqlCommandHelper.CmdExecuteNonQuery(sqlBackKC, cmd);
  2487. }
  2488. else
  2489. {
  2490. ICSManufactureReceiveDocASKDCS DetailList = new ICSManufactureReceiveDocASKDCS();
  2491. DetailList.Seq = item["Seq"].ToString();
  2492. DetailList.PickID = item["PickID"].ToString();
  2493. DetailList.InvCode = item["InvCode"].ToString();
  2494. DetailList.WHCode = item["WHCode"].ToString();
  2495. DetailList.Quantity = Convert.ToDecimal(item["EATTRIBUTE2"]) * BCNum;
  2496. DetailList.Amount = Convert.ToDecimal(item["Amount"]);
  2497. DetailList.ProjectCode = "";
  2498. DetailList.Brand = "";
  2499. DetailList.BatchCode = "";
  2500. DetailList.cFree1 = "";
  2501. DetailList.cFree2 = "";
  2502. DetailList.cFree3 = "";
  2503. DetailList.cFree4 = "";
  2504. DetailList.cFree5 = "";
  2505. DetailList.cFree6 = "";
  2506. DetailList.cFree7 = "";
  2507. DetailList.cFree8 = "";
  2508. DetailList.cFree9 = "";
  2509. DetailList.cFree10 = "";
  2510. ass.details.Add(DetailList);
  2511. }
  2512. //OffspringBc = "|" + OffspringBc.TrimEnd('|') + "|";
  2513. }
  2514. #endregion
  2515. ass.User = MUSER;
  2516. ass.MTime = MTIME;
  2517. ass.WorkPoint = WorkPoint;
  2518. ass.DepCode = dtHead.Rows[0]["DepCode"].ToString();
  2519. ass.BatchCode = LotAllBC;
  2520. ass.MOCode = Code;
  2521. asn.Add(ass);
  2522. string input = JsonConvert.SerializeObject(asn);
  2523. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "ManufactureReceiveDocASKDC/Create";
  2524. string result = HttpPost(APIURL, input);
  2525. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  2526. string MessAge = Obj["Message"].ToString();
  2527. string Success = Obj["Success"].ToString();
  2528. if (Success.ToUpper() == "FALSE")
  2529. {
  2530. throw new Exception(MessAge);
  2531. }
  2532. cmd.Transaction.Commit();
  2533. }
  2534. catch (Exception ex)
  2535. {
  2536. cmd.Transaction.Rollback();
  2537. msg = ex.Message;
  2538. }
  2539. finally
  2540. {
  2541. if (conn.State == ConnectionState.Open)
  2542. {
  2543. conn.Close();
  2544. }
  2545. conn.Dispose();
  2546. }
  2547. return msg;
  2548. }
  2549. //接口api解析
  2550. public static string HttpPost(string url, string body)
  2551. {
  2552. try
  2553. {
  2554. Encoding encoding = Encoding.UTF8;
  2555. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  2556. request.Method = "POST";
  2557. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  2558. request.ContentType = "application/json; charset=utf-8";
  2559. byte[] buffer = encoding.GetBytes(body);
  2560. request.ContentLength = buffer.Length;
  2561. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  2562. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  2563. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  2564. {
  2565. return reader.ReadToEnd();
  2566. }
  2567. }
  2568. catch (WebException ex)
  2569. {
  2570. throw new Exception(ex.Message);
  2571. }
  2572. }
  2573. public string DeleteLoadingItemLot(string keyValue)
  2574. {
  2575. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2576. string msg = string.Empty;
  2577. string sqls= string.Empty;
  2578. keyValue = keyValue.TrimEnd(',');
  2579. string[] pairs = keyValue.Split(',');
  2580. foreach (string pair in pairs)
  2581. {
  2582. string sql = string.Format(@"SELECT * FROM dbo.ICSInspection
  2583. WHERE LotNo IN (SELECT LotNO FROM dbo.ICSInventoryLot WHERE LotNo IN ({0})) and WorkPoint in ('{1}')", pair.ToString(), WorkPoint);
  2584. DataTable dtASN = SqlHelper.GetDataTableBySql(sql);
  2585. if (dtASN != null && dtASN.Rows.Count > 0)
  2586. {
  2587. msg = "所选条码" + pair.ToString() + "已生成检验单,无法删除!";
  2588. }
  2589. sql = string.Format(@"SELECT * FROM dbo.ICSWareHouseLotInfo WHERE LotNO IN (SELECT LotNO FROM dbo.ICSInventoryLot WHERE LotNo = {0}) and WorkPoint in ('{1}')", pair.ToString(), WorkPoint);
  2590. DataTable dtCarton = SqlHelper.GetDataTableBySql(sql);
  2591. if (dtCarton != null && dtCarton.Rows.Count > 0)
  2592. {
  2593. msg += "所选条码" + pair.ToString() + "已入库,无法删除!";
  2594. }
  2595. sql = string.Format(@"select d.BatchCode from ICSInventoryLot a inner join dbo.ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  2596. inner join ICSExtension c on a.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
  2597. left join ICSBackflushBCLog d on b.TransCode=d.TransCode and b.TransSequence=d.TransSequence and c.BatchCode=d.BatchCode and a.WorkPoint=d.WorkPoint
  2598. where a.LotNo={0}", pair.ToString(), WorkPoint);
  2599. DataTable dtLoad = SqlHelper.GetDataTableBySql(sql);
  2600. if (dtLoad.Rows[0]["BatchCode"].ToString() != "" )
  2601. {
  2602. msg += "所选条码"+ pair.ToString() + "已上传,无法删除!";
  2603. }
  2604. if (string.IsNullOrEmpty(msg))
  2605. {
  2606. sqls += @"
  2607. DELETE FROM ICSInventoryLotDetail WHERE LotNO IN (select LotNO from ICSInventoryLot where LotNo ={0} ) and WorkPoint ='{1}'
  2608. DELETE FROM dbo.ICSInventoryLot WHERE LotNo ={0} and WorkPoint ='{1}'";
  2609. //string sqls = string.Format("DELETE FROM ICSInventoryLotDetail WHERE LotNO IN (select LotNO from ICSInventoryLot where ID in ({0}) ) and WorkPoint in ('{1}')", keyValue.TrimEnd(','), WorkPoint);
  2610. //sqls += string.Format("DELETE FROM dbo.ICSInventoryLot WHERE ID IN ({0}) and WorkPoint in ('{1}')", keyValue.TrimEnd(','), WorkPoint);
  2611. sqls = string.Format(sqls,pair.ToString(), WorkPoint);
  2612. }
  2613. }
  2614. if (sqls!="")
  2615. {
  2616. SqlHelper.CmdExecuteNonQueryLi(sqls);
  2617. }
  2618. return msg;
  2619. }
  2620. }
  2621. }