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.

410 lines
20 KiB

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