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.

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