public MainWindowViewModel() { MenuSelectionChangedCommand = new RelayCommand <Window>((p) => { return(p != null); }, (p) => { var gridCursor = p.FindName("gridCursor") as Grid; var listViewMenu = p.FindName("ListViewMenu") as ListView; var listViewSelectedItem = (listViewMenu).SelectedItem as ListViewItem; gridCursor.Margin = new Thickness(0, 60 * listViewMenu.SelectedIndex, 0, 0); GridMain.Children.Clear(); switch (listViewSelectedItem.Name) { case "LibrarianManager": GridMain.Children.Add(this.PageLibrarianManager); break; case "MemberManager": GridMain.Children.Add(this.PageMemberManager); break; case "BookManager": GridMain.Children.Add(this.PageBookManager); break; case "PublisherManager": GridMain.Children.Add(this.PagePublisherManager); break; case "BookCategoryManager": GridMain.Children.Add(this.PageBookCategoryManager); break; case "AuthorManager": GridMain.Children.Add(this.PageAuthorManager); break; case "Statistic": GridMain.Children.Add(this.PageStatistic); break; case "ChangePassword": var dataContext = new ChangePasswordWindowViewModel("admin"); var changePasswordWindow = new ChangePasswordWindow() { DataContext = dataContext }; changePasswordWindow.ShowDialog(); break; case "AboutSoftware": GridMain.Children.Add(this.PageAboutSoftware); break; case "Logout": var messageboxResult = MyMessageBox.Show("Bạn có muốn đăng xuất khỏi phần mềm ?", "Cảnh báo", "Không", "Có", MessageBoxImage.Warning); if (messageboxResult == true) { listViewMenu.SelectedIndex = 0; MenuSelectionChangedCommand.Execute(p); } else { System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); } break; } }); LoadedWindow = new RelayCommand <Window>((p) => { return(p != null); }, (p) => { InitPage(); GridMain = p.FindName("gridMain") as Grid; GridMain.Children.Add(this.PageLibrarianManager); }); }
public LibrarianWindowViewModel(Account accountLogin) { LibrarianLogin = LibrarianDAL.Instance.GetLibrarian(accountLogin.PersonId); MenuSelectionChangedCommand = new RelayCommand <Window>((p) => { return(p != null); }, (p) => { var gridCursor = p.FindName("gridCursor") as Grid; var listViewMenu = p.FindName("ListViewMenu") as ListView; var listViewSelectedItem = (listViewMenu).SelectedItem as ListViewItem; gridCursor.Margin = new Thickness(0, 60 * listViewMenu.SelectedIndex, 0, 0); GridMain.Children.Clear(); switch (listViewSelectedItem.Name) { case "AccountInfo": GridMain.Children.Add(this.PageLibrarianInfor); break; case "MemberManager": GridMain.Children.Add(this.PageMemberManager); break; case "BookManager": GridMain.Children.Add(this.PageBookManager); break; case "PublisherManager": GridMain.Children.Add(this.PagePublisherManager); break; case "BookCategoryManager": GridMain.Children.Add(this.PageBookCategoryManager); break; case "AuthorManager": GridMain.Children.Add(this.PageAuthorManager); break; case "ChangePassword": var dataContext = new ChangePasswordWindowViewModel(LibrarianLogin.Id); var changePasswordWindow = new ChangePasswordWindow() { DataContext = dataContext }; changePasswordWindow.Show(); break; case "AboutSoftware": GridMain.Children.Add(this.PageAboutSoftware); break; case "Logout": var messageboxResult = MyMessageBox.Show("Bạn có muốn đăng xuất khỏi phần mềm ?", "Cảnh báo", "Không", "Có", MessageBoxImage.Warning); if (messageboxResult == true) { listViewMenu.SelectedIndex = 2; this.MenuSelectionChangedCommand.Execute(p); } else { System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); } break; } }); LoadedWindow = new RelayCommand <Window>((p) => { return(p != null); }, (p) => { var titleBar = p.FindName("titleBar") as TitleBar; titleBar.Tag = "Library Manager - " + LibrarianLogin.LastName + " " + LibrarianLogin.FirstName; if (LibrarianLogin.Status != true) { MyMessageBox.Show("Tài khoản của bạn đã bị khóa!\n\rLiên hệ với quản trị viên để mở lại", "Thông báo", "OK", "", MessageBoxImage.Error); p.Close(); } InitPage(accountLogin); GridMain = p.FindName("gridMain") as Grid; GridMain.Children.Add(this.PageBookManager); var icoAccount = p.FindName("icoAccount") as PackIcon; int firstChar = char.ToUpper(LibrarianLogin.FirstName[0]); if (firstChar == 'A') { icoAccount.Kind = PackIconKind.AlphaACircle; } else if (firstChar == 'B') { icoAccount.Kind = PackIconKind.AlphaBCircle; } else { icoAccount.Kind = (PackIconKind)(158 + 5 * (firstChar - (int)'A' + 2)); } }); }