//Showing or Hiding the search controls and fields depending on received Enum private void ShowAndHideSearchFields(eShowOrHide showHide) { //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[] searchControls = { lblName, txtName, lblAuthor, txtAuthor, lblIssue, txtIssue, lblBaseCategory, cmbBaseCategory, lblInnerCategory, cmbInnerCategory }; //Switch depending on enum switch (showHide) { //Show the search controls case eShowOrHide.Show: //Show the elements from the created array GuiChanges.Show(searchControls); //Fill the ComboBox of Base category GuiChanges.FillComboWithBaseCategory(cmbBaseCategory); //If no selection of Base Category made if (cmbBaseCategory.SelectedItem == null) { //Hide the inner Category ComboBox GuiChanges.Hide(lblInnerCategory, cmbInnerCategory); } break; //Hide the search controls case eShowOrHide.Hide: //Hide the elements from the created array GuiChanges.Hide(searchControls); //Search for the text fields in elements array foreach (UIElement item in searchControls) { //If the Control is Text Box if (item is TextBox) { //Clear the contents of the Text Box, so //this way there's no interfear with feauture search options //when the fields will be enabled and visible again ((TextBox)item).Text = string.Empty; } } //Clean the Combo Boxes of Base and Inner Categories cmbBaseCategory.ItemsSource = cmbInnerCategory.ItemsSource = null; break; } }
//Ctor for add new Item window public AddNewItem() { InitializeComponent(); //Hide the labels and the text boxes ubtil user chooses Item Type GuiChanges.Hide(lblIssue, lblAuthor, txtIssue, txtAuthor); //Obvously understandable by function name GuiChanges.FillComboWithBaseCategory(cmbBaseCat); //Untill user choose the BaseCategory - disable inner GuiChanges.Disable(cmbInnerCat); }
//Update the fields from current Item public void UpdateFromItem() { //creating the arrays for easy handling the Journal controls UIElement[] issue = { lblIssue, txtIssue }; //creating the arrays for easy handling the Book controls UIElement[] author = { lblAuthor, txtAuthor }; //-------------- Updating the fields from Current Item -------------// lblISBN.Text = $"ISBN: {CurrentItem.ISBN}"; lblTypeOf.Text = CurrentItem.ItemType; chkBorrowed.IsChecked = CurrentItem.IsBorrowed; GuiChanges.FillComboWithBaseCategory(cmbBaseCat); cmbBaseCat.SelectedItem = CurrentItem.BaseCategory; txtName.Text = CurrentItem.Name; dtPick.SelectedDate = CurrentItem.PrintDate; switch (CurrentItem.ItemType) { case "Book": GuiChanges.Hide(issue); GuiChanges.Show(author); txtAuthor.Text = ((Book)CurrentItem).Author; break; case "Journal": GuiChanges.Hide(author); GuiChanges.Show(issue); txtIssue.Text = ((Journal)CurrentItem).IssueNumber.ToString(); break; } //-------------- Updating the fields from Current Item -------------// }