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.

269 lines
11 KiB

3 weeks ago
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using NFine.Data.Extensions;
  4. using NFine.Domain._03_Entity.SRM;
  5. using NFine.Repository;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.IO;
  14. using System.Net;
  15. using NFine.Code;
  16. using System.Data.Common;
  17. namespace NFine.Application.WMS
  18. {
  19. public class ICSOIssueApp : RepositoryFactory<ICSVendor>
  20. {
  21. public static DataTable Invmes = new DataTable();
  22. /// <summary>
  23. /// 委外出库表 删除
  24. /// </summary>
  25. /// <param name="keyValue"></param>
  26. /// <returns></returns>
  27. /// <exception cref="Exception"></exception>
  28. public string DeleteICSOIssueApplyNeg(string keyValue)
  29. {
  30. //站点信息
  31. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  32. string msg = "";
  33. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  34. string sql = string.Empty;
  35. sql += string.Format(@"DELETE FROM dbo.ICSOIssue WHERE IssueCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  36. //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  37. try
  38. {
  39. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  40. {
  41. }
  42. }
  43. catch (Exception ex)
  44. {
  45. throw new Exception(ex.Message);
  46. }
  47. return msg;
  48. }
  49. /// <summary>
  50. /// 委外出库表 查询
  51. /// </summary>
  52. /// <param name="jqgridparam"></param>
  53. /// <returns></returns>
  54. public DataTable GetOIssueApplyNeg(ref Pagination jqgridparam)
  55. {
  56. DataTable dt = new DataTable();
  57. List<DbParameter> parameter = new List<DbParameter>();
  58. string sql = @"select a.IssueCode,a.CreatePerson from ICSOIssue a
  59. group by a.IssueCode,a.CreatePerson";
  60. sql = string.Format(sql);
  61. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  62. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  63. }
  64. /// <summary>
  65. /// 委外出库表 明细查询
  66. /// </summary>
  67. /// <param name="jqgridparam"></param>
  68. /// <returns></returns>
  69. public DataTable GetOIssueApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  70. {
  71. DataTable dt = new DataTable();
  72. object Figure = GetDecimalDigits();
  73. List<DbParameter> parameter = new List<DbParameter>();
  74. string sql = @"SELECT a.ID,a.IssueCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity,a.WHCode,e.WarehouseName as WHName,a.Type,a.Status,a.CreatePerson,a.CreateDateTime
  75. ,a.PickID,a.ApplyDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName
  76. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  77. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE as EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  78. a.EATTRIBUTE9,a.EATTRIBUTE10
  79. from ICSOIssue a
  80. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  81. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  82. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  83. where a.IssueCode = '" + ApplyNegCode + "' ";
  84. sql = string.Format(sql, Figure);
  85. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  86. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  87. }
  88. public object GetDecimalDigits()
  89. {
  90. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  91. try
  92. {
  93. string sql = string.Empty;
  94. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  95. object Figure = SqlHelper.ExecuteScalar(sql);
  96. return Figure;
  97. }
  98. catch (Exception ex)
  99. {
  100. throw new Exception(ex.Message.ToString());
  101. }
  102. }
  103. public void ClearTemp()
  104. {
  105. Invmes.Rows.Clear();
  106. }
  107. /// <summary>
  108. /// 新增
  109. /// </summary>
  110. /// <param name="ICSASN"></param>
  111. /// <returns></returns>
  112. public string SaveICSOIssueApplyNeg(string ICSASN)
  113. {
  114. string msg = "";
  115. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OIssue/Create";
  116. string result = HttpPost(APIURL, ICSASN);
  117. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  118. string MessAge = Obj["Message"].ToString();
  119. string Success = Obj["Success"].ToString();
  120. if (Success.ToUpper() == "FALSE")
  121. {
  122. msg = MessAge;
  123. }
  124. return msg;
  125. }
  126. /// <summary>
  127. /// 修改
  128. /// </summary>
  129. /// <param name="ICSASN"></param>
  130. /// <returns></returns>
  131. public string UpdateICSOIssueApplyNeg(string ICSASN)
  132. {
  133. string msg = "";
  134. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OIssue/Update";
  135. string result = HttpPost(APIURL, ICSASN);
  136. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  137. string MessAge = Obj["Message"].ToString();
  138. string Success = Obj["Success"].ToString();
  139. if (Success.ToUpper() == "FALSE")
  140. {
  141. msg = MessAge;
  142. }
  143. return msg;
  144. }
  145. /// <summary>
  146. /// 获取单号
  147. /// </summary>
  148. /// <param name="WorkPoint"></param>
  149. /// <returns></returns>
  150. public string GetOOCode(string WorkPoint)
  151. {
  152. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  153. string OOCode = string.Empty;
  154. if (!string.IsNullOrEmpty(WorkPoint))
  155. {
  156. OOCode = GetSerialCode(WorkPoint, "ICSOIssue", "IssueCode", "OI", 8);
  157. }
  158. if (!string.IsNullOrWhiteSpace(OOCode))
  159. {
  160. string sqlISHave = @"SELECT IssueCode FROM ICSOIssue a
  161. WHERE a.IssueCode = '{0}'";
  162. sqlISHave = string.Format(sqlISHave, OOCode);
  163. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  164. if (dtIsHave.Rows.Count > 0)
  165. {
  166. throw new Exception("单号已存在!");
  167. }
  168. }
  169. return OOCode;
  170. }
  171. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  172. {
  173. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  174. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  175. return SqlHelper.ExecuteScalar(sql).ToString();
  176. }
  177. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  178. {
  179. var data = json.ToJObject();
  180. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  181. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  182. if (info != null && info.Length > 0)
  183. {
  184. info[0]["ZJID"] = data["ZJID"];
  185. info[0]["InvName"] = data["InvName"];
  186. }
  187. else
  188. {
  189. DataRow newrow = Invmes.NewRow();
  190. newrow["ZJID"] = data["ZJID"];
  191. Invmes.Rows.Add(newrow);
  192. }
  193. }
  194. public DataTable GetICSOIssueReturnTemporary(string IssueCode)
  195. {
  196. string sql = @"SELECT a.ID,a.IssueCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity
  197. ,a.WHCode,a.Type,a.Status,a.CreatePerson,a.CreateDateTime,b.InvName
  198. ,a.PickID,a.ApplyDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
  199. from ICSOIssue a
  200. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  201. where a.IssueCode ='" + IssueCode + "' ";
  202. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  203. DataTable dtCloned = table.Clone();
  204. foreach (DataColumn col in dtCloned.Columns)
  205. {
  206. col.DataType = typeof(string);
  207. }
  208. foreach (DataRow row in table.Rows)
  209. {
  210. DataRow newrow = dtCloned.NewRow();
  211. foreach (DataColumn column in dtCloned.Columns)
  212. {
  213. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  214. }
  215. dtCloned.Rows.Add(newrow);
  216. }
  217. if (Invmes.Rows.Count > 0)
  218. {
  219. dtCloned.Merge(Invmes, false);
  220. }
  221. return dtCloned;
  222. }
  223. /// <summary>
  224. /// 接口api解析
  225. /// </summary>
  226. /// <param name="url"></param>
  227. /// <param name="body"></param>
  228. /// <returns></returns>
  229. /// <exception cref="Exception"></exception>
  230. public static string HttpPost(string url, string body)
  231. {
  232. try
  233. {
  234. Encoding encoding = Encoding.UTF8;
  235. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  236. request.Method = "POST";
  237. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  238. request.ContentType = "application/json; charset=utf-8";
  239. byte[] buffer = encoding.GetBytes(body);
  240. request.ContentLength = buffer.Length;
  241. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  242. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  243. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  244. {
  245. return reader.ReadToEnd();
  246. }
  247. }
  248. catch (WebException ex)
  249. {
  250. throw new Exception(ex.Message);
  251. }
  252. }
  253. }
  254. }