From c9de968c550f731de1547658f0de5f9a9c27f81c Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Fri, 19 Apr 2024 08:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=83=8F=E6=9C=BA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E4=BC=9A=E5=9C=A8=E7=99=BB=E5=BD=95=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=98=BE=E7=A4=BA=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/HIKVISION/CHKFunction.cs | 54 ++++++++++++-------- DM_Weight/ViewModels/LoginWindowViewModel.cs | 13 ++++- DM_Weight/Views/LoginWindow.xaml | 5 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/DM_Weight/HIKVISION/CHKFunction.cs b/DM_Weight/HIKVISION/CHKFunction.cs index e6dc95a..fc0a713 100644 --- a/DM_Weight/HIKVISION/CHKFunction.cs +++ b/DM_Weight/HIKVISION/CHKFunction.cs @@ -7,11 +7,14 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows; +using DM_Weight.Port; +using log4net; namespace DM_Weight.HIKVISION { public class CHKFunction { + private readonly ILog logger = LogManager.GetLogger(typeof(CHKFunction)); private bool m_bInitSDK = false; private Int32 m_lRealHandle = -1; @@ -38,6 +41,7 @@ namespace DM_Weight.HIKVISION { //MessageBox.Show("NET_DVR_Init error!"); //return; + logger.Info("NET_DVR_Init error!"); } else { @@ -90,12 +94,13 @@ namespace DM_Weight.HIKVISION { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_Login_V40 failed, error code= " + iLastErr; //登录失败,输出错误号 - MessageBox.Show(str); + logger.Info(str); } else { //登录成功 //MessageBox.Show("Login Success!"); + logger.Info("Login Success!"); } } @@ -105,12 +110,14 @@ namespace DM_Weight.HIKVISION if (m_lRealHandle >= 0) { //MessageBox.Show("Please stop live view firstly"); + logger.Info("Please stop live view firstly"); } if (!CHCNetSDK.NET_DVR_Logout(HKUserId)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_Logout failed, error code= " + iLastErr; + logger.Info(str); } HKUserId = -1; } @@ -121,46 +128,51 @@ namespace DM_Weight.HIKVISION { if (m_lRealHandle >= 0) { - CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); + bool stopRealPlay= CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); + logger.Info($"录像机NET_DVR_StopRealPlay接口返回{stopRealPlay}"); } if (HKUserId >= 0) { - CHCNetSDK.NET_DVR_Logout(HKUserId); + bool logout= CHCNetSDK.NET_DVR_Logout(HKUserId); + logger.Info($"录像机NET_DVR_Logout接口返回{logout}"); } if (m_bInitSDK == true) { - CHCNetSDK.NET_DVR_Cleanup(); + bool cleanUp= CHCNetSDK.NET_DVR_Cleanup(); + logger.Info($"录像机NET_DVR_Cleanup接口返回{cleanUp}"); } } public bool HIKStartDVRRecord() { bool isStart= CHCNetSDK.NET_DVR_StartDVRRecord(HKUserId, 0xffff, 0); + logger.Info($"录像机NET_DVR_StartDVRRecord接口返回{isStart}"); return isStart; } public bool HIKStopDVRRecord() { - bool isStart = CHCNetSDK.NET_DVR_StopDVRRecord(HKUserId, 0xffff); - return isStart; + bool isStop = CHCNetSDK.NET_DVR_StopDVRRecord(HKUserId, 0xffff); + logger.Info($"录像机NET_DVR_StopDVRRecord接口返回{isStop}"); + return isStop; } /// /// 清理所有正在使用的资源。 /// - public void Dispose() - { - if (m_lRealHandle >= 0) - { - CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); - } - if (HKUserId >= 0) - { - CHCNetSDK.NET_DVR_Logout(HKUserId); - } - if (m_bInitSDK == true) - { - CHCNetSDK.NET_DVR_Cleanup(); - } - } + //public void Dispose() + //{ + // if (m_lRealHandle >= 0) + // { + // bool stopRealPlay= CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); + // } + // if (HKUserId >= 0) + // { + // CHCNetSDK.NET_DVR_Logout(HKUserId); + // } + // if (m_bInitSDK == true) + // { + // CHCNetSDK.NET_DVR_Cleanup(); + // } + //} } } diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs index 8e050ca..84acc0d 100644 --- a/DM_Weight/ViewModels/LoginWindowViewModel.cs +++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs @@ -25,6 +25,7 @@ using Microsoft.Win32; using System.Xml; using System.Diagnostics; using DM_Weight.HIKVISION; +using System.Security.AccessControl; namespace DM_Weight.ViewModels { @@ -75,13 +76,21 @@ namespace DM_Weight.ViewModels get => _portUtil._canBusExsit && !_portUtil.canBusSerial.IsOpen; } - private bool _fingerMsg; + private bool _fingerMsg= CHKFunction.HKUserId>=0; public bool FingerMsg { get => _fingerMsg; set => SetProperty(ref _fingerMsg, value); } + //录像机登录状态 + private bool _hikMsg; + public bool HIKMsg + { + get=>_hikMsg; + set=>SetProperty(ref _hikMsg, value); + } + //public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil, FingerprintUtil fingerprintUtil) //{ // _fingerprintUtil = fingerprintUtil; @@ -289,7 +298,7 @@ _exitCommand ??= new DelegateCommand(Exit); void Exit() { - _chkFunction.Dispose(); + _chkFunction.HIKLoginOut(); Process.GetCurrentProcess().Kill(); Environment.Exit(0); } diff --git a/DM_Weight/Views/LoginWindow.xaml b/DM_Weight/Views/LoginWindow.xaml index 6fe3a46..38d2646 100644 --- a/DM_Weight/Views/LoginWindow.xaml +++ b/DM_Weight/Views/LoginWindow.xaml @@ -194,10 +194,11 @@ - + - + +