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.

183 lines
6.4 KiB

3 weeks ago
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using NFine.Domain._03_Entity.SRM;
  6. using NFine.Repository;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Data.Common;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace NFine.Application.WMS
  18. {
  19. /// <summary>
  20. /// 供应商
  21. /// </summary>
  22. public class ICSVendorApp : RepositoryFactory<ICSVendor>
  23. {
  24. public static DataTable Invmes = new DataTable();
  25. /// <summary>
  26. /// 供应商删除
  27. /// </summary>
  28. /// <param name="keyValue"></param>
  29. /// <returns></returns>
  30. /// <exception cref="Exception"></exception>
  31. public string DeleteVendorApplyNeg(string keyValue)
  32. {
  33. //站点信息
  34. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  35. string msg = "";
  36. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  37. string sql = string.Empty;
  38. sql += string.Format(@"DELETE FROM dbo.ICSVendor WHERE ApplyCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  39. //sql += string.Format(@"DELETE FROM dbo.ICSMDNNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  40. try
  41. {
  42. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  43. {
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. throw new Exception(ex.Message);
  49. }
  50. return msg;
  51. }
  52. public object GetDecimalDigits()
  53. {
  54. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  55. try
  56. {
  57. string sql = string.Empty;
  58. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  59. object Figure = SqlHelper.ExecuteScalar(sql);
  60. return Figure;
  61. }
  62. catch (Exception ex)
  63. {
  64. throw new Exception(ex.Message.ToString());
  65. }
  66. }
  67. public void ClearTemp()
  68. {
  69. Invmes.Rows.Clear();
  70. }
  71. /// <summary>
  72. /// 新增
  73. /// </summary>
  74. /// <param name="ICSASN"></param>
  75. /// <returns></returns>
  76. public string SaveICSVendorApplyNeg(string ICSASN)
  77. {
  78. string msg = "";
  79. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Vendor/Create";
  80. string result = HttpPost(APIURL, ICSASN);
  81. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  82. string MessAge = Obj["Message"].ToString();
  83. string Success = Obj["Success"].ToString();
  84. if (Success.ToUpper() == "FALSE")
  85. {
  86. msg = MessAge;
  87. }
  88. return msg;
  89. }
  90. /// <summary>
  91. /// 修改
  92. /// </summary>
  93. /// <param name="ICSASN"></param>
  94. /// <returns></returns>
  95. public string UpdateICSVendorApplyNeg(string ICSASN)
  96. {
  97. string msg = "";
  98. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Vendor/Update";
  99. string result = HttpPost(APIURL, ICSASN);
  100. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  101. string MessAge = Obj["Message"].ToString();
  102. string Success = Obj["Success"].ToString();
  103. if (Success.ToUpper() == "FALSE")
  104. {
  105. msg = MessAge;
  106. }
  107. return msg;
  108. }
  109. /// <summary>
  110. /// 供应商 修改数据来源
  111. /// </summary>
  112. /// <param name="VenCode"></param>
  113. /// <returns></returns>
  114. public DataTable GetICSVendorReturnTemporary(string VenCode)
  115. {
  116. string sql = @"select VenCode,VenName,VenAbbName,VCCode,VCName,VenAddress,VenRegCode,VenBank,VenAccount
  117. ,VenDevDate,VenLPerson,VenPhone,VenEmail,VenPerson,VenHand,VenDisRate,VenCreLine,VenCreDate,VenPayCond,PayName,VenExch_name,MUSER,MUSERName from ICSVendor
  118. where a.VenCode ='" + VenCode + "' ";
  119. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  120. DataTable dtCloned = table.Clone();
  121. foreach (DataColumn col in dtCloned.Columns)
  122. {
  123. col.DataType = typeof(string);
  124. }
  125. foreach (DataRow row in table.Rows)
  126. {
  127. DataRow newrow = dtCloned.NewRow();
  128. foreach (DataColumn column in dtCloned.Columns)
  129. {
  130. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  131. }
  132. dtCloned.Rows.Add(newrow);
  133. }
  134. if (Invmes.Rows.Count > 0)
  135. {
  136. dtCloned.Merge(Invmes, false);
  137. }
  138. return dtCloned;
  139. }
  140. /// <summary>
  141. /// 接口api解析
  142. /// </summary>
  143. /// <param name="url"></param>
  144. /// <param name="body"></param>
  145. /// <returns></returns>
  146. /// <exception cref="Exception"></exception>
  147. public static string HttpPost(string url, string body)
  148. {
  149. try
  150. {
  151. Encoding encoding = Encoding.UTF8;
  152. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  153. request.Method = "POST";
  154. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  155. request.ContentType = "application/json; charset=utf-8";
  156. byte[] buffer = encoding.GetBytes(body);
  157. request.ContentLength = buffer.Length;
  158. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  159. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  160. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  161. {
  162. return reader.ReadToEnd();
  163. }
  164. }
  165. catch (WebException ex)
  166. {
  167. throw new Exception(ex.Message);
  168. }
  169. }
  170. }
  171. }