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

402 lines
16 KiB

  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Text;
  6. using NFine.Code;
  7. using NFine.Repository;
  8. using System.Data.Common;
  9. using NFine.Domain._03_Entity.SRM;
  10. using Newtonsoft.Json;
  11. using System.Configuration;
  12. using Newtonsoft.Json.Linq;
  13. using System.Net;
  14. using System.IO;
  15. namespace NFine.Application.WMS
  16. {
  17. public class WWProductionRAFMRApp : RepositoryFactory<ICSVendor>
  18. {
  19. public static DataTable WWPRInvmes = new DataTable();
  20. public DataTable GetICSOApplyNeg(ref Pagination jqgridparam)
  21. {
  22. DataTable dt = new DataTable();
  23. List<DbParameter> parameter = new List<DbParameter>();
  24. string sql = @" select a.ID,a.OApplyNegCode,a.WHCode,b.WarehouseName,a.Status,a.Type,a.Memo,a.CreatePerson,a.CreateDateTime,a.MUSER,a.MUSERName
  25. from ICSOApplyNeg a
  26. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  27. where a.Type='2'";
  28. sql = string.Format(sql);
  29. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  30. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  31. }
  32. public DataTable GetICSOApplyNegDetail(string OApplyNegCode, ref Pagination jqgridparam)
  33. {
  34. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  35. DataTable dt = new DataTable();
  36. //var queryParam = queryJson.ToJObject();
  37. List<DbParameter> parameter = new List<DbParameter>();
  38. string sql = @"select ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,MUSERName,MTIME from ICSOApplyNegDetail
  39. WHERE OApplyNegCode='" + OApplyNegCode + "' ";
  40. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  41. }
  42. public string DeleteICSMOApplyNeg(string keyValue)
  43. {
  44. //站点信息
  45. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  46. string msg = "";
  47. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  48. string sql = string.Empty;
  49. sql += string.Format(@"DELETE FROM dbo.ICSOApplyNeg WHERE OApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  50. sql += string.Format(@"DELETE FROM dbo.ICSOApplyNegDetail WHERE OApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  51. try
  52. {
  53. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  54. {
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. throw new Exception(ex.Message);
  60. }
  61. return msg;
  62. }
  63. public DataTable GetICSReturnTemporary(string rfqno)
  64. {
  65. string sql = @"SELECT
  66. a.OApplyNegCode,
  67. a.InvCode,
  68. a.Quantity,
  69. a.Amount,
  70. a.SourceDetailID as ZJID,
  71. b.InvName,
  72. b.InvStd,
  73. b.InvUnit,
  74. a.IssueNegQuantity,
  75. a.ExtensionID,
  76. '' as tuinum
  77. FROM
  78. ICSOApplyNegDetail a
  79. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint where a.OApplyNegCode='" + rfqno + "'";
  80. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  81. DataTable dtCloned = table.Clone();
  82. foreach (DataColumn col in dtCloned.Columns)
  83. {
  84. col.DataType = typeof(string);
  85. }
  86. foreach (DataRow row in table.Rows)
  87. {
  88. DataRow newrow = dtCloned.NewRow();
  89. foreach (DataColumn column in dtCloned.Columns)
  90. {
  91. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  92. }
  93. dtCloned.Rows.Add(newrow);
  94. }
  95. if (WWPRInvmes.Rows.Count > 0)
  96. {
  97. dtCloned.Merge(WWPRInvmes, false);
  98. }
  99. return dtCloned;
  100. }
  101. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  102. {
  103. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  104. List<DbParameter> parameter = new List<DbParameter>();
  105. DataTable table = new DataTable();
  106. string wherestr = "";
  107. if (!string.IsNullOrEmpty(invcode))
  108. {
  109. wherestr += " and a.InvCode like '%" + invcode + "'%";
  110. }
  111. string sql = @" SELECT
  112. a.ApplyDetailID AS ZJID,
  113. a.ApplyCode,
  114. a.Sequence AS MuHang,
  115. a.InvCode,
  116. a.Quantity,
  117. a.Amount,
  118. b.InvName,
  119. b.InvStd,
  120. b.InvUnit,
  121. a.IssueQuantity,
  122. a.ExtensionID,
  123. isnull(d.Quantity, 0) as tuinum
  124. FROM ICSOApply a
  125. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode AND a.WorkPoint = b.WorkPoint
  126. LEFT JOIN (select a.SourceDetailID, a.WorkPoint, sum(a.Quantity) as Quantity FROM ICSOApplyNegDetail a
  127. left join ICSOApplyNeg b ON a.OApplyNegCode=b.OApplyNegCode AND a.WorkPoint=b.WorkPoint
  128. where b.Type='2' GROUP BY a.SourceDetailID, a.WorkPoint) d ON a.ApplyDetailID = d.SourceDetailID AND a.WorkPoint = d.WorkPoint
  129. where a.IssueQuantity > 0 and a.WorkPoint = '{0}' ";
  130. sql = string.Format(sql, WorkPoint);
  131. sql = sql + wherestr;
  132. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  133. }
  134. public void AddMOApplyNegTemp(string json)
  135. {
  136. var data = json.ToJObject();
  137. if (WWPRInvmes.Columns.Count <= 0)
  138. {
  139. WWPRInvmes.Columns.Add("ZJID", typeof(string));
  140. WWPRInvmes.Columns.Add("InvCode", typeof(string));
  141. WWPRInvmes.Columns.Add("INVNAME", typeof(string));
  142. WWPRInvmes.Columns.Add("InvStd", typeof(string));
  143. WWPRInvmes.Columns.Add("InvUnit", typeof(string));
  144. WWPRInvmes.Columns.Add("Quantity", typeof(string));
  145. WWPRInvmes.Columns.Add("Amount", typeof(string));
  146. WWPRInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  147. WWPRInvmes.Columns.Add("ExtensionID", typeof(string));
  148. WWPRInvmes.Columns.Add("ID", typeof(string));
  149. WWPRInvmes.Columns.Add("TLZID", typeof(string));
  150. WWPRInvmes.Columns.Add("tuinum", typeof(string));
  151. }
  152. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  153. DataRow newrow = WWPRInvmes.NewRow();
  154. newrow["ZJID"] = data["ZJID"];
  155. newrow["InvName"] = data["InvName"];
  156. newrow["InvCode"] = data["InvCode"];
  157. newrow["InvStd"] = data["InvStd"];
  158. newrow["InvUnit"] = data["InvUnit"];
  159. newrow["Amount"] = data["Amount"];
  160. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  161. newrow["ExtensionID"] = data["ExtensionID"];
  162. newrow["Quantity"] = "0";
  163. newrow["ID"] = data["ID"];
  164. newrow["TLZID"] = data["TLZID"];
  165. newrow["tuinum"] = data["tuinum"];
  166. WWPRInvmes.Rows.Add(newrow);
  167. }
  168. public void ClearTemp()
  169. {
  170. WWPRInvmes.Rows.Clear();
  171. }
  172. public string SaveICSMOApplyNeg(string ICSASN)
  173. {
  174. string msg = "";
  175. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Create";
  176. string result = HttpPost(APIURL, ICSASN);
  177. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  178. string MessAge = Obj["Message"].ToString();
  179. string Success = Obj["Success"].ToString();
  180. if (Success.ToUpper() == "FALSE")
  181. {
  182. msg = MessAge;
  183. }
  184. return msg;
  185. }
  186. public DataTable GetICSMOApplyNegDetailTemp(string OApplyNegCode)
  187. {
  188. string sql = @"SELECT
  189. a.ID,
  190. a.ID as TLZID,
  191. a.OApplyNegCode,
  192. a.InvCode,
  193. a.Quantity,
  194. a.Amount,
  195. a.SourceDetailID as ZJID,
  196. b.InvName,
  197. b.InvStd,
  198. b.InvUnit,
  199. c.IssueQuantity AS IssueNegQuantity,
  200. a.ExtensionID,
  201. isnull(d.Quantity,0) as tuinum
  202. FROM
  203. ICSOApplyNegDetail a
  204. left join ICSOApply c on c.ApplyDetailID=a.SourceDetailID AND c.WorkPoint=a.WorkPoint
  205. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  206. LEFT JOIN (select SourceDetailID,WorkPoint,sum(Quantity) as Quantity FROM ICSOApplyNegDetail GROUP BY SourceDetailID,WorkPoint) d
  207. ON a.SourceDetailID = d.SourceDetailID AND a.WorkPoint = d.WorkPoint
  208. where a.OApplyNegCode='" + OApplyNegCode + "'";
  209. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  210. if (WWPRInvmes == null || WWPRInvmes.Columns.Count <= 0)
  211. WWPRInvmes = table.Clone();
  212. DataTable dtCloned = table.Clone();
  213. foreach (DataColumn col in dtCloned.Columns)
  214. {
  215. col.DataType = typeof(string);
  216. }
  217. foreach (DataRow row in table.Rows)
  218. {
  219. DataRow newrow = dtCloned.NewRow();
  220. foreach (DataColumn column in dtCloned.Columns)
  221. {
  222. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  223. }
  224. dtCloned.Rows.Add(newrow);
  225. }
  226. if (WWPRInvmes.Rows.Count > 0)
  227. {
  228. //dtCloned.Merge(WWInvmes, false);
  229. foreach (DataRow data in WWPRInvmes.Rows)
  230. {
  231. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  232. if (info != null && info.Length > 0)
  233. {
  234. info[0]["ZJID"] = data["ZJID"];
  235. info[0]["InvName"] = data["InvName"];
  236. info[0]["InvCode"] = data["InvCode"];
  237. info[0]["InvStd"] = data["InvStd"];
  238. info[0]["InvUnit"] = data["InvUnit"];
  239. info[0]["Amount"] = data["Amount"];
  240. info[0]["Quantity"] = 0;
  241. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  242. info[0]["ExtensionID"] = data["ExtensionID"];
  243. info[0]["tuinum"] = data["tuinum"];
  244. }
  245. else
  246. {
  247. DataRow newrow = dtCloned.NewRow();
  248. newrow["ZJID"] = data["ZJID"];
  249. newrow["InvName"] = data["InvName"];
  250. newrow["InvCode"] = data["InvCode"];
  251. newrow["InvStd"] = data["InvStd"];
  252. newrow["InvUnit"] = data["InvUnit"];
  253. newrow["Amount"] = data["Amount"];
  254. newrow["Quantity"] = 0;
  255. newrow["ID"] = data["ID"];
  256. newrow["TLZID"] = data["TLZID"];
  257. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  258. newrow["ExtensionID"] = data["ExtensionID"];
  259. newrow["tuinum"] = data["tuinum"];
  260. dtCloned.Rows.Add(newrow);
  261. }
  262. }
  263. }
  264. return dtCloned;
  265. }
  266. public string UpdateICSMOApplyNeg(string ICSASN)
  267. {
  268. string msg = "";
  269. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Update";
  270. string result = HttpPost(APIURL, ICSASN);
  271. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  272. string MessAge = Obj["Message"].ToString();
  273. string Success = Obj["Success"].ToString();
  274. if (Success.ToUpper() == "FALSE")
  275. {
  276. msg = MessAge;
  277. }
  278. return msg;
  279. }
  280. public string AuditICSMOApplyNeg(string ICSASN)
  281. {
  282. string msg = "";
  283. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Approve";
  284. string result = HttpPost(APIURL, ICSASN);
  285. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  286. string MessAge = Obj["Message"].ToString();
  287. string Success = Obj["Success"].ToString();
  288. if (Success.ToUpper() == "FALSE")
  289. {
  290. msg = MessAge;
  291. }
  292. return msg;
  293. }
  294. public void UpdateMOApplyNegTemp(string json)
  295. {
  296. var data = json.ToJObject();
  297. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  298. var info = WWPRInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  299. if (info != null && info.Length > 0)
  300. {
  301. info[0]["ZJID"] = data["ZJID"];
  302. info[0]["InvName"] = data["InvName"];
  303. info[0]["InvCode"] = data["InvCode"];
  304. info[0]["InvStd"] = data["InvStd"];
  305. info[0]["InvUnit"] = data["InvUnit"];
  306. info[0]["Amount"] = data["Amount"];
  307. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  308. info[0]["ExtensionID"] = data["ExtensionID"];
  309. info[0]["tuinum"] = data["tuinum"];
  310. info[0]["Quantity"] = 0;
  311. }
  312. else
  313. {
  314. DataRow newrow = WWPRInvmes.NewRow();
  315. newrow["ZJID"] = data["ZJID"];
  316. newrow["InvName"] = data["InvName"];
  317. newrow["InvCode"] = data["InvCode"];
  318. newrow["InvStd"] = data["InvStd"];
  319. newrow["InvUnit"] = data["InvUnit"];
  320. newrow["Amount"] = data["Amount"];
  321. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  322. newrow["ExtensionID"] = data["ExtensionID"];
  323. newrow["tuinum"] = data["tuinum"];
  324. newrow["Quantity"] = 0;
  325. newrow["ID"] = data["ID"];
  326. newrow["TLZID"] = data["TLZID"];
  327. WWPRInvmes.Rows.Add(newrow);
  328. }
  329. }
  330. public static string HttpPost(string url, string body)
  331. {
  332. try
  333. {
  334. Encoding encoding = Encoding.UTF8;
  335. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  336. request.Method = "POST";
  337. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  338. request.ContentType = "application/json; charset=utf-8";
  339. byte[] buffer = encoding.GetBytes(body);
  340. request.ContentLength = buffer.Length;
  341. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  342. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  343. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  344. {
  345. return reader.ReadToEnd();
  346. }
  347. }
  348. catch (WebException ex)
  349. {
  350. throw new Exception(ex.Message);
  351. }
  352. }
  353. }
  354. }