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

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