ZnlcInterface.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.121.16.36:8888/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. w.MeteringTime = meterWorkCarActualFirst.createTime.ToString();
  45. LimisResponse ls = sendDataToZn(w);
  46. if (ls.Success)
  47. {
  48. strResult = ls.Msg;
  49. }
  50. else
  51. {
  52. if (ls.Code.Equals("401") || ls.Code.Equals("402") || ls.Code.Equals("404"))
  53. {
  54. }
  55. }
  56. }
  57. catch (Exception eee)
  58. {
  59. strResult = "error:"+eee.Message;
  60. }
  61. return strResult;
  62. }
  63. public static string sendNet(MeterWorkCarActual meterWorkCarActual)
  64. {
  65. string strResult = "";
  66. try
  67. {
  68. WeightInfoBeta w = new WeightInfoBeta();
  69. w.DeviceNo = meterWorkCarActual.baseSpot2No;//计量站点
  70. w.ConveyanceNo = meterWorkCarActual.carNo;//车号
  71. w.WeightVoucherNo = meterWorkCarActual.predictionNo;//委托编号
  72. w.GrossWeight = meterWorkCarActual.grossWeight / 1000;
  73. w.TareWeight = meterWorkCarActual.tareWeight / 1000;
  74. w.NetWeight = meterWorkCarActual.netWeight / 1000;
  75. w.MeteringPerson = meterWorkCarActual.createManNo;
  76. w.MeteringTime = meterWorkCarActual.createTime.ToString();
  77. LimisResponse ls = sendDataToZn(w);
  78. if (ls.Success)
  79. {
  80. strResult = ls.Msg;
  81. }
  82. else
  83. {
  84. if (ls.Code.Equals("401") || ls.Code.Equals("402") || ls.Code.Equals("404"))
  85. {
  86. }
  87. }
  88. }
  89. catch (Exception eee)
  90. {
  91. strResult = "error:" + eee.Message;
  92. }
  93. return strResult;
  94. }
  95. }
  96. public class LimisResponse
  97. {
  98. public bool Success { get; set; }
  99. public string Msg { get; set; }
  100. public string Code { get; set; }
  101. }
  102. public class WeightInfoBeta
  103. {
  104. public string ConveyanceNo { get; set; }
  105. public string DeviceNo { get; set; }
  106. public double? GrossWeight { get; set; }
  107. public string MeteringPerson { get; set; }
  108. public string MeteringTime { get; set; }
  109. public double? NetWeight { get; set; }
  110. public double? TareWeight { get; set; }
  111. public string WeightVoucherNo { get; set; }
  112. }
  113. }