diff --git a/Aucma.Core.CodeBinding/App.xaml b/Aucma.Core.CodeBinding/App.xaml index 232a0f2d..56655e32 100644 --- a/Aucma.Core.CodeBinding/App.xaml +++ b/Aucma.Core.CodeBinding/App.xaml @@ -17,13 +17,20 @@ - - - + + + - - + + + + + diff --git a/Aucma.Core.CodeBinding/App.xaml.cs b/Aucma.Core.CodeBinding/App.xaml.cs index 7dde0091..019b92e4 100644 --- a/Aucma.Core.CodeBinding/App.xaml.cs +++ b/Aucma.Core.CodeBinding/App.xaml.cs @@ -25,8 +25,26 @@ namespace Aucma.Core.CodeBinding var host = CreateHostBuilder(e.Args).Build();//生成宿主。 ServiceProvider = host.Services; - host.Services.GetRequiredService()?.Show(); - await host.StartAsync(); + + try + { + var loginWindow = host.Services.GetRequiredService(); + if (loginWindow != null && !loginWindow.IsActive) + { + loginWindow.Show(); + await host.StartAsync(); + } + else + { + // 处理窗口已关闭的情况 + // 可以选择重新创建主窗口或者退出应用程序 + Application.Current.Shutdown(); + } + } + catch (Exception ex) + { + Application.Current.Shutdown(); + } } /// diff --git a/Aucma.Core.CodeBinding/Assets/Images/login-background.png b/Aucma.Core.CodeBinding/Assets/Images/login-background.png new file mode 100644 index 00000000..40909f97 Binary files /dev/null and b/Aucma.Core.CodeBinding/Assets/Images/login-background.png differ diff --git a/Aucma.Core.CodeBinding/Aucma.Core.CodeBinding.csproj b/Aucma.Core.CodeBinding/Aucma.Core.CodeBinding.csproj index 2b3d3121..b549e7fd 100644 --- a/Aucma.Core.CodeBinding/Aucma.Core.CodeBinding.csproj +++ b/Aucma.Core.CodeBinding/Aucma.Core.CodeBinding.csproj @@ -28,6 +28,7 @@ + @@ -50,6 +51,9 @@ + + + diff --git a/Aucma.Core.CodeBinding/Common/OSKHelper.cs b/Aucma.Core.CodeBinding/Common/OSKHelper.cs new file mode 100644 index 00000000..cfbea0e3 --- /dev/null +++ b/Aucma.Core.CodeBinding/Common/OSKHelper.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Aucma.Core.CodeBinding.Common +{ + public class OSKHelper + { + #region 打开软盘 + /// + /// 打开软盘 + /// + public static void OpenOsk() + { + try + { + Process proc = new Process(); + proc.StartInfo.FileName = @"C:\Windows\System32\osk.exe"; + proc.StartInfo.UseShellExecute = true; + proc.StartInfo.Verb = "runas"; + proc.Start(); + } + catch + { + } + } + #endregion + + + #region 关闭软盘 + /// + /// 关闭软盘 + /// + public static void CloseOsk() + { + try + { + // 查找并关闭 osk.exe 进程 + foreach (Process proc in Process.GetProcessesByName("osk")) + { + proc.Kill(); + } + } + catch + { + // 可以在这里处理异常情况 + } + } + #endregion + } +} diff --git a/Aucma.Core.CodeBinding/Config/AppConfig.cs b/Aucma.Core.CodeBinding/Config/AppConfig.cs new file mode 100644 index 00000000..50467b5a --- /dev/null +++ b/Aucma.Core.CodeBinding/Config/AppConfig.cs @@ -0,0 +1,79 @@ +using Admin.Core.Common.Config; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Aucma.Core.CodeBinding.Config +{ + public sealed class AppConfig + { + private static IniHelper iniHelper = new IniHelper(System.Environment.CurrentDirectory + "/config/App.InI"); + + + private static readonly Lazy lazy = new Lazy(() => new AppConfig()); + public static AppConfig Instance + { + get + { + return lazy.Value; + } + } + + + public AppConfig() + { + + } + + + /// + /// 产线编号 + /// + public string ProductlineCode + { + get { return iniHelper.IniReadValue("system", "ProductlineCode"); } + set { iniHelper.IniWriteValue("system", "ProductlineCode", value); } + } + + + /// + /// 工位编号 + /// + public string StationCode + { + get { return iniHelper.IniReadValue("system", "StationCode"); } + set { iniHelper.IniWriteValue("system", "StationCode", value); } + } + /// + /// 班组代码 + /// + public string TeamCode + { + get { return iniHelper.IniReadValue("system", "TeamCode"); } + set { iniHelper.IniWriteValue("system", "TeamCode", value); } + } + + /// + /// 班组名称 + /// + public string TeamName + { + get { return iniHelper.IniReadValue("system", "TeamName"); } + set { iniHelper.IniWriteValue("system", "TeamName", value); } + } + + /// + /// 用户名 + /// + public string Account + { + get { return iniHelper.IniReadValue("system", "Account"); } + set { iniHelper.IniWriteValue("system", "Account", value); } + } + + + + } +} diff --git a/Aucma.Core.CodeBinding/Models/Result.cs b/Aucma.Core.CodeBinding/Models/Result.cs new file mode 100644 index 00000000..d61743fd --- /dev/null +++ b/Aucma.Core.CodeBinding/Models/Result.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Aucma.Core.CodeBinding.Models +{ + /** + * 登录返回结果 + * */ + public class Result + { + /// + /// 返回结果 + /// + public string msg { get; set; } + /// + /// 返回状态 + /// + public int code { get; set; } + /// + /// 返回令牌 + /// + public string token { get; set; } + } +} diff --git a/Aucma.Core.CodeBinding/ViewModels/LoginPageViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/LoginPageViewModel.cs new file mode 100644 index 00000000..acc68993 --- /dev/null +++ b/Aucma.Core.CodeBinding/ViewModels/LoginPageViewModel.cs @@ -0,0 +1,135 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using log4net; +using System.Windows; +using Admin.Core.Common; +using Admin.Core.IService; +using Admin.Core.Service; +using Microsoft.Extensions.DependencyInjection; +using System.Collections.ObjectModel; +using Admin.Core.Model.Model_New; +using StackExchange.Profiling.Internal; +using System; +using System.Text.Json; +using System.Windows.Input; +using MaterialDesignThemes.Wpf; +using NPOI.Util.Collections; +using Aucma.Core.CodeBinding.Config; +using Aucma.Core.CodeBinding.Models; +using Aucma.Core.CodeBinding.Views; + +namespace Aucma.Core.CodeBinding.ViewModels +{ + public partial class LoginPageViewModel : ObservableObject + { + private static readonly log4net.ILog log = LogManager.GetLogger(typeof(LoginPageViewModel)); + protected readonly IBaseTeamMembersServices _baseTeamMembersServices; + private AppConfig appConfig = AppConfig.Instance; + public LoginPageViewModel() { + _baseTeamMembersServices = App.ServiceProvider.GetService(); + AddTeamData(); + } + + #region 登录 + /// + /// 登录 + /// + /// 选择的班组信息 + /// 用户名 + /// 密码 + public void Login(BaseTeamMembers team, string userName, string passWord,object parameter) + { + try + { + //获取Token + string url = $"http://10.100.72.10:8080/login"; + var content = new + { + username = userName, + password = passWord + }; + + var loginResult = HttpHelper.Post(url, content.ToJson());//发送用户名密码给API + Result result = JsonSerializer.Deserialize(loginResult); + if (result == null) + { + MessageBox.Show("登录失败!", "系统提醒"); + return; + } + if (result.code == 200) + { + // 存储账号信息 + appConfig.TeamCode = team.TeamCode; + appConfig.TeamName = team.TeamName; + appConfig.Account = userName; + //跳转 + var window = parameter as LoginPageView; + + if (window == null) return; + window.Hide(); + MainWindow indexPage = new MainWindow(); + indexPage.Show(); + + window.Close(); + } + else + { + MessageBox.Show($"登录失败!{result.msg}", "系统提醒"); + return; + } + } + catch (Exception ex) + { + log.Error($"登录异常:{ex.Message}"); + } + } + #endregion + + #region 关闭当前界面 + /// + /// 关闭当前界面 + /// + /// + + public void CloseWindow(object parameter) + { + var window = parameter as Window; + if (window == null) return; + + window.Close(); + } + + #endregion + + #region 班组数据 + /// + /// 班组数据 + /// + private ObservableCollection _teamMembersList = new ObservableCollection(); + public ObservableCollection TeamMembersList + { + get + { + return this._teamMembersList; + } + set + { + SetProperty(ref _teamMembersList, value); + } + } + #endregion + + #region 班组添加到集合中 + public void AddTeamData() + { + var baseTeamMembersList = _baseTeamMembersServices.QueryAsync(d => d.ProductLineCode==appConfig.ProductlineCode).Result; + if (baseTeamMembersList == null) return; + foreach (var item in baseTeamMembersList) + { + TeamMembersList.Add(item); + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs index 50452852..a5e06f8f 100644 --- a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs @@ -25,6 +25,7 @@ using MvCodeHelper = Aucma.Core.CodeBinding.Business.MvCodeHelper; using Aucma.Core.HwPLc; using Admin.Core.Socket; using System.Collections.Generic; +using Aucma.Core.CodeBinding.Config; namespace Aucma.Core.CodeBinding.ViewModels { @@ -40,7 +41,7 @@ namespace Aucma.Core.CodeBinding.ViewModels // sn扫码器ip private static string SnScannerIp = allScanners.First(x => x.Name == "sn扫码器").Ip; - + private AppConfig appConfig = AppConfig.Instance; /// /// 查询信息更新 @@ -54,10 +55,9 @@ namespace Aucma.Core.CodeBinding.ViewModels UserContent = firstPage; - // 创建一个DispatcherTimer对象 DispatcherTimer timer = new DispatcherTimer(); - timer.Interval = TimeSpan.FromSeconds(1); - timer.Tick += Timer_Tick; + timer.Interval = new TimeSpan(0, 0, 1); //间隔1秒 + timer.Tick += new EventHandler(timer_Tick); timer.Start(); Scanner1State(false); Scanner2State(false); @@ -74,6 +74,7 @@ namespace Aucma.Core.CodeBinding.ViewModels #region 初始化班组刷新定时任务 public void init() { + TeamName = $"班组:{appConfig.TeamName} 用户:{appConfig.Account}"; // 设备状态刷新定时器 System.Timers.Timer timer = new System.Timers.Timer(1000 * 5); timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshStatus); @@ -83,6 +84,17 @@ namespace Aucma.Core.CodeBinding.ViewModels } #endregion + #region 班组信息 + /// + /// 班组信息 + /// + public string _teamName; + public string TeamName + { + get => _teamName; + set => SetProperty(ref _teamName, value); + } + #endregion #region 开启海康扫码器 //public void InitHikRobot() @@ -92,10 +104,10 @@ namespace Aucma.Core.CodeBinding.ViewModels // Task.Run(() => // { // Thread.Sleep(2000); - - + + // Business.MvCodeHelper.Shell(); - + // }); // Task.Run(() => @@ -120,7 +132,7 @@ namespace Aucma.Core.CodeBinding.ViewModels - + // Business.MvCodeHelper.Liner(); // }); @@ -201,15 +213,7 @@ namespace Aucma.Core.CodeBinding.ViewModels string controlType = obj as string; switch (controlType) { - // 关闭当前窗口 - case "Exit": - if (System.Windows.MessageBox.Show("确定要退出系统吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) - { - Application.Current.Shutdown(); - Environment.Exit(0); - } - - break; + // 打开软盘 case "TabTip": @@ -229,10 +233,7 @@ namespace Aucma.Core.CodeBinding.ViewModels } break; - // 最小化当前窗口 - case "Minimized": - Application.Current.MainWindow.WindowState = WindowState.Minimized; - break; + default: break; } @@ -243,6 +244,52 @@ namespace Aucma.Core.CodeBinding.ViewModels } } + + #region 最小化界面 + /// + /// 关闭当前界面 + /// + /// + [RelayCommand] + public void MinWindow(object parameter) + { + var window = parameter as Window; + if (window == null) return; + window.WindowState = WindowState.Minimized; + + } + + #endregion + + + #region 关闭当前界面 + /// + /// 关闭当前界面 + /// + /// + [RelayCommand] + public void CloseWindow(object parameter) + { + var window = parameter as Window; + if (window == null) return; + + if (MessageBox.Show("确定要退出系统吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) + { + appConfig.TeamCode = ""; + appConfig.TeamName = ""; + appConfig.Account = ""; + + window.Hide(); + //跳转到登录页 + LoginPageView login = new LoginPageView(); + login.Show(); + window.Close(); + } + } + + #endregion + + #endregion #region 打开软盘 @@ -519,23 +566,17 @@ namespace Aucma.Core.CodeBinding.ViewModels set => SetProperty(ref _shiftStr, value); } - private void Timer_Tick(object sender, EventArgs e) + #region 定时刷新时间 + void timer_Tick(object sender, EventArgs e) { - DateTime now = DateTime.Now; - - // 判断当前是否是白班时间段 - if (now.Hour >= 8 && now.Hour < 20) - { - ShiftStr = $"白班 08点-20点"; - } - else + System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { + CurrentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - ShiftStr = $"夜班 20点-08点"; - } - CurrentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - } + })); + } + #endregion } } diff --git a/Aucma.Core.CodeBinding/Views/IndexPageView.xaml b/Aucma.Core.CodeBinding/Views/IndexPageView.xaml index 43e1cea6..c2309628 100644 --- a/Aucma.Core.CodeBinding/Views/IndexPageView.xaml +++ b/Aucma.Core.CodeBinding/Views/IndexPageView.xaml @@ -146,7 +146,7 @@ -