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

379 lines
15 KiB

  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 MaterialsDeliveredRTMApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable MDInvmes = new DataTable();
  26. public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
  27. {
  28. DataTable dt = new DataTable();
  29. List<DbParameter> parameter = new List<DbParameter>();
  30. string sql = @" SELECT a.ID,a.ApplyNegCode,c.WHCode,b.WarehouseName,a.Status,a.Type,
  31. a.Memo,a.CreatePerson,a.CreateDateTime,a.MUSER,a.MUSERName
  32. FROM
  33. ICSMOApplyNeg a
  34. INNER JOIN ICSMOApplyNegDetail c ON a.ApplyNegCode=c.ApplyNegCode
  35. LEFT JOIN ICSWarehouse b ON c.WHCode= b.WarehouseCode AND a.WorkPoint= b.WorkPoint
  36. WHERE a.Type= '3'";
  37. sql = string.Format(sql);
  38. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  39. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  40. }
  41. public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  42. {
  43. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  44. DataTable dt = new DataTable();
  45. //var queryParam = queryJson.ToJObject();
  46. List<DbParameter> parameter = new List<DbParameter>();
  47. string sql = @"select a.ID,a.ApplyNegCode,a.Sequence,a.SourceDetailID,a.InvCode,a.Quantity,a.Amount,a.IssueNegQuantity,a.ExtensionID,a.MUSER
  48. ,a.MUSERName,a.MTIME
  49. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  50. from ICSMOApplyNegDetail a
  51. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  52. WHERE a.ApplyNegCode='" + ApplyNegCode + "' ";
  53. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  54. }
  55. public string DeleteICSMOApplyNeg(string keyValue)
  56. {
  57. //站点信息
  58. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  59. string msg = "";
  60. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  61. string sql = string.Empty;
  62. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNeg WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  63. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  64. try
  65. {
  66. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  67. {
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. throw new Exception(ex.Message);
  73. }
  74. return msg;
  75. }
  76. public DataTable GetICSReturnTemporary(string rfqno)
  77. {
  78. string sql = @"SELECT
  79. a.ApplyNegCode,
  80. a.InvCode,
  81. a.Quantity,
  82. a.Amount,
  83. a.SourceDetailID as ZJID,
  84. b.InvName,
  85. b.InvStd,
  86. b.InvUnit,
  87. a.IssueNegQuantity,
  88. a.ExtensionID,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  89. FROM
  90. ICSMOApplyNegDetail a
  91. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  92. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  93. where a.ApplyNegCode='" + rfqno + "'";
  94. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  95. DataTable dtCloned = table.Clone();
  96. foreach (DataColumn col in dtCloned.Columns)
  97. {
  98. col.DataType = typeof(string);
  99. }
  100. foreach (DataRow row in table.Rows)
  101. {
  102. DataRow newrow = dtCloned.NewRow();
  103. foreach (DataColumn column in dtCloned.Columns)
  104. {
  105. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  106. }
  107. dtCloned.Rows.Add(newrow);
  108. }
  109. if (MDInvmes.Rows.Count > 0)
  110. {
  111. dtCloned.Merge(MDInvmes, false);
  112. }
  113. return dtCloned;
  114. }
  115. public void ClearTemp()
  116. {
  117. MDInvmes.Rows.Clear();
  118. }
  119. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  120. {
  121. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  122. List<DbParameter> parameter = new List<DbParameter>();
  123. DataTable table = new DataTable();
  124. string wherestr = "";
  125. if (!string.IsNullOrEmpty(invcode))
  126. {
  127. wherestr += " and a.InvCode like '%" + invcode + "%'";
  128. }
  129. string sql = @"SELECT DISTINCT a.IssueDetailID as ZJID,a.IssueCode,a.Sequence as MuHang,a.InvCode,a.Quantity,a.Amount,b.InvName,b.InvStd,b.InvUnit,a.IssueQuantity as IssueNegQuantity,a.ExtensionID
  130. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  131. FROM ICSMOIssue a left JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  132. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  133. where a.IssueQuantity>0 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  134. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  135. }
  136. public void AddMOApplyNegTemp(string json)
  137. {
  138. var data = json.ToJObject();
  139. if (MDInvmes.Columns.Count <= 0)
  140. {
  141. MDInvmes.Columns.Add("ZJID", typeof(string));
  142. MDInvmes.Columns.Add("InvCode", typeof(string));
  143. MDInvmes.Columns.Add("INVNAME", typeof(string));
  144. MDInvmes.Columns.Add("InvStd", typeof(string));
  145. MDInvmes.Columns.Add("InvUnit", typeof(string));
  146. MDInvmes.Columns.Add("Quantity", typeof(string));
  147. MDInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  148. MDInvmes.Columns.Add("ExtensionID", typeof(string));
  149. MDInvmes.Columns.Add("Amount", typeof(string));
  150. MDInvmes.Columns.Add("ID", typeof(string));
  151. }
  152. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  153. DataRow newrow = MDInvmes.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"] = "";
  163. newrow["ID"] = data["ID"];
  164. MDInvmes.Rows.Add(newrow);
  165. }
  166. public void UpdateMOApplyNegTemp(string json)
  167. {
  168. var data = json.ToJObject();
  169. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  170. var info = MDInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  171. if (info != null && info.Length > 0)
  172. {
  173. info[0]["ZJID"] = data["ZJID"];
  174. info[0]["InvName"] = data["InvName"];
  175. info[0]["InvCode"] = data["InvCode"];
  176. info[0]["InvStd"] = data["InvStd"];
  177. info[0]["InvUnit"] = data["InvUnit"];
  178. info[0]["Amount"] = data["Amount"];
  179. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  180. info[0]["ExtensionID"] = data["ExtensionID"];
  181. info[0]["Quantity"] = 0;
  182. }
  183. else
  184. {
  185. DataRow newrow = MDInvmes.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. MDInvmes.Rows.Add(newrow);
  198. }
  199. }
  200. public string SaveICSMOApplyNeg(string ICSASN)
  201. {
  202. string msg = "";
  203. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Create";
  204. string result = HttpPost(APIURL, ICSASN);
  205. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  206. string MessAge = Obj["Message"].ToString();
  207. string Success = Obj["Success"].ToString();
  208. if (Success.ToUpper() == "FALSE")
  209. {
  210. msg = MessAge;
  211. }
  212. return msg;
  213. }
  214. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  215. {
  216. string sql = @"SELECT
  217. a.ID,
  218. a.ID as TLZID,
  219. a.ApplyNegCode,
  220. a.InvCode,
  221. a.Quantity,
  222. a.Amount,
  223. a.SourceDetailID as ZJID,
  224. b.InvName,
  225. b.InvStd,
  226. b.InvUnit,
  227. a.IssueNegQuantity,
  228. a.ExtensionID,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  229. FROM
  230. ICSMOApplyNegDetail a
  231. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  232. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  233. where a.ApplyNegCode='" + ApplyNegCode + "'";
  234. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  235. if (MDInvmes == null || MDInvmes.Columns.Count <= 0)
  236. MDInvmes = table.Clone();
  237. DataTable dtCloned = table.Clone();
  238. foreach (DataColumn col in dtCloned.Columns)
  239. {
  240. col.DataType = typeof(string);
  241. }
  242. foreach (DataRow row in table.Rows)
  243. {
  244. DataRow newrow = dtCloned.NewRow();
  245. foreach (DataColumn column in dtCloned.Columns)
  246. {
  247. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  248. }
  249. dtCloned.Rows.Add(newrow);
  250. }
  251. if (MDInvmes.Rows.Count > 0)
  252. {
  253. //dtCloned.Merge(Invmes, false);
  254. foreach (DataRow data in MDInvmes.Rows)
  255. {
  256. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  257. if (info != null && info.Length > 0)
  258. {
  259. info[0]["ZJID"] = data["ZJID"];
  260. info[0]["InvName"] = data["InvName"];
  261. info[0]["InvCode"] = data["InvCode"];
  262. info[0]["InvStd"] = data["InvStd"];
  263. info[0]["InvUnit"] = data["InvUnit"];
  264. info[0]["Amount"] = data["Amount"];
  265. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  266. info[0]["ExtensionID"] = data["ExtensionID"];
  267. info[0]["Quantity"] = 0;
  268. }
  269. else
  270. {
  271. DataRow newrow = dtCloned.NewRow();
  272. newrow["ZJID"] = data["ZJID"];
  273. newrow["InvName"] = data["InvName"];
  274. newrow["InvCode"] = data["InvCode"];
  275. newrow["InvStd"] = data["InvStd"];
  276. newrow["InvUnit"] = data["InvUnit"];
  277. newrow["Amount"] = data["Amount"];
  278. newrow["Quantity"] = 0;
  279. newrow["ID"] = data["ID"];
  280. newrow["TLZID"] = data["TLZID"];
  281. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  282. newrow["ExtensionID"] = data["ExtensionID"];
  283. dtCloned.Rows.Add(newrow);
  284. }
  285. }
  286. }
  287. return dtCloned;
  288. }
  289. public string UpdateICSMOApplyNeg(string ICSASN)
  290. {
  291. string msg = "";
  292. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  293. string result = HttpPost(APIURL, ICSASN);
  294. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  295. string MessAge = Obj["Message"].ToString();
  296. string Success = Obj["Success"].ToString();
  297. if (Success.ToUpper() == "FALSE")
  298. {
  299. msg = MessAge;
  300. }
  301. return msg;
  302. }
  303. public static string HttpPost(string url, string body)
  304. {
  305. try
  306. {
  307. Encoding encoding = Encoding.UTF8;
  308. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  309. request.Method = "POST";
  310. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  311. request.ContentType = "application/json; charset=utf-8";
  312. byte[] buffer = encoding.GetBytes(body);
  313. request.ContentLength = buffer.Length;
  314. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  315. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  316. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  317. {
  318. return reader.ReadToEnd();
  319. }
  320. }
  321. catch (WebException ex)
  322. {
  323. throw new Exception(ex.Message);
  324. }
  325. }
  326. }
  327. }