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

239 lines
11 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. namespace NFine.Application.WMS
  19. {
  20. public class ICSDisassemblyDocApp : 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. #region [SQL]
  28. string sql = @"
  29. select a.DABDOCType,
  30. a.ExtensionID as ExtensionID,
  31. a.DABDOCCode as Code,
  32. a.Sequence as Seq,
  33. a.Quantity as Qty,
  34. a.InvCode,
  35. a.WHCode,
  36. b.InvName,
  37. CASE WHEN c.TransSequence IS NOT NULL THEN '' ELSE '' END AS isInput,
  38. CASE WHEN f.TransCode IS NOT NULL THEN '' ELSE '' END AS isCreate,e.*
  39. from ICSDisassemblyDoc a
  40. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  41. left join (select TransCode,TransSequence,WorkPoint FROM ICSWareHouseLotInfoLog WHERE BusinessCode='37' group by TransCode,TransSequence,WorkPoint)c
  42. ON a.DABDOCCode=c.TransCode AND a.Sequence=c.TransSequence AND a.WorkPoint=c.WorkPoint
  43. left join (select TransCode,WorkPoint FROM ICSInventoryLotDetail group by TransCode,WorkPoint)f
  44. ON a.DABDOCCode=f.TransCode AND a.WorkPoint=f.WorkPoint
  45. LEFT JOIN ICSWarehouse d ON a.WHCode=d.WarehouseCode AND a.WorkPoint=d.WorkPoint
  46. left join ICSExtension e on a.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  47. where a.DABDOCType='1'";
  48. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  49. #endregion
  50. if (!string.IsNullOrWhiteSpace(queryJson))
  51. {
  52. if (!string.IsNullOrWhiteSpace(queryParam["DABDOCCode"].ToString()))
  53. {
  54. sql += " and a.DABDOCCode like '%" + queryParam["DABDOCCode"].ToString() + "%' ";
  55. }
  56. }
  57. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  58. {
  59. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  60. }
  61. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  62. }
  63. public DataTable GetSubGridJson(string Code)
  64. {
  65. DataTable dt = new DataTable();
  66. //var queryParam = queryJson.ToJObject();
  67. string sql = string.Empty;
  68. List<DbParameter> parameter = new List<DbParameter>();
  69. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  70. sql = @"select
  71. a.Sequence,
  72. a.DABDOCType,
  73. a.DABDOCCode as Code,
  74. a.Quantity as Qty,
  75. a.InvCode,
  76. a.WHCode,
  77. e.BatchCode,
  78. b.InvName,
  79. f.LotNo
  80. from ICSDisassemblyDoc a
  81. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  82. left join (select TransCode,TransSequence,WorkPoint,LotNo FROM ICSInventoryLotDetail group by TransCode,TransSequence,WorkPoint,LotNo)f
  83. ON a.DABDOCCode=f.TransCode AND a.Sequence=f.TransSequence AND a.WorkPoint=f.WorkPoint
  84. LEFT JOIN ICSWarehouse d ON a.WHCode=d.WarehouseCode AND a.WorkPoint=d.WorkPoint
  85. left join ICSExtension e on a.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
  86. where a.DABDOCType='2' and a.DABDOCCode='{0}'
  87. order by a.Sequence";
  88. sql = string.Format(sql, Code, WorkPoint);
  89. return Repository().FindTableBySql(sql.ToString());
  90. }
  91. //查询符合套件的在库条码
  92. public DataTable GetLotNoByKit(string InvCode, string WHCode, string ExtensionID, ref Pagination jqgridparam)
  93. {
  94. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  95. List<DbParameter> parameter = new List<DbParameter>();
  96. DataTable table = new DataTable();
  97. string sql = string.Empty;
  98. sql = @"select a.LotNo,a.InvCode,a.WarehouseCode,a.LocationCode,c.BatchCode,a.Quantity from dbo.ICSWareHouseLotInfo a
  99. left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  100. left join ICSExtension c on b.ExtensionID=c.ID and b.WorkPoint=c.WorkPoint
  101. where a.InvCode='{0}' and a.WarehouseCode='{1}' and b.ExtensionID='{2}'";
  102. sql = string.Format(sql, InvCode, WHCode, ExtensionID);
  103. //return Repository().FindTableBySql(sql.ToString());
  104. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  105. }
  106. //绑定套件
  107. public string CreateLogByKit(string Code, string Parameter)
  108. {
  109. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  110. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  111. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  112. string msg = "";
  113. string sql = string.Empty;
  114. JArray res = (JArray)JsonConvert.DeserializeObject(Parameter);
  115. string Identification = Guid.NewGuid().ToString();
  116. foreach (var item in res)
  117. {
  118. JObject jo = (JObject)item;
  119. sql += @"update ICSWareHouseLotInfo set LockQuantity='{6}' where LotNo='{2}' and WorkPoint='{9}'";
  120. sql += @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,FromWarehouseCode,FromLocationCode,
  121. ToWarehouseCode,ToLocationCode,Quantity,Memo,Lock,TransType,BusinessCode,ERPUpload,
  122. ERPID,ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  123. Values(NEWID(),'{0}','{1}','1','{2}','{3}','{4}','{5}','','','{6}','',1,'11','37',0,'','','','','{7}','{8}',getdate(),'{9}','')";
  124. sql = string.Format(sql, Identification, Code, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["WHCode"].ToString(), jo["LocationCode"].ToString(), jo["Quantity"].ToString(), MUSER, MUSERNAME, WorkPoint);
  125. }
  126. try
  127. {
  128. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  129. {
  130. }
  131. else
  132. {
  133. msg = "绑定失败";
  134. }
  135. }
  136. catch (Exception ex)
  137. {
  138. throw new Exception(ex.Message);
  139. }
  140. return msg;
  141. }
  142. //批量生成条码
  143. public string CreateInventoryLot(string Code)
  144. {
  145. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  146. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  147. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  148. string msg = "";
  149. string sql = string.Empty;
  150. string sqls= string.Empty;
  151. string sqlLot = string.Empty;
  152. sqls = @"select DABDOCCode,Sequence,InvCode,Quantity,Amount,ExtensionID from ICSDisassemblyDoc where DABDOCType='2' and DABDOCCode='{0}'";
  153. sqls = string.Format(sqls, Code);
  154. var parent = Repository().FindTableBySql(sqls.ToString());
  155. sqlLot = string.Format(@"SELECT A.LotNO AS LOTNO FROM ICSInventoryLot A WHERE A.LotNO LIKE '{0}%'", Code);
  156. var parentLot = Repository().FindTableBySql(sqlLot.ToString());
  157. foreach (DataRow dts in parent.Rows)
  158. {
  159. string LotNo = "";
  160. string DABDOCCode = dts["DABDOCCode"].ToString();
  161. string Sequence = dts["Sequence"].ToString();
  162. var drs=parentLot.Select("LOTNO", "LOTNO DESC");
  163. if (drs.Length==0)
  164. {
  165. LotNo = DABDOCCode + Sequence + "00001";
  166. }
  167. else
  168. {
  169. var OldLotNo = drs[0]["LOTNO"].ToString();
  170. LotNo = DABDOCCode + Sequence + (Convert.ToInt64(OldLotNo.Substring(OldLotNo.Length - 5))+1).ToString().PadLeft(5,'0');
  171. }
  172. sql += @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,
  173. PrintTimes,LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,WorkPoint)
  174. Values(NEWID(),'{0}','{1}',getdate(),'2999-12-31','{2}','{3}','{4}','100','','','','{5}','{6}',getdate(),'{7}')";
  175. sql+= @"INSERT INTO ICSInventoryLotDetail( LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  176. Values('{0}','{8}','{9}','{5}','{6}',getdate(),'{7}')";
  177. sql = string.Format(sql, LotNo, dts["InvCode"].ToString(), dts["Quantity"].ToString(), dts["Amount"].ToString(), dts["ExtensionID"].ToString(), MUSER, MUSERNAME, WorkPoint, dts["DABDOCCode"].ToString(), dts["Sequence"].ToString());
  178. }
  179. try
  180. {
  181. if (SqlHelper.CmdExecuteNonQueryLi(sql.ToString()) > 0)
  182. {
  183. }
  184. else
  185. {
  186. msg = "生成失败";
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. throw new Exception(ex.Message);
  192. }
  193. return msg;
  194. }
  195. //批量删除条码
  196. public string DeleteInventoryLot(string Code)
  197. {
  198. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  199. string msg = string.Empty;
  200. string sql = string.Format(@"select * from dbo.ICSInventoryLot a
  201. inner join dbo.ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  202. inner join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  203. where b.TransCode='{0}' and a.WorkPoint='{1}'", Code, WorkPoint);
  204. DataTable dtASN = SqlHelper.GetDataTableBySql(sql);
  205. if (dtASN != null && dtASN.Rows.Count > 0)
  206. {
  207. msg = "该单据下的条码已入库,无法删除!";
  208. }
  209. if (string.IsNullOrEmpty(msg))
  210. {
  211. string sqls = string.Format("delete a from ICSInventoryLot a inner join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint where b.TransCode='{0}' and a.WorkPoint='{1}'", Code, WorkPoint);
  212. sqls += string.Format("delete from ICSInventoryLotDetail where TransCode='{0}' and WorkPoint='{1}'", Code, WorkPoint);
  213. SqlHelper.CmdExecuteNonQueryLi(sqls);
  214. }
  215. return msg;
  216. }
  217. }
  218. }