Browse Source

更新人脸识别界面

zhangliwen 1 year ago
parent
commit
03467ca5e3
13 changed files with 536 additions and 481 deletions
  1. 90 0
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/FaceRecognition/DevicesModel.cs
  2. 4 5
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/FaceRecognition/UsersModel.cs
  3. 0 50
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/HttpModel/ResponseModel.cs
  4. 0 146
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/HttpPayloadMode/VerifyUserPayload.cs
  5. 0 56
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/HttpResponseMode/VerifyUserResModel.cs
  6. 1 12
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Service/Controllers/HttpForFaceController.cs
  7. 30 16
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Service/websocket/WssForFace.cs
  8. 17 13
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmFaceRecognition.xaml
  9. 168 107
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmFaceRecognition.xaml.cs
  10. 1 1
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmProcessingManagement.xaml.cs
  11. 19 21
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Uct/UctAddUserInfo.xaml
  12. 204 53
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Uct/UctAddUserInfo.xaml.cs
  13. 2 1
      aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Uct/UctManagerControl.xaml

+ 90 - 0
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/FaceRecognition/DevicesModel.cs

@@ -0,0 +1,90 @@
+using SCADA.CommonLib;
+using SCADA_DAQ.Customer.Service.Websocket;
+using SqlSchema.DBNames;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SCADA_DAQ.Customer.Models.FaceRecognition
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    public class DevicesModel : ObservableObject
+    {
+
+        /// <summary>
+        /// ID
+        /// </summary>
+        [Column(T_Col_Name.App_HongShi_Devices.ID)]
+        public int ID
+        {
+            get { return _ID; }
+            set
+            {
+                if (value != _ID)
+                {
+                    _ID = value;
+                    OnPropertyChanged(nameof(ID));
+                }
+            }
+        }
+        private int _ID;
+
+
+        /// <summary>
+        /// 设备编号
+        /// </summary>
+        [Column(T_Col_Name.App_HongShi_Devices.DeviceId)]
+        public string DeviceId
+        {
+            get { return _DeviceId; }
+            set
+            {
+                if (value != _DeviceId)
+                {
+                    _DeviceId = value;
+                    OnPropertyChanged(nameof(DeviceId));
+                }
+            }
+        }
+        private string _DeviceId;
+
+
+        /// <summary>
+        /// 设备名称
+        /// </summary>
+        [AutoViewProperty("设备名称", Icon = "", IsEnable = true, OptionItemsSource = nameof(DeviceList),
+            StringType = StringType.IsLimited,
+            DisplayMemberPath = "DeviceName",
+            SelectedValuePath = "DeviceName")]
+        [Column(T_Col_Name.App_HongShi_Devices.DeviceName)]
+        [Required]   // 必须
+        public string DeviceName
+        {
+            get { return _DeviceName; }
+            set
+            {
+                if (value != _DeviceName)
+                {
+                    _DeviceName = value;
+                    OnPropertyChanged(nameof(DeviceName));
+                }
+            }
+        }
+        private string _DeviceName;
+        /// <summary>
+        /// 获取在线的设备列表
+        /// </summary>
+        public List<WebSocketClient> DeviceList { get; set; } 
+            = ServiceHost.Instance.GetService<WssForFace>("FaceRecognitionWs").Sockets.Values
+            .Where(t => t.DeviceName != null && t.DeviceName != "").ToList();
+
+
+    }
+}

+ 4 - 5
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/FaceRecognition/UsersModel.cs

@@ -14,8 +14,7 @@ namespace SCADA_DAQ.Customer.Models.FaceRecognition
     /// </summary>
     public class UsersModel : ObservableObject
     {
-
-
+  
         /// <summary>
         /// ID
         /// </summary>
@@ -179,7 +178,7 @@ namespace SCADA_DAQ.Customer.Models.FaceRecognition
                 }
             }
         }
-        private DateTime _IdValid = DateTime.Now.Date;
+        private DateTime _IdValid = DateTime.Now.Date.AddYears(10);
 
 
 
@@ -188,7 +187,7 @@ namespace SCADA_DAQ.Customer.Models.FaceRecognition
         /// </summary>
         [AutoViewProperty("置信度", Icon = "", IsEnable = true)]
         [Column(T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo)]
-        public float ConfidenceLevel
+        public double ConfidenceLevel
         {
             get { return _ConfidenceLevel; }
             set
@@ -200,7 +199,7 @@ namespace SCADA_DAQ.Customer.Models.FaceRecognition
                 }
             }
         }
-        private float _ConfidenceLevel;
+        private double _ConfidenceLevel;
 
     }
 }

+ 0 - 50
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/HttpModel/ResponseModel.cs

@@ -1,50 +0,0 @@
-using SCADA.CommonLib;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SCADA_DAQ.Customer.Models.HttpModel
-{
-    public class ResponseModel : ObservableObject
-    {
-
-        /// <summary>
-        /// 结果
-        /// </summary>
-        public string Result
-        {
-            get { return _Result; }
-            set
-            {
-                if (value != _Result)
-                {
-                    _Result = value;
-                    OnPropertyChanged(nameof(Result));
-                }
-            }
-        }
-        private string _Result;
-
-
-
-        /// <summary>
-        /// 消息
-        /// </summary>
-        public string Msg
-        {
-            get { return _Msg; }
-            set
-            {
-                if (value != _Msg)
-                {
-                    _Msg = value;
-                    OnPropertyChanged(nameof(Msg));
-                }
-            }
-        }
-        private string _Msg;
-
-    }
-}

+ 0 - 146
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/HttpPayloadMode/VerifyUserPayload.cs

