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

383 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 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 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 (WWMDInvmes.Rows.Count > 0)
  96. {
  97. dtCloned.Merge(WWMDInvmes, 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 DISTINCT
  112. a.IssueDetailID AS ZJID,
  113. a.IssueCode,
  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 ICSOIssue 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.IssueDetailID = 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 (WWMDInvmes.Columns.Count <= 0)
  138. {
  139. WWMDInvmes.Columns.Add("ZJID", typeof(string));
  140. WWMDInvmes.Columns.Add("InvCode", typeof(string));
  141. WWMDInvmes.Columns.Add("INVNAME", typeof(string));
  142. WWMDInvmes.Columns.Add("InvStd", typeof(string));
  143. WWMDInvmes.Columns.Add("InvUnit", typeof(string));
  144. WWMDInvmes.Columns.Add("Quantity", typeof(string));
  145. WWMDInvmes.Columns.Add("Amount", typeof(string));
  146. WWMDInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  147. WWMDInvmes.Columns.Add("ExtensionID", typeof(string));
  148. WWMDInvmes.Columns.Add("ID", typeof(string));
  149. WWMDInvmes.Columns.Add("TLZID", typeof(string));
  150. WWMDInvmes.Columns.Add("tuinum", typeof(string));
  151. }
  152. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  153. DataRow newrow = WWMDInvmes.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. WWMDInvmes.Rows.Add(newrow);
  167. }
  168. public void ClearTemp()
  169. {
  170. WWMDInvmes.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 ICSOIssue c ON a.SourceDetailID=c.IssueDetailID and a.WorkPoint=c.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 ON a.SourceDetailID = d.SourceDetailID AND a.WorkPoint = d.WorkPoint
  207. where a.OApplyNegCode='" + OApplyNegCode + "'";
  208. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  209. if (WWMDInvmes == null || WWMDInvmes.Columns.Count <= 0)
  210. WWMDInvmes = table.Clone();
  211. DataTable dtCloned = table.Clone();
  212. foreach (DataColumn col in dtCloned.Columns)
  213. {
  214. col.DataType = typeof(string);
  215. }
  216. foreach (DataRow row in table.Rows)
  217. {
  218. DataRow newrow = dtCloned.NewRow();
  219. foreach (DataColumn column in dtCloned.Columns)
  220. {
  221. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  222. }
  223. dtCloned.Rows.Add(newrow);
  224. }
  225. if (WWMDInvmes.Rows.Count > 0)
  226. {
  227. //dtCloned.Merge(WWInvmes, false);
  228. foreach (DataRow data in WWMDInvmes.Rows)
  229. {
  230. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  231. if (info != null && info.Length > 0)
  232. {
  233. info[0]["ZJID"] = data["ZJID"];
  234. info[0]["InvName"] = data["InvName"];
  235. info[0]["InvCode"] = data["InvCode"];
  236. info[0]["InvStd"] = data["InvStd"];
  237. info[0]["InvUnit"] = data["InvUnit"];
  238. info[0]["Amount"] = data["Amount"];
  239. info[0]["Quantity"] = 0;
  240. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  241. info[0]["ExtensionID"] = data["ExtensionID"];
  242. info[0]["tuinum"] = data["tuinum"];
  243. }
  244. else
  245. {
  246. DataRow newrow = dtCloned.NewRow();
  247. newrow["ZJID"] = data["ZJID"];
  248. newrow["InvName"] = data["InvName"];
  249. newrow["InvCode"] = data["InvCode"];
  250. newrow["InvStd"] = data["InvStd"];
  251. newrow["InvUnit"] = data["InvUnit"];
  252. newrow["Amount"] = data["Amount"];
  253. newrow["Quantity"] = 0;
  254. newrow["ID"] = data["ID"];
  255. newrow["TLZID"] = data["TLZID"];
  256. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  257. newrow["ExtensionID"] = data["ExtensionID"];
  258. newrow["tuinum"] = data["tuinum"];
  259. dtCloned.Rows.Add(newrow);
  260. }
  261. }
  262. }
  263. return dtCloned;
  264. }
  265. public string UpdateICSMOApplyNeg(string ICSASN)
  266. {
  267. string msg = "";
  268. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Update";
  269. string result = HttpPost(APIURL, ICSASN);
  270. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  271. string MessAge = Obj["Message"].ToString();
  272. string Success = Obj["Success"].ToString();
  273. if (Success.ToUpper() == "FALSE")
  274. {
  275. msg = MessAge;
  276. }
  277. return msg;
  278. }
  279. public string AuditICSMOApplyNeg(string ICSASN)
  280. {
  281. string msg = "";
  282. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingIssueDoNegativeApply/Approve";
  283. string result = HttpPost(APIURL, ICSASN);
  284. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  285. string MessAge = Obj["Message"].ToString();
  286. string Success = Obj["Success"].ToString();
  287. if (Success.ToUpper() == "FALSE")
  288. {
  289. msg = MessAge;
  290. }
  291. return msg;
  292. }
  293. public static string HttpPost(string url, string body)
  294. {
  295. try
  296. {
  297. Encoding encoding = Encoding.UTF8;
  298. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  299. request.Method = "POST";
  300. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  301. request.ContentType = "application/json; charset=utf-8";
  302. byte[] buffer = encoding.GetBytes(body);
  303. request.ContentLength = buffer.Length;
  304. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  305. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  306. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  307. {
  308. return reader.ReadToEnd();
  309. }
  310. }
  311. catch (WebException ex)
  312. {
  313. throw new Exception(ex.Message);
  314. }
  315. }
  316. public void UpdateMOApplyNegTemp(string json)
  317. {
  318. var data = json.ToJObject();
  319. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  320. var info = WWMDInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  321. if (info != null && info.Length > 0)
  322. {
  323. info[0]["ZJID"] = data["ZJID"];
  324. info[0]["InvName"] = data["InvName"];
  325. info[0]["InvCode"] = data["InvCode"];
  326. info[0]["InvStd"] = data["InvStd"];
  327. info[0]["InvUnit"] = data["InvUnit"];
  328. info[0]["Amount"] = data["Amount"];
  329. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  330. info[0]["ExtensionID"] = data["ExtensionID"];
  331. info[0]["tuinum"] = data["tuinum"];
  332. info[0]["Quantity"] = 0;
  333. }
  334. else
  335. {
  336. DataRow newrow = WWMDInvmes.NewRow();
  337. newrow["ZJID"] = data["ZJID"];
  338. newrow["InvName"] = data["InvName"];
  339. newrow["InvCode"] = data["InvCode"];
  340. newrow["InvStd"] = data["InvStd"];
  341. newrow["InvUnit"] = data["InvUnit"];
  342. newrow["Amount"] = data["Amount"];
  343. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  344. newrow["ExtensionID"] = data["ExtensionID"];
  345. newrow["tuinum"] = data["tuinum"];
  346. newrow["Quantity"] = 0;
  347. newrow["ID"] = data["ID"];
  348. newrow["TLZID"] = data["TLZID"];
  349. WWMDInvmes.Rows.Add(newrow);
  350. }
  351. }
  352. }
  353. }