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(@" search {0} {1} {2} 0 0 true 0 999 ", 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 metetBaseRailwayAiweights = new List(); 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> 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 } }