@@ -1,146 +0,0 @@
-using SCADA.CommonLib;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SCADA_DAQ.Customer.Models.HttpPayloadMode
-{
-
-    /// <summary>
-    /// 
-    /// </summary>
-    public class VerifyUserPayload : ObservableObject
-    {
-
-        /// <summary>
-        /// 设备号
-        /// </summary>
-        public string Sn
-        {
-            get { return _Sn; }
-            set
-            {
-                if (value != _Sn)
-                {
-                    _Sn = value;
-                    OnPropertyChanged(nameof(Sn));
-                }
-            }
-        }
-        private string _Sn;
-
-        /// <summary>
-        /// 温度
-        /// </summary>
-        public float Temperature
-        {
-            get { return _Temperature; }
-            set
-            {
-                if (value != _Temperature)
-                {
-                    _Temperature = value;
-                    OnPropertyChanged(nameof(Temperature));
-                }
-            }
-        }
-        private float _Temperature;
-
-
-        /// <summary>
-        /// 设备识别类型:1:刷人脸 2:刷卡 3:刷身份证
-        /// </summary>
-        public int Type
-        {
-            get { return _Type; }
-            set
-            {
-                if (value != _Type)
-                {
-                    _Type = value;
-                    OnPropertyChanged(nameof(Type));
-                }
-            }
-        }
-        private int _Type;
-
-
-
-        /// <summary>
-        /// 用户id
-        /// </summary>
-        public int User_Id
-        {
-            get { return _User_Id; }
-            set
-            {
-                if (value != _User_Id)
-                {
-                    _User_Id = value;
-                    OnPropertyChanged(nameof(User_Id));
-                }
-            }
-        }
-        private int _User_Id;
-
-
-        /// <summary>
-        /// 刷卡用户的卡号,type 为 3 时为空,为 1 或者 2 时取人员信息中的卡号
-        /// </summary>
-        public string Card
-        {
-            get { return _Card; }
-            set
-            {
-                if (value != _Card)
-                {
-                    _Card = value;
-                    OnPropertyChanged(nameof(Card));
-                }
-            }
-        }
-        private string _Card;
-
-
-
-        /// <summary>
-        /// 这个值为人证访客接口下发的 user_id ,只有 type 为 3 并且设备使用【指定身份证模式】这个字段的内容才有值
-        /// </summary>
-        public string Visit_Id
-        {
-            get { return _Visit_Id; }
-            set
-            {
-                if (value != _Visit_Id)
-                {
-                    _Visit_Id = value;
-                    OnPropertyChanged(nameof(Visit_Id));
-                }
-            }
-        }
-        private string _Visit_Id;
-
-
-        /// <summary>
-        /// 人脸算法识别到的相识度
-        /// </summary>
-        public float Confidence
-        {
-            get { return _Confidence; }
-            set
-            {
-                if (value != _Confidence)
-                {
-                    _Confidence = value;
-                    OnPropertyChanged(nameof(Confidence));
-                }
-            }
-        }
-        private float _Confidence;
-
-
-
-    }
-}

+ 0 - 56
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/HttpResponseMode/VerifyUserResModel.cs

@@ -1,56 +0,0 @@
-using SCADA.CommonLib;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SCADA_DAQ.Customer.Models.HttpResponseMode
-{
-
-    /// <summary>
-    /// 
-    /// </summary>
-    public class VerifyUserResModel : ObservableObject
-    {
-
-        /// <summary>
-        /// 结果
-        /// </summary>
-        public string Result
-        {
-            get { return _Result; }
-            set
-            {
-                if (value != _Result)
-                {
-                    _Result = value;
-                    OnPropertyChanged(nameof(Result));
-                }
-            }
-        }
-        private string _Result;
-
-
-
-        /// <summary>
-        /// 消息
-        /// </summary>
-        public string Msg
-        {
-            get { return _Msg; }
-            set
-            {
-                if (value != _Msg)
-                {
-                    _Msg = value;
-                    OnPropertyChanged(nameof(Msg));
-                }
-            }
-        }
-        private string _Msg;
-
-
-
-    }
-}

+ 1 - 12
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Service/Controllers/HttpForFaceController.cs

@@ -1,20 +1,9 @@
-using Nancy.Extensions;
-using SCADA.CommonLib;
-using SCADA.CommonLib.Data;
-using SCADA.CommonLib.Data.DIL;
-using SCADA.CommonLib.Helper;
+using SCADA.CommonLib.Data.DIL;
 using SCADA_DAQ.Customer.Models.FaceRecognition;
-using SCADA_DAQ.Customer.Models.HttpModel;
-using SCADA_DAQ.Customer.Models.HttpPayloadMode;
-using SCADA_DAQ.Customer.Models.HttpResponseMode;
 using SqlSchema.DBNames;
 using System;
 using System.Collections.Generic;
-using System.Drawing;
-using System.IO;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Web.Http;
 
 namespace SCADA_DAQ.Customer.Service.Controllers

+ 30 - 16
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Service/websocket/WssForFace.cs

@@ -33,7 +33,7 @@ namespace SCADA_DAQ.Customer.Service.Websocket
         /// <summary>
         /// 所有的socket链接
         /// </summary>
-        public readonly ConcurrentDictionary<string, IWebSocketConnection> Sockets = new ConcurrentDictionary<string, IWebSocketConnection>();
+        public readonly ConcurrentDictionary<string, WebSocketClient> Sockets = new ConcurrentDictionary<string, WebSocketClient>();
 
         /// <summary>
         /// 接收消息事件
@@ -105,24 +105,29 @@ namespace SCADA_DAQ.Customer.Service.Websocket
                     socket.OnOpen = () =>
                     {
                         string clientUrl = socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort;
-                        FleckLog.Info($"{clientUrl} Open!");
+                        FleckLog.Info($"{clientUrl} Open!");                        
                         ClientConnected?.Invoke(this, new WebSocketClientConnected()
                         {
                             SocketConnection = socket,
                         });
                         AllSockets.TryAdd(socket, socket);
-                        Sockets.TryAdd(socket.ConnectionInfo.Id.ToString(), socket);
+                        Sockets.TryAdd(socket.ConnectionInfo.Id.ToString(), new WebSocketClient()
+                        {
+                            Guid = socket.ConnectionInfo.Id,
+                            SocketConnection = socket
+                        });
                     };
                     socket.OnClose = () =>
                     {
                         string clientUrl = socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort;
-                        FleckLog.Info($"{clientUrl} Close!");
+                        FleckLog.Info($"{clientUrl} Close!");                        
                         ClientDisconnected?.Invoke(this, new WebSocketClientDisconnected()
                         {
                             SocketConnection = socket
                         });
                         AllSockets.TryRemove(socket, out var _);
                         Sockets.TryRemove(socket.ConnectionInfo.Id.ToString(), out var _);
+
                     };
                     socket.OnMessage = message =>
                     {
@@ -135,14 +140,15 @@ namespace SCADA_DAQ.Customer.Service.Websocket
                         FleckLog.Info($"{message}");
 
                         var requestInfo = JsonHelper.JsonDeserialize<ReceiveModel>(message);
+                        // 处理函数
+                        ReceiveHandler(socket, requestInfo);
+
                         // 接收事件
                         ClientMessage?.Invoke(this, new WebSocketClientMessage()
                         {
                             Guid = socket.ConnectionInfo.Id,
                             Message = requestInfo
                         });
-
-                        ReceiveHandler(socket, requestInfo);
                     };
                     socket.OnPing = ping =>
                     {
@@ -189,15 +195,6 @@ namespace SCADA_DAQ.Customer.Service.Websocket
         }
 
 
-        /// <summary>
-        /// 
-        /// </summary>
-        public void Test()
-        {
-            
-        }
-
-
         /// <summary>
         /// 公共消息回复
         /// </summary>
@@ -209,10 +206,13 @@ namespace SCADA_DAQ.Customer.Service.Websocket
             switch (msg.Cmd)
             {
                 case "ping":
+                    // 心跳包响应
                     socket.Send(JsonHelper.JsonSerialize(new { cmd = "pong"}));
                     break;
                 case "declare":
-                    socket.Send(JsonHelper.JsonSerialize(new { cmd = "declare", client_id = clientId }));
+                    // 设备声明响应
+                    socket.Send(JsonHelper.JsonSerialize(new { cmd = "declare", client_id = clientId.ToString() }));
+                    Sockets[clientId.ToString()].DeviceName = msg.Sn;
                     break;
                 default:
                     break;
@@ -221,6 +221,20 @@ namespace SCADA_DAQ.Customer.Service.Websocket
         
     }
 
+    /// <summary>
+    /// ws客户端socket
+    /// </summary>
+    public class WebSocketClient
+    {
+        public Guid Guid { get; set; }
+
+        public string DeviceName { get; set; }
+
+        //public object Message { get; set; }
+
+        public IWebSocketConnection SocketConnection { get; set; }
+}
+
 
     /// <summary>
     /// 接收消息事件模型

+ 17 - 13
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmFaceRecognition.xaml

@@ -12,11 +12,11 @@
              d:DesignWidth="800">
     <Grid>
         <Grid.RowDefinitions>
-            <RowDefinition Height="auto"/>
-            <RowDefinition Height="3"/>
+            <!--<RowDefinition Height="auto"/>
+            <RowDefinition Height="3"/>-->
             <RowDefinition/>
         </Grid.RowDefinitions>
-        <Grid>
+        <!--<Grid>
             <Grid.ColumnDefinitions>
                 <ColumnDefinition />
                 <ColumnDefinition />
@@ -29,13 +29,9 @@
                                 ButtonStyle="Primary" Title="测试" Margin="10" 
                                 Width="80" Height="30" HorizontalAlignment="Right" FontSize="20"
                                 Click="IconButton_Click" Cursor="Hand"/>
-                <!--<wpfcontrol:IconButton ButtonKind="AddButton"
-                                ButtonStyle="Primary" Title="新增" Margin="10" 
-                                Width="80" Height="30" HorizontalAlignment="Right" FontSize="20"
-                                Click="IconButton_Click_Add" Cursor="Hand"/>-->
             </StackPanel>
         </Grid>
-        <Rectangle Height="2" Width="10000" Fill="Gray" Grid.Row="1"/>
+        <Rectangle Height="2" Width="10000" Fill="Gray" Grid.Row="1"/>-->
         <Grid Grid.Row="2">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition />
@@ -46,9 +42,14 @@
                                   CanUserDeleteRows="{Binding IsAdmin,ElementName=this}" 
                                   AutoGenerateColumns="True" IsReadOnly="True">
                     <wpfcontrol:SmartGrid.HeaderExControl>
-                        <wpfcontrol:IconButton ButtonKind="AddButton" ButtonStyle="Primary"
+                        <StackPanel Orientation="Horizontal">
+                            <wpfcontrol:IconButton ButtonKind="AddButton" ButtonStyle="Success"
                                     Title="新增" Margin="10" Cursor="Hand" FontSize="14"
-                                    Tag="add" Click="AddAndUpdate_Click"/>
+                                    Tag="add" Click="Bt_Click"/>
+                            <wpfcontrol:IconButton ButtonKind="DownLoadButton" ButtonStyle="Info"
+                                    Title="下发用户" Margin="0 0" Cursor="Hand" FontSize="14"
+                                    Tag="set" Click="Bt_Click_Set"/>
+                        </StackPanel>
                     </wpfcontrol:SmartGrid.HeaderExControl>
                     <wpfcontrol:SmartGrid.RowStyle>
                         <Style TargetType="DataGridRow">
@@ -64,9 +65,12 @@
                             <DataGridTemplateColumn.CellTemplate>
                                 <DataTemplate>
                                     <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
-                                        <wpfcontrol:IconButton ButtonKind="AddButton" ButtonStyle="Warning"
-                                                    Title="编辑" Margin="1" Cursor="Hand" FontSize="12" 
-                                                    Tag="update" Click="AddAndUpdate_Click" />
+                                        <wpfcontrol:IconButton ButtonKind="EditButton" ButtonStyle="Warning"
+                                                    Title="编辑" Margin="2" Cursor="Hand" FontSize="13" 
+                                                    Tag="update" Click="Bt_Click" />
+                                        <wpfcontrol:IconButton ButtonKind="DeleteButton" ButtonStyle="Danger"
+                                                    Title="删除" Margin="2" Cursor="Hand" FontSize="13" 
+                                                    Tag="delete" Click="Bt_Click" />
                                     </StackPanel>
                                 </DataTemplate>
                             </DataGridTemplateColumn.CellTemplate>

+ 168 - 107
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmFaceRecognition.xaml.cs

@@ -1,42 +1,17 @@
-using Fleck;
-using log4net;
-using Microsoft.DwayneNeed.Win32.Gdi32;
-using NPOI.SS.Formula.Functions;
-using NPOI.SS.UserModel;
-using Opc.Ua.Gds;
-using SCADA.CommonCtrl.WpfControl;
+using SCADA.CommonCtrl.WpfControl;
 using SCADA.CommonLib;
-using SCADA.CommonLib.CommonModel;
 using SCADA.CommonLib.Data.DIL;
 using SCADA.CommonLib.Helper;
-using SCADA.Drive.Mitsubishi.QPLC;
-using SCADA_DAQ.Customer.Models;
 using SCADA_DAQ.Customer.Models.FaceRecognition;
-using SCADA_DAQ.Customer.Models.ProcessingManagement;
-using SCADA_DAQ.Customer.Models.PropertyManagement;
-using SCADA_DAQ.Customer.Models.TaskManagement;
-using SCADA_DAQ.Customer.Service;
 using SCADA_DAQ.Customer.Service.Websocket;
 using SCADA_DAQ.Customer.Views.Uct;
 using SqlSchema.DBNames;
 using System;
-using System.Collections.Generic;
-using System.IO;
+using System.Data;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
 using System.Web;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Forms;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-using static Mono.Security.X509.X520;
 
 namespace SCADA_DAQ.Customer
 {
@@ -47,7 +22,7 @@ namespace SCADA_DAQ.Customer
     public partial class UctFrmFaceRecognition : BaseUctFrm
     {
         // 服务示实例
-        private WssForFace wssForFace = ServiceHost.Instance.GetService<WssForFace>("FaceRecognitionWs");
+        private WssForFace WssForFaceService = ServiceHost.Instance.GetService<WssForFace>("FaceRecognitionWs");
 
         /// <summary>
         /// 
@@ -56,40 +31,46 @@ namespace SCADA_DAQ.Customer
         {
             InitializeComponent();
             //ToolBar.Visibility = Visibility.Collapsed; // 屏蔽顶部工具栏
+
             FrmQuery.QueryModel = new QueryUsersModel();
             var cloumn = SmartGridHeaderMapping.CreateMapping<UsersModel>();
             cloumn.Remove(T_Col_Name.App_HongShi_Users.Photo_Str);
             MainGrid.DataTableColumnLables = cloumn;
+            MainGrid.ExportSheetName = "人员信息";  // 导出表的名称
 
-            //wssForFace.ClientMessage += WssForFace_ClientMessage;
+            WssForFaceService.ClientMessage += WssForFace_ClientMessage;
         }
 
+
+        /// <summary>
+        /// ws消息接收事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void WssForFace_ClientMessage(object sender, WebSocketClientMessage e)
         {
-            var id = e.Guid;
-            var msg = e.Message as ReceiveModel;
-            //Dispatcher.Invoke(() =>
-            //{
-            //    MsgText.Text = $"{id} \r\n {msg.Cmd}";
-            //});
-            object cmd = null;
-            msg.Data?.TryGetValue("cmd", out cmd);
-            if (cmd == null) return;
-            if (cmd.ToString() == "onlineAuthorizationRet")
+            //var id = e.Guid;
+            var message = e.Message as ReceiveModel;
+            if (message.Data != null)
             {
-                object photo = null;
-                msg.Data?.TryGetValue("vl_face_template", out photo);
-                string base64 = HttpUtility.UrlDecode(photo.ToString(), Encoding.UTF8);
-                base64 = base64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
-                byte[] bytes = Convert.FromBase64String(base64);
-                MemoryStream memStream = new MemoryStream(bytes);
-                ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
-                //Dispatcher.Invoke(() =>
-                //{
-                //    FaceImg.Source = (ImageSource)imageSourceConverter.ConvertFrom(memStream);
-                //});
-                
+                message.Data.TryGetValue("cmd", out object cmd);
+                if (cmd == null) return;
+                if (cmd.ToString() == "addUserRet")
+                {
+                    message.Data.TryGetValue("user_id", out object userId);
+                    message.Data.TryGetValue("code", out object code);
+                    message.Data.TryGetValue("msg", out object msg);
+                    if (code.ToString() == "0")
+                    {
+                        ((IApp)System.Windows.Application.Current).ShowShortToast($"{userId} - " + msg.ToString(), ControlStyle.Success);
+                    }
+                    else
+                    {
+                        ((IApp)System.Windows.Application.Current).ShowShortToast($"{userId} - " + msg.ToString(), ControlStyle.Warning);
+                    }
+                }
             }
+            
         }
 
         private void Schedual_DateTimeChanged(object sender, DateTimeChangedArgs e)
@@ -108,84 +89,156 @@ namespace SCADA_DAQ.Customer
             }
         }
 
-        private void IconButton_Click(object sender, RoutedEventArgs e)
+        /// <summary>
+        /// 下发用户按钮事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void Bt_Click_Set(object sender, RoutedEventArgs e)
         {
-            // 抓拍
-            //var keys = wssForFace.Sockets.Keys.ToList();
-            //keys.ForEach(n => {
-            //    wssForFace.Sockets[n]?.Send(JsonHelper.JsonSerialize(new 
-            //    { 
-            //        cmd = "to_device",
-            //        form = n,
-            //        to = "T68318",
-            //        data = new { cmd = "onlineAuthorization" }
-            //    }));
-            //});
-
-            // 下发用户
-            //var user = Env.SgIDAL.App_HongShi_Users.GetData<UsersModel>().FirstOrDefault();
-            //var keys = wssForFace.Sockets.Keys.ToList();
-            //keys.ForEach(n => {
-            //    wssForFace.Sockets[n]?.Send(JsonHelper.JsonSerialize(new
-            //    {
-            //        cmd = "to_device",
-            //        form = n,
-            //        to = "T68318",
-            //        data = new { 
-            //            cmd = "addUser",
-            //            user_id = user.UserId,
-            //            name = user.Name,
-            //            id_valid = user.IdValid.ToString().Substring(0, 9).Replace("/", "-"),
-            //            face_template = HttpUtility.UrlEncode(user.Photo, Encoding.UTF8),
-            //            confidence_level = user.ConfidenceLevel
-            //        }
-            //    }));
-            //});
-            //
+            var deviceMode = new DevicesModel();
+            
+            ShowChildWindow(new AutoView(deviceMode), true, true, "选择在线设备", () => {
+                Dispatcher.Invoke(() =>
+                {
+                    // 下发用户
+                    for (int i = 0; i < MainGrid.SelectedItems.Count; i++)
+                    {
+                        var item = MainGrid.SelectedItems[i] as DataRowView;
+                        if (item == null)
+                            continue;
+                        var device = WssForFaceService.Sockets.Values.Where(t => t.DeviceName == deviceMode.DeviceName)?.LastOrDefault();
+                        device.SocketConnection.Send(JsonHelper.JsonSerialize(new
+                        {
+                            cmd = "to_device",
+                            form = device.Guid.ToString(),
+                            to = device.DeviceName,
+                            data = new
+                            {
+                                cmd = "addUser",
+                                user_id = item[T_Col_Name.App_HongShi_Users.UserId_Str]?.ToString(),
+                                name = item[T_Col_Name.App_HongShi_Users.Name_Str]?.ToString(),
+                                id_valid = Convert.ToDateTime(item[T_Col_Name.App_HongShi_Users.IdValid_Dt] is DBNull
+                                        ? DateTime.Now.AddYears(1) : item[T_Col_Name.App_HongShi_Users.IdValid_Dt]).Format("yyyy-MM-dd"),
+                                face_template = HttpUtility.UrlEncode(item[T_Col_Name.App_HongShi_Users.Photo_Str]?.ToString(), Encoding.UTF8),
+                                confidence_level = Convert.ToDouble(item[T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo] is DBNull
+                                        ? 0.0 : item[T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo])
+                            }
+                        }));
+                    }
+                });                
+                return true;
+            });
+            
         }
 
-
-        private void AddAndUpdate_Click(object sender, RoutedEventArgs e)
+        /// <summary>
+        /// 增删改按钮事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void Bt_Click(object sender, RoutedEventArgs e)
         {
             string btTag = (sender as IconButton).Tag.ToString();  // 获取Tag
-            //var childWindow = new UctAddUserInfo();
-            UctAddUserInfo childWindow = null;
-            if (btTag == "add")
+            UctAddUserInfo childWindow = null;  // 子窗口
+            int id = 0;  // 选择项id
+            
+            if (btTag == "delete")
             {
-                childWindow = new UctAddUserInfo();
+                // 获取选中项信息
+                var item = MainGrid.CurrentItem as DataRowView;
+                id = Convert.ToInt32(item[T_Col_Name.App_HongShi_Users.ID]);
+                var uid = item[T_Col_Name.App_HongShi_Users.UserId_Str]?.ToString();
+                if (MessageBox.Show($"是否确认删除{uid}?", "提示", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
+                    return;
+                var res = Env.SgIDAL.App_HongShi_Users.Delete($"ID={id}");
+                if (res)
+                {
+                    ((IApp)System.Windows.Application.Current).ShowShortToast("删除成功!", ControlStyle.Success);
+                    Dispatcher.Invoke(() =>
+                    {
+                        // 不用委托会报错
+                        Query();
+                    });
+                }
+                else
+                {
+                    ((IApp)System.Windows.Application.Current).ShowShortToast("删除失败,请重试!", ControlStyle.Warning);
+                }
+                return;
+            }
+
+            if(btTag == "add")
+            {
+                childWindow = new UctAddUserInfo(new UsersModel());
             }
             else if (btTag == "update")
             {
-                childWindow.UsersModelValues = new UsersModel()
+                // 获取选中项信息
+                var item = MainGrid.CurrentItem as DataRowView;
+                var userInfo = new UsersModel()
                 {
-                    UserId = "1"
+                    UserId = item[T_Col_Name.App_HongShi_Users.UserId_Str]?.ToString(),
+                    Name = item[T_Col_Name.App_HongShi_Users.Name_Str]?.ToString(),
+                    Photo = item[T_Col_Name.App_HongShi_Users.Photo_Str]?.ToString(),
+                    IdCard = item[T_Col_Name.App_HongShi_Users.IdCard_Str]?.ToString(),
+                    IcCard = item[T_Col_Name.App_HongShi_Users.IcCard_Str]?.ToString(),
+                    IdValid = Convert.ToDateTime(item[T_Col_Name.App_HongShi_Users.IdValid_Dt] is DBNull
+                        ? DateTime.Now.AddYears(1) : item[T_Col_Name.App_HongShi_Users.IdValid_Dt]),
+                    ConfidenceLevel = Convert.ToDouble(item[T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo] is DBNull
+                        ? 0.0 : item[T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo])
                 };
+                id = Convert.ToInt32(item[T_Col_Name.App_HongShi_Users.ID]);
+
+                childWindow = new UctAddUserInfo(userInfo);
             }
             
             // 显示子窗口
-            ShowChildWindow(childWindow, true, true, "新增用户", () => {
+            ShowChildWindow(childWindow, true, true, "", () => {
                 var userInfo = childWindow.UsersModelValues;
-
-                bool res = Env.SgIDAL.App_HongShi_Users.Insert(
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.UserId_Str, userInfo.UserId),
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.Name_Str, userInfo.Name),
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.IcCard_Str, userInfo.IcCard),
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.IdCard_Str, userInfo.IdCard),
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.Photo_Str, userInfo.Photo),
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.IdValid_Dt, userInfo.IdValid),
-                    new UpdateItem(T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo, userInfo.ConfidenceLevel)
-                );
+                bool res = false;
+                if (btTag == "add")
+                {
+                    res = Env.SgIDAL.App_HongShi_Users.Insert(
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.UserId_Str, userInfo.UserId),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.Name_Str, userInfo.Name),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.IcCard_Str, userInfo.IcCard),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.IdCard_Str, userInfo.IdCard),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.Photo_Str, userInfo.Photo),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.IdValid_Dt, userInfo.IdValid),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo, userInfo.ConfidenceLevel)
+                    );
+                }
+                else
+                {
+                    res = Env.SgIDAL.App_HongShi_Users.Update($"ID={id}",
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.UserId_Str, userInfo.UserId),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.Name_Str, userInfo.Name),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.IcCard_Str, userInfo.IcCard),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.IdCard_Str, userInfo.IdCard),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.Photo_Str, userInfo.Photo),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.IdValid_Dt, userInfo.IdValid),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.ConfidenceLevel_Flo, userInfo.ConfidenceLevel),
+                        new UpdateItem(T_Col_Name.App_HongShi_Users.ModifyTime_Dt, DateTime.Now.Format())
+                    );
+                }
+                
                 if (res)
                 {
-                    ((IApp)System.Windows.Application.Current).ShowShortToast("添加成功!", ControlStyle.Success);
-                    Query();
+                    ((IApp)System.Windows.Application.Current).ShowShortToast("保存成功!", ControlStyle.Success);
+                    Dispatcher.Invoke(() =>
+                    {
+                        // 不用委托会报错
+                        Query();
+                    });
                 }
                 else
                 {
-                    ((IApp)System.Windows.Application.Current).ShowShortToast("添加失败,请重试!", ControlStyle.Warning);
+                    ((IApp)System.Windows.Application.Current).ShowShortToast("保存失败,请重试!", ControlStyle.Warning);
                 }
                 return res;
             });
+            
         }
 
 
@@ -198,7 +251,15 @@ namespace SCADA_DAQ.Customer
             base.Query();
         }
 
-        
+        /// <summary>
+        /// 关闭页面
+        /// </summary>
+        protected override void CloseThis()
+        {
+            WssForFaceService.ClientMessage -= WssForFace_ClientMessage;
+            base.CloseThis();
+        }
+
     }
 
 }

+ 1 - 1
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmProcessingManagement.xaml.cs

@@ -74,7 +74,7 @@ namespace SCADA_DAQ.Customer
             string filter = "";
             string orderString = "";
             int count = grid.SelectedItems.Count;
-
+            // 遍历选中项
             for (int i = 0; i < count; i++)
             {
                 var drv = grid.SelectedItems[i] as DataRowView;

+ 19 - 21
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Uct/UctAddUserInfo.xaml

@@ -1,12 +1,13 @@
-<wpfcontrol:BaseUserControl x:Class="SCADA_DAQ.Customer.Views.Uct.UctAddUserInfo"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:SCADA_DAQ.Customer.Views.Uct" xmlns:wpfcontrol="clr-namespace:SCADA.CommonCtrl.WpfControl;assembly=SCADA.CommonCtrl"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800"
-                 x:Name="this">
+<wpfcontrol:BaseUserControl 
+    x:Class="SCADA_DAQ.Customer.Views.Uct.UctAddUserInfo"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+    xmlns:wpfcontrol="clr-namespace:SCADA.CommonCtrl.WpfControl;assembly=SCADA.CommonCtrl"
+    mc:Ignorable="d" 
+    d:DesignHeight="450" d:DesignWidth="800"
+    x:Name="this">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="5*"/>
@@ -17,7 +18,7 @@
                 <ColumnDefinition Width="350"/>
                 <ColumnDefinition />
             </Grid.ColumnDefinitions>
-            <ContentControl Grid.Column="0" x:Name="User"/>
+            <ContentControl Grid.Column="0" x:Name="User" Margin="10 20"/>
             <StackPanel Grid.Column="1" Orientation="Horizontal">
                 <Grid Width="145" Height="230" Margin="10 20" VerticalAlignment="Top">
                     <Rectangle Height="auto" Width="auto" Fill="LightGray" Stroke="Gray" StrokeThickness="1"/>
@@ -26,34 +27,31 @@
                 <StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="10 20">
                     <StackPanel Orientation="Vertical" Margin="10 20">
                         <TextBlock Text="方式一:本地上传照片" FontSize="14"/>
-                        <wpfcontrol:IconButton ButtonKind="UpLoadButton" VerticalAlignment="Top"
+                        <wpfcontrol:IconButton x:Name="UploadBt" ButtonKind="UpLoadButton" VerticalAlignment="Top"
                             ButtonStyle="Primary" Title="上传照片" Margin="10" 
                             Width="auto" Height="30" HorizontalAlignment="Left" FontSize="20"
                             Click="IconButton_Click_Upload" Cursor="Hand"/>
+                        <!--<wpfcontrol:OpenFileButton x:Name="UploadBt" ButtonKind="UpLoadButton" VerticalAlignment="Top"
+                            ButtonStyle="Primary" Title="上传照片" Margin="10" FileType="Image"
+                            Width="auto" Height="30" HorizontalAlignment="Left" FontSize="20"
+                            Click="UploadBt_Click" Cursor="Hand"/>-->
                     </StackPanel>
                     <StackPanel Orientation="Vertical" Margin="10 20">
                         <TextBlock Text="方式二:设备拍照" FontSize="14"/>
                         <StackPanel Orientation="Horizontal">
                             <ComboBox Height="30" Width="130" x:Name="MyComboBox" SelectedIndex="0">
-                                <!--<ComboBox.ItemTemplate>
-                        <DataTemplate>
-                            <StackPanel Orientation="Horizontal">
-                                <TextBlock Text="{Binding Content}" Visibility="{Binding Visibility}"/>
-                            </StackPanel>
-                        </DataTemplate>
-                    </ComboBox.ItemTemplate>-->
                             </ComboBox>
                             <wpfcontrol:IconButton ButtonKind="Camera"  VerticalAlignment="Top"
                                 ButtonStyle="Primary" Title="设备拍照" Margin="10" 
                                 Width="auto" Height="30" HorizontalAlignment="Right" FontSize="20"
-                                Click="IconButton_Click_Device" Cursor="Hand"/>
+                                Click="IconButton_Click_Capture" Cursor="Hand"/>
                         </StackPanel>
                     </StackPanel>
                 </StackPanel>
 
             </StackPanel>
         </Grid>
-        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
+        <!--<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
             <wpfcontrol:IconButton ButtonKind="CancelButton" VerticalAlignment="Center" HorizontalAlignment="Center"
                 ButtonStyle="Warning" Title="取消" Margin="10" 
                 Width="auto" Height="30" FontSize="25"
@@ -62,6 +60,6 @@
                 ButtonStyle="Success" Title="保存" Margin="10" 
                 Width="auto" Height="30" FontSize="25"
                 Click="IconButton_Click_Confirm" Cursor="Hand"/>
-        </StackPanel>
+        </StackPanel>-->
     </Grid>
 </wpfcontrol:BaseUserControl>

+ 204 - 53
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Uct/UctAddUserInfo.xaml.cs

@@ -1,113 +1,264 @@
-using DBNames;
-using NPOI.SS.Formula.Functions;
-using SCADA.CommonCtrl.WpfControl;
-using SCADA.CommonLib;
-using SCADA.CommonLib.Data.DIL;
+using SCADA.CommonCtrl.WpfControl;
 using SCADA.CommonLib.Helper;
-using SCADA_DAQ.Customer.Models;
 using SCADA_DAQ.Customer.Models.FaceRecognition;
 using SCADA_DAQ.Customer.Service.Websocket;
-using SCADA_DAQ.Plugin.CoreUI.UserManage;
 using System;
-using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.IO;
 using System.Linq;
+using System.Security;
 using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
 using System.Web;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Forms;
-using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-using static System.Windows.Forms.VisualStyles.VisualStyleElement;
-
+using System.Windows.Input;
+using System.Windows.Controls.Primitives;
+using System.Windows.Threading;
+using NPOI.POIFS.Properties;
 
 namespace SCADA_DAQ.Customer.Views.Uct
 {
     /// <summary>
-    /// UctOrderingIssue.xaml 的交互逻辑
+    /// UctAddUserInfo.xaml 的交互逻辑
     /// </summary>
     public partial class UctAddUserInfo : BaseUserControl
     {
 
         // 服务示实例
-        private WssForFace WssForFace = ServiceHost.Instance.GetService<WssForFace>("FaceRecognitionWs");
+        private WssForFace WssForFaceService = ServiceHost.Instance.GetService<WssForFace>("FaceRecognitionWs");
+
+        // 设备列表
+        private ObservableCollection<string> DeviceCell = new ObservableCollection<string>();
 
         /// <summary>
         /// 表单
         /// </summary>
-        public UsersModel UsersModelValues = new UsersModel();
+        public UsersModel UsersModelValues { get; set; }
+
+
+        ///// <summary>
+        ///// 
+        ///// </summary>
+        //public UctAddUserInfo()
+        //{
+        //    InitializeComponent();
+        //    User.Content = new AutoView(UsersModelValues) { MaxTitleWidth = 300, MaxWidth = 500, FontSize = 18 };
+        //    WssForFace.ClientMessage += WssForFace_ClientMessage;
+
+        //    MyComboBox.ItemsSource = new string[] {};
+        //}
+
 
         /// <summary>
         /// 
         /// </summary>
-        public UctAddUserInfo()
+        /// <param name="usersModel"></param>
+        public UctAddUserInfo(UsersModel usersModel)
         {
             InitializeComponent();
-            User.Content = new AutoView(UsersModelValues) { MaxTitleWidth = 300, MaxWidth = 500, FontSize = 18 };
-            WssForFace.ClientMessage += WssForFace_ClientMessage;
-
-            MyComboBox.ItemsSource = new string[] {};
+            UsersModelValues = usersModel;
 
-        }
+            User.Content = new AutoView(UsersModelValues) { MaxTitleWidth = 300, MaxWidth = 500, FontSize = 18 };
+            WssForFaceService.ClientMessage += WssForFace_ClientMessage;
+            WssForFaceService.ClientConnected += WssForFaceService_ClientConnected;
+            WssForFaceService.ClientDisconnected += WssForFaceService_ClientDisconnected;
 
+            // 绑定设备列表
+            MyComboBox.ItemsSource = DeviceCell;
+            // 加载数据
+            var deviceList = WssForFaceService.Sockets.Values
+                .Where(t => t.DeviceName != null && t.DeviceName != "")
+                .Select(t => t.DeviceName).ToList();
+            deviceList.ForEach(t => DeviceCell.Add(t));
 
-        private void WssForFace_ClientMessage(object sender, WebSocketClientMessage e)
-        {
-            var id = e.Guid;
-            var msg = e.Message as ReceiveModel;
-            object cmd = null;
-            msg.Data?.TryGetValue("cmd", out cmd);
-            if (cmd == null) return;
-            if (cmd.ToString() == "onlineAuthorizationRet")
+            // 读取图片
+            try
             {
-                object photo = null;
-                msg.Data?.TryGetValue("vl_face_template", out photo);
-                string base64 = HttpUtility.UrlDecode(photo.ToString(), Encoding.UTF8);
-                //base64 = base64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
-                byte[] bytes = Convert.FromBase64String(base64);
+                byte[] bytes = Convert.FromBase64String(UsersModelValues.Photo);
                 MemoryStream memStream = new MemoryStream(bytes);
                 ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                 Dispatcher.Invoke(() =>
                 {
                     FaceImg.Source = (ImageSource)imageSourceConverter.ConvertFrom(memStream);
                 });
-                UsersModelValues.Photo = base64;
+            }
+            catch (Exception e)
+            {
+                //Log.Warn("Image",e);
             }
         }
+        
+        /// <summary>
+        /// 连接事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void WssForFaceService_ClientConnected(object sender, Plugin.Core.Service.WebSocketClientConnected e)
+        {
+            // 更新设备列表
+            //Dispatcher.Invoke(() =>
+            //{
+            //    deviceCell.Add(WssForFaceService.Sockets[e.SocketConnection.ConnectionInfo.Id.ToString()].DeviceName);
+            //});
+        }
 
-        private void IconButton_Click_Device(object sender, RoutedEventArgs e)
+        /// <summary>
+        /// 断开连接事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void WssForFaceService_ClientDisconnected(object sender, Plugin.Core.Service.WebSocketClientDisconnected e)
         {
-            // 抓拍
-            var keys = WssForFace.Sockets.Keys.ToList();
-            keys.ForEach(n =>
+            // 更新设备列表
+            Dispatcher.Invoke(() =>
             {
-                WssForFace.Sockets[n]?.Send(JsonHelper.JsonSerialize(new
-                {
-                    cmd = "to_device",
-                    form = n,
-                    to = "T68318",
-                    data = new { cmd = "onlineAuthorization" }
-                }));
+                DeviceCell.Remove(WssForFaceService.Sockets[e.SocketConnection.ConnectionInfo.Id.ToString()].DeviceName);
             });
         }
 
+        /// <summary>
+        /// 接收消息事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void WssForFace_ClientMessage(object sender, WebSocketClientMessage e)
+        {
+            //var id = e.Guid;
+            var message = e.Message as ReceiveModel;
+            if (message.Cmd == "declare")
+            {
+                if (message.Sn != "")
+                {
+                    Dispatcher.Invoke(() =>
+                    {
+                        DeviceCell.Add(message.Sn);
+                    });
+                }
+            }
+            else if (message.Cmd == "to_client")
+            {
+                object cmd = null;
+                message.Data?.TryGetValue("cmd", out cmd);
+                if (cmd == null) return;
+                if (cmd.ToString() == "onlineAuthorizationRet")
+                {
+                    object photo = null;
+                    message.Data?.TryGetValue("vl_face_template", out photo);
+                    string base64 = HttpUtility.UrlDecode(photo.ToString(), Encoding.UTF8);
+                    //base64 = base64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
+                    byte[] bytes = Convert.FromBase64String(base64);
+                    MemoryStream memStream = new MemoryStream(bytes);
+                    ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
+                    Dispatcher.Invoke(() =>
+                    {
+                        FaceImg.Source = (ImageSource)imageSourceConverter.ConvertFrom(memStream);
+                    });
+                    
+                    UsersModelValues.Photo = base64;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 设备拍照按钮事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void IconButton_Click_Capture(object sender, RoutedEventArgs e)
+        {
+            var deviceName = MyComboBox.SelectedItem?.ToString();
+            if (deviceName == null) return;
+            var device = WssForFaceService.Sockets.Values.Where(t => t.DeviceName == deviceName).LastOrDefault();
+            device.SocketConnection.Send(JsonHelper.JsonSerialize(new
+            {
+                cmd = "to_device",
+                form = device.Guid.ToString(),
+                to = device.DeviceName,
+                data = new { cmd = "onlineAuthorization" }
+            }));
+
+        }
+
+
+        /// <summary>
+        /// 上传照片
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void UploadBt_Click(object sender, OpenFileButton.OpenFileButtonMouseEventArgs e)
+        {
+            //BitmapImage result = new BitmapImage(new Uri(e.OpenFileName));
+            //Dispatcher.Invoke(() =>
+            //{
+            //    FaceImg.Source = result;
+            //});
+        }
+
+        /// <summary>
+        /// 上传照片按钮事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void IconButton_Click_Upload(object sender, RoutedEventArgs e)
         {
 
+            // 创建"打开文件"对话框
+            OpenFileDialog dlg = new OpenFileDialog();
+            //设置文件类型过滤
+            dlg.Filter = "图片|*.jpg;*.png;*.gif;*.bmp;*.jpeg";
+            dlg.Title = "选择图片";
+
+            if (dlg.ShowDialog() == DialogResult.OK)
+            {
+                try
+                {
+                    // 预览
+                    string filename = dlg.FileName;
+
+                    // 复制到内存中
+                    //Image img = Image.FromFile(filename);
+                    //Bitmap bmp = new Bitmap(img);
+                    //img.Dispose();
+                    //MemoryStream memStream = new MemoryStream();
+                    //bmp.Save(memStream, ImageFormat.Png);
+                    //memStream.Position = 0;
+                    //BitmapImage result = new BitmapImage();
+                    //result.BeginInit();
+                    //result.CacheOption = BitmapCacheOption.OnLoad;
+                    //result.StreamSource = memStream;
+                    //result.EndInit();
+                    //result.Freeze();
+
+                    // 直接打开
+                    BitmapImage result = new BitmapImage(new Uri(filename));
+                    Dispatcher.Invoke(() =>
+                    {
+                        FaceImg.Source = result;
+                    });
+                }
+                catch (SecurityException ex)
+                {
+                    System.Windows.MessageBox.Show($"Error: {ex.Message}\n\n");
+                }
+            }
         }
 
-        private void IconButton_Click_Confirm(object sender, RoutedEventArgs e)
+
+        /// <summary>
+        /// 关闭页面
+        /// </summary>
+        protected override void CloseThis()
         {
+            WssForFaceService.ClientMessage -= WssForFace_ClientMessage;
+            WssForFaceService.ClientConnected -= WssForFaceService_ClientConnected;
+            WssForFaceService.ClientDisconnected -= WssForFaceService_ClientDisconnected;
 
+            base.CloseThis();
         }
+
     }
 }

+ 2 - 1
aliyun_eicp3.0/skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Uct/UctManagerControl.xaml

@@ -3,7 +3,8 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:SCADA_DAQ.Customer.Views.Uct" xmlns:wpfcontrol="clr-namespace:SCADA.CommonCtrl.WpfControl;assembly=SCADA.CommonCtrl"
+             xmlns:local="clr-namespace:SCADA_DAQ.Customer.Views.Uct" 
+             xmlns:wpfcontrol="clr-namespace:SCADA.CommonCtrl.WpfControl;assembly=SCADA.CommonCtrl"
              mc:Ignorable="d" 
              x:Name="this"
              d:DesignHeight="450" d:DesignWidth="800">