text.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. namespace TrainVideoDataDispose
  20. {
  21. public partial class text : Form
  22. {
  23. public int m_lUserID = -1;
  24. public int m_lGetFaceParamCfgHandle = -1;
  25. private CHCNetSDK.REALDATACALLBACK RealData = null;
  26. public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo;
  27. public CHCNetSDK.NET_DVR_DEVICEINFO_V40 tDeviceInfo;
  28. public CHCNetSDK.NET_DVR_IPPARACFG_V40 m_struIpParaCfgV40;
  29. public CHCNetSDK.NET_DVR_STREAM_MODE m_struStreamMode;
  30. public CHCNetSDK.NET_DVR_IPCHANINFO m_struChanInfo;
  31. public CHCNetSDK.NET_DVR_PU_STREAM_URL m_struStreamURL;
  32. public CHCNetSDK.NET_DVR_IPCHANINFO_V40 m_struChanInfoV40;
  33. public CHCNetSDK.NET_DVR_USER_LOGIN_INFO pLoginInfo;
  34. public CHCNetSDK.LOGINRESULTCALLBACK LoginCallBack;
  35. public CHCNetSDK.RemoteConfigCallback remoteConfigCallback;
  36. //private PlayCtrl.DECCBFUN m_fDisplayFun = null;
  37. public delegate void MyDebugInfo(string str);
  38. private MetetBaseRailwayAiweightService metetBaseRailwayAiweightService = new MetetBaseRailwayAiweightService();
  39. private Label labelLogin;
  40. public text()
  41. {
  42. InitializeComponent();
  43. }
  44. private void button1_Click(object sender, EventArgs e)
  45. {
  46. #region 海康
  47. //bool m_bInitSDK = CHCNetSDK.NET_DVR_Init();
  48. //string DVRIPAddress = '10.111.67.23'; //设备IP地址或者域名 Device IP
  49. //Int16 DVRPortNumber = Int16.Parse('8000');//设备服务端口号 Device Port
  50. //string DVRUserName = 'admin';//设备登录用户名 User name to login
  51. //string DVRPassword = 'Admin12345';//设备登录密码 Password to login
  52. ////设备IP地址或者域名
  53. //byte[] byIP = System.Text.Encoding.Default.GetBytes(DVRIPAddress);
  54. //pLoginInfo.sDeviceAddress = new byte[129];
  55. //byIP.CopyTo(pLoginInfo.sDeviceAddress, 0);
  56. ////设备用户名
  57. //byte[] byUserName = System.Text.Encoding.Default.GetBytes(DVRUserName);
  58. //pLoginInfo.sUserName = new byte[64];
  59. //byUserName.CopyTo(pLoginInfo.sUserName, 0);
  60. ////设备密码
  61. //byte[] byPassword = System.Text.Encoding.Default.GetBytes(DVRPassword);
  62. //pLoginInfo.sPassword = new byte[64];
  63. //byPassword.CopyTo(pLoginInfo.sPassword, 0);
  64. //pLoginInfo.wPort = 8000;
  65. //if (LoginCallBack == null)
  66. //{
  67. // LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
  68. //}
  69. //pLoginInfo.cbLoginResult = LoginCallBack;
  70. //pLoginInfo.bUseAsynLogin = true;
  71. ////登录设备 Login the device
  72. ////m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref pLoginInfo, ref tDeviceInfo);
  73. //m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref pLoginInfo, ref tDeviceInfo);
  74. //if (m_lUserID < 0)
  75. //{
  76. // uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
  77. // string str = 'NET_DVR_Login_V30 failed, error code= ' + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
  78. // textinfo.Text = str;
  79. // return;
  80. //}
  81. //else
  82. //{
  83. // //登录成功
  84. // //停止远程配置
  85. // if (m_lGetFaceParamCfgHandle != -1)
  86. // {
  87. // CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceParamCfgHandle);
  88. // }
  89. // //清除表格信息
  90. // //listViewFaceConfig.Items.Clear();
  91. // //LpArr.Clear();
  92. // //定义查询信息对象
  93. // CHCNetSDK.NET_DVR_TRAFFIC_DATA_QUERY_COND struCond = new CHCNetSDK.NET_DVR_TRAFFIC_DATA_QUERY_COND();
  94. // struCond.dwSize = (uint)Marshal.SizeOf(struCond);
  95. // //保留
  96. // byte[] byRes = System.Text.Encoding.Default.GetBytes('0');
  97. // struCond.byRes = new byte[254];
  98. // byRes.CopyTo(struCond.byRes, 0);
  99. // //struCond.dwQueryCond
  100. // if (remoteConfigCallback == null)
  101. // {
  102. // remoteConfigCallback = new CHCNetSDK.RemoteConfigCallback(cbStateCallback);//注册回调函数
  103. // }
  104. // int dwSize = Marshal.SizeOf(struCond);
  105. // IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);
  106. // Marshal.StructureToPtr(struCond, ptrStruCond, true);
  107. // m_lGetFaceParamCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_TRAFFIC_DATA, ptrStruCond, dwSize, remoteConfigCallback, IntPtr.Zero);
  108. // if (m_lGetFaceParamCfgHandle < 0)
  109. // {
  110. // uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
  111. // string str = 'NET_DVR_StartRemoteConfig failed, error code= ' + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
  112. // textinfo.Text = str;
  113. // return;
  114. // }
  115. // else
  116. // {
  117. // Marshal.FreeHGlobal(ptrStruCond);
  118. // }
  119. //}
  120. #endregion
  121. try
  122. {
  123. //string strUrl = "http://10.111.67.23/ISAPI/System/deviceInfo";
  124. string strUrl = "http://10.111.67.23/ISAPI/Traffic/ContentMgmt/dataOperation";
  125. WebClient client = new WebClient();
  126. int interval = int.Parse(ConfigurationManager.AppSettings["interval"].ToString());
  127. string startTime = DateTime.Now.ToString("yyyy-MM-dd") + "Y" + DateTime.Now.ToString("HH:mm:ss") + "Z";
  128. string endTime = DateTime.Now.AddMinutes(interval).ToString("yyyy-MM-dd") + "Y" + DateTime.Now.AddMinutes(interval).ToString("HH:mm:ss") + "Z";
  129. string searchID =  System.Guid.NewGuid().ToString();
  130. // 设置用户名和密码
  131. client.Credentials = new NetworkCredential("admin", "Admin12345");
  132. string requestXmls = string.Format(@"<?xml version:'1.0' encoding='utf-8'?>
  133. <DataOperation>
  134. <operationType>search</operationType>
  135. <searchCond>
  136. <searchID>{0}</searchID>
  137. <timeSpanList>
  138. <timeSpan>
  139. <startTime>{1}</startTime>
  140. <endTime>{2}</endTime>
  141. </timeSpan>
  142. </timeSpanList>
  143. <criteria>
  144. <dataType>0</dataType>
  145. <channel/>
  146. <plateType/>
  147. <plateColor/>
  148. <direction/>
  149. <plate/>
  150. <speedMin/>
  151. <speedMax/>
  152. <vehicleType/>
  153. <vehicleColor/>
  154. <laneNo/>
  155. <surveilType>0</surveilType>
  156. <romoteHost/>
  157. <analysised>true</analysised>
  158. <sendFlag/>
  159. </criteria>
  160. <searchResultPosition>0</searchResultPosition>
  161. <maxResults>999</maxResults>
  162. </searchCond>
  163. </DataOperation>", searchID,startTime,endTime);
  164. byte[] sendData = Encoding.UTF8.GetBytes(requestXmls);
  165. byte[] responseData = client.UploadData(strUrl,"POST", sendData);
  166. string strResponseData = Encoding.UTF8.GetString(responseData);
  167. XmlToDataSet(strResponseData);
  168. XmlDocument xmlDoc = new XmlDocument();//初始化一个实例
  169. xmlDoc.LoadXml(strResponseData);//读取文件
  170. List<MetetBaseRailwayAiweight> metetBaseRailwayAiweights = new List<MetetBaseRailwayAiweight>();
  171. XmlNodeList s = xmlDoc.DocumentElement.GetElementsByTagName("matchElement");
  172. foreach (XmlElement node in s)
  173. {
  174. MetetBaseRailwayAiweight metetBaseRailwayAiweight = new MetetBaseRailwayAiweight();
  175. int stratIndex = node.GetElementsByTagName("plate")[0].InnerText.Length - 7;
  176. metetBaseRailwayAiweight.railwayNo = node.GetElementsByTagName("plate")[0].InnerText.Substring(stratIndex, 7);
  177. metetBaseRailwayAiweight.railwayType = node.GetElementsByTagName("plate")[0].InnerText.Substring(0, stratIndex);
  178. metetBaseRailwayAiweight.meterWeight = node.GetElementsByTagName("selfWeight")[0].InnerText;
  179. metetBaseRailwayAiweight.railwaySpeed = node.GetElementsByTagName("speed")[0].InnerText;
  180. metetBaseRailwayAiweights.Add(metetBaseRailwayAiweight);
  181. }
  182. if (metetBaseRailwayAiweights.Count > 0)
  183. {
  184. RESTfulResult<List<MetetBaseRailwayAiweight>> result = metetBaseRailwayAiweightService.add(metetBaseRailwayAiweights);
  185. if (result.Succeed)
  186. {
  187. // 输出接收的消息
  188. this.textinfo.Text = "成功";
  189. }
  190. }
  191. }
  192. catch (Exception ex)
  193. {
  194. this.textinfo.Text = ex.Message;
  195. }
  196. return;
  197. }
  198. #region Xml To DataSet
  199. public static DataSet XmlToDataSet(string xmlString)
  200. {
  201. XmlDocument xmldoc = new XmlDocument();
  202. xmldoc.LoadXml(xmlString);
  203. StringReader stream = null;
  204. XmlTextReader reader = null;
  205. try
  206. {
  207. DataSet xmlDS = new DataSet();
  208. stream = new StringReader(xmldoc.InnerXml);
  209. reader = new XmlTextReader(stream);
  210. xmlDS.ReadXml(reader);
  211. reader.Close();
  212. return xmlDS;
  213. }
  214. catch (System.Exception ex)
  215. {
  216. reader.Close();
  217. throw ex;
  218. }
  219. }
  220. #endregion
  221. }
  222. }