using System; using System.Collections.Generic; using System.Windows; using System.Windows.Threading; using CommonServiceLocator; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Views; using SubCabinetSolution.Model; using SubCabinetSolution.Views; namespace SubCabinetSolution.ViewModel { public class CabinetViewModel : ViewModelBase { public string CurrentTime { get { return _currentTime; } set { _currentTime = value; RaisePropertyChanged(() => CurrentTime); } } private string _currentTime; public RelayCommand<CabinetWindow> LoginOutCommand { get; set; } public List<FunctionModel> FunctionModelList { get; set; } public List<FunctionModel> SettingsModelList { get; set; } public RelayCommand<object> FuncSelectedCommand { get; set; } public string MainTopTitle { get { return _mainTopTitle; } set { _mainTopTitle = value; RaisePropertyChanged(() => MainTopTitle); } } private string _mainTopTitle; public string MainTopImage { get { return _mainTopImage; } set { _mainTopImage = value; RaisePropertyChanged(() => MainTopImage); } } private string _mainTopImage; public string UserInputKeywords { get { return _inputKeywords; } set { _inputKeywords = value; RaisePropertyChanged(() => UserInputKeywords); } } private string _inputKeywords; public RelayCommand SearchDataCommand { get; set; } public CabinetViewModel() { DispatcherTimer showTimer = new DispatcherTimer(); showTimer.Tick += ShowCurTimer; //起个Timer一直获取当前时间 showTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); showTimer.Start(); this.LoginOutCommand = new RelayCommand<CabinetWindow>(LoginOut); // 初始化左侧功能列表 this.FunctionModelList = new List<FunctionModel> { new FunctionModel("/Images/手术单领用.png", "手术单领用"), new FunctionModel("/Images/归还.png", "归还"), new FunctionModel("/Images/紧急领用.png", "紧急领用"), new FunctionModel("/Images/上架.png", "上架"), new FunctionModel("/Images/盘点.png", "盘点"), new FunctionModel("/Images/退SPD库.png", "退SPD库"), new FunctionModel("/Images/文档查询.png", "查询"), new FunctionModel("/Images/主页.png", "主页") }; // 初始化左侧底部功能列表 this.SettingsModelList = new List<FunctionModel> { new FunctionModel("/Images/settings.png", "设置"), new FunctionModel("/Images/灯泡.png", "灯光"), new FunctionModel("/Images/近消耗品.png", "近消耗品") }; this.FuncSelectedCommand = new RelayCommand<object>(ItemSelectionChanged); this.SearchDataCommand = new RelayCommand(SearchData); // 设置默认值 this.MainTopImage = FunctionModelList[7].Image; this.MainTopTitle = FunctionModelList[7].Title; // TODO 显示默认功能项数据 } private void ShowCurTimer(object sender, EventArgs e) { this.CurrentTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); } private void LoginOut(CabinetWindow window) { MessageBoxResult result = MessageBox.Show("确定退出吗?", "温馨提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (result != MessageBoxResult.OK) return; //退出 MainWindow mainWindow = new MainWindow(); mainWindow.Show(); window.Close(); } private void ItemSelectionChanged(object sender) { if (!(sender is FunctionModel functionModel)) { return; } this.MainTopImage = functionModel.Image; this.MainTopTitle = functionModel.Title; switch (functionModel.Title) { case "手术单领用": break; case "归还": break; case "紧急领用": break; case "上架": break; case "盘点": break; case "退SPD库": break; case "查询": INavigationService navigationService = ServiceLocator.Current.GetInstance<INavigationService>(); navigationService.NavigateTo("InquirePage"); break; case "主页": break; } } private void SearchData() { if (!string.IsNullOrWhiteSpace(_inputKeywords)) return; MessageBox.Show("请输入关键字", "错误", MessageBoxButton.OK, MessageBoxImage.Error); return; // TODO 搜索数据库 } } }