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.

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