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.

458 lines
20 KiB

  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  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.Configuration;
  10. using System.Data;
  11. using System.Data.Common;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Threading;
  16. using System.Reflection.Emit;
  17. namespace NFine.Application.DHAY
  18. {
  19. public class ICSCustomerSuppliedInApp : RepositoryFactory<ICSVendor>
  20. {
  21. public static DataTable Invmes = new DataTable();
  22. #region 删除杂收单
  23. public string DeleteICSOtherIn(string keyValue)
  24. {
  25. //站点信息
  26. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  27. string msg = "";
  28. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  29. string sql = string.Empty;
  30. sql += string.Format(@"DELETE FROM dbo.ICSOtherIn WHERE InCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  31. try
  32. {
  33. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  34. {
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. throw new Exception(ex.Message);
  40. }
  41. return msg;
  42. }
  43. #endregion
  44. #region 保存发料信息
  45. public string SaveICSOtherIn(string ICSASN)
  46. {
  47. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  48. string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  49. string msg = "";
  50. List<JsonData> parsedData = JsonConvert.DeserializeObject<List<JsonData>>(ICSASN);
  51. string sql = "";
  52. string Colspan = "";
  53. string str1 = "";
  54. List<string> ExtensionIDList = new List<string>();
  55. // 获取解析后的数据
  56. JsonData data = parsedData[0];
  57. foreach (var detail in data.Detail)
  58. {
  59. Colspan ="~" + detail.Batch + "~~~~~~~~~~~~";
  60. string sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  61. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  62. bool flag = true;
  63. foreach (var item in ExtensionIDList)
  64. {
  65. if (item == Colspan + WorkPoint)
  66. {
  67. flag = false;
  68. }
  69. }
  70. if (ExtensionID == null && flag == true)
  71. {
  72. str1 = Guid.NewGuid().ToString();
  73. sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  74. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  75. str1, Colspan, "", detail.Batch, "", "", "", "", "", "", "", "", "", "", "", "",
  76. data.User, UserName, WorkPoint);
  77. }
  78. else if (ExtensionID != null)
  79. {
  80. str1 = ExtensionID.ToString();
  81. }
  82. ExtensionIDList.Add(Colspan + WorkPoint);
  83. sql += "INSERT INTO ICSOtherIn(ID,InCode,WHCode,Sequence,InvCode,Quantity,CreatePerson,CreateDateTime,WorkPoint,Status,InID,InDetailID,ExtensionID,MUSER,MUSERName,MTIME,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7)" +
  84. " select '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',newID(),newID(),'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'";
  85. sql = string.Format(sql, detail.ID, data.Code, detail.WHCode, detail.Sequence, detail.InvCode, detail.Quantity, data.User, data.MTIME, WorkPoint,'1', str1, data.User, UserName, data.MTIME,data.Dept, data.CodeType, data.ApplyNegCode, data.Custmer, data.Remarks,detail.DetailReamrk,data.SYproject);
  86. }
  87. try
  88. {
  89. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  90. {
  91. }
  92. }
  93. catch (Exception ex)
  94. {
  95. msg=ex.Message;
  96. }
  97. return msg;
  98. }
  99. #region 杂收单主表信息查询
  100. public DataTable GetICSOtherIn(ref Pagination jqgridparam,string queryJson)
  101. {
  102. DataTable dt = new DataTable();
  103. var queryParam = queryJson.ToJObject();
  104. List<DbParameter> parameter = new List<DbParameter>();
  105. string sql = @" SELECT DISTINCT
  106. a.InCode
  107. ,a.Status
  108. ,a.CreatePerson
  109. ,a.CreateDateTime
  110. ,a.MUSER
  111. ,a.MUSERName
  112. ,a.EATTRIBUTE1
  113. ,a.EATTRIBUTE2
  114. ,a.EATTRIBUTE3
  115. ,a.EATTRIBUTE4
  116. ,a.EATTRIBUTE5
  117. ,a.EATTRIBUTE7
  118. ,a.EATTRIBUTE8
  119. ,a.EATTRIBUTE9
  120. ,a.EATTRIBUTE10
  121. from dbo.ICSOtherIn a
  122. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint where 1=1";
  123. if (!string.IsNullOrWhiteSpace(queryJson))
  124. {
  125. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  126. {
  127. sql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' ";
  128. }
  129. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  130. {
  131. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  132. }
  133. if (!string.IsNullOrWhiteSpace(queryParam["CreatedBy"].ToString()))
  134. {
  135. sql += " and a.CreatePerson like '%" + queryParam["CreatedBy"].ToString() + "%' ";
  136. }
  137. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  138. {
  139. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  140. }
  141. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  142. {
  143. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  144. }
  145. }
  146. sql = string.Format(sql);
  147. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  148. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  149. }
  150. #endregion
  151. #region 杂收单主表信息查询
  152. public DataTable GetICSOtherInByInCode(string InCode)
  153. {
  154. DataTable dt = new DataTable();
  155. List<DbParameter> parameter = new List<DbParameter>();
  156. string sql = @" SELECT DISTINCT
  157. a.InCode
  158. ,a.Status
  159. ,a.CreatePerson
  160. ,a.CreateDateTime
  161. ,a.MUSER
  162. ,a.MUSERName
  163. ,a.EATTRIBUTE1
  164. ,a.EATTRIBUTE2
  165. ,a.EATTRIBUTE3
  166. ,a.EATTRIBUTE4
  167. ,a.EATTRIBUTE5
  168. ,a.EATTRIBUTE7
  169. ,a.EATTRIBUTE8
  170. ,a.EATTRIBUTE9
  171. ,a.EATTRIBUTE10
  172. from dbo.ICSOtherIn a
  173. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  174. WHERE a.InCode='{0}'";
  175. sql = string.Format(sql, InCode);
  176. return Repository().FindTableBySql(sql.ToString());
  177. }
  178. #endregion
  179. #region 主页面子表信息查询
  180. public DataTable GetICSOtherInDetail(string InCode,string queryJson, ref Pagination jqgridparam)
  181. {
  182. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  183. DataTable dt = new DataTable();
  184. var queryParam = queryJson.ToJObject();
  185. //var queryParam = queryJson.ToJObject();
  186. List<DbParameter> parameter = new List<DbParameter>();
  187. string sql = @" select a.ID
  188. ,a.InCode
  189. ,a.Sequence
  190. ,a.InvCode
  191. ,a.Quantity
  192. ,a.Amount
  193. ,a.ExtensionID
  194. ,a.MUSER
  195. ,a.MUSERName
  196. ,a.MTIME
  197. ,a.InQuantity
  198. ,f.Colspan
  199. ,f.ProjectCode
  200. ,f.BatchCode
  201. ,f.Version
  202. ,f.Brand
  203. ,f.cFree1
  204. ,f.cFree2
  205. ,f.cFree3
  206. ,f.cFree4
  207. ,f.cFree5
  208. ,f.cFree6
  209. ,f.cFree7
  210. ,f.cFree8
  211. ,f.cFree9
  212. ,f.cFree10
  213. ,a.EATTRIBUTE1
  214. ,a.EATTRIBUTE2
  215. ,a.EATTRIBUTE3
  216. ,a.EATTRIBUTE4
  217. ,a.EATTRIBUTE5
  218. ,a.EATTRIBUTE6
  219. ,a.EATTRIBUTE7
  220. ,a.EATTRIBUTE8
  221. ,a.EATTRIBUTE9
  222. ,a.EATTRIBUTE10
  223. from ICSOtherIn a
  224. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  225. WHERE a.InCode='" + InCode + "' ";
  226. if (!string.IsNullOrWhiteSpace(queryJson))
  227. {
  228. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  229. {
  230. sql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' ";
  231. }
  232. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  233. {
  234. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  235. }
  236. if (!string.IsNullOrWhiteSpace(queryParam["CreatedBy"].ToString()))
  237. {
  238. sql += " and a.CreatePerson like '%" + queryParam["CreatedBy"].ToString() + "%' ";
  239. }
  240. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  241. {
  242. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  243. }
  244. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  245. {
  246. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  247. }
  248. }
  249. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  250. }
  251. #endregion
  252. public string DeleteICSOtherInByCode(string keyValue)
  253. {
  254. //站点信息
  255. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  256. string msg = "";
  257. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  258. string sql = string.Empty;
  259. sql += string.Format(@"DELETE FROM dbo.ICSOtherIn WHERE InCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  260. try
  261. {
  262. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  263. {
  264. }
  265. }
  266. catch (Exception ex)
  267. {
  268. throw new Exception(ex.Message);
  269. }
  270. return msg;
  271. }
  272. public string GetBidCode(string WorkPoint)
  273. {
  274. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  275. string BidCide = string.Empty;
  276. if (!string.IsNullOrEmpty(WorkPoint))
  277. {
  278. string DateString = DateTime.Now.ToString("yyyyMMdd");
  279. string Pre = "ZS" + DateString;
  280. BidCide = GetSerialCode(WorkPoint, "ICSOtherIn", "InCode", Pre, 4);
  281. }
  282. if (!string.IsNullOrWhiteSpace(BidCide))
  283. {
  284. string sqlISHave = @"SELECT InCode FROM ICSOtherIn a
  285. WHERE a.InCode = '{0}'";
  286. sqlISHave = string.Format(sqlISHave, BidCide);
  287. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  288. if (dtIsHave.Rows.Count > 0)
  289. {
  290. throw new Exception("单号已存在!");
  291. }
  292. }
  293. return BidCide;
  294. }
  295. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  296. {
  297. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  298. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  299. //return Repository().FindTableBySql(sql.ToString());
  300. return SqlHelper.ExecuteScalar(sql).ToString();
  301. //return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
  302. }
  303. public string UpdateICSOtherIn(string ICSASN)
  304. {
  305. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  306. string UserName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  307. string msg = "";
  308. List<JsonData> parsedData = JsonConvert.DeserializeObject<List<JsonData>>(ICSASN);
  309. string sql = "";
  310. string Colspan = "";
  311. string str1 = "";
  312. List<string> ExtensionIDList = new List<string>();
  313. // 获取解析后的数据
  314. JsonData data = parsedData[0];
  315. foreach (var detail in data.Detail)
  316. {
  317. Colspan = "~" + detail.Batch + "~~~~~~~~~~~~";
  318. string sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, WorkPoint);
  319. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  320. bool flag = true;
  321. foreach (var item in ExtensionIDList)
  322. {
  323. if (item == Colspan + WorkPoint)
  324. {
  325. flag = false;
  326. }
  327. }
  328. if (ExtensionID == null && flag == true)
  329. {
  330. str1 = Guid.NewGuid().ToString();
  331. sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  332. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  333. str1, Colspan, "", detail.Batch, "", "", "", "", "", "", "", "", "", "", "", "",
  334. data.User, UserName, WorkPoint);
  335. }
  336. else if (ExtensionID != null)
  337. {
  338. str1 = ExtensionID.ToString();
  339. }
  340. ExtensionIDList.Add(Colspan + WorkPoint);
  341. sql += @" IF NOT EXISTS(SELECT * FROM dbo.ICSOtherIn WHERE ID='{0}')
  342. BEGIN
  343. INSERT INTO ICSOtherIn(ID,INCode,WHCode,Sequence,InvCode,Quantity,CreatePerson,CreateDateTime,WorkPoint,Status,InID,InDetailID,ExtensionID,MUSER,MUSERName,MTIME,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7)
  344. select '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',newID(),newID(),'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'
  345. END
  346. ELSE
  347. BEGIN
  348. UPDATE dbo.ICSOtherIn
  349. SET WHCode='{2}',InvCode='{4}',Quantity='{5}',CreatePerson='{6}',
  350. CreateDateTime='{7}' ,MTIME='{13}',EATTRIBUTE1='{14}',EATTRIBUTE2='{15}',EATTRIBUTE3='{16}',EATTRIBUTE4='{17}',EATTRIBUTE5='{18}',EATTRIBUTE6='{19}',EATTRIBUTE7='{20}'
  351. WHERE ID='{0}'
  352. END";
  353. sql = string.Format(sql, detail.ID, data.Code, detail.WHCode, detail.Sequence, detail.InvCode, detail.Quantity, data.User, data.MTIME, WorkPoint, '1', str1, data.User, UserName, data.MTIME, data.Dept, data.CodeType, data.ApplyNegCode, data.Custmer, data.Remarks, detail.DetailReamrk, data.SYproject);
  354. }
  355. try
  356. {
  357. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  358. {
  359. }
  360. }
  361. catch (Exception ex)
  362. {
  363. msg = ex.Message;
  364. }
  365. return msg;
  366. }
  367. public DataTable GetICSReturnTemporary(string rfqno)
  368. {
  369. string sql = @"SELECT
  370. a.ID,
  371. a.InCode,
  372. a.InvCode,
  373. b.InvName,
  374. b.InvStd,
  375. a.Quantity,
  376. a.WHCode,
  377. a.WHCode as WHCodeHHH,
  378. a.EATTRIBUTE6,
  379. a.Quantity
  380. ,f.BatchCode as Batch
  381. ,c.WarehouseName as WHCodeName
  382. FROM ICSOtherIn a
  383. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode
  384. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  385. LEFT JOIN dbo.ICSWarehouse c ON a.WHCode=c.WarehouseCode AND a.WorkPoint=c.WorkPoint
  386. where a.InCode='" + rfqno + "'";
  387. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  388. DataTable dtCloned = table.Clone();
  389. foreach (DataColumn col in dtCloned.Columns)
  390. {
  391. col.DataType = typeof(string);
  392. }
  393. foreach (DataRow row in table.Rows)
  394. {
  395. DataRow newrow = dtCloned.NewRow();
  396. foreach (DataColumn column in dtCloned.Columns)
  397. {
  398. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  399. }
  400. dtCloned.Rows.Add(newrow);
  401. }
  402. if (Invmes.Rows.Count > 0)
  403. {
  404. dtCloned.Merge(Invmes, false);
  405. }
  406. return dtCloned;
  407. }
  408. // 定义一个类来表示 JSON 数据的结构
  409. public class JsonData
  410. {
  411. public string Dept { get; set; }
  412. public string CodeType { get; set; }
  413. public string ApplyNegCode { get; set; }
  414. public string Custmer { get; set; }
  415. public string Remarks { get; set; }
  416. public string Code { get; set; }
  417. public string MTIME { get; set; }
  418. public string User { get; set; }
  419. public string SYproject { get; set; }
  420. public List<JsonDetail> Detail { get; set; }
  421. }
  422. public class JsonDetail
  423. {
  424. public string ID;
  425. public int Sequence { get; set; }
  426. public string InvCode { get; set; }
  427. public decimal Quantity { get; set; }
  428. public string WHCode { get; set; }
  429. public string DetailReamrk { get; set; }
  430. public string Batch { get;set; }
  431. }
  432. #endregion
  433. }
  434. }