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.

408 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 ICSOtherInApp : 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 DeleteOtherInApplyNeg(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.ICSOtherIn WHERE InCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  39. //sql += string.Format(@"DELETE FROM dbo.ICSMOtherInNegDetail 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 GetOtherInApplyNeg(ref Pagination jqgridparam)
  58. {
  59. DataTable dt = new DataTable();
  60. List<DbParameter> parameter = new List<DbParameter>();
  61. string sql = @"select a.InCode, a.MUSERName,a.MTIME,a.Status from ICSOtherIn a
  62. group by a.InCode, 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 GetOtherInApplyNegDetail(string InCode, 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.InCode,a.Sequence,a.InvCode,a.Quantity,a.Amount,a.InQuantity,a.WHCode,e.WarehouseName as WHName
  78. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName,a.CreateDateTime,a.CreatePerson,a.InID,a.InDetailID,a.TransferID,a.TransferDetailID
  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 ICSOtherIn 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.InCode = '" + InCode + "' ";
  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 SaveICSOtherInApplyNeg(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<ICSOtherInEdit>>(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<Entity.ICSOtherIn>(item);
  121. sql += string.Format(@"DELETE FROM dbo.ICSOtherIn 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.InCode))
  133. {
  134. throw new Exception("其他出库单号错误!");
  135. }
  136. //新增
  137. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSOtherIn where InCode ='" + model.InCode + "' 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 ICSOtherIn();
  168. ConvertExt.Mapping(model, entity);
  169. entity.ID = Guid.NewGuid().ToString();
  170. entity.InID = "";
  171. entity.InDetailID = "";
  172. //entity.TransferID = "";
  173. //entity.TransferDetailID = "";
  174. entity.Status = "1";
  175. entity.CreatePerson = MUSER;
  176. entity.CreateDateTime = Dates;
  177. entity.MUSER = MUSER;
  178. entity.MUSERName = MUSERNAME;
  179. entity.MTIME = Dates;
  180. entity.WorkPoint = WorkPoint;
  181. entity.ExtensionID = IDD;
  182. var result = MsSqlData.Insert<ICSOtherIn>(entity);
  183. if (!result)
  184. {
  185. returnValue = "其他出库单新增失败";
  186. }
  187. }
  188. else
  189. {
  190. //修改
  191. var entity = MsSqlData.Get<ICSOtherIn>(model.ID);
  192. if (entity == null)
  193. {
  194. //新增
  195. if (string.IsNullOrEmpty(model.InCode))
  196. {
  197. throw new Exception("生成出库单号错误!");
  198. }
  199. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSOtherIn where InCode ='" + model.InCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  200. if (count > 0)
  201. {
  202. throw new Exception("当前出库单号以及行号已存在");
  203. }
  204. //检验自由项
  205. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  206. + "~" + model.Brand + "~" + model.cFree1
  207. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  208. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  209. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  210. sql = @"select ID,Colspan from ICSExtension a
  211. where Colspan='{0}' and WorkPoint='{1}'";
  212. sql = string.Format(sql, Colspan, model.WorkPoint);
  213. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  214. if (dttt.Rows.Count == 0)
  215. {
  216. IDD = Guid.NewGuid().ToString();
  217. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  218. 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}'";
  219. 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);
  220. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  221. {
  222. throw new Exception("自由项添加失败");
  223. }
  224. }
  225. else
  226. {
  227. IDD = dttt.Rows[0]["ID"].ToString();
  228. }
  229. entity = new ICSOtherIn();
  230. ConvertExt.Mapping<ICSOtherInEdit, ICSOtherIn>(model, entity);
  231. entity.ID = Guid.NewGuid().ToString();
  232. entity.InID = "";
  233. entity.InDetailID = "";
  234. //entity.TransferID = "";
  235. //entity.TransferDetailID = "";
  236. entity.CreatePerson = MUSER;
  237. entity.CreateDateTime = Dates;
  238. entity.Status = "1";
  239. entity.MUSER = MUSER;
  240. entity.MUSERName = MUSERNAME;
  241. entity.MTIME = Dates;
  242. entity.WorkPoint = WorkPoint;
  243. entity.ExtensionID = IDD;
  244. var result = MsSqlData.Insert<ICSOtherIn>(entity);
  245. if (!result)
  246. {
  247. returnValue = "新增失败";
  248. }
  249. }
  250. else
  251. {
  252. //检验自由项
  253. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  254. + "~" + model.Brand + "~" + model.cFree1
  255. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  256. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  257. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  258. sql = @"select ID,Colspan from ICSExtension a
  259. where Colspan='{0}' and WorkPoint='{1}'";
  260. sql = string.Format(sql, Colspan, model.WorkPoint);
  261. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  262. if (dtt.Rows.Count == 0)
  263. {
  264. IDD = Guid.NewGuid().ToString();
  265. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  266. 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}'";
  267. 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);
  268. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  269. {
  270. throw new Exception("自由项添加失败");
  271. }
  272. }
  273. else
  274. {
  275. IDD = dtt.Rows[0]["ID"].ToString();
  276. }
  277. ConvertExt.Mapping<ICSOtherInEdit, ICSOtherIn>(model, entity);
  278. entity.InID = "";
  279. entity.InDetailID = "";
  280. //entity.TransferID = "";
  281. //entity.TransferDetailID = "";
  282. entity.CreatePerson = MUSER;
  283. entity.CreateDateTime = Dates;
  284. entity.MUSER = MUSER;
  285. entity.MUSERName = MUSERNAME;
  286. entity.MTIME = Dates;
  287. entity.ExtensionID = IDD;
  288. var result = MsSqlData.Update<ICSOtherIn>(entity);
  289. if (!result)
  290. {
  291. returnValue = "修改失败";
  292. }
  293. }
  294. }
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. returnValue = ex.Message;
  300. }
  301. return returnValue;
  302. }
  303. /// <summary>
  304. /// 创建自增单号
  305. /// </summary>
  306. /// <param name="WorkPoint"></param>
  307. /// <returns></returns>
  308. public string GetOOCode(string WorkPoint)
  309. {
  310. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  311. string OOCode = string.Empty;
  312. if (!string.IsNullOrEmpty(WorkPoint))
  313. {
  314. OOCode = GetSerialCode(WorkPoint, "ICSOtherIn", "InCode", "00", 8);
  315. }
  316. if (!string.IsNullOrWhiteSpace(OOCode))
  317. {
  318. string sqlISHave = @"SELECT InCode FROM ICSOtherIn a
  319. WHERE a.InCode = '{0}'";
  320. sqlISHave = string.Format(sqlISHave, OOCode);
  321. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  322. if (dtIsHave.Rows.Count > 0)
  323. {
  324. throw new Exception("单号已存在!");
  325. }
  326. }
  327. return OOCode;
  328. }
  329. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  330. {
  331. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  332. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  333. return SqlHelper.ExecuteScalar(sql).ToString();
  334. }
  335. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  336. {
  337. var data = json.ToJObject();
  338. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  339. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  340. if (info != null && info.Length > 0)
  341. {
  342. info[0]["ZJID"] = data["ZJID"];
  343. info[0]["InvName"] = data["InvName"];
  344. }
  345. else
  346. {
  347. DataRow newrow = Invmes.NewRow();
  348. newrow["ZJID"] = data["ZJID"];
  349. Invmes.Rows.Add(newrow);
  350. }
  351. }
  352. public DataTable GetICSOtherInReturnTemporary(string InCode)
  353. {
  354. string sql = @"SELECT a.ID,a.InCode,a.Sequence,a.InvCode,a.Quantity,a.Amount,a.InQuantity
  355. ,a.WHCode,b.InvName,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
  356. from ICSOtherIn a
  357. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  358. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  359. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  360. where a.InCode ='" + InCode + "' ";
  361. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  362. DataTable dtCloned = table.Clone();
  363. foreach (DataColumn col in dtCloned.Columns)
  364. {
  365. col.DataType = typeof(string);
  366. }
  367. foreach (DataRow row in table.Rows)
  368. {
  369. DataRow newrow = dtCloned.NewRow();
  370. foreach (DataColumn column in dtCloned.Columns)
  371. {
  372. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  373. }
  374. dtCloned.Rows.Add(newrow);
  375. }
  376. if (Invmes.Rows.Count > 0)
  377. {
  378. dtCloned.Merge(Invmes, false);
  379. }
  380. return dtCloned;
  381. }
  382. }
  383. }