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

398 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 WWMaterialsDeliveredRTMApp : RepositoryFactory<ICSVendor>
  18. {
  19. public static DataTable WWMDInvmes = 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='3'";
  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 (WWMDInvmes.Rows.Count > 0)
  105. {
  106. dtCloned.Merge(WWMDInvmes, 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 DISTINCT
  121. a.IssueDetailID AS ZJID,
  122. a.IssueCode,
  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 ICSOIssue 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.IssueDetailID = 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 (WWMDInvmes.Columns.Count <= 0)
  150. {
  151. WWMDInvmes.Columns.Add("ZJID", typeof(string));
  152. WWMDInvmes.Columns.Add("InvCode", typeof(string));
  153. WWMDInvmes.Columns.Add("INVNAME", typeof(string));
  154. WWMDInvmes.Columns.Add("InvStd", typeof(string));
  155. WWMDInvmes.Columns.Add("InvUnit", typeof(string));
  156. WWMDInvmes.Columns.Add("Quantity", typeof(string));
  157. WWMDInvmes.Columns.Add("Amount", typeof(string));
  158. WWMDInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  159. WWMDInvmes.Columns.Add("ExtensionID", typeof(string));
  160. WWMDInvmes.Columns.Add("ID", typeof(string));
  161. WWMDInvmes.Columns.Add("TLZID", typeof(string));
  162. WWMDInvmes.Columns.Add("tuinum", typeof(string));
  163. }
  164. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  165. DataRow newrow = WWMDInvmes.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. WWMDInvmes.Rows.Add(newrow);
  179. }
  180. public void ClearTemp()
  181. {
  182. WWMDInvmes.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 ICSOIssue c ON a.SourceDetailID=c.IssueDetailID and a.WorkPoint=c.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 ON a.SourceDetailID = d.SourceDetailID AND a.WorkPoint = d.WorkPoint
  221. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  222. where a.OApplyNegCode='" + OApplyNegCode + "'";
  223. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  224. if (WWMDInvmes == null || WWMDInvmes.Columns.Count <= 0)
  225. WWMDInvmes = table.Clone();
  226. DataTable dtCloned = table.Clone();
  227. foreach (DataColumn col in dtCloned.Columns)
  228. {
  229. col.DataType = typeof(string);
  230. }
  231. foreach (DataRow row in table.Rows)
  232. {
  233. DataRow newrow = dtCloned.NewRow();
  234. foreach (DataColumn column in dtCloned.Columns)
  235. {
  236. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  237. }
  238. dtCloned.Rows.Add(newrow);
  239. }
  240. if (WWMDInvmes.Rows.Count > 0)
  241. {
  242. //dtCloned.Merge(WWInvmes, false);
  243. foreach (DataRow data in WWMDInvmes.Rows)
  244. {
  245. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  246. if (info != null && info.Length > 0)
  247. {
  248. info[0]["ZJID"] = data["ZJID"];
  249. info[0]["InvName"] = data["InvName"];
  250. info[0]["InvCode"] = data["InvCode"];
  251. info[0]["InvStd"] = data["InvStd"];
  252. info[0]["InvUnit"] = data["InvUnit"];
  253. info[0]["Amount"] = data["Amount"];
  254. info[0]["Quantity"] = 0;
  255. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  256. info[0]["ExtensionID"] = data["ExtensionID"];
  257. info[0]["tuinum"] = data["tuinum"];
  258. }
  259. else
  260. {
  261. DataRow newrow = dtCloned.NewRow();
  262. newrow["ZJID"] = data["ZJID"];
  263. newrow["InvName"] = data["InvName"];
  264. newrow["InvCode"] = data["InvCode"];
  265. newrow["InvStd"] = data["InvStd"];
  266. newrow["InvUnit"] = data["InvUnit"];
  267. newrow["Amount"] = data["Amount"];
  268. newrow["Quantity"] = 0;
  269. newrow["ID"] = data["ID"];
  270. newrow["TLZID"] = data["TLZID"];
  271. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  272. newrow["ExtensionID"] = data["ExtensionID"];
  273. newrow["tuinum"] = data["tuinum"];
  274. dtCloned.Rows.Add(newrow);
  275. }
  276. }
  277. }
  278. return dtCloned;
  279. }
  280. public string UpdateICSMOApplyNeg(string ICSASN)
  281. {
  282. string msg = "";
  283. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Update";
  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 string AuditICSMOApplyNeg(string ICSASN)
  295. {
  296. string msg = "";
  297. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Approve";
  298. string result = HttpPost(APIURL, ICSASN);
  299. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  300. string MessAge = Obj["Message"].ToString();
  301. string Success = Obj["Success"].ToString();
  302. if (Success.ToUpper() == "FALSE")
  303. {
  304. msg = MessAge;
  305. }
  306. return msg;
  307. }
  308. public static string HttpPost(string url, string body)
  309. {
  310. try
  311. {
  312. Encoding encoding = Encoding.UTF8;
  313. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  314. request.Method = "POST";
  315. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  316. request.ContentType = "application/json; charset=utf-8";
  317. byte[] buffer = encoding.GetBytes(body);
  318. request.ContentLength = buffer.Length;
  319. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  320. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  321. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  322. {
  323. return reader.ReadToEnd();
  324. }
  325. }
  326. catch (WebException ex)
  327. {
  328. throw new Exception(ex.Message);
  329. }
  330. }
  331. public void UpdateMOApplyNegTemp(string json)
  332. {
  333. var data = json.ToJObject();
  334. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  335. var info = WWMDInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  336. if (info != null && info.Length > 0)
  337. {
  338. info[0]["ZJID"] = data["ZJID"];
  339. info[0]["InvName"] = data["InvName"];
  340. info[0]["InvCode"] = data["InvCode"];
  341. info[0]["InvStd"] = data["InvStd"];
  342. info[0]["InvUnit"] = data["InvUnit"];
  343. info[0]["Amount"] = data["Amount"];
  344. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  345. info[0]["ExtensionID"] = data["ExtensionID"];
  346. info[0]["tuinum"] = data["tuinum"];
  347. info[0]["Quantity"] = 0;
  348. }
  349. else
  350. {
  351. DataRow newrow = WWMDInvmes.NewRow();
  352. newrow["ZJID"] = data["ZJID"];
  353. newrow["InvName"] = data["InvName"];
  354. newrow["InvCode"] = data["InvCode"];
  355. newrow["InvStd"] = data["InvStd"];
  356. newrow["InvUnit"] = data["InvUnit"];
  357. newrow["Amount"] = data["Amount"];
  358. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  359. newrow["ExtensionID"] = data["ExtensionID"];
  360. newrow["tuinum"] = data["tuinum"];
  361. newrow["Quantity"] = 0;
  362. newrow["ID"] = data["ID"];
  363. newrow["TLZID"] = data["TLZID"];
  364. WWMDInvmes.Rows.Add(newrow);
  365. }
  366. }
  367. }
  368. }