using System; using System.Collections.Generic; using System.Linq; using System.Text; using AGV_WPF.Commands; using System.Windows; using System.Collections.ObjectModel; using AGV_WPF_DisMember; using AGV_WPF.ExtraUI; using AGV_WPF_Global; using System.Windows.Media; using System.Windows.Media.Imaging; using System.IO; using System.Windows.Controls; using AGV_WPF.Forms; namespace AGV_WPF.Models { class MainWindowModel : NotificationObject { public MainWindowModel() { ShowSelCommand = new DelegateCommand(); ShowSelCommand.ExecuteAction = new Action(this.ShowSel); ShowNoSelCommand = new DelegateCommand(); ShowNoSelCommand.ExecuteAction = new Action(this.ShowNoSel); HideSelCommand = new DelegateCommand(); HideSelCommand.ExecuteAction = new Action(this.HideSel); HideNoSelCommand = new DelegateCommand(); HideNoSelCommand.ExecuteAction = new Action(this.HideNoSel); ShowAllCommand = new DelegateCommand(); ShowAllCommand.ExecuteAction = new Action(this.ShowAll); HideAllCommand = new DelegateCommand(); HideAllCommand.ExecuteAction = new Action(this.HideAll); SetAgvAliasCommand = new DelegateCommand(); SetAgvAliasCommand.ExecuteAction = new Action(this.SetAgvAlias); ReadCheckSetCommand = new DelegateCommand(); ReadCheckSetCommand.ExecuteAction = new Action(this.ReadCheckSet); RemoteRouteSetCommand = new DelegateCommand(); RemoteRouteSetCommand.ExecuteAction = new Action(this.RemoteRouteSet); ReadCheckRecordCommand = new DelegateCommand(); ReadCheckRecordCommand.ExecuteAction = new Action(this.ReadCheckRecord); ChangeDisplayCommand = new DelegateCommand(); ChangeDisplayCommand.ExecuteAction = new Action(this.ChangeDisplay); HideCurrentColumnCommand = new DelegateCommand(); HideCurrentColumnCommand.ExecuteAction = new Action(this.HideCurrentColumn); ShowAllColumnsCommand = new DelegateCommand(); ShowAllColumnsCommand.ExecuteAction = new Action(this.ShowAllColumns); ExtendModuleDisplayCommand = new DelegateCommand(); ExtendModuleDisplayCommand.ExecuteAction = new Action(this.ExtendModuleDisplay); ClientListDisplayCommand = new DelegateCommand(); ClientListDisplayCommand.ExecuteAction = new Action(this.ClientListDisplay); UseRateDisplayCommand = new DelegateCommand(); UseRateDisplayCommand.ExecuteAction = new Action(this.UseRateDisplay); OpenManagerWindowCommand = new DelegateCommand(); OpenManagerWindowCommand.ExecuteAction = new Action(this.OpenManagerWindow); } public bool IsManager { get { return GlobalPara.IsManager; } } //private bool isShowName; public ImageSource HeaderImage { get { if (File.Exists(@"Image\header.png")) { return MainWindow.GetImageFromFile(@"Image\header.png"); } else { return new BitmapImage(new Uri(@"Image\Header1.jpg", UriKind.RelativeOrAbsolute)); } } } public DelegateCommand ShowSelCommand { get; set; } public DelegateCommand ShowNoSelCommand { get; set; } public DelegateCommand HideSelCommand { get; set; } public DelegateCommand HideNoSelCommand { get; set; } public DelegateCommand ShowAllCommand { get; set; } public DelegateCommand HideAllCommand { get; set; } public DelegateCommand ReadCheckSetCommand { get; set; } public DelegateCommand SetAgvAliasCommand { get; set; } public DelegateCommand RemoteRouteSetCommand { get; set; } public DelegateCommand ReadCheckRecordCommand { get; set; } public DelegateCommand ChangeDisplayCommand { get; set; } public DelegateCommand HideCurrentColumnCommand { get; set; } public DelegateCommand ShowAllColumnsCommand { get; set; } public DelegateCommand ExtendModuleDisplayCommand { get; set; } public DelegateCommand ClientListDisplayCommand { get; set; } public DelegateCommand UseRateDisplayCommand { get; set; } public DelegateCommand OpenManagerWindowCommand { get; set; } public void UseRateDisplay(object parameter) { Form1 form = new Form1(); form.Show(); } public void ClientListDisplay(object parameter) { ClientListWindow window = new ClientListWindow(); window.Show(); } public void ExtendModuleDisplay(object parameter) { ExtendModuleWindow window = new ExtendModuleWindow(); window.Show(); } public void ReadCheckRecord(object parameter) { ReadCheckRecordWindow window = new ReadCheckRecordWindow(); window.Show(); } public void RemoteRouteSet(object parameter) { RemoteRouteSetWindow window = new RemoteRouteSetWindow(); window.Show(); } public void ReadCheckSet(object parameter) { CardCheckSetWindow window = new CardCheckSetWindow(); window.Show(); } public void SetAgvAlias(object parameter) { AgvAliasWindow aliasWindow = new AgvAliasWindow(); aliasWindow.Show(); } public void ShowSel(object parameter) { foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems) { agv.AgvLabel.Visibility = Visibility.Visible; } } public void ShowNoSel(object parameter) { foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items) { agv.AgvLabel.Visibility = Visibility.Visible; } foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems) { agv.AgvLabel.Visibility = Visibility.Hidden; } } public void HideSel(object parameter) { foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems) { agv.AgvLabel.Visibility = Visibility.Hidden; } } public void HideNoSel(object parameter) { foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items) { agv.AgvLabel.Visibility = Visibility.Hidden; } foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.SelectedItems) { agv.AgvLabel.Visibility = Visibility.Visible; } } public void ShowAll(object parameter) { foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items) { agv.AgvLabel.Visibility = Visibility.Visible; } } public void HideAll(object parameter) { foreach (AGV_DisMember agv in MainWindow.mainWindow.dataGrid.Items) { agv.AgvLabel.Visibility = Visibility.Hidden; } } public void ChangeDisplay(object parameter) { if (MainWindow.mainWindow.contextMenuChangeDisplay.IsChecked) { UpdateText("AGV名称"); } else { UpdateText("AGV编号"); } } void UpdateText(string type) { if (type == "AGV名称") { foreach (AGV_DisMember agv in MainWindow.mainWindow.memberData) { if (agv.txtStatus == "运行") { agv.AgvLabel.Content = agv.txtAgvAlias; } else if (agv.txtStatus == "暂停") { agv.AgvLabel.Content = agv.txtAgvAlias + agv.txtStatus.Trim(); } else if (agv.txtStatus == "结束地标停止") { agv.AgvLabel.Content = agv.txtAgvAlias; } else { agv.AgvLabel.Content = agv.txtAgvAlias + agv.txtStatus.Trim(); } } } else if (type == "AGV编号") { foreach (AGV_DisMember agv in MainWindow.mainWindow.memberData) { if (agv.txtStatus == "运行") { agv.AgvLabel.Content = agv.txtAGVNum; } else if (agv.txtStatus == "暂停") { agv.AgvLabel.Content = agv.txtAGVNum.Remove(0, 3) + agv.txtStatus.Trim(); } else if (agv.txtStatus == "结束地标停止") { agv.AgvLabel.Content = agv.txtAGVNum.Remove(0, 3); } else { agv.AgvLabel.Content = agv.txtAGVNum.Remove(0, 3) + agv.txtStatus.Trim(); } } } } int GetColumnIndex(string columnName) { int index = MainWindow.mainWindow.dataGrid.Columns.IndexOf(MainWindow.mainWindow.dataGrid.Columns.First(c => c.Header.ToString() == columnName)); return index; } public void HideCurrentColumn(object parameter) { MainWindow.mainWindow.dataGrid.Columns[MainWindow.mainWindow.dataGrid.CurrentColumn.DisplayIndex].Visibility = Visibility.Hidden; } public void ShowAllColumns(object parameter) { for (int i = 0; i < MainWindow.mainWindow.dataGrid.Columns.Count; i++) { MainWindow.mainWindow.dataGrid.Columns[i].Visibility = Visibility.Visible; } } public void OpenManagerWindow(object parameter) { ManagerWindow window = new ManagerWindow(); window.Show(); } } }