纽威
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.

496 lines
20 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. using NFine.Domain._03_Entity.WMS;
  19. using System.Net;
  20. using System.IO;
  21. namespace NFine.Application.WMS
  22. {
  23. public class ProductionIssueApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable Invmes = new DataTable();
  26. // public static DataTable Supplier = new DataTable();
  27. /// <summary>
  28. /// 退料
  29. /// </summary>
  30. /// <param name="jqgridparam"></param>
  31. /// <returns></returns>
  32. public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
  33. {
  34. DataTable dt = new DataTable();
  35. List<DbParameter> parameter = new List<DbParameter>();
  36. string sql = @" select a.ID,a.ApplyNegCode,a.WHCode,b.WarehouseName,a.Status,a.Type,a.Memo,a.CreatePerson,a.CreateDateTime,a.MUSER,a.MUSERName
  37. from ICSMOApplyNeg a
  38. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  39. where a.Type='1' ";
  40. sql = string.Format(sql);
  41. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  42. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  43. }
  44. //子表查询
  45. public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  46. {
  47. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  48. DataTable dt = new DataTable();
  49. //var queryParam = queryJson.ToJObject();
  50. List<DbParameter> parameter = new List<DbParameter>();
  51. string sql = @"select a.ID,a.ApplyNegCode,a.Sequence,a.SourceDetailID,a.InvCode,a.Quantity,a.Amount,a.IssueNegQuantity,a.ExtensionID,a.MUSER
  52. ,a.MUSERName,a.MTIME
  53. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  54. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  55. from ICSMOApplyNegDetail a
  56. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  57. WHERE a.ApplyNegCode='" + ApplyNegCode + "' ";
  58. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  59. }
  60. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  61. {
  62. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  63. List<DbParameter> parameter = new List<DbParameter>();
  64. DataTable table = new DataTable();
  65. string wherestr = "";
  66. if (!string.IsNullOrEmpty(invcode))
  67. {
  68. wherestr += " and a.InvCode like '%" + invcode + "%'";
  69. }
  70. string sql = @"SELECT DISTINCT a.PickID as ZJID,c.MOCode,c.Sequence as MuHang,a.InvCode,a.Quantity,a.Amount,b.InvName,b.InvStd,b.InvUnit
  71. ,a.IssueQuantity,a.ExtensionID
  72. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  73. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  74. FROM ICSMOPick a
  75. left JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  76. left join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  77. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  78. where a.IssueQuantity>0 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  79. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  80. }
  81. public DataTable GetICSMOPickLog(string invcode, ref Pagination jqgridparam)
  82. {
  83. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  84. List<DbParameter> parameter = new List<DbParameter>();
  85. DataTable table = new DataTable();
  86. //string wherestr = "";
  87. //if (!string.IsNullOrEmpty(invcode))
  88. //{
  89. // wherestr += " and a.InvCode like '%" + invcode + "'%";
  90. //}
  91. string sql = @" select distinct a.WHCode,b.MOCode,b.Sequence,a.Sequence as ZJHH,c.BatchCode,a.Quantity,a.Amount,a.ID,a.InvCode
  92. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  93. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  94. from ICSMOPick a
  95. left join ICSMO b on b.ID=a.MODetailID and b.WorkPoint=a.WorkPoint
  96. left join ICSExtension f on a.ExtensionID=f.ID
  97. where a.InvCode='{0}' and a.WorkPoint='{1}'
  98. ";
  99. sql = string.Format(sql, invcode, WorkPoint);
  100. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  101. }
  102. /// <summary>
  103. /// 获取仓库列表
  104. /// </summary>
  105. /// <returns></returns>
  106. public DataTable GetWHCode()
  107. {
  108. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  109. string sql = @"
  110. select '' as WarehouseCode,'' as WarehouseName
  111. union all
  112. select WarehouseCode,WarehouseName from ICSWarehouse where Enable='1' and WorkPoint='{0}'
  113. ";
  114. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  115. //if (role != "admin")
  116. //{
  117. // sql += " and b.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  118. //}
  119. sql = string.Format(sql, WorkPoint);
  120. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  121. return dt;
  122. }
  123. public DataTable GetICSReturnTemporary(string rfqno)
  124. {
  125. string sql = @"SELECT
  126. a.ApplyNegCode,
  127. a.InvCode,
  128. a.Quantity,
  129. a.Amount,
  130. a.SourceDetailID as ZJID,
  131. b.InvName,
  132. b.InvStd,
  133. b.InvUnit
  134. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  135. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  136. FROM
  137. ICSMOApplyNegDetail a
  138. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode
  139. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  140. where a.ApplyNegCode='" + rfqno + "'";
  141. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  142. DataTable dtCloned = table.Clone();
  143. foreach (DataColumn col in dtCloned.Columns)
  144. {
  145. col.DataType = typeof(string);
  146. }
  147. foreach (DataRow row in table.Rows)
  148. {
  149. DataRow newrow = dtCloned.NewRow();
  150. foreach (DataColumn column in dtCloned.Columns)
  151. {
  152. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  153. }
  154. dtCloned.Rows.Add(newrow);
  155. }
  156. if (Invmes.Rows.Count > 0)
  157. {
  158. dtCloned.Merge(Invmes, false);
  159. }
  160. return dtCloned;
  161. }
  162. public string GetNewid()
  163. {
  164. string sql = "select newid() AS ID";
  165. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  166. }
  167. public void AddMOApplyNegTemp(string json)
  168. {
  169. var data = json.ToJObject();
  170. if (Invmes.Columns.Count <= 0)
  171. {
  172. Invmes.Columns.Add("ZJID", typeof(string));
  173. Invmes.Columns.Add("InvCode", typeof(string));
  174. Invmes.Columns.Add("INVNAME", typeof(string));
  175. Invmes.Columns.Add("InvStd", typeof(string));
  176. Invmes.Columns.Add("InvUnit", typeof(string));
  177. Invmes.Columns.Add("Quantity", typeof(string));
  178. Invmes.Columns.Add("IssueQuantity", typeof(string));
  179. Invmes.Columns.Add("ExtensionID", typeof(string));
  180. Invmes.Columns.Add("Amount", typeof(string));
  181. Invmes.Columns.Add("ID", typeof(string));
  182. }
  183. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  184. DataRow newrow = Invmes.NewRow();
  185. newrow["ZJID"] = data["ZJID"];
  186. newrow["InvName"] = data["InvName"];
  187. newrow["InvCode"] = data["InvCode"];
  188. newrow["InvStd"] = data["InvStd"];
  189. newrow["InvUnit"] = data["InvUnit"];
  190. newrow["Amount"] = data["Amount"];
  191. newrow["IssueQuantity"] = data["IssueQuantity"];
  192. newrow["ExtensionID"] = data["ExtensionID"];
  193. newrow["Quantity"] = "";
  194. newrow["ID"] = data["ID"];
  195. Invmes.Rows.Add(newrow);
  196. }
  197. public string DeleteMopick(string json)
  198. {
  199. try
  200. {
  201. string wheresql = "(";
  202. string[] id = json.Split(',');
  203. for (int i = 0; i < id.Length; i++)
  204. {
  205. wheresql += "'" + id[i].Replace(']', ' ').Replace('[', ' ').Replace('"', ' ').Trim() + "',";
  206. }
  207. wheresql = wheresql.Trim(',') + ")";
  208. string sql = "delete from ICSMOApplyNeg where id in" + wheresql;
  209. int count = DbHelper.ExecuteNonQuery(CommandType.Text, sql);
  210. DataRow[] row = Invmes.Select("ID in " + wheresql + "");
  211. foreach (DataRow a in row)
  212. {
  213. Invmes.Rows.Remove(a);
  214. }
  215. return "删除成功!";
  216. }
  217. catch (Exception ex)
  218. {
  219. return ex.Message + " 删除失败!";
  220. }
  221. }
  222. public void ClearTemp()
  223. {
  224. Invmes.Rows.Clear();
  225. }
  226. public string SaveICSMOApplyNeg(string ICSASN)
  227. {
  228. string msg = "";
  229. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Create";
  230. string result = HttpPost(APIURL, ICSASN);
  231. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  232. string MessAge = Obj["Message"].ToString();
  233. string Success = Obj["Success"].ToString();
  234. if (Success.ToUpper() == "FALSE")
  235. {
  236. msg = MessAge;
  237. }
  238. return msg;
  239. }
  240. public string UpdateICSMOApplyNeg(string ICSASN)
  241. {
  242. string msg = "";
  243. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  244. string result = HttpPost(APIURL, ICSASN);
  245. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  246. string MessAge = Obj["Message"].ToString();
  247. string Success = Obj["Success"].ToString();
  248. if (Success.ToUpper() == "FALSE")
  249. {
  250. msg = MessAge;
  251. }
  252. return msg;
  253. }
  254. //接口api解析
  255. public static string HttpPost(string url, string body)
  256. {
  257. try
  258. {
  259. Encoding encoding = Encoding.UTF8;
  260. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  261. request.Method = "POST";
  262. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  263. request.ContentType = "application/json; charset=utf-8";
  264. byte[] buffer = encoding.GetBytes(body);
  265. request.ContentLength = buffer.Length;
  266. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  267. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  268. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  269. {
  270. return reader.ReadToEnd();
  271. }
  272. }
  273. catch (WebException ex)
  274. {
  275. throw new Exception(ex.Message);
  276. }
  277. }
  278. /// <summary>
  279. /// 获取料品属性修改文本框值
  280. /// </summary>
  281. /// <param name="POCode"></param>
  282. /// <param name="PORow"></param>
  283. /// <returns></returns>
  284. public DataTable GetInputValue(string ID)
  285. {
  286. try
  287. {
  288. DataTable dt = new DataTable();
  289. //var queryParam = queryJson.ToJObject();
  290. List<DbParameter> parameter = new List<DbParameter>();
  291. string sql = @"select InvCode,InvName,InvDesc,InvStd,InvUnit,AmountUnit, ClassCode,ClassName,InvRate,InvVersion,InvBrand,InvIQC,
  292. InvFQC,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable,PrintEnable,WHUser
  293. from ICSInventory
  294. WHERE 1=1 AND ID='{0}' ";
  295. sql = string.Format(sql, ID);
  296. return Repository().FindTableBySql(sql.ToString());
  297. }
  298. catch (Exception ex)
  299. {
  300. throw new Exception(ex.Message.ToString());
  301. }
  302. }
  303. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  304. {
  305. string sql = @"SELECT
  306. a.ID,
  307. a.ID as TLZID,
  308. a.ApplyNegCode,
  309. a.InvCode,
  310. a.Quantity,
  311. a.Amount,
  312. a.SourceDetailID as ZJID,
  313. b.InvName,
  314. b.InvStd,
  315. b.InvUnit,
  316. a.IssueNegQuantity,
  317. a.ExtensionID
  318. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  319. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  320. FROM
  321. ICSMOApplyNegDetail a
  322. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode
  323. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  324. where a.ApplyNegCode='" + ApplyNegCode + "'";
  325. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  326. if(Invmes==null || Invmes.Columns.Count<=0)
  327. Invmes = table.Clone();
  328. DataTable dtCloned = table.Clone();
  329. foreach (DataColumn col in dtCloned.Columns)
  330. {
  331. col.DataType = typeof(string);
  332. }
  333. foreach (DataRow row in table.Rows)
  334. {
  335. DataRow newrow = dtCloned.NewRow();
  336. foreach (DataColumn column in dtCloned.Columns)
  337. {
  338. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  339. }
  340. dtCloned.Rows.Add(newrow);
  341. }
  342. if (Invmes.Rows.Count > 0)
  343. {
  344. //dtCloned.Merge(Invmes, false);
  345. foreach (DataRow data in Invmes.Rows)
  346. {
  347. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  348. if (info != null && info.Length > 0)
  349. {
  350. info[0]["ZJID"] = data["ZJID"];
  351. info[0]["InvName"] = data["InvName"];
  352. info[0]["InvCode"] = data["InvCode"];
  353. info[0]["InvStd"] = data["InvStd"];
  354. info[0]["InvUnit"] = data["InvUnit"];
  355. info[0]["Amount"] = data["Amount"];
  356. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  357. info[0]["ExtensionID"] = data["ExtensionID"];
  358. info[0]["Quantity"] = 0;
  359. }
  360. else
  361. {
  362. DataRow newrow = dtCloned.NewRow();
  363. newrow["ZJID"] = data["ZJID"];
  364. newrow["InvName"] = data["InvName"];
  365. newrow["InvCode"] = data["InvCode"];
  366. newrow["InvStd"] = data["InvStd"];
  367. newrow["InvUnit"] = data["InvUnit"];
  368. newrow["Amount"] = data["Amount"];
  369. newrow["Quantity"] = 0;
  370. newrow["ID"] = data["ID"];
  371. newrow["TLZID"] = data["TLZID"];
  372. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  373. newrow["ExtensionID"] = data["ExtensionID"];
  374. dtCloned.Rows.Add(newrow);
  375. }
  376. }
  377. }
  378. return dtCloned;
  379. }
  380. public void UpdateMOApplyNegTemp(string json)
  381. {
  382. var data = json.ToJObject();
  383. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  384. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  385. if (info != null && info.Length > 0)
  386. {
  387. info[0]["ZJID"] = data["ZJID"];
  388. info[0]["InvName"] = data["InvName"];
  389. info[0]["InvCode"] = data["InvCode"];
  390. info[0]["InvStd"] = data["InvStd"];
  391. info[0]["InvUnit"] = data["InvUnit"];
  392. info[0]["Amount"] = data["Amount"];
  393. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  394. info[0]["ExtensionID"] = data["ExtensionID"];
  395. info[0]["Quantity"] = 0;
  396. }
  397. else
  398. {
  399. DataRow newrow = Invmes.NewRow();
  400. newrow["ZJID"] = data["ZJID"];
  401. newrow["InvName"] = data["InvName"];
  402. newrow["InvCode"] = data["InvCode"];
  403. newrow["InvStd"] = data["InvStd"];
  404. newrow["InvUnit"] = data["InvUnit"];
  405. newrow["Amount"] = data["Amount"];
  406. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  407. newrow["ExtensionID"] = data["ExtensionID"];
  408. newrow["Quantity"] = 0;
  409. newrow["ID"] = data["ID"];
  410. newrow["TLZID"] = data["TLZID"];
  411. Invmes.Rows.Add(newrow);
  412. }
  413. }
  414. public string AuditICSMOApplyNeg(string ICSASN)
  415. {
  416. string msg = "";
  417. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Approve";
  418. string result = HttpPost(APIURL, ICSASN);
  419. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  420. string MessAge = Obj["Message"].ToString();
  421. string Success = Obj["Success"].ToString();
  422. if (Success.ToUpper() == "FALSE")
  423. {
  424. msg = MessAge;
  425. }
  426. return msg;
  427. }
  428. public string DeleteICSMOApplyNeg(string keyValue)
  429. {
  430. //站点信息
  431. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  432. string msg = "";
  433. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  434. string sql = string.Empty;
  435. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNeg WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  436. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  437. try
  438. {
  439. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  440. {
  441. }
  442. }
  443. catch (Exception ex)
  444. {
  445. throw new Exception(ex.Message);
  446. }
  447. return msg;
  448. }
  449. }
  450. }