|
|
@@ -1,15 +1,20 @@
|
|
|
using DeviceCenter.model;
|
|
|
using DeviceCenter.utils;
|
|
|
+using DeviceCenter.views;
|
|
|
using log4net;
|
|
|
using Notifications.Wpf;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Drawing;
|
|
|
using System.IO;
|
|
|
+using System.Linq;
|
|
|
using System.Runtime.InteropServices;
|
|
|
+using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Interop;
|
|
|
|
|
|
namespace DeviceCenter
|
|
|
{
|
|
|
@@ -27,13 +32,79 @@ namespace DeviceCenter
|
|
|
private CHCNetSDK.MSGCallBack alarmCallback = null;
|
|
|
private static CarCamSDK.FGetImageCB2 carPlateCallback;
|
|
|
|
|
|
+ private int m_lGetCardCfgHandle = -1;
|
|
|
+ private CHCNetSDK.RemoteConfigCallback g_fGetGatewayCardCallback = null;
|
|
|
+
|
|
|
+ private System.Windows.Forms.NotifyIcon notifyIcon = null;
|
|
|
+ private System.Windows.Forms.ContextMenu contextMenuExit;
|
|
|
+ private System.Windows.Forms.MenuItem menuItem1;
|
|
|
+ private System.ComponentModel.IContainer components;
|
|
|
+
|
|
|
public MainWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
+ notifyIcon = new System.Windows.Forms.NotifyIcon();
|
|
|
+ notifyIcon.Click += new EventHandler(notifyIcon_Click);
|
|
|
+ notifyIcon.Icon = new Icon("assets\\icon.ico");
|
|
|
+
|
|
|
+ this.components = new System.ComponentModel.Container();
|
|
|
+ this.contextMenuExit = new System.Windows.Forms.ContextMenu();
|
|
|
+ this.menuItem1 = new System.Windows.Forms.MenuItem();
|
|
|
+
|
|
|
+ // Initialize contextMenuExit
|
|
|
+ this.contextMenuExit.MenuItems.AddRange(
|
|
|
+ new System.Windows.Forms.MenuItem[] { this.menuItem1 });
|
|
|
+
|
|
|
+ // Initialize menuItem1
|
|
|
+ this.menuItem1.Index = 0;
|
|
|
+ this.menuItem1.Text = "退出";
|
|
|
+ this.menuItem1.Click += new EventHandler(this.menuItem1_Click);
|
|
|
+ notifyIcon.ContextMenu = this.contextMenuExit;
|
|
|
+
|
|
|
initSdk();
|
|
|
|
|
|
lv_device.ItemsSource = devices;
|
|
|
+
|
|
|
+ System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
|
|
|
+ dispatcherTimer.Tick += GetAllCard;
|
|
|
+ dispatcherTimer.Interval = new TimeSpan(0, 30, 0);
|
|
|
+ dispatcherTimer.Start();
|
|
|
+
|
|
|
+ GetAllCard(null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ notifyIcon.Visible = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void notifyIcon_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void menuItem1_Click(object Sender, EventArgs e)
|
|
|
+ {
|
|
|
+ ExitConfirm ex = new ExitConfirm();
|
|
|
+ if (ex.ShowDialog() ?? false)
|
|
|
+ {
|
|
|
+ if(ex.password.Password == config.password)
|
|
|
+ {
|
|
|
+ notifyIcon.Dispose();
|
|
|
+ Application.Current.Shutdown();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ notificationManager.Show(new NotificationContent
|
|
|
+ {
|
|
|
+ Title = "Error",
|
|
|
+ Message = "密码错误",
|
|
|
+ Type = NotificationType.Error
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private async void initSdk()
|
|
|
@@ -88,7 +159,8 @@ namespace DeviceCenter
|
|
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
{
|
|
|
- //e.Cancel = true;
|
|
|
+ e.Cancel = true;
|
|
|
+ Hide();
|
|
|
}
|
|
|
|
|
|
private void btn_add_device_Click(object sender, RoutedEventArgs e)
|
|
|
@@ -170,5 +242,113 @@ namespace DeviceCenter
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+ private void GetAllCard(object source, EventArgs e)
|
|
|
+ {
|
|
|
+ int m_userId = -1;
|
|
|
+ AcsDevice device = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ device = (AcsDevice)devices.First(i => i.type == DeviceType.ACS && i.status == DeviceStatus.CONNECTED);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ if (device == null)
|
|
|
+ {
|
|
|
+ log.Info("no connected device");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ m_userId = device.userId;
|
|
|
+ if (-1 != m_lGetCardCfgHandle)
|
|
|
+ {
|
|
|
+ if (CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetCardCfgHandle))
|
|
|
+ {
|
|
|
+ m_lGetCardCfgHandle = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CHCNetSDK.NET_DVR_CARD_CFG_COND struCond = new CHCNetSDK.NET_DVR_CARD_CFG_COND();
|
|
|
+ struCond.dwSize = (uint)Marshal.SizeOf(struCond);
|
|
|
+ struCond.wLocalControllerID = 0;
|
|
|
+ struCond.dwCardNum = 0xffffffff;
|
|
|
+ struCond.byCheckCardNo = 1;
|
|
|
+
|
|
|
+ int dwSize = Marshal.SizeOf(struCond);
|
|
|
+ IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);
|
|
|
+ Marshal.StructureToPtr(struCond, ptrStruCond, false);
|
|
|
+ g_fGetGatewayCardCallback = new CHCNetSDK.RemoteConfigCallback(ProcessGetGatewayCardCallback);
|
|
|
+
|
|
|
+ m_lGetCardCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_userId, CHCNetSDK.NET_DVR_GET_CARD_CFG_V50, ptrStruCond, dwSize, g_fGetGatewayCardCallback, new WindowInteropHelper(this).Handle);
|
|
|
+ if (m_lGetCardCfgHandle == -1)
|
|
|
+ {
|
|
|
+ log.Info(string.Format("NET_DVR_GET_CARD_CFG_V50 FAIL, ERROR CODE {0}", CHCNetSDK.NET_DVR_GetLastError()));
|
|
|
+ Marshal.FreeHGlobal(ptrStruCond);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log.Info("SUCC NET_DVR_GET_CARD_CFG_V50");
|
|
|
+ }
|
|
|
+ Marshal.FreeHGlobal(ptrStruCond);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ProcessGetGatewayCardCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData)
|
|
|
+ {
|
|
|
+ if (pUserData == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dwType == (uint)CHCNetSDK.NET_SDK_CALLBACK_TYPE.NET_SDK_CALLBACK_TYPE_DATA)
|
|
|
+ {
|
|
|
+ CHCNetSDK.NET_DVR_CARD_CFG_V50 struCardCfg = new CHCNetSDK.NET_DVR_CARD_CFG_V50();
|
|
|
+ struCardCfg = (CHCNetSDK.NET_DVR_CARD_CFG_V50)Marshal.PtrToStructure(lpBuffer, typeof(CHCNetSDK.NET_DVR_CARD_CFG_V50));
|
|
|
+ string strCardNo = System.Text.Encoding.UTF8.GetString(struCardCfg.byCardNo);
|
|
|
+ IntPtr pCardInfo = Marshal.AllocHGlobal(Marshal.SizeOf(struCardCfg));
|
|
|
+ Marshal.StructureToPtr(struCardCfg, pCardInfo, true);
|
|
|
+ CHCNetSDK.PostMessage(pUserData, 1003, (Int64)pCardInfo, 0);
|
|
|
+
|
|
|
+ string cardNo = Encoding.UTF8.GetString(struCardCfg.byCardNo);
|
|
|
+ string isValid = 1 == struCardCfg.byCardValid ? "YES" : "NO";
|
|
|
+ string cardPasswod = Encoding.UTF8.GetString(struCardCfg.byCardPassword);
|
|
|
+ string cardType = (struCardCfg.byCardType == 0 || struCardCfg.byCardType > 7) ?
|
|
|
+ AcsDemoPublic.strCardType[0] : AcsDemoPublic.strCardType[struCardCfg.byCardType];
|
|
|
+ string leaderCard = 1 == struCardCfg.byLeaderCard ? "YES" : "NO";
|
|
|
+ string name = Encoding.UTF8.GetString(struCardCfg.byName);
|
|
|
+
|
|
|
+ log.Info(string.Format("cardNo:{0} name:{1}", cardNo, name));
|
|
|
+
|
|
|
+ //var request = new RestRequest("staffInfo/saveStaffInfo", DataFormat.Json);
|
|
|
+ //request.AddParameter("name", name);
|
|
|
+ //request.AddParameter("cardNo", cardNo);
|
|
|
+ //restClient.Post(request);
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (dwType == (uint)CHCNetSDK.NET_SDK_CALLBACK_TYPE.NET_SDK_CALLBACK_TYPE_STATUS)
|
|
|
+ {
|
|
|
+ uint dwStatus = (uint)Marshal.ReadInt32(lpBuffer);
|
|
|
+ if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_SUCCESS)
|
|
|
+ {
|
|
|
+ log.Info("NET_DVR_GET_CARD_CFG_V50 Get finish");
|
|
|
+ CHCNetSDK.PostMessage(pUserData, 1002, 0, 0);
|
|
|
+ }
|
|
|
+ else if (dwStatus == (uint)CHCNetSDK.NET_SDK_CALLBACK_STATUS_NORMAL.NET_SDK_CALLBACK_STATUS_FAILED)
|
|
|
+ {
|
|
|
+ byte[] bRawData = new byte[40];//4字节状态 + 4字节错误码 + 32字节卡号
|
|
|
+ Marshal.Copy(lpBuffer, bRawData, 0, 40);//将非托管内存指针数据复制到数组中
|
|
|
+
|
|
|
+ byte[] errorb = new byte[4];//4字节错误码
|
|
|
+ Array.Copy(bRawData, 4, errorb, 0, 4);
|
|
|
+ int errorCode = BitConverter.ToInt32(errorb, 0);
|
|
|
+
|
|
|
+ byte[] byCardNo = new byte[32];//32字节卡号
|
|
|
+ Array.Copy(bRawData, 8, byCardNo, 0, 32);
|
|
|
+ string strCardNo = Encoding.ASCII.GetString(byCardNo).TrimEnd('\0');
|
|
|
+
|
|
|
+ log.Info(string.Format("NET_DVR_GET_CARD_CFG_V50 Get Failed,ErrorCode:{0},CardNo:{1}", errorCode, byCardNo));
|
|
|
+ CHCNetSDK.PostMessage(pUserData, 1002, 0, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
}
|