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

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