private void AdvSearch_Click(object sender, RoutedEventArgs e) { string name = sNameField.Value.ToLower(); string iSBN = sISBNField.Value; string author = sAuthorField.Value.ToLower(); string publisher = sPublisherField.Value.ToLower(); string edition = sEditionField.Value.ToLower(); string Cata = sCataField.Value; GenresView genres = sGenerBox.Geners; DateTime? date = sDateField.SelectedDate; List <Predicate <StoreItemView> > predics = new List <Predicate <StoreItemView> >(8); if (name != string.Empty) { predics.Add((i) => i.Name.ToLower().Contains(name)); } if (iSBN != string.Empty) { predics.Add((i) => i.ISBN.Contains(iSBN)); } if (author != string.Empty) { predics.Add((i) => { BookView item = i as BookView; if (item == null) { return(false); } return(item.Author.ToLower().Contains(author)); }); } if (publisher != string.Empty) { predics.Add((i) => { BookView item = i as BookView; if (item == null) { return(false); } return(item.Publisher.ToLower().Contains(publisher)); }); } if (edition != string.Empty) { predics.Add((i) => { BookView item = i as BookView; if (item == null) { return(false); } return(item.Edition.Contains(edition)); }); } if (Cata != string.Empty) { predics.Add((i) => { BookView item = i as BookView; if (item == null) { return(false); } int num; if (!int.TryParse(Cata, out num)) { return(false); } return(item.CatalogNumber == num); }); } if (genres.Count != 0) { predics.Add((i) => { BookView item = i as BookView; if (item == null) { return(false); } bool contain = false; for (int j = 0; j < GenresView.AllGenres.Length; j++) { if (genres[j].Active) { if (item.Genres[j].Active) { contain = true; } else { return(false); } } } return(contain); }); } if (date != null) { predics.Add((i) => i.PublishedDate.Equals(date)); } if (predics.Count == 0) { return; } listView.ItemsSource = Logic.Instance.GetStoreItems(predics.ToArray()); advanceSearch.IsOpen = false; }
private bool BuildBook(out BookView book) { book = null; string name = nameField.Value; if (name == "" || name == null) { errorBox.Pop("Invalid Name."); return(false); } decimal price; if (!decimal.TryParse(priceField.Value, out price)) { errorBox.Pop("Invalid Price."); return(false); } int precent = 0; if (!string.IsNullOrWhiteSpace(discountField.Value)) { string[] split = discountField.Value.Split('%'); if (!int.TryParse(split[0], out precent)) { errorBox.Pop("Invalid Discount."); return(false); } } float discount = precent / 100.0f; string isbn = isbnField.Value; if (isbn == "" || isbn == null) { errorBox.Pop("Invalid ISBN."); return(false); } int uIS = unitInStockField.NumValue; byte[] image = null; if (!imageField.IsDefault) { image = imageField.ImageBytes; } DateTime?publishedDate = dateField.SelectedDate; if (publishedDate == null) { errorBox.Pop("Invalid Date."); return(false); } if (publishedDate > DateTime.Now) { errorBox.Pop("Invalid Date."); return(false); } string author = authorField.Value; if (author == "" || author == null) { errorBox.Pop("Invalid Author."); return(false); } string publisher = publisherField.Value; if (publisher == "" || publisher == null) { errorBox.Pop("Invalid Publisher."); return(false); } GenresView genres = genresField.Geners; if (genres.Count == 0) { errorBox.Pop("Must Choose at Least One Genre"); return(false); } string summary = null; TextRange text = new TextRange(summaryField.Document.ContentStart, summaryField.Document.ContentEnd); if (text.Text != "") { summary = text.Text; } int cataNum = -1; if (cataNumField.Value != null && cataNumField.Value != "") { if (!int.TryParse(cataNumField.Value, out cataNum)) { errorBox.Pop("Invalid Catalog Num."); return(false); } } string edition = editionField.Value; book = new BookView(0, name, edition, cataNum, summary, price, discount, isbn, uIS, author, publisher, genres, publishedDate.GetValueOrDefault(), image); return(true); }
public ComboBox Combo => ddlGenres; // test public MultiSelectionBox(GenresView genres) { InitializeComponent(); Geners = genres; }