ZnlcInterface.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Common;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Runtime.Serialization.Json;
  11. using System.Text;
  12. namespace OtherInterface
  13. {
  14. public static class ZnlcInterface
  15. {
  16. private static LimisResponse sendDataToZn(WeightInfoBeta model)
  17. {
  18. DataContractJsonSerializer objseria = new DataContractJsonSerializer(typeof(WeightInfoBeta));
  19. MemoryStream mem = new MemoryStream();
  20. objseria.WriteObject(mem, model);
  21. string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
  22. WebClient webClient = new WebClient();
  23. webClient.Headers["Content-type"] = "application/json";
  24. webClient.Encoding = Encoding.UTF8;
  25. string retStr = webClient.UploadString("http://10.1.213.84:8080/LimsService.svc/SendWeightResultBeta", "POST", data);
  26. LimisResponse limisResponse = JsonConvert.DeserializeObject<LimisResponse>(retStr);
  27. return limisResponse;
  28. }
  29. public static string sendFirst(MeterWorkCarActualFirst meterWorkCarActualFirst)
  30. {
  31. string strResult = "";
  32. try
  33. {
  34. WeightInfoBeta w = new WeightInfoBeta();
  35. w.DeviceNo = meterWorkCarActualFirst.baseSpotNo;//计量站点
  36. w.ConveyanceNo = meterWorkCarActualFirst.carNo;//车号
  37. w.WeightVoucherNo = meterWorkCarActualFirst.predictionNo;//委托编号
  38. //double t =double.Parse( meterWorkCarActualFirst.meterWeight.Value.ToString());
  39. //w.GrossWeight =double.Parse( MyStringUtils.div1000(t.ToString()));
  40. w.GrossWeight = meterWorkCarActualFirst.meterWeight / 1000;
  41. w.TareWeight = null;
  42. w.NetWeight = null;
  43. w.MeteringPerson = meterWorkCarActualFirst.createManNo;
  44. //DateTime dt =DateTime.Parse( meterWorkCarActualFirst.createTime.ToString());
  45. //w.MeteringTime = dt.ToString("yyyy-MM-dd hh:mm:ss");
  46. w.MeteringTime = meterWorkCarActualFirst.createTime.ToString();
  47. LimisResponse ls = sendDataToZn(w);
  48. if (ls.Success)
  49. {
  50. strResult = ls.Msg;
  51. }
  52. else
  53. {
  54. if (ls.Code.Equals("401") || ls.Code.Equals("402") || ls.Code.Equals("404"))
  55. {
  56. }
  57. }
  58. }
  59. catch (Exception eee)
  60. {
  61. strResult = "error:"+eee.Message;
  62. }
  63. return strResult;
  64. }
  65. public static string sendNet(MeterWorkCarActual meterWorkCarActual)
  66. {
  67. string strResult = "";
  68. try
  69. {
  70. WeightInfoBeta w = new WeightInfoBeta();
  71. w.DeviceNo = meterWorkCarActual.baseSpot2No;//计量站点
  72. w.ConveyanceNo = meterWorkCarActual.carNo;//车号
  73. w.WeightVoucherNo = meterWorkCarActual.predictionNo;//委托编号
  74. w.GrossWeight = meterWorkCarActual.grossWeight / 1000;
  75. w.TareWeight = meterWorkCarActual.tareWeight / 1000;
  76. w.NetWeight = meterWorkCarActual.netWeight / 1000;
  77. w.MeteringPerson = meterWorkCarActual.createManNo;
  78. w.MeteringTime = meterWorkCarActual.createTime.ToString();
  79. LimisResponse ls = sendDataToZn(w);
  80. if (ls.Success)
  81. {
  82. strResult = ls.Msg;
  83. }
  84. else
  85. {
  86. if (ls.Code.Equals("401") || ls.Code.Equals("402") || ls.Code.Equals("404"))
  87. {
  88. }
  89. }
  90. }
  91. catch (Exception eee)
  92. {
  93. strResult = "error:" + eee.Message;
  94. }
  95. return strResult;
  96. }
  97. }
  98. public class LimisResponse
  99. {
  100. public bool Success { get; set; }
  101. public string Msg { get; set; }
  102. public string Code { get; set; }
  103. }
  104. public class WeightInfoBeta
  105. {
  106. public string ConveyanceNo { get; set; }
  107. public string DeviceNo { get; set; }
  108. public double? GrossWeight { get; set; }
  109. public string MeteringPerson { get; set; }
  110. public string MeteringTime { get; set; }
  111. public double? NetWeight { get; set; }
  112. public double? TareWeight { get; set; }
  113. public string WeightVoucherNo { get; set; }
  114. }
  115. }