diff --git a/Aucma.Core.PrintTo/ViewModels/MainWindowViewModel.cs b/Aucma.Core.PrintTo/ViewModels/MainWindowViewModel.cs index 6e82980a..b3c9342e 100644 --- a/Aucma.Core.PrintTo/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.PrintTo/ViewModels/MainWindowViewModel.cs @@ -25,21 +25,29 @@ namespace Aucma.Core.PrintTo.ViewModels public MainWindowViewModel() { - UserContent = firstPage; - - _sysUserInfoServices = App.ServiceProvider.GetService(); - //Task.Run(async () => - //{ - // await RefreshTeamTime();//班组时间 - //}); - InitUserInfo(); - DispatcherTimer timer = new DispatcherTimer(); - timer.Interval = new TimeSpan(0, 0, 1); //间隔1秒 - timer.Tick += new EventHandler(timer_Tick); - timer.Start(); + InitializeAsync(); } + private async void InitializeAsync() + { + await Task.Run(() => + { + UserContent = firstPage; + + _sysUserInfoServices = App.ServiceProvider.GetService(); + //Task.Run(async () => + //{ + // await RefreshTeamTime();//班组时间 + //}); + InitUserInfo(); + DispatcherTimer timer = new DispatcherTimer(); + timer.Interval = new TimeSpan(0, 0, 1); //间隔1秒 + timer.Tick += new EventHandler(timer_Tick); + timer.Start(); + }); + } + #region 更换界面 public System.Windows.Controls.UserControl _content; diff --git a/Aucma.Core.ProductOffLine/App.xaml b/Aucma.Core.ProductOffLine/App.xaml index 5f367774..93af66e0 100644 --- a/Aucma.Core.ProductOffLine/App.xaml +++ b/Aucma.Core.ProductOffLine/App.xaml @@ -22,8 +22,15 @@ - - + + + + + diff --git a/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs b/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs index 397682c8..40f70a57 100644 --- a/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs +++ b/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs @@ -417,7 +417,7 @@ namespace Aucma.Core.ProductOffLine.Business // 产线 info11.ProductLineCode = appConfig.ProductlineCode.ToString(); info11.SaveRetuenInfo = TempOffLineInfo.MsgInfo; - info11.LoginTeam = appConfig.LoginTeam; + info11.LoginTeam = appConfig.TeamName; info11.PlcResult = 1; // 查询本地数据库是否有数据 OffLineInfo offLineInfo = _offLineInfoServices.FirstAsync(x => x.ProductSNCode == TempOffLineInfo.ProductSNCode).Result; diff --git a/Aucma.Core.ProductOffLine/Config/AppConfig.cs b/Aucma.Core.ProductOffLine/Config/AppConfig.cs index 46d4355e..34009523 100644 --- a/Aucma.Core.ProductOffLine/Config/AppConfig.cs +++ b/Aucma.Core.ProductOffLine/Config/AppConfig.cs @@ -44,14 +44,7 @@ namespace Aucma.Core.ProductOffLine.Config set { iniHelper.IniWriteValue("system", "ProductlineCode", value); } } - /// - /// 当前登录班组 - /// - public string LoginTeam - { - get { return iniHelper.IniReadValue("system", "LoginTeam"); } - set { iniHelper.IniWriteValue("system", "LoginTeam", value); } - } + /// /// 扫码枪放行方向,0外侧,1内侧,-1都未选中 diff --git a/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs index 997020a5..3f2f2031 100644 --- a/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs @@ -62,18 +62,27 @@ namespace Aucma.Core.ProductOffLine.ViewModels public IndexPageViewModel() { - OffLineBusiness.RefreshScanMateriaCodeEvent += ModelToPage; - OffLineBusiness.RefreshChartsEvent += RefreshCharts; - MainWindowViewModel.RefreshFirstPageChartsEvent += RefreshCharts; _offLineInfoServices = App.ServiceProvider.GetService(); _baseBomInfoServices = App.ServiceProvider.GetService(); - - RefreshCharts(); + InitializeAsync(); + } - listTime = _baseBomInfoServices.getWorkTime().Result; + private async void InitializeAsync() + { + await Task.Run(() => + { + OffLineBusiness.RefreshScanMateriaCodeEvent += ModelToPage; + OffLineBusiness.RefreshChartsEvent += RefreshCharts; + MainWindowViewModel.RefreshFirstPageChartsEvent += RefreshCharts; + + + RefreshCharts(); + listTime = _baseBomInfoServices.getWorkTime().Result; + }); } + /// /// 刷新页面展示图表 /// diff --git a/Aucma.Core.ProductOffLine/ViewModels/LoginPageViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/LoginPageViewModel.cs index b032a1d5..0cc7b7af 100644 --- a/Aucma.Core.ProductOffLine/ViewModels/LoginPageViewModel.cs +++ b/Aucma.Core.ProductOffLine/ViewModels/LoginPageViewModel.cs @@ -27,6 +27,7 @@ namespace Aucma.Core.PrintTo.ViewModels 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(); @@ -39,7 +40,7 @@ namespace Aucma.Core.PrintTo.ViewModels /// 选择的班组信息 /// 用户名 /// 密码 - public void Login(BaseTeamMembers team, string userName, string passWord,object parameter) + public void Login(BaseTeamMembers team, string barCode,string userName, string passWord,object parameter) { try { @@ -64,13 +65,14 @@ namespace Aucma.Core.PrintTo.ViewModels appConfig.TeamCode = team.TeamCode; appConfig.TeamName = team.TeamName; appConfig.Account = userName; + appConfig.BarCodeAccount = barCode; //跳转 var window = parameter as LoginPageView; if (window == null) return; window.Hide(); - MainWindow indexPage = new MainWindow(); - indexPage.Show(); + MainWindow mainPage = new MainWindow(); + mainPage.Show(); window.Close(); } diff --git a/Aucma.Core.ProductOffLine/ViewModels/LoginViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/LoginViewModel.cs deleted file mode 100644 index bbe0ee96..00000000 --- a/Aucma.Core.ProductOffLine/ViewModels/LoginViewModel.cs +++ /dev/null @@ -1,118 +0,0 @@ -using Admin.Core.IService; -using Admin.Core.Model; -using Admin.Core.Service; -using Aucma.Core.ProductOffLine.Config; -using Aucma.Core.ProductOffLine.Models; -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; - -namespace Aucma.Core.ProductOffLine.ViewModels -{ - public partial class LoginViewModel : ObservableObject - { - private AppConfig appConfig = AppConfig.Instance; - - public RelayCommand CloseWindowCommand { get; set; } - - public RelayCommand SaveCommand { get; set; } - - - public LoginViewModel() - { - _barcodeAccount = appConfig.BarCodeAccount; - // SelectedMaterialType.Content = appConfig.LoginTeam; - CloseWindowCommand = new RelayCommand(t => CloseWindow(t)); - SaveCommand = new RelayCommand(Login); - - } - - - //关闭窗口 - private void CloseWindow(object parameter) - { - var window = parameter as Window; - if (window != null) - { - window.Close(); - } - - } - - private async void Login() - { - - if (SelectedMaterialType == null) - { - MessageBox.Show("未选择班组"); - - return; - - } - if (_barcodeAccount =="") - { - MessageBox.Show("未设置条码系统账号"); - - return; - - } - else - { - MessageBoxResult result = MessageBox.Show("确认登录吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (result == MessageBoxResult.Yes) - { - appConfig.BarCodeAccount = _barcodeAccount; - appConfig.LoginTeam = SelectedMaterialType.Content.ToString(); - MessageBox.Show("登录成功"); - // CloseWindow(); - } - - - } - - - } - - - - /// - /// 班组,二线白班,二线夜班 - /// - /// private string _selectedMaterialType; - private ComboBoxItem _selectedMaterialType; - public ComboBoxItem SelectedMaterialType - { - get { return _selectedMaterialType; } - set - { - if (_selectedMaterialType != value) - { - _selectedMaterialType = value; - OnPropertyChanged(nameof(SelectedMaterialType)); - } - } - } - - #region 条码系统账号 - private string _barcodeAccount; - public string BarcodeAccount - { - get { return _barcodeAccount; } - set - { - _barcodeAccount = value; - OnPropertyChanged(nameof(BarcodeAccount)); - } - } - #endregion - - - } -} diff --git a/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs index 91828649..a3cdac25 100644 --- a/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs @@ -18,6 +18,8 @@ using Aucma.Core.ProductOffLine.Config; using Admin.Core.Socket; using Aucma.Core.Scanner; using System.Collections.Generic; +using Admin.Core.IService; +using Microsoft.Extensions.DependencyInjection; namespace Aucma.Core.ProductOffLine.ViewModels { @@ -44,7 +46,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels // 箱壳扫码器ip private static string ShellScannerIp = allScanners.First(x => x.Name == "外侧扫码器2").Ip; - + ISysUserInfoServices _sysUserInfoServices; private static readonly log4net.ILog log = LogManager.GetLogger(typeof(MainWindowViewModel)); private IndexPageView firstPage = new IndexPageView();//首页 @@ -53,29 +55,43 @@ namespace Aucma.Core.ProductOffLine.ViewModels public MainWindowViewModel() { - UserContent = firstPage; - // 创建一个DispatcherTimer对象 + + InitializeAsync(); 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(); - // MvCodeHelper.RefreshStateEvent += RefreshScanner; - TouchSocketService.RefreshStateEvent += RefreshScanner; - MesDbState(true); - PlcState(false); - //PlcState(true); - Scanner1State(false); - Scanner2State(false); + } + + + + + private async void InitializeAsync() + { + await Task.Run(() => + { + UserContent = firstPage; - // Job_AllState_Quartz.RefreshStateEvent += RefreshStatus; - InitHikRobotAndGun(); + _sysUserInfoServices = App.ServiceProvider.GetService(); + //Task.Run(async () => + //{ + // await RefreshTeamTime();//班组时间 + //}); + InitUserInfo(); + + }); + } - init(); + private void InitUserInfo() + { + TeamName = $"班组:{appConfig.TeamName} 用户:{appConfig.Account} 条码系统: {appConfig.BarCodeAccount}"; } #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); @@ -345,6 +361,55 @@ namespace Aucma.Core.ProductOffLine.ViewModels } #endregion + + #region 定时刷新时间 + void timer_Tick(object sender, EventArgs e) + { + System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => + { + CurrentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + })); + + } + #endregion + + + #region 刷新时间 + + public string _currentDateTime; + public string CurrentDateTime + { + get => _currentDateTime; + set => SetProperty(ref _currentDateTime, value); + } + #endregion + + #region 班组信息 + /// + /// 班组信息 + /// + public string _teamName; + public string TeamName + { + get => _teamName; + set => SetProperty(ref _teamName, value); + } + #endregion + + #region 登陆人信息 + /// + /// 班组信息 + /// + public string account; + public string Account + { + get => account; + set => SetProperty(ref account, value); + } + #endregion + + #region MES数据库状态 /// /// MES数据库-文字 @@ -374,6 +439,9 @@ namespace Aucma.Core.ProductOffLine.ViewModels set => SetProperty(ref _mesUIIcon, value); } + + + /// /// MES数据库连接状态 /// @@ -569,13 +637,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels } - public string _currentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - public string CurrentDateTime - { - get => _currentDateTime; - set => SetProperty(ref _currentDateTime, value); - } - + public string _shiftStr = string.Empty; public string ShiftStr { @@ -583,30 +645,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels set => SetProperty(ref _shiftStr, value); } - private void Timer_Tick(object sender, EventArgs e) - { - DateTime now = DateTime.Now; - if (appConfig.LoginTeam == "") - { - ShiftStr = $"未登录"; - } - else - { - ShiftStr = appConfig.LoginTeam; - } - - // 判断当前是否是白班时间段 - //if (now.Hour >= 8 && now.Hour < 20) - //{ - // ShiftStr = $"白班 08点-20点"; - //} - //else - //{ - - // ShiftStr = $"夜班 20点-08点"; - //} - CurrentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - } + diff --git a/Aucma.Core.ProductOffLine/Views/Login.xaml b/Aucma.Core.ProductOffLine/Views/Login.xaml deleted file mode 100644 index 7878d409..00000000 --- a/Aucma.Core.ProductOffLine/Views/Login.xaml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -