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.

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