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.

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