华恒Mes鼎捷代码
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.

140 lines
5.4 KiB

5 months ago
  1. using ICSSoft.Base.Config.AppConfig;
  2. using ICSSoft.Frame.Data.Entity;
  3. using ICSSoft.Frame.Data.Entity.OM_PO;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Text;
  12. namespace ICSSoft.Frame.Data.DAL
  13. {
  14. public static class ICSIntSupCalDAL
  15. {
  16. public static void Delete(List<string> id, string conn) {
  17. FramDataContext frame = new FramDataContext(conn);
  18. frame.Connection.Open();
  19. frame.Transaction = frame.Connection.BeginTransaction();
  20. try {
  21. var cal = frame.ICSIntSupCalLog.Where(a => id.Contains(a.id)).Select(a => a);
  22. frame.ICSIntSupCalLog.DeleteAllOnSubmit(cal);
  23. frame.SubmitChanges();
  24. frame.Transaction.Commit();
  25. }
  26. catch (Exception ex) {
  27. frame.Transaction.Rollback();
  28. throw ex;
  29. }
  30. }
  31. #region 内部供应商结算
  32. public static void Calculate(List<ICSIntSupCalLog> list,string conn)
  33. {
  34. FramDataContext db = new FramDataContext(conn);
  35. db.Connection.Open();
  36. db.Transaction = db.Connection.BeginTransaction();
  37. try
  38. {
  39. string cIWhCode = ConfigurationManager.AppSettings["WHICode"].ToString();
  40. string cOWhCode = ConfigurationManager.AppSettings["WHOCode"].ToString();
  41. List<OM_POmain> headList = new List<OM_POmain>();
  42. OM_POmain head = new OM_POmain();
  43. string key = "";
  44. foreach (var info in list)
  45. {
  46. var MO = db.ICSMO.Where(a => a.MOCODE == info.Mocode && a.MOSEQ == info.Moseq).Select(a => a).FirstOrDefault();
  47. if (headList.Where(a => a.MODId == MO.ID && a.POID == info.Pocode.Split('-')[0]).FirstOrDefault() == null)
  48. {
  49. head = new OM_POmain();
  50. head.UserCode = AppConfig.UserName;
  51. head.POID = info.Pocode.Split('-')[0];
  52. head.cIWhCode = cIWhCode;
  53. head.cOWhCode = cOWhCode;
  54. head.MODId = MO.ID;
  55. head.list = new List<OM_PODetails>();
  56. headList.Add(head);
  57. }
  58. else
  59. {
  60. head = headList.Where(a => a.MODId == MO.ID && a.POID == info.Pocode.Split('-')[0]).FirstOrDefault();
  61. }
  62. OM_PODetails body = new OM_PODetails();
  63. body.ID = info.Pocode.Split('-')[1];
  64. body.cInvCode = MO.ITEMCODE+"_"+info.Opcode;
  65. body.iQuantity = Convert.ToDecimal(info.Prqty);
  66. body.iNum = Decimal.Parse(info.Moseq);
  67. head.list.Add(body);
  68. }
  69. string Istr = JsonConvert.SerializeObject(headList);
  70. string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APIOM_POMain1", Istr);
  71. //string iresult = HttpPost("http://localhost:51182/api/" + "APIOM_POMain1", Istr);
  72. Result INVOUTResult = new Result();
  73. INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
  74. if (INVOUTResult.code != "200")
  75. {
  76. throw new Exception(INVOUTResult.msg);
  77. }
  78. //内部供应商结算
  79. List<String> id = list.Select(a => a.id).ToList();
  80. var c=db.ICSIntSupCalLog.Where(a => id.Contains(a.id));
  81. foreach (ICSIntSupCalLog sup in c) {
  82. sup.ISInput = true;
  83. db.SubmitChanges();
  84. }
  85. db.Transaction.Commit();
  86. }
  87. catch (Exception ex)
  88. {
  89. db.Transaction.Rollback();
  90. throw ex;
  91. }
  92. }
  93. #endregion
  94. public static string HttpPost(string url, string body)
  95. {
  96. try
  97. {
  98. System.Text.Encoding encoding = Encoding.UTF8;
  99. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  100. request.Method = "POST";
  101. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  102. request.ContentType = "application/json; charset=utf-8";
  103. byte[] buffer = encoding.GetBytes(body);
  104. request.ContentLength = buffer.Length;
  105. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  106. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  107. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  108. {
  109. return reader.ReadToEnd();
  110. }
  111. }
  112. catch (WebException ex)
  113. {
  114. var res = (HttpWebResponse)ex.Response;
  115. StringBuilder sb = new StringBuilder();
  116. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  117. sb.Append(sr.ReadToEnd());
  118. throw new Exception(sb.ToString());
  119. }
  120. }
  121. }
  122. }