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