text.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using NVRCsharpDemo;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.Xml;
  16. using Common;
  17. using System.Configuration;
  18. using com.hnshituo.core.webapp.vo;
  19. using System.Resources;
  20. using System.Security.Cryptography;
  21. using TrainVideoDataDispose.Properties;
  22. namespace TrainVideoDataDispose
  23. {
  24. public partial class text : Form
  25. {
  26. public int m_lUserID = -1;
  27. public int m_lGetFaceParamCfgHandle = -1;
  28. private CHCNetSDK.REALDATACALLBACK RealData = null;
  29. public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo;
  30. public CHCNetSDK.NET_DVR_DEVICEINFO_V40 tDeviceInfo;
  31. public CHCNetSDK.NET_DVR_IPPARACFG_V40 m_struIpParaCfgV40;
  32. public CHCNetSDK.NET_DVR_STREAM_MODE m_struStreamMode;
  33. public CHCNetSDK.NET_DVR_IPCHANINFO m_struChanInfo;
  34. public CHCNetSDK.NET_DVR_PU_STREAM_URL m_struStreamURL;
  35. public CHCNetSDK.NET_DVR_IPCHANINFO_V40 m_struChanInfoV40;
  36. public CHCNetSDK.NET_DVR_USER_LOGIN_INFO pLoginInfo;
  37. public CHCNetSDK.LOGINRESULTCALLBACK LoginCallBack;
  38. public CHCNetSDK.RemoteConfigCallback remoteConfigCallback;
  39. //private PlayCtrl.DECCBFUN m_fDisplayFun = null;
  40. public delegate void MyDebugInfo(string str);
  41. private MetetBaseRailwayAiweightService metetBaseRailwayAiweightService = new MetetBaseRailwayAiweightService();
  42. private Label labelLogin;
  43. public text()
  44. {
  45. InitializeComponent();
  46. }
  47. private void button1_Click(object sender, EventArgs e)
  48. {
  49. try
  50. {
  51. //string strUrl = "http://10.111.67.23/ISAPI/System/deviceInfo";
  52. string strUrl = "http://10.111.67.23/ISAPI/Traffic/ContentMgmt/dataOperation";
  53. WebClient client = new WebClient();
  54. int interval = int.Parse(ConfigurationManager.AppSettings["interval"].ToString());
  55. string startTime = DateTime.Now.ToString("yyyy-MM-dd") + "Y" + DateTime.Now.ToString("HH:mm:ss") + "Z";
  56. string endTime = DateTime.Now.AddMinutes(interval).ToString("yyyy-MM-dd") + "Y" + DateTime.Now.AddMinutes(interval).ToString("HH:mm:ss") + "Z";
  57. string searchID =  System.Guid.NewGuid().ToString();
  58. // 设置用户名和密码
  59. client.Credentials = new NetworkCredential("admin", "Admin12345");
  60. string requestXmls = string.Format(@"<?xml version:'1.0' encoding='utf-8'?>
  61. <DataOperation>
  62. <operationType>search</operationType>
  63. <searchCond>
  64. <searchID>{0}</searchID>
  65. <timeSpanList>
  66. <timeSpan>
  67. <startTime>{1}</startTime>
  68. <endTime>{2}</endTime>
  69. </timeSpan>
  70. </timeSpanList>
  71. <criteria>
  72. <dataType>0</dataType>
  73. <channel/>
  74. <plateType/>
  75. <plateColor/>
  76. <direction/>
  77. <plate/>
  78. <speedMin/>
  79. <speedMax/>
  80. <vehicleType/>
  81. <vehicleColor/>
  82. <laneNo/>
  83. <surveilType>0</surveilType>
  84. <romoteHost/>
  85. <analysised>true</analysised>
  86. <sendFlag/>
  87. </criteria>
  88. <searchResultPosition>0</searchResultPosition>
  89. <maxResults>999</maxResults>
  90. </searchCond>
  91. </DataOperation>", searchID,startTime,endTime);
  92. byte[] sendData = Encoding.UTF8.GetBytes(requestXmls);
  93. byte[] responseData = client.UploadData(strUrl,"POST", sendData);
  94. string strResponseData = Encoding.UTF8.GetString(responseData);
  95. XmlToDataSet(strResponseData);
  96. XmlDocument xmlDoc = new XmlDocument();//初始化一个实例
  97. xmlDoc.LoadXml(strResponseData);//读取文件
  98. List<MetetBaseRailwayAiweight> metetBaseRailwayAiweights = new List<MetetBaseRailwayAiweight>();
  99. XmlNodeList s = xmlDoc.DocumentElement.GetElementsByTagName("matchElement");
  100. foreach (XmlElement node in s)
  101. {
  102. MetetBaseRailwayAiweight metetBaseRailwayAiweight = new MetetBaseRailwayAiweight();
  103. int stratIndex = node.GetElementsByTagName("plate")[0].InnerText.Length - 7;
  104. metetBaseRailwayAiweight.railwayNo = node.GetElementsByTagName("plate")[0].InnerText.Substring(stratIndex, 7);
  105. metetBaseRailwayAiweight.railwayType = node.GetElementsByTagName("plate")[0].InnerText.Substring(0, stratIndex);
  106. metetBaseRailwayAiweight.meterWeight = node.GetElementsByTagName("selfWeight")[0].InnerText;
  107. metetBaseRailwayAiweight.railwaySpeed = node.GetElementsByTagName("speed")[0].InnerText;
  108. metetBaseRailwayAiweights.Add(metetBaseRailwayAiweight);
  109. }
  110. if (metetBaseRailwayAiweights.Count > 0)
  111. {
  112. RESTfulResult<List<MetetBaseRailwayAiweight>> result = metetBaseRailwayAiweightService.add(metetBaseRailwayAiweights);
  113. if (result.Succeed)
  114. {
  115. // 输出接收的消息
  116. this.textinfo.Text = "成功";
  117. }
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. this.textinfo.Text = ex.Message;
  123. }
  124. return;
  125. }
  126. #region Xml To DataSet
  127. public static DataSet XmlToDataSet(string xmlString)
  128. {
  129. XmlDocument xmldoc = new XmlDocument();
  130. xmldoc.LoadXml(xmlString);
  131. StringReader stream = null;
  132. XmlTextReader reader = null;
  133. try
  134. {
  135. DataSet xmlDS = new DataSet();
  136. stream = new StringReader(xmldoc.InnerXml);
  137. reader = new XmlTextReader(stream);
  138. xmlDS.ReadXml(reader);
  139. reader.Close();
  140. return xmlDS;
  141. }
  142. catch (System.Exception ex)
  143. {
  144. reader.Close();
  145. throw ex;
  146. }
  147. }
  148. #endregion
  149. }
  150. }