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.

404 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.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace NFine.Application.WMS
  18. {
  19. /// <summary>
  20. /// 材料出库
  21. /// </summary>
  22. public class ICSMOIssueApp : 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 DeleteMOIssueApplyNeg(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.ICSMOIssue WHERE IssueCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  39. //sql += string.Format(@"DELETE FROM dbo.ICSMMOIssueNegDetail 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 GetMOIssueApplyNeg(ref Pagination jqgridparam)
  58. {
  59. DataTable dt = new DataTable();
  60. List<DbParameter> parameter = new List<DbParameter>();
  61. string sql = @"select a.IssueCode, a.MUSERName,a.MTIME,a.Status,a.Type from ICSMOIssue a
  62. group by a.IssueCode, a.MUSERName,a.MTIME,a.Status,a.Type";
  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 GetMOIssueApplyNegDetail(string IssueCode, 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.IssueCode,a.Sequence,a.SourceSequence,a.SourceCode,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity,a.WHCode,e.WarehouseName as WHName,a.Type
  78. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName,a.CreateDateTime,a.CreatePerson
  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.EATTRIBUTE,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10
  82. from ICSMOIssue a
  83. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  84. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  85. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  86. where a.IssueCode = '" + IssueCode + "' ";
  87. //sql = string.Format(sql, Figure);
  88. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  89. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  90. }
  91. public void ClearTemp()
  92. {
  93. Invmes.Rows.Clear();
  94. }
  95. /// <summary>
  96. /// 新增、修改
  97. /// </summary>
  98. /// <param name="ICSASN"></param>
  99. /// <returns></returns>
  100. public string SaveICSMOIssueApplyNeg(string keyValue, string deleteIDs)
  101. {
  102. string returnValue = string.Empty;
  103. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  104. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  105. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  106. var Dates = DateTime.Now;
  107. string Colspan = string.Empty;
  108. string IDD = string.Empty;
  109. var sql = string.Empty;
  110. try
  111. {
  112. var modelList = JsonConvert.DeserializeObject<List<ICSMOIssueEdit>>(keyValue);
  113. if (!string.IsNullOrEmpty(deleteIDs))
  114. {
  115. var deleteentityList = deleteIDs.Split(',');
  116. foreach (var item in deleteentityList)
  117. {
  118. if (!string.IsNullOrEmpty(item))
  119. {
  120. var deleteEntity = MsSqlData.Get<ICSMOIssue>(item);
  121. sql += string.Format(@"DELETE FROM dbo.ICSMOIssue WHERE ID IN ({0}) and WorkPoint ='{1}'", item, WorkPoint);
  122. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  123. {
  124. }
  125. }
  126. }
  127. }
  128. foreach (var model in modelList)
  129. {
  130. if (string.IsNullOrEmpty(model.ID))
  131. {
  132. if (string.IsNullOrEmpty(model.IssueCode))
  133. {
  134. throw new Exception("生成出库单号错误!");
  135. }
  136. //新增
  137. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSMOIssue where IssueCode ='" + model.IssueCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  138. if (count > 0)
  139. {
  140. throw new Exception("当前代码已经存在");
  141. }
  142. //检验自由项
  143. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  144. + "~" + model.Brand + "~" + model.cFree1
  145. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  146. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  147. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  148. sql = @"select ID,Colspan from ICSExtension a
  149. where Colspan='{0}' and WorkPoint='{1}'";
  150. sql = string.Format(sql, Colspan, model.WorkPoint);
  151. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  152. if (dttt.Rows.Count == 0)
  153. {
  154. IDD = Guid.NewGuid().ToString();
  155. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  156. 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}'";
  157. 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);
  158. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  159. {
  160. throw new Exception("自由项添加失败");
  161. }
  162. }
  163. else
  164. {
  165. IDD = dttt.Rows[0]["ID"].ToString();
  166. }
  167. var entity = new ICSMOIssue();
  168. ConvertExt.Mapping<ICSMOIssueEdit, ICSMOIssue>(model, entity);
  169. entity.ID = Guid.NewGuid().ToString();
  170. entity.IssueID = "";
  171. entity.IssueDetailID = "";
  172. entity.Status = "1";
  173. entity.CreatePerson = MUSER;
  174. entity.CreateDateTime = Dates;
  175. entity.MUSER = MUSER;
  176. entity.MUSERName = MUSERNAME;
  177. entity.MTIME = Dates;
  178. entity.WorkPoint = WorkPoint;
  179. entity.ExtensionID = IDD;
  180. var result = MsSqlData.Insert<ICSMOIssue>(entity);
  181. if (!result)
  182. {
  183. returnValue = "新增失败";
  184. }
  185. }
  186. else
  187. {
  188. //修改
  189. var entity = MsSqlData.Get<ICSMOIssue>(model.ID);
  190. if (entity == null)
  191. {
  192. //新增
  193. if (string.IsNullOrEmpty(model.IssueCode))
  194. {
  195. throw new Exception("生成出库单号错误!");
  196. }
  197. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSMOIssue where IssueCode ='" + model.IssueCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  198. if (count > 0)
  199. {
  200. throw new Exception("当前代码已经存在");
  201. }
  202. //检验自由项
  203. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  204. + "~" + model.Brand + "~" + model.cFree1
  205. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  206. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  207. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  208. sql = @"select ID,Colspan from ICSExtension a
  209. where Colspan='{0}' and WorkPoint='{1}'";
  210. sql = string.Format(sql, Colspan, model.WorkPoint);
  211. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  212. if (dttt.Rows.Count == 0)
  213. {
  214. IDD = Guid.NewGuid().ToString();
  215. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  216. 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}'";
  217. 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);
  218. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  219. {
  220. throw new Exception("自由项添加失败");
  221. }
  222. }
  223. else
  224. {
  225. IDD = dttt.Rows[0]["ID"].ToString();
  226. }
  227. entity = new ICSMOIssue();
  228. ConvertExt.Mapping<ICSMOIssueEdit, ICSMOIssue>(model, entity);
  229. entity.ID = Guid.NewGuid().ToString();
  230. entity.IssueID = "";
  231. entity.IssueDetailID = "";
  232. entity.CreatePerson = MUSER;
  233. entity.CreateDateTime = Dates;
  234. entity.Status = "1";
  235. entity.MUSER = MUSER;
  236. entity.MUSERName = MUSERNAME;
  237. entity.MTIME = Dates;
  238. entity.WorkPoint = WorkPoint;
  239. entity.ExtensionID = IDD;
  240. var result = MsSqlData.Insert<ICSMOIssue>(entity);
  241. if (!result)
  242. {
  243. returnValue = "新增失败";
  244. }
  245. }
  246. else
  247. {
  248. //检验自由项
  249. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  250. + "~" + model.Brand + "~" + model.cFree1
  251. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  252. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  253. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  254. sql = @"select ID,Colspan from ICSExtension a
  255. where Colspan='{0}' and WorkPoint='{1}'";
  256. sql = string.Format(sql, Colspan, model.WorkPoint);
  257. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  258. if (dtt.Rows.Count == 0)
  259. {
  260. IDD = Guid.NewGuid().ToString();
  261. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  262. 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}'";
  263. 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);
  264. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  265. {
  266. throw new Exception("自由项添加失败");
  267. }
  268. }
  269. else
  270. {
  271. IDD = dtt.Rows[0]["ID"].ToString();
  272. }
  273. ConvertExt.Mapping<ICSMOIssueEdit, ICSMOIssue>(model, entity);
  274. entity.IssueID = "";
  275. entity.IssueDetailID = "";
  276. entity.CreatePerson = MUSER;
  277. entity.CreateDateTime = Dates;
  278. entity.MUSER = MUSER;
  279. entity.MUSERName = MUSERNAME;
  280. entity.MTIME = Dates;
  281. entity.ExtensionID = IDD;
  282. var result = MsSqlData.Update<ICSMOIssue>(entity);
  283. if (!result)
  284. {
  285. returnValue = "修改失败";
  286. }
  287. }
  288. }
  289. }
  290. }
  291. catch (Exception ex)
  292. {
  293. returnValue = ex.Message;
  294. }
  295. return returnValue;
  296. }
  297. /// <summary>
  298. /// 创建自增单号
  299. /// </summary>
  300. /// <param name="WorkPoint"></param>
  301. /// <returns></returns>
  302. public string GetOOCode(string WorkPoint)
  303. {
  304. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  305. string OOCode = string.Empty;
  306. if (!string.IsNullOrEmpty(WorkPoint))
  307. {
  308. OOCode = GetSerialCode(WorkPoint, "ICSMOIssue", "IssueCode", "00", 8);
  309. }
  310. if (!string.IsNullOrWhiteSpace(OOCode))
  311. {
  312. string sqlISHave = @"SELECT IssueCode FROM ICSMOIssue a
  313. WHERE a.IssueCode = '{0}'";
  314. sqlISHave = string.Format(sqlISHave, OOCode);
  315. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  316. if (dtIsHave.Rows.Count > 0)
  317. {
  318. throw new Exception("单号已存在!");
  319. }
  320. }
  321. return OOCode;
  322. }
  323. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  324. {
  325. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  326. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  327. return SqlHelper.ExecuteScalar(sql).ToString();
  328. }
  329. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  330. {
  331. var data = json.ToJObject();
  332. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  333. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  334. if (info != null && info.Length > 0)
  335. {
  336. info[0]["ZJID"] = data["ZJID"];
  337. info[0]["InvName"] = data["InvName"];
  338. }
  339. else
  340. {
  341. DataRow newrow = Invmes.NewRow();
  342. newrow["ZJID"] = data["ZJID"];
  343. Invmes.Rows.Add(newrow);
  344. }
  345. }
  346. public DataTable GetICSMOIssueReturnTemporary(string IssueCode)
  347. {
  348. string sql = @"SELECT a.ID,a.IssueCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity
  349. ,a.WHCode,a.Type,b.InvName,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
  350. from ICSMOIssue a
  351. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  352. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  353. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  354. where a.IssueCode ='" + IssueCode + "' ";
  355. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  356. DataTable dtCloned = table.Clone();
  357. foreach (DataColumn col in dtCloned.Columns)
  358. {
  359. col.DataType = typeof(string);
  360. }
  361. foreach (DataRow row in table.Rows)
  362. {
  363. DataRow newrow = dtCloned.NewRow();
  364. foreach (DataColumn column in dtCloned.Columns)
  365. {
  366. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  367. }
  368. dtCloned.Rows.Add(newrow);
  369. }
  370. if (Invmes.Rows.Count > 0)
  371. {
  372. dtCloned.Merge(Invmes, false);
  373. }
  374. return dtCloned;
  375. }
  376. }
  377. }