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

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