xiongzhu 5 سال پیش
والد
کامیت
0c670bfe8f
8فایلهای تغییر یافته به همراه319 افزوده شده و 5 حذف شده
  1. 11 1
      DeviceCenter.csproj
  2. 61 1
      model/AcsDevice.cs
  3. 17 0
      views/ExitConfirm.xaml
  4. 39 0
      views/ExitConfirm.xaml.cs
  5. 1 1
      views/Login.xaml
  6. 8 0
      views/Login.xaml.cs
  7. 1 1
      views/MainWindow.xaml
  8. 181 1
      views/MainWindow.xaml.cs

+ 11 - 1
DeviceCenter.csproj

@@ -76,6 +76,7 @@
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
     <Reference Include="System.Web" />
     <Reference Include="System.Web.Extensions" />
     <Reference Include="System.Windows.Forms" />
@@ -120,6 +121,9 @@
     <Compile Include="utils\ProcessUtil.cs" />
     <Compile Include="utils\TypeMap.cs" />
     <Compile Include="utils\VehicleUtil.cs" />
+    <Compile Include="views\ExitConfirm.xaml.cs">
+      <DependentUpon>ExitConfirm.xaml</DependentUpon>
+    </Compile>
     <Compile Include="views\Splash.xaml.cs">
       <DependentUpon>Splash.xaml</DependentUpon>
     </Compile>
@@ -127,6 +131,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="views\ExitConfirm.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="views\Login.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -191,7 +199,9 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
-    <Resource Include="assets\icon.ico" />
+    <Content Include="assets\icon.ico">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
   </ItemGroup>
   <ItemGroup>
     <Resource Include="assets\loading.jpg" />

+ 61 - 1
model/AcsDevice.cs

@@ -1,5 +1,7 @@
-using log4net;
+using DeviceCenter.utils;
+using log4net;
 using System;
+using System.Collections.Generic;
 using System.IO;
 using System.Runtime.InteropServices;
 using System.Threading.Tasks;
@@ -293,7 +295,65 @@ namespace DeviceCenter
                 }
                 szInfoBuf = szInfoBuf + "SavePath:" + path;
             }
+            log.Info(ip + " received alerm::");
             log.Info(szInfoBuf);
+
+
+            try
+            {
+                if (szInfoBuf.Contains("MINOR_FACE_VERIFY_PASS") || szInfoBuf.Contains("MINOR_FACE_VERIFY_FAIL"))
+                {
+                    string cardNo = AcsUtil.getCardNo(szInfoBuf);
+                    string doorNo = AcsUtil.getDoorNo(szInfoBuf);
+                    string readerNo = AcsUtil.getCardReaderNo(szInfoBuf);
+                    string channel = AcsUtil.getChannel(szInfoBuf);
+                    string picture = AcsUtil.getPicturePath(szInfoBuf);
+                    Dictionary<string, string> data = new Dictionary<string, string>();
+                   
+                    data.Add("pass", szInfoBuf.Contains("MINOR_FACE_VERIFY_PASS").ToString());
+                    data.Add("cardNo", cardNo);
+                    data.Add("doorNo", doorNo);
+                    data.Add("readerNo", readerNo);
+                    data.Add("channel", channel);
+                    data.Add("ip", ip);
+                    data.Add("direction", direction.ToString());
+                    if (picture != null)
+                    {
+                        data.Add("pic", Convert.ToBase64String(file_get_byte_contents(picture)));
+                    }
+                    http.post<string>("staffAccess/access", data);
+
+                }
+            }
+            catch (Exception e)
+            {
+                log.Error("上传门禁事件出错", e);
+            }
+        }
+
+        static byte[] file_get_byte_contents(string fileName)
+        {
+            byte[] sContents;
+            if (fileName.ToLower().IndexOf("http:") > -1)
+            {
+                // URL 
+                System.Net.WebClient wc = new System.Net.WebClient();
+                sContents = wc.DownloadData(fileName);
+            }
+            else
+            {
+                // Get file size
+                FileInfo fi = new FileInfo(fileName);
+
+                // Disk
+                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
+                BinaryReader br = new BinaryReader(fs);
+                sContents = br.ReadBytes((int)fi.Length);
+                br.Close();
+                fs.Close();
+            }
+
+            return sContents;
         }
     }
 }

