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.

334 lines
13 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;
  11. using System.Data.Common;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Reflection.Emit;
  18. namespace NFine.Application.WMS
  19. {
  20. /// <summary>
  21. /// 委外订单查询
  22. /// </summary>
  23. public class ICSOutsourcingOrderApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable Invmes = new DataTable();
  26. /// <summary>
  27. /// 委外订单查询
  28. /// </summary>
  29. /// <param name="jqgridparam"></param>
  30. /// <returns></returns>
  31. public DataTable GetOutsourcingOrderApplyNeg(ref Pagination jqgridparam)
  32. {
  33. DataTable dt = new DataTable();
  34. List<DbParameter> parameter = new List<DbParameter>();
  35. string sql = @"select a.OOCode, a.CreatePerson,a.CreateDateTime from ICSOutsourcingOrder a
  36. group by a.OOCode,a.CreatePerson,a.CreateDateTime";
  37. sql = string.Format(sql);
  38. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  39. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  40. }
  41. /// <summary>
  42. /// 委外订单明细查询
  43. /// </summary>
  44. /// <param name="jqgridparam"></param>
  45. /// <returns></returns>
  46. public DataTable GetOutsourcingOrderApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  47. {
  48. DataTable dt = new DataTable();
  49. object Figure = GetDecimalDigits();
  50. List<DbParameter> parameter = new List<DbParameter>();
  51. string sql = @"select a.ID,a.OOCode,a.Sequence,a.VenCode,e.VenName,a.DepCode,a.PersonCode,case when a.Type = '1' then '委外' else a.Type end as Type,a.InvCode,b.InvName,b.InvStd,b.InvDesc,b.InvUnit
  52. ,a.Amount,CAST(a.Quantity AS DECIMAL(18,{0})) as Quantity,g.DepName,
  53. CAST(a.UnitPrice AS DECIMAL(18,{0})) as UnitPrice,a.Currency,a.Status,a.ReleaseState,a.PlanArriveDate,a.CreatePerson,a.CreateDateTime
  54. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  55. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  56. a.EATTRIBUTE9,a.EATTRIBUTE10
  57. from ICSOutsourcingOrder a
  58. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  59. left join ICSVendor e on a.VenCode = e.VenCode and a.WorkPoint = e.WorkPoint
  60. left join ICSDepartment g on a.DepCode = g.DepCode and a.WorkPoint = g.WorkPoint
  61. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  62. where a.OOCode = '" + ApplyNegCode + "' ";
  63. sql = string.Format(sql, Figure);
  64. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  65. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  66. }
  67. public object GetDecimalDigits()
  68. {
  69. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  70. try
  71. {
  72. string sql = string.Empty;
  73. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  74. object Figure = SqlHelper.ExecuteScalar(sql);
  75. return Figure;
  76. }
  77. catch (Exception ex)
  78. {
  79. throw new Exception(ex.Message.ToString());
  80. }
  81. }
  82. public string DeleteMopick(string json)
  83. {
  84. try
  85. {
  86. string wheresql = "(";
  87. string[] id = json.Split(',');
  88. for (int i = 0; i < id.Length; i++)
  89. {
  90. wheresql += "'" + id[i].Replace(']', ' ').Replace('[', ' ').Replace('"', ' ').Trim() + "',";
  91. }
  92. wheresql = wheresql.Trim(',') + ")";
  93. string sql = "delete from ICSOutsourcingOrder where OOCode in" + wheresql;
  94. int count = DbHelper.ExecuteNonQuery(CommandType.Text, sql);
  95. DataRow[] row = Invmes.Select("OOCode in " + wheresql + "");
  96. foreach (DataRow a in row)
  97. {
  98. Invmes.Rows.Remove(a);
  99. }
  100. return "删除成功!";
  101. }
  102. catch (Exception ex)
  103. {
  104. return ex.Message + " 删除失败!";
  105. }
  106. }
  107. public string DeleteOutsourcingOrderApplyNeg(string keyValue)
  108. {
  109. //站点信息
  110. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  111. string msg = "";
  112. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  113. string sql = string.Empty;
  114. sql += string.Format(@"DELETE FROM dbo.ICSOutsourcingOrder WHERE OOCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  115. try
  116. {
  117. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  118. {
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. throw new Exception(ex.Message);
  124. }
  125. return msg;
  126. }
  127. public void ClearTemp()
  128. {
  129. Invmes.Rows.Clear();
  130. }
  131. /// <summary>
  132. /// 新增
  133. /// </summary>
  134. /// <param name="ICSASN"></param>
  135. /// <returns></returns>
  136. public string SaveICSOutsourcingOrderApplyNeg(string ICSASN)
  137. {
  138. string msg = "";
  139. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingOrder/Create";
  140. string result = HttpPost(APIURL, ICSASN);
  141. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  142. string MessAge = Obj["Message"].ToString();
  143. string Success = Obj["Success"].ToString();
  144. if (Success.ToUpper() == "FALSE")
  145. {
  146. msg = MessAge;
  147. }
  148. return msg;
  149. }
  150. /// <summary>
  151. /// 修改
  152. /// </summary>
  153. /// <param name="ICSASN"></param>
  154. /// <returns></returns>
  155. public string UpdateICSOutsourcingOrderApplyNeg(string ICSASN)
  156. {
  157. string msg = "";
  158. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingOrder/Update";
  159. string result = HttpPost(APIURL, ICSASN);
  160. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  161. string MessAge = Obj["Message"].ToString();
  162. string Success = Obj["Success"].ToString();
  163. if (Success.ToUpper() == "FALSE")
  164. {
  165. msg = MessAge;
  166. }
  167. return msg;
  168. }
  169. /// <summary>
  170. /// 获取部门
  171. /// </summary>
  172. /// <param name="InvCode"></param>
  173. /// <returns></returns>
  174. public DataTable GetSelectICSDepCode()
  175. {
  176. string sql = string.Empty;
  177. DataTable dt = null;
  178. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  179. sql = @"
  180. select DepCode ,DepName
  181. from dbo.ICSDepartment a";
  182. sql = string.Format(sql, WorkPoint);
  183. // sql = @"select BadCode,BadDesc from dbo.ICSBadCode a left join
  184. //ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  185. //where b.InvCode='{0}'";
  186. dt = SqlHelper.GetDataTableBySql(sql);
  187. return dt;
  188. }
  189. /// <summary>
  190. /// 获取部门
  191. /// </summary>
  192. /// <param name="InvCode"></param>
  193. /// <returns></returns>
  194. public DataTable GetSelectICSVenCode()
  195. {
  196. string sql = string.Empty;
  197. DataTable dt = null;
  198. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  199. sql = @"
  200. select a.VenCode,a.VenName from dbo.ICSVendor a";
  201. sql = string.Format(sql, WorkPoint);
  202. dt = SqlHelper.GetDataTableBySql(sql);
  203. return dt;
  204. }
  205. /// <summary>
  206. /// 接口api解析
  207. /// </summary>
  208. /// <param name="url"></param>
  209. /// <param name="body"></param>
  210. /// <returns></returns>
  211. /// <exception cref="Exception"></exception>
  212. public static string HttpPost(string url, string body)
  213. {
  214. try
  215. {
  216. Encoding encoding = Encoding.UTF8;
  217. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  218. request.Method = "POST";
  219. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  220. request.ContentType = "application/json; charset=utf-8";
  221. byte[] buffer = encoding.GetBytes(body);
  222. request.ContentLength = buffer.Length;
  223. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  224. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  225. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  226. {
  227. return reader.ReadToEnd();
  228. }
  229. }
  230. catch (WebException ex)
  231. {
  232. throw new Exception(ex.Message);
  233. }
  234. }
  235. /// <summary>
  236. /// 获取单号
  237. /// </summary>
  238. /// <param name="WorkPoint"></param>
  239. /// <returns></returns>
  240. public string GetOOCode(string WorkPoint)
  241. {
  242. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  243. string OOCode = string.Empty;
  244. if (!string.IsNullOrEmpty(WorkPoint))
  245. {
  246. OOCode = GetSerialCode(WorkPoint, "ICSOutsourcingOrder", "OOCode", "OO", 8);
  247. }
  248. if (!string.IsNullOrWhiteSpace(OOCode))
  249. {
  250. string sqlISHave = @"SELECT ApplyCode FROM ICSMOApply a
  251. WHERE a.ApplyCode = '{0}'";
  252. sqlISHave = string.Format(sqlISHave, OOCode);
  253. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  254. if (dtIsHave.Rows.Count > 0)
  255. {
  256. throw new Exception("单号已存在!");
  257. }
  258. }
  259. return OOCode;
  260. }
  261. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  262. {
  263. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  264. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  265. return SqlHelper.ExecuteScalar(sql).ToString();
  266. }
  267. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  268. {
  269. var data = json.ToJObject();
  270. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  271. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  272. if (info != null && info.Length > 0)
  273. {
  274. info[0]["ZJID"] = data["ZJID"];
  275. info[0]["InvName"] = data["InvName"];
  276. }
  277. else
  278. {
  279. DataRow newrow = Invmes.NewRow();
  280. newrow["ZJID"] = data["ZJID"];
  281. Invmes.Rows.Add(newrow);
  282. }
  283. }
  284. public DataTable GetICSOutsourcingOrderReturnTemporary(string rfqno)
  285. {
  286. string sql = @"select a.ID,a.OOCode,a.Sequence,a.VenCode,a.DepCode,a.PersonCode,a.Type,a.InvCode,a.Quantity,a.Amount,
  287. a.InQuantity,a.UnitPrice,a.Currency,a.Status,a.ReleaseState,a.ReleaseDate,a.PlanArriveDate,
  288. a.CreatePerson,a.CreateDateTime, a.MUSER,a.MUSERName from ICSOutsourcingOrder a where a.OOCode ='"
  289. + rfqno + "' ";
  290. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  291. DataTable dtCloned = table.Clone();
  292. foreach (DataColumn col in dtCloned.Columns)
  293. {
  294. col.DataType = typeof(string);
  295. }
  296. foreach (DataRow row in table.Rows)
  297. {
  298. DataRow newrow = dtCloned.NewRow();
  299. foreach (DataColumn column in dtCloned.Columns)
  300. {
  301. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  302. }
  303. dtCloned.Rows.Add(newrow);
  304. }
  305. if (Invmes.Rows.Count > 0)
  306. {
  307. dtCloned.Merge(Invmes, false);
  308. }
  309. return dtCloned;
  310. }
  311. }
  312. }