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.

400 lines
20 KiB

3 weeks ago
  1. using Newtonsoft.Json;
  2. using NFine.Application.Entity;
  3. using NFine.Application.Models;
  4. using NFine.Code;
  5. using NFine.Data.Extensions;
  6. using NFine.Domain._03_Entity.SRM;
  7. using NFine.Repository;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Data.Common;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace NFine.Application.WMS
  16. {
  17. /// <summary>
  18. /// 产成品入库
  19. /// </summary>
  20. public class ICSManufactureReceiveApp : RepositoryFactory<ICSVendor>
  21. {
  22. public static DataTable Invmes = new DataTable();
  23. /// <summary>
  24. /// 产成品入库删除
  25. /// </summary>
  26. /// <param name="keyValue"></param>
  27. /// <returns></returns>
  28. /// <exception cref="Exception"></exception>
  29. public string DeleteManufactureReceiveApplyNeg(string keyValue)
  30. {
  31. //站点信息
  32. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  33. string msg = "";
  34. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  35. string sql = string.Empty;
  36. sql += string.Format(@"DELETE FROM dbo.ICSManufactureReceive WHERE RCVCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  37. //sql += string.Format(@"DELETE FROM dbo.ICSMManufactureReceiveNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  38. try
  39. {
  40. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  41. {
  42. }
  43. }
  44. catch (Exception ex)
  45. {
  46. throw new Exception(ex.Message);
  47. }
  48. return msg;
  49. }
  50. /// <summary>
  51. /// 产成品入库查询
  52. /// </summary>
  53. /// <param name="jqgridparam"></param>
  54. /// <returns></returns>
  55. public DataTable GetManufactureReceiveApplyNeg(ref Pagination jqgridparam)
  56. {
  57. DataTable dt = new DataTable();
  58. List<DbParameter> parameter = new List<DbParameter>();
  59. string sql = @"select a.RCVCode, a.MUSERName,a.MTIME,a.Status,a.Type from ICSManufactureReceive a
  60. group by a.RCVCode, a.MUSERName,a.MTIME,a.Status,a.Type";
  61. sql = string.Format(sql);
  62. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  63. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  64. }
  65. /// <summary>
  66. /// 订单备料明细查询
  67. /// </summary>
  68. /// <param name="jqgridparam"></param>
  69. /// <returns></returns>
  70. public DataTable GetManufactureReceiveApplyNegDetail(string RCVCode, ref Pagination jqgridparam)
  71. {
  72. DataTable dt = new DataTable();
  73. //object Figure = GetDecimalDigits();
  74. List<DbParameter> parameter = new List<DbParameter>();
  75. string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.SourceSequence,a.SourceCode,a.InvCode,a.Quantity,a.Amount,a.RCVQuantity,a.WHCode,e.WarehouseName as WHName,a.Type
  76. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName,a.CreateDateTime,a.CreatePerson
  77. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  78. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  79. ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10
  80. from ICSManufactureReceive a
  81. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  82. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  83. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  84. where a.RCVCode = '" + RCVCode + "' ";
  85. //sql = string.Format(sql, Figure);
  86. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  87. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  88. }
  89. public void ClearTemp()
  90. {
  91. Invmes.Rows.Clear();
  92. }
  93. /// <summary>
  94. /// 新增、修改
  95. /// </summary>
  96. /// <param name="ICSASN"></param>
  97. /// <returns></returns>
  98. public string SaveICSManufactureReceiveApplyNeg(string keyValue, string deleteIDs)
  99. {
  100. string returnValue = string.Empty;
  101. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  102. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  103. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  104. var Dates = DateTime.Now;
  105. string Colspan = string.Empty;
  106. string IDD = string.Empty;
  107. var sql = string.Empty;
  108. try
  109. {
  110. var modelList = JsonConvert.DeserializeObject<List<ICSManufactureReceiveEdit>>(keyValue);
  111. if (!string.IsNullOrEmpty(deleteIDs))
  112. {
  113. var deleteentityList = deleteIDs.Split(',');
  114. foreach (var item in deleteentityList)
  115. {
  116. if (!string.IsNullOrEmpty(item))
  117. {
  118. var deleteEntity = MsSqlData.Get<ICSManufactureReceive>(item);
  119. sql += string.Format(@"DELETE FROM dbo.ICSManufactureReceive WHERE ID IN ({0}) and WorkPoint ='{1}'", item, WorkPoint);
  120. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  121. {
  122. }
  123. }
  124. }
  125. }
  126. foreach (var model in modelList)
  127. {
  128. if (string.IsNullOrEmpty(model.ID))
  129. {
  130. if (string.IsNullOrEmpty(model.RCVCode))
  131. {
  132. throw new Exception("产成品入库单号错误!");
  133. }
  134. //新增
  135. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSManufactureReceive where RCVCode ='" + model.RCVCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  136. if (count > 0)
  137. {
  138. throw new Exception("当前入库单号以及行号已存在");
  139. }
  140. //检验自由项
  141. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  142. + "~" + model.Brand + "~" + model.cFree1
  143. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  144. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  145. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  146. sql = @"select ID,Colspan from ICSExtension a
  147. where Colspan='{0}' and WorkPoint='{1}'";
  148. sql = string.Format(sql, Colspan, model.WorkPoint);
  149. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  150. if (dttt.Rows.Count == 0)
  151. {
  152. IDD = Guid.NewGuid().ToString();
  153. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  154. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  155. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  156. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  157. {
  158. throw new Exception("自由项添加失败");
  159. }
  160. }
  161. else
  162. {
  163. IDD = dttt.Rows[0]["ID"].ToString();
  164. }
  165. var entity = new ICSManufactureReceive();
  166. ConvertExt.Mapping(model, entity);
  167. entity.ID = Guid.NewGuid().ToString();
  168. entity.RCVID = "";
  169. entity.RCVDetailID = "";
  170. entity.Status = "1";
  171. entity.CreatePerson = MUSER;
  172. entity.CreateDateTime = Dates;
  173. entity.MUSER = MUSER;
  174. entity.MUSERName = MUSERNAME;
  175. entity.MTIME = Dates;
  176. entity.WorkPoint = WorkPoint;
  177. entity.ExtensionID = IDD;
  178. var result = MsSqlData.Insert<ICSManufactureReceive>(entity);
  179. if (!result)
  180. {
  181. returnValue = "产成品入库单新增失败";
  182. }
  183. }
  184. else
  185. {
  186. //修改
  187. var entity = MsSqlData.Get<ICSManufactureReceive>(model.ID);
  188. if (entity == null)
  189. {
  190. //新增
  191. if (string.IsNullOrEmpty(model.RCVCode))
  192. {
  193. throw new Exception("生成出库单号错误!");
  194. }
  195. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSManufactureReceive where RCVCode ='" + model.RCVCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  196. if (count > 0)
  197. {
  198. throw new Exception("当前入库单号以及行号已存在");
  199. }
  200. //检验自由项
  201. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  202. + "~" + model.Brand + "~" + model.cFree1
  203. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  204. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  205. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  206. sql = @"select ID,Colspan from ICSExtension a
  207. where Colspan='{0}' and WorkPoint='{1}'";
  208. sql = string.Format(sql, Colspan, model.WorkPoint);
  209. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  210. if (dttt.Rows.Count == 0)
  211. {
  212. IDD = Guid.NewGuid().ToString();
  213. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  214. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  215. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  216. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  217. {
  218. throw new Exception("自由项添加失败");
  219. }
  220. }
  221. else
  222. {
  223. IDD = dttt.Rows[0]["ID"].ToString();
  224. }
  225. entity = new ICSManufactureReceive();
  226. ConvertExt.Mapping<ICSManufactureReceiveEdit, ICSManufactureReceive>(model, entity);
  227. entity.ID = Guid.NewGuid().ToString();
  228. entity.RCVID = "";
  229. entity.RCVDetailID = "";
  230. entity.CreatePerson = MUSER;
  231. entity.CreateDateTime = Dates;
  232. entity.Status = "1";
  233. entity.MUSER = MUSER;
  234. entity.MUSERName = MUSERNAME;
  235. entity.MTIME = Dates;
  236. entity.WorkPoint = WorkPoint;
  237. entity.ExtensionID = IDD;
  238. var result = MsSqlData.Insert<ICSManufactureReceive>(entity);
  239. if (!result)
  240. {
  241. returnValue = "新增失败";
  242. }
  243. }
  244. else
  245. {
  246. //检验自由项
  247. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  248. + "~" + model.Brand + "~" + model.cFree1
  249. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  250. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  251. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  252. sql = @"select ID,Colspan from ICSExtension a
  253. where Colspan='{0}' and WorkPoint='{1}'";
  254. sql = string.Format(sql, Colspan, model.WorkPoint);
  255. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  256. if (dtt.Rows.Count == 0)
  257. {
  258. IDD = Guid.NewGuid().ToString();
  259. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  260. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  261. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  262. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  263. {
  264. throw new Exception("自由项添加失败");
  265. }
  266. }
  267. else
  268. {
  269. IDD = dtt.Rows[0]["ID"].ToString();
  270. }
  271. ConvertExt.Mapping<ICSManufactureReceiveEdit, ICSManufactureReceive>(model, entity);
  272. entity.RCVID = "";
  273. entity.RCVDetailID = "";
  274. entity.CreatePerson = MUSER;
  275. entity.CreateDateTime = Dates;
  276. entity.MUSER = MUSER;
  277. entity.MUSERName = MUSERNAME;
  278. entity.MTIME = Dates;
  279. entity.ExtensionID = IDD;
  280. var result = MsSqlData.Update<ICSManufactureReceive>(entity);
  281. if (!result)
  282. {
  283. returnValue = "修改失败";
  284. }
  285. }
  286. }
  287. }
  288. }
  289. catch (Exception ex)
  290. {
  291. returnValue = ex.Message;
  292. }
  293. return returnValue;
  294. }
  295. /// <summary>
  296. /// 创建自增单号
  297. /// </summary>
  298. /// <param name="WorkPoint"></param>
  299. /// <returns></returns>
  300. public string GetOOCode(string WorkPoint)
  301. {
  302. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  303. string OOCode = string.Empty;
  304. if (!string.IsNullOrEmpty(WorkPoint))
  305. {
  306. OOCode = GetSerialCode(WorkPoint, "ICSManufactureReceive", "RCVCode", "00", 8);
  307. }
  308. if (!string.IsNullOrWhiteSpace(OOCode))
  309. {
  310. string sqlISHave = @"SELECT RCVCode FROM ICSManufactureReceive a
  311. WHERE a.RCVCode = '{0}'";
  312. sqlISHave = string.Format(sqlISHave, OOCode);
  313. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  314. if (dtIsHave.Rows.Count > 0)
  315. {
  316. throw new Exception("单号已存在!");
  317. }
  318. }
  319. return OOCode;
  320. }
  321. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  322. {
  323. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  324. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  325. return SqlHelper.ExecuteScalar(sql).ToString();
  326. }
  327. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  328. {
  329. var data = json.ToJObject();
  330. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  331. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  332. if (info != null && info.Length > 0)
  333. {
  334. info[0]["ZJID"] = data["ZJID"];
  335. info[0]["InvName"] = data["InvName"];
  336. }
  337. else
  338. {
  339. DataRow newrow = Invmes.NewRow();
  340. newrow["ZJID"] = data["ZJID"];
  341. Invmes.Rows.Add(newrow);
  342. }
  343. }
  344. public DataTable GetICSManufactureReceiveReturnTemporary(string RCVCode)
  345. {
  346. string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.RCVQuantity
  347. ,a.WHCode,a.Type,b.InvName,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
  348. from ICSManufactureReceive a
  349. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  350. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  351. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  352. where a.RCVCode ='" + RCVCode + "' ";
  353. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  354. DataTable dtCloned = table.Clone();
  355. foreach (DataColumn col in dtCloned.Columns)
  356. {
  357. col.DataType = typeof(string);
  358. }
  359. foreach (DataRow row in table.Rows)
  360. {
  361. DataRow newrow = dtCloned.NewRow();
  362. foreach (DataColumn column in dtCloned.Columns)
  363. {
  364. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  365. }
  366. dtCloned.Rows.Add(newrow);
  367. }
  368. if (Invmes.Rows.Count > 0)
  369. {
  370. dtCloned.Merge(Invmes, false);
  371. }
  372. return dtCloned;
  373. }
  374. }
  375. }