+ 17 - 0
views/ExitConfirm.xaml

@@ -0,0 +1,17 @@
+<Window x:Class="DeviceCenter.views.ExitConfirm"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:DeviceCenter.views"
+        mc:Ignorable="d"
+        Title="退出" Height="159.375" Width="234.219" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
+    <StackPanel Orientation="Vertical" Margin="10 10 10 10">
+        <Label Content="请输入密码"/>
+        <PasswordBox Margin="0 5 0 0" Height="30" Name="password" VerticalContentAlignment="Center"/>
+        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 10 0 0">
+            <Button Content="取消" Width="45" Height="25" Name="cancel" Click="cancel_Click"/>
+            <Button Content="确认" Margin="20 0 0 0" Width="45" Height="25" Name="confirm" Click="confirm_Click"/>
+        </StackPanel>
+    </StackPanel>
+</Window>

+ 39 - 0
views/ExitConfirm.xaml.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace DeviceCenter.views
+{
+    /// <summary>
+    /// ExitConfirm.xaml 的交互逻辑
+    /// </summary>
+    public partial class ExitConfirm : Window
+    {
+        public ExitConfirm()
+        {
+            InitializeComponent();
+        }
+
+        private void cancel_Click(object sender, RoutedEventArgs e)
+        {
+            DialogResult = false;
+            Close();
+        }
+
+        private void confirm_Click(object sender, RoutedEventArgs e)
+        {
+            DialogResult = true;
+            Close();
+        }
+    }
+}

+ 1 - 1
views/Login.xaml

@@ -7,7 +7,7 @@
         xmlns:fa5="http://schemas.fontawesome.com/icons/"
         xmlns:sys="clr-namespace:System;assembly=mscorlib"
         mc:Ignorable="d" WindowStyle="None"
-        Title="设备中心登录" Height="236.5" Width="305.5" WindowStartupLocation="CenterScreen">
+        Title="设备中心登录" Height="236.5" Width="305.5" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
     <Window.Resources>
         <Style x:Key="iconStyle" TargetType="fa5:SvgAwesome">
             <Setter Property="Foreground" Value="#409EFF" />

+ 8 - 0
views/Login.xaml.cs

@@ -98,5 +98,13 @@ namespace DeviceCenter
                     MessageBox.Show(e.Message);
                 });
         }
+
+        private void Window_Loaded(object sender, RoutedEventArgs e)
+        {
+            if (!string.IsNullOrWhiteSpace(config.username) && !string.IsNullOrWhiteSpace(config.password))
+            {
+                btn_login_Click(null, null);
+            }
+        }
     }
 }

+ 1 - 1
views/MainWindow.xaml

@@ -6,7 +6,7 @@
         xmlns:local="clr-namespace:DeviceCenter"
         mc:Ignorable="d"
         xmlns:fa5="http://schemas.fontawesome.com/icons/"
-        Title="设备中心" Height="450" Width="800" ResizeMode="NoResize" Closing="Window_Closing" WindowStartupLocation="CenterScreen">
+        Title="设备中心" Height="450" Width="800" ResizeMode="NoResize" Closing="Window_Closing" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
     <Window.Resources>
         <local:EnumItemsSource x:Key="deviceTypeConverter" Type="{x:Type local:DeviceType}"/>
         <local:EnumItemsSource x:Key="directionConverter" Type="{x:Type local:Direction}"/>

+ 181 - 1
views/MainWindow.xaml.cs

@@ -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;
+        }
     }
 }