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

472 lines
19 KiB

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