diff --git a/DM_Weight/App.config b/DM_Weight/App.config index 7cba26c..eab09b1 100644 --- a/DM_Weight/App.config +++ b/DM_Weight/App.config @@ -20,13 +20,13 @@ - + - + diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 74894b6..94b1199 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -38,17 +38,17 @@ namespace DM_Weight public partial class App : PrismApplication { #region 当前登录用户的发药人信息 - private static UserList _currentFaUserList=new UserList(); + private static UserList _currentFaUserList = new UserList(); public static UserList CurrentFaUserList { get => _currentFaUserList; - set=> _currentFaUserList = value; + set => _currentFaUserList = value; } #endregion 当前登录用户的发药人信息 #region 当前登录用户的审核人信息 - private static UserList _currentShenUserList= new UserList(); + private static UserList _currentShenUserList = new UserList(); public static UserList CurrentShenUserList { get => _currentShenUserList; @@ -90,6 +90,10 @@ namespace DM_Weight foreach (Exception item in e.Exception.InnerExceptions) { logger.Error($"异常类型:{item.StackTrace};{item.GetType()}{Environment.NewLine}来自:{item.Source}{Environment.NewLine}异常内容:{item.Message}"); + if (item.GetType() == typeof(SqlSugar.SqlSugarException)) + { + UserList userList = new UserService().CheckUserByFingerPrinter(1); + } } //将异常标识为已经观察到 @@ -260,7 +264,7 @@ namespace DM_Weight //containerRegistry.RegisterSingleton(() => SqlSugarHelperNew.GetInstance()); //账册页面 - containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); //账册服务类 containerRegistry.Register(); } diff --git a/DM_Weight/Components/pagination/Pagination.xaml.cs b/DM_Weight/Components/pagination/Pagination.xaml.cs index 3b404f6..4024568 100644 --- a/DM_Weight/Components/pagination/Pagination.xaml.cs +++ b/DM_Weight/Components/pagination/Pagination.xaml.cs @@ -1,4 +1,4 @@ -using NetTaste; +//using NetTaste; using Prism.Commands; using System; using System.Collections.Generic; diff --git a/DM_Weight/DM_Weight.csproj b/DM_Weight/DM_Weight.csproj index 0a29539..58922b8 100644 --- a/DM_Weight/DM_Weight.csproj +++ b/DM_Weight/DM_Weight.csproj @@ -71,10 +71,11 @@ + - + diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs index 295f7a5..0503e3d 100644 --- a/DM_Weight/Port/PortUtil.cs +++ b/DM_Weight/Port/PortUtil.cs @@ -1,6 +1,6 @@ using log4net; using log4net.Repository.Hierarchy; -using NetTaste; +//using NetTaste; using Prism.Events; using Prism.Ioc; using SqlSugar; @@ -24,6 +24,7 @@ using DM_Weight.msg; using DM_Weight.Views; using System.Reflection; using System.Threading; +using System.Speech.Recognition; namespace DM_Weight.Port { @@ -653,8 +654,51 @@ namespace DM_Weight.Port } - } + ////创建一组语音识别的语法约束选择 + //Choices choices = new Choices(); + ////添加语音识别关键字 + //choices.Add(new string[] { "取药", "加药", "盘点", "开始" }); + ////以编程的方式为语音生成约束 + //GrammarBuilder gb = new GrammarBuilder(choices); + ////grammarbuilder封装对象 + //Grammar grm = new Grammar(gb); + ////SpeechRecognitionEngine异步方式 + //recognitionEngine.LoadGrammarAsync(grm); + ////音频输入 + //recognitionEngine.SetInputToDefaultAudioDevice(); + ////创建语音接收事件 + //recognitionEngine.SpeechRecognized += recognitionEngine_SpeechRecognized; + // //开始语音识别 + //recognitionEngine.RecognizeAsync(RecognizeMode.Multiple); + + //停止语音识别 + //recognitionEngine.RecognizeAsyncStop(); + + } + // //创建接收事件函数 + //private void recognitionEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) + //{ + // switch (e.Result.Text) + // { + // case "雪糕": + // MessageBox.Show("很好吃"); + // break; + // case "大米": + // MessageBox.Show("好好吃"); + // break; + // case "饭团": + // MessageBox.Show("好吃"); + // break; + // case "开始": + // MessageBox.Show("你好"); + // break; + // default: + + // break; + + // } + //} private byte[] GetBufferByPort(SerialPort serialPort, int length, int timeout) { @@ -748,6 +792,9 @@ namespace DM_Weight.Port speechSynthesizer.SpeakAsync(textinfo); } + //创建语音识别引擎 + //SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine(); + #region 抽屉串口操作 diff --git a/DM_Weight/Services/UserService.cs b/DM_Weight/Services/UserService.cs index c4bd4fa..1609283 100644 --- a/DM_Weight/Services/UserService.cs +++ b/DM_Weight/Services/UserService.cs @@ -1,7 +1,9 @@ using DM_Weight.Models; using log4net; using log4net.Repository.Hierarchy; -using MySqlConnector; +using MySql.Data.MySqlClient; +//using MySql.Data.MySqlClient; +//using MySqlConnector; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -18,65 +20,61 @@ namespace DM_Weight.Services private readonly ILog logger = LogManager.GetLogger(typeof(UserService)); //public static string connStr = ConfigurationManager.AppSettings["database"].ToString(); public static string connStr = ConfigurationManager.ConnectionStrings["database"].ToString(); - public UserList CheckUserByFingerPrinter(int fingerPrinterId) + public UserList CheckUserByFingerPrinter(int fingerPrinterId) { UserList? user = null; using (MySqlConnection con = new MySqlConnection(connStr)) { logger.Info($"connStr:{connStr}"); - //try - //{ - // con.Open(); - //} - //catch (Exception ex) - //{ - // logger.Info($"Open失败:{ex.ToString()}"); - // if (con.State == System.Data.ConnectionState.Open) - // { - // con.Close(); - // } - // Thread.Sleep(200); - // logger.Info("再次Open"); - // con.Open(); - //} - connOpen(con); - Thread.Sleep(100); - while(con.State != System.Data.ConnectionState.Open) + try { - logger.Info($"再次Open:{con.State}"); - connOpen(con); - Thread.Sleep(100); + con.Open(); } - - logger.Info("数据库连接已打开"); - string sql = @"select ul.id as id,ul.User_name as userName,r.id,r.role_name,r.permissions,r.machine_id from user_list ul - INNER JOIN role r on ul.machine_role_id=r.id where ul.Id=@ID and ul.machine_id=@machine_id and r.machine_id=@machine_id;"; - MySqlCommand cmd = new MySqlCommand(sql, con); - cmd.Parameters.Clear(); - MySqlParameter[] mySqlParameter = new MySqlParameter[] { new MySqlParameter("ID", fingerPrinterId), new MySqlParameter("machine_id", (ConfigurationManager.AppSettings["machineId"] ?? "DM1")) }; - cmd.Parameters.AddRange(mySqlParameter); - //执行语句 - MySqlDataReader reader = cmd.ExecuteReader(); - logger.Info("MySqlDataReader读数据"); - while (reader.Read()) + catch (Exception ex) { - user = new UserList(); - user.Id = reader.GetInt32("id"); - user.UserName = reader["userName"] is DBNull ? "" : reader.GetString("userName"); - //user.UserName = reader["id"] is DBNull ? "" : reader.GetString("id"); - user.Nickname = reader["userName"] is DBNull ? "" : reader.GetString("userName"); - user.MachineId = reader["machine_id"] is DBNull ? "" : reader.GetString("machine_id"); - RoleDm role = new RoleDm(); - role.Id = reader.GetInt32("id"); - //role.Permissions = reader["permissions"] is DBNull ? "" : reader.GetString("permissions"); - role.RoleName = reader["role_name"] is DBNull ? "" : reader.GetString("role_name"); - role.Permissions = JsonConvert.DeserializeObject>(reader["permissions"] is DBNull ? "" : reader.GetString("permissions")); // JsonConvert.SerializeObject(reader.GetString("permissions")).ToList(); - user.Role = role; + con.Close(); + logger.Info($"Open失败:{ex.ToString()};连接状态:{con.State}"); + logger.Info("再次Open"); + con.Open(); } + //connOpen(con); + //Thread.Sleep(10); + //while (con.State != System.Data.ConnectionState.Open) + //{ + // logger.Info($"再次Open:{con.State}"); + // connOpen(con); + // Thread.Sleep(10); + //} - reader.Close(); - logger.Info($"sql:{sql}"); + logger.Info($"数据库连接状态{con.State}"); + //string sql = @"select ul.id as id,ul.User_name as userName,r.id,r.role_name,r.permissions,r.machine_id from user_list ul + // INNER JOIN role r on ul.machine_role_id=r.id where ul.Id=@ID and ul.machine_id=@machine_id and r.machine_id=@machine_id;"; + //MySqlCommand cmd = new MySqlCommand(sql, con); + //cmd.Parameters.Clear(); + //MySqlParameter[] mySqlParameter = new MySqlParameter[] { new MySqlParameter("ID", fingerPrinterId), new MySqlParameter("machine_id", (ConfigurationManager.AppSettings["machineId"] ?? "DM1")) }; + //cmd.Parameters.AddRange(mySqlParameter); + ////执行语句 + //MySqlDataReader reader = cmd.ExecuteReader(); + //logger.Info("MySqlDataReader读数据"); + //while (reader.Read()) + //{ + // user = new UserList(); + // user.Id = reader.GetInt32("id"); + // user.UserName = reader["userName"] is DBNull ? "" : reader.GetString("userName"); + // //user.UserName = reader["id"] is DBNull ? "" : reader.GetString("id"); + // user.Nickname = reader["userName"] is DBNull ? "" : reader.GetString("userName"); + // user.MachineId = reader["machine_id"] is DBNull ? "" : reader.GetString("machine_id"); + // RoleDm role = new RoleDm(); + // role.Id = reader.GetInt32("id"); + // //role.Permissions = reader["permissions"] is DBNull ? "" : reader.GetString("permissions"); + // role.RoleName = reader["role_name"] is DBNull ? "" : reader.GetString("role_name"); + // role.Permissions = JsonConvert.DeserializeObject>(reader["permissions"] is DBNull ? "" : reader.GetString("permissions")); // JsonConvert.SerializeObject(reader.GetString("permissions")).ToList(); + // user.Role = role; + //} + + //reader.Close(); + //logger.Info($"sql:{sql}"); return user; } @@ -85,7 +83,7 @@ namespace DM_Weight.Services { return Task.Run(() => { - if (con.State == System.Data.ConnectionState.Open) + if (con.State != System.Data.ConnectionState.Closed) { con.Close(); } @@ -100,6 +98,5 @@ namespace DM_Weight.Services }); } - } } diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs index 7786bed..26e7cee 100644 --- a/DM_Weight/ViewModels/HomeWindowViewModel.cs +++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs @@ -35,6 +35,8 @@ namespace DM_Weight.ViewModels private UserList? _userList; private UserList? _userList2; + + private int loginMode = Convert.ToInt32(ConfigurationManager.AppSettings["loginMode"]?.ToString() ?? "1"); public bool MultiLogin { @@ -389,14 +391,22 @@ namespace DM_Weight.ViewModels // 30秒内无人操作鼠标键盘 if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit) { - logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录"); - Operator = null; - Reviewer = null; - Application.Current.Dispatcher.Invoke(() => + if (Operator is null) { - _regionManager.RequestNavigate("MainRegion", "LoginWindow"); timer.Stop(); - }); + } + else + { + logger.Info($"设备{autoExit}秒内无人操作,用户【{Operator?.Nickname}】自动退出登录"); + Operator = null; + Reviewer = null; + timer.Stop(); + Application.Current.Dispatcher.Invoke(() => + { + _regionManager.RequestNavigate("MainRegion", "LoginWindow"); + timer.Stop(); + }); + } } } }; diff --git a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs index b3b19f7..d3ed51b 100644 --- a/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/InvoiceTakeDialogViewModel.cs @@ -1,6 +1,6 @@ using log4net; using Microsoft.Xaml.Behaviors; -using NetTaste; +//using NetTaste; using Prism.Commands; using Prism.Events; using Prism.Mvvm; diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs index 048a019..ebaecc4 100644 --- a/DM_Weight/ViewModels/LoginWindowViewModel.cs +++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs @@ -379,6 +379,10 @@ _exitCommand ??= new DelegateCommand(Exit); catch (Exception e) { logger.Info($"LoginEvent存在异常:{e.Message}"); + if(e.GetType().Name== "SqlSugarException") + { + UserList userList = new UserService().CheckUserByFingerPrinter(1); + } } } diff --git a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs index 54df2e3..f04da9e 100644 --- a/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderReturnDialogViewModel.cs @@ -1,7 +1,7 @@ using log4net; using log4net.Repository.Hierarchy; using Microsoft.Xaml.Behaviors; -using NetTaste; +//using NetTaste; using Prism.Commands; using Prism.Events; using Prism.Mvvm; diff --git a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs index 330e155..2518fa0 100644 --- a/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs +++ b/DM_Weight/ViewModels/OrderTakeDialogViewModel.cs @@ -1,6 +1,6 @@ using log4net; using Microsoft.Xaml.Behaviors; -using NetTaste; +//using NetTaste; using Prism.Commands; using Prism.Events; using Prism.Mvvm;