private void btnAdd_Click(object sender, RoutedEventArgs e) { ///////////////////////// VALIDATION OF THE USER INPUT ////////////////// if (CurrentItem == ItemType.Default) { GuiMsgs.Warning ("Please Choose the Item Type:" + "\nBook or Journal!"); } //if Base category is choosen else if (cmbBaseCat.SelectedIndex < 0) { GuiMsgs.Warning("Please choose the Base Category!"); } else if (!Validity.StringOK(txtName.Text)) { GuiMsgs.Warning("Please Enter The Name of The Item!"); } else if (dtPick.SelectedDate == null) { GuiMsgs.Warning("Please Select a Publishing Date!"); } else { switch (CurrentItem) { case ItemType.Book: if (!Validity.StringOK(txtAuthor.Text)) { GuiMsgs.Warning("Please Enter The Author Name!"); } else { CreateItem(); this.Close(); } break; case ItemType.Journal: if (!Validity.StringOK(txtIssue.Text)) { GuiMsgs.Warning("Please Enter The Issue Number!"); } else if (!Validity.PositiveInteger(txtIssue.Text)) { GuiMsgs.Warning("Please Enter the valid Issue Number!"); } else //If All the fields are OK - create new Item and add him into the Library { CreateItem(); this.Close(); } break; } } ///////////////////////// VALIDATION OF THE USER INPUT ////////////////// }
/// <summary> /// Validation method that checks if all the fields are valid /// before Update the Current Item /// </summary> /// <returns>true if the fields are OK and false if opposite</returns> private bool FieldsValidForUpdate() { if (!Validity.StringOK(txtName.Text)) { GuiMsgs.Warning("Please enter the Item Name!"); return(false); } else if (dtPick.SelectedDate == null) { GuiMsgs.Warning("Please Select the Publishing Date!"); return(false); } else { switch (CurrentItem.ItemType) { case "Book": if (!Validity.StringOK(txtAuthor.Text)) { GuiMsgs.Warning("Please Enter the Author Name!"); return(false); } break; case "Journal": if (!Validity.StringOK(txtIssue.Text)) { GuiMsgs.Warning("Please Enter The Issue Number!"); return(false); } else if (!Validity.PositiveInteger(txtIssue.Text)) { GuiMsgs.Warning("Please Enter the valid Issue Number!"); return(false); } break; } } return(true); }
//Event for Issue Search TextBox, //Search for the Journal by It's Issue number private void IssueSearch(object sender, TextChangedEventArgs e) { //if the the User inputs is not Positive integer - //don't search, instead clear the TextBox contents if (!Validity.PositiveInteger(txtIssue.Text)) { txtIssue.Text = string.Empty; } //If we in the regular search mode (not multiply) else if (!IsMultiSearch) { dataLib.ItemsSource = mainLibrary.FindJournal(j => j.IssueNumber == int.Parse(txtIssue.Text)); } //if the user deletes the text from issue search box, //Show all the item in the library if (string.IsNullOrWhiteSpace(txtIssue.Text)) { RefreshDataGrid(); } }