| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- using NVRCsharpDemo;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml;
- using Common;
- using System.Configuration;
- using com.hnshituo.core.webapp.vo;
- using System.Resources;
- using System.Security.Cryptography;
- using TrainVideoDataDispose.Properties;
- namespace TrainVideoDataDispose
- {
- public partial class text : Form
- {
- public int m_lUserID = -1;
- public int m_lGetFaceParamCfgHandle = -1;
- private CHCNetSDK.REALDATACALLBACK RealData = null;
- public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo;
- public CHCNetSDK.NET_DVR_DEVICEINFO_V40 tDeviceInfo;
- public CHCNetSDK.NET_DVR_IPPARACFG_V40 m_struIpParaCfgV40;
- public CHCNetSDK.NET_DVR_STREAM_MODE m_struStreamMode;
- public CHCNetSDK.NET_DVR_IPCHANINFO m_struChanInfo;
- public CHCNetSDK.NET_DVR_PU_STREAM_URL m_struStreamURL;
- public CHCNetSDK.NET_DVR_IPCHANINFO_V40 m_struChanInfoV40;
- public CHCNetSDK.NET_DVR_USER_LOGIN_INFO pLoginInfo;
- public CHCNetSDK.LOGINRESULTCALLBACK LoginCallBack;
- public CHCNetSDK.RemoteConfigCallback remoteConfigCallback;
- //private PlayCtrl.DECCBFUN m_fDisplayFun = null;
- public delegate void MyDebugInfo(string str);
- private MetetBaseRailwayAiweightService metetBaseRailwayAiweightService = new MetetBaseRailwayAiweightService();
- private Label labelLogin;
- public text()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- #region 海康
- //bool m_bInitSDK = CHCNetSDK.NET_DVR_Init();
- //string DVRIPAddress = '10.111.67.23'; //设备IP地址或者域名 Device IP
- //Int16 DVRPortNumber = Int16.Parse('8000');//设备服务端口号 Device Port
- //string DVRUserName = 'admin';//设备登录用户名 User name to login
- //string DVRPassword = 'Admin12345';//设备登录密码 Password to login
- ////设备IP地址或者域名
- //byte[] byIP = System.Text.Encoding.Default.GetBytes(DVRIPAddress);
- //pLoginInfo.sDeviceAddress = new byte[129];
- //byIP.CopyTo(pLoginInfo.sDeviceAddress, 0);
- ////设备用户名
- //byte[] byUserName = System.Text.Encoding.Default.GetBytes(DVRUserName);
- //pLoginInfo.sUserName = new byte[64];
- //byUserName.CopyTo(pLoginInfo.sUserName, 0);
- ////设备密码
- //byte[] byPassword = System.Text.Encoding.Default.GetBytes(DVRPassword);
- //pLoginInfo.sPassword = new byte[64];
- //byPassword.CopyTo(pLoginInfo.sPassword, 0);
- //pLoginInfo.wPort = 8000;
- //if (LoginCallBack == null)
- //{
- // LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
- //}
- //pLoginInfo.cbLoginResult = LoginCallBack;
- //pLoginInfo.bUseAsynLogin = true;
- ////登录设备 Login the device
- ////m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref pLoginInfo, ref tDeviceInfo);
- //m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref pLoginInfo, ref tDeviceInfo);
- //if (m_lUserID < 0)
- //{
- // uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
- // string str = 'NET_DVR_Login_V30 failed, error code= ' + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
- // textinfo.Text = str;
- // return;
- //}
- //else
- //{
- // //登录成功
- // //停止远程配置
- // if (m_lGetFaceParamCfgHandle != -1)
- // {
- // CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceParamCfgHandle);
- // }
- // //清除表格信息
- // //listViewFaceConfig.Items.Clear();
- // //LpArr.Clear();
- // //定义查询信息对象
- // CHCNetSDK.NET_DVR_TRAFFIC_DATA_QUERY_COND struCond = new CHCNetSDK.NET_DVR_TRAFFIC_DATA_QUERY_COND();
- // struCond.dwSize = (uint)Marshal.SizeOf(struCond);
- // //保留
- // byte[] byRes = System.Text.Encoding.Default.GetBytes('0');
- // struCond.byRes = new byte[254];
- // byRes.CopyTo(struCond.byRes, 0);
- // //struCond.dwQueryCond
- // if (remoteConfigCallback == null)
- // {
- // remoteConfigCallback = new CHCNetSDK.RemoteConfigCallback(cbStateCallback);//注册回调函数
- // }
- // int dwSize = Marshal.SizeOf(struCond);
- // IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);
- // Marshal.StructureToPtr(struCond, ptrStruCond, true);
- // m_lGetFaceParamCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_TRAFFIC_DATA, ptrStruCond, dwSize, remoteConfigCallback, IntPtr.Zero);
- // if (m_lGetFaceParamCfgHandle < 0)
- // {
- // uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
- // string str = 'NET_DVR_StartRemoteConfig failed, error code= ' + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
- // textinfo.Text = str;
- // return;
- // }
- // else
- // {
- // Marshal.FreeHGlobal(ptrStruCond);
- // }
- //}
- #endregion
- try
- {
- //string strUrl = "http://10.111.67.23/ISAPI/System/deviceInfo";
- string strUrl = "http://10.111.67.23/ISAPI/Traffic/ContentMgmt/dataOperation";
- WebClient client = new WebClient();
- int interval = int.Parse(ConfigurationManager.AppSettings["interval"].ToString());
- string startTime = DateTime.Now.ToString("yyyy-MM-dd") + "Y" + DateTime.Now.ToString("HH:mm:ss") + "Z";
- string endTime = DateTime.Now.AddMinutes(interval).ToString("yyyy-MM-dd") + "Y" + DateTime.Now.AddMinutes(interval).ToString("HH:mm:ss") + "Z";
- string searchID = System.Guid.NewGuid().ToString();
- // 设置用户名和密码
- client.Credentials = new NetworkCredential("admin", "Admin12345");
- string requestXmls = string.Format(@"<?xml version:'1.0' encoding='utf-8'?>
- <DataOperation>
- <operationType>search</operationType>
- <searchCond>
- <searchID>{0}</searchID>
- <timeSpanList>
- <timeSpan>
- <startTime>{1}</startTime>
- <endTime>{2}</endTime>
- </timeSpan>
- </timeSpanList>
- <criteria>
- <dataType>0</dataType>
- <channel/>
- <plateType/>
- <plateColor/>
- <direction/>
- <plate/>
- <speedMin/>
- <speedMax/>
- <vehicleType/>
- <vehicleColor/>
- <laneNo/>
- <surveilType>0</surveilType>
- <romoteHost/>
- <analysised>true</analysised>
- <sendFlag/>
- </criteria>
- <searchResultPosition>0</searchResultPosition>
- <maxResults>999</maxResults>
- </searchCond>
- </DataOperation>", searchID,startTime,endTime);
- byte[] sendData = Encoding.UTF8.GetBytes(requestXmls);
- byte[] responseData = client.UploadData(strUrl,"POST", sendData);
- string strResponseData = Encoding.UTF8.GetString(responseData);
- XmlToDataSet(strResponseData);
- XmlDocument xmlDoc = new XmlDocument();//初始化一个实例
- xmlDoc.LoadXml(strResponseData);//读取文件
- List<MetetBaseRailwayAiweight> metetBaseRailwayAiweights = new List<MetetBaseRailwayAiweight>();
- XmlNodeList s = xmlDoc.DocumentElement.GetElementsByTagName("matchElement");
- foreach (XmlElement node in s)
- {
- MetetBaseRailwayAiweight metetBaseRailwayAiweight = new MetetBaseRailwayAiweight();
- int stratIndex = node.GetElementsByTagName("plate")[0].InnerText.Length - 7;
- metetBaseRailwayAiweight.railwayNo = node.GetElementsByTagName("plate")[0].InnerText.Substring(stratIndex, 7);
- metetBaseRailwayAiweight.railwayType = node.GetElementsByTagName("plate")[0].InnerText.Substring(0, stratIndex);
- metetBaseRailwayAiweight.meterWeight = node.GetElementsByTagName("selfWeight")[0].InnerText;
- metetBaseRailwayAiweight.railwaySpeed = node.GetElementsByTagName("speed")[0].InnerText;
- metetBaseRailwayAiweights.Add(metetBaseRailwayAiweight);
- }
- if (metetBaseRailwayAiweights.Count > 0)
- {
- RESTfulResult<List<MetetBaseRailwayAiweight>> result = metetBaseRailwayAiweightService.add(metetBaseRailwayAiweights);
- if (result.Succeed)
- {
- // 输出接收的消息
- this.textinfo.Text = "成功";
- }
- }
- }
- catch (Exception ex)
- {
- this.textinfo.Text = ex.Message;
- }
- return;
- }
- #region Xml To DataSet
- public static DataSet XmlToDataSet(string xmlString)
- {
- XmlDocument xmldoc = new XmlDocument();
- xmldoc.LoadXml(xmlString);
- StringReader stream = null;
- XmlTextReader reader = null;
- try
- {
- DataSet xmlDS = new DataSet();
- stream = new StringReader(xmldoc.InnerXml);
- reader = new XmlTextReader(stream);
- xmlDS.ReadXml(reader);
- reader.Close();
- return xmlDS;
- }
- catch (System.Exception ex)
- {
- reader.Close();
- throw ex;
- }
- }
- #endregion
- }
- }
|