//Enable "edit" and "delete" buttons if the Selected Index is valid private void EnableCommands(object sender, SelectionChangedEventArgs e) { if (SelectedIndexIsValid()) { GuiChanges.Enable(btnEdit, btnDelete); } }
/// <summary> /// Manipulation with the GUI Elements depending on selection that user made /// </summary> /// <returns>Selected Item Index if it's in valid range</returns> public int GridSelected() { //Creating the Array of elements for simple handling of GUI, //instead of passing to GuiChanges class Methods each one of the controls, //pass only one array variable. Simple and Effective UIElement[] controlsForDataGrid = { btnEdit, btnDetails, btnDelete, btnBorrow, btnQuantity }; //if user clicks in the DataGrid - check if the click Event //Occurred in the valid range to prevent Exception if (dataLib.SelectedIndex >= 0 && dataLib.SelectedIndex < mainLibrary.Items.Count) { //Enable the buttons GuiChanges.Enable(controlsForDataGrid); //Fine tuning the controls depending on current user Rights ButtonsAvailable(); //Temp variable for Changing the controls text var tmpItem = (AbstractItem)dataLib.SelectedItem; //------------ Changing the controls Caption depending ------------// //------------ on the current Item choosed from the Library ------------// btnDelete.Content = $"Delete this {tmpItem.ItemType}"; btnDetails.Content = $"Details of this {tmpItem.ItemType}"; btnEdit.Content = $"Edit this {tmpItem.ItemType}"; btnQuantity.Content = $"Quantity of this {tmpItem.ItemType}"; //------------ Changing the controls Caption depending ------------// //------------ on the current Item choosed from the Library ------------// //Switch for Borrowing Button - depends on current Item "IsBorrowed" State switch (tmpItem.IsBorrowed) { case true: btnBorrow.Content = $"Return this {tmpItem.ItemType}"; break; case false: btnBorrow.Content = $"Borrow this {tmpItem.ItemType}"; break; } //Return Selected Item index return(dataLib.SelectedIndex); } //If the Selected Index is in invalid range else { //Disable the related controls GuiChanges.Disable(controlsForDataGrid); //Fine tuning the controls depending on current user Rights ButtonsAvailable(); //Return the index (even tough it's invalid) return(dataLib.SelectedIndex); } }
//checks the validity of input from the user and enables //or disables the login button relatively private void CanLogin() { if (!Validity.StringOK(pswPassword.Password) || !Validity.StringOK(txtUserName.Text)) { GuiChanges.Disable(btnLogin); } else { GuiChanges.Enable(btnLogin); } }
//init all elements depending on current working state private void InitEditItemWindow() { this.WindowStyle = WindowStyle.SingleBorderWindow; this.ResizeMode = ResizeMode.NoResize; this.WindowStartupLocation = WindowStartupLocation.CenterScreen; lblISBN.TextAlignment = TextAlignment.Center; if (!EditMode) //showing details mode { this.Title = "Item Details"; //Show check button for Telling to the user if the item is borrowed or not GuiChanges.Show(chkBorrowed); //Disable all the controls because we're in "Show Details" mode foreach (UIElement item in this.grdWindowGrid.Children) { GuiChanges.Disable(item); } //Button caption changed to "Exit" btnSaveExit.Content = "Exit"; //After all controls being disabled because of "Show Details" mode, //Enable the Exit button GuiChanges.Enable(btnSaveExit); } else //editing Item Mode { //Button caption changed to "Save Changes" btnSaveExit.Content = "Save Changes"; //Hide "Item is Borrowed" indicator CheckBox GuiChanges.Hide(chkBorrowed); } }
//Fills inner category relative to base that user chooses //and enables the combo for Inner private void FillInnerCombo(object sender, SelectionChangedEventArgs e) { GuiChanges.Enable(cmbInnerCat); GuiChanges.FillComboWithInnerCategory(cmbInnerCat, cmbBaseCat.SelectedItem); cmbInnerCat.SelectedIndex = 0; }