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

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