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

413 lines
17 KiB

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