private void BookList(object sender, RoutedEventArgs e) { BookList open = new BookList(); open.Show(); this.Close(); }
private void Save(Object param) { IEnumerable <Book> newData = BookList.Cast <Book>(); XDocument newDoc = new XDocument( new XDeclaration("1.0", "utf-8", "true")); XElement bookLibrary = new XElement("BookLibrary"); if (newData.Last().Title == null || newData.Last().Author == null || newData.Last().Publisher == null || newData.Last().PublishDate == null || newData.Last().Language == null || newData.Last().Pages == null) { MessageBox.Show("信息填写不完整!", "提示"); return; } if (!RegexTxt.IsChinEngNum(newData.Last().Title)) { MessageBox.Show("书名格式:中文,英文,数字!", "提示"); return; } if (!RegexTxt.IsChiEng(newData.Last().Author)) { MessageBox.Show("作者格式:中文,英文!", "提示"); return; } if (!RegexTxt.IsChiEng(newData.Last().Publisher)) { MessageBox.Show("出版机构格式:中文,英文!", "提示"); return; } if (!RegexTxt.IsDate(newData.Last().PublishDate)) { MessageBox.Show("日期格式为xxxx/xx/xx", "提示"); return; } if (!RegexTxt.IsChiEng(newData.Last().Language)) { MessageBox.Show("语言格式:中文,英文!", "提示"); return; } if (!RegexTxt.IsPositiveInt(newData.Last().Pages)) { MessageBox.Show("页数格式为非零正整数!", "提示"); return; } foreach (var b in newData) { XElement book = new XElement("Book", new XAttribute("ID", b.ID), new XElement("Title", b.Title), new XElement("Author", b.Author), new XElement("Publisher", b.Publisher), new XElement("PublishDate", b.PublishDate), new XElement("Language", b.Language), new XElement("Pages", b.Pages) ); bookLibrary.Add(book); } newDoc.Add(bookLibrary); newDoc.Save(strFilePath); MessageBox.Show("保存成功!", "提示"); }
private void Search(object param) { if (!String.IsNullOrEmpty(SearchText)) { IEnumerable <Book> search = null; switch (SearchType) { case 0: search = from b in BookList.Cast <Book>() where b.Title.ToLower().Contains(SearchText.ToLower()) select b; break; case 1: search = from b in BookList.Cast <Book>() where b.Author.ToLower().Contains(SearchText.ToLower()) select b; break; case 2: search = from b in BookList.Cast <Book>() where b.Publisher.ToLower().Contains(SearchText.ToLower()) select b; break; } BookList = search.ToObservableCollection <Book>(); } else { BookList = _bookLibrary.ToObservableCollection <Book>(); } }
private void Delete(object param) { if (SelectedBook != null) { BookList.Remove(SelectedBook); _bookLibrary = BookList.ToIEnumerable <Book>(); SelectedBook = BookList.LastOrDefault(); MessageBox.Show("删除成功!", "提示"); } }
private void Add(object param) { Book newBook = new Book() { ID = (Convert.ToInt32((from b in BookList.Cast <Book>() select b.ID).Max <string>()) + 1).ToString() }; BookList.Add(newBook); _bookLibrary = BookList.ToIEnumerable <Book>(); SelectedBook = newBook; }
private void textBox3_TextChanged(object sender, EventArgs e) //ISBN textBox changed { textBox4.Text = null; List <string> ISBNList = context.BookLists.Select(x => x.ISBN).ToList(); foreach (string ISBN in ISBNList) { if (ISBN == textBox3.Text) { book = context.BookLists.Where(x => x.ISBN == ISBN).First(); textBox4.Text = book.BookTitle; } } }
private void AddButton_Click(object sender, EventArgs e) { String errorMessage; // Get Entity Context SA45Team13bLibraryEntities context = new SA45Team13bLibraryEntities(); // Display error if values are invalid if (!ValidateValues(out errorMessage)) { MessageBox.Show(errorMessage, "Unable to add new Book", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Continue to add book BookList book = new BookList(); book.BookTitle = TitleTextBox.Text; book.Author = AuthorTextBox.Text; book.Publisher = PublisherTextBox.Text; book.ISBN = ISBNTextBox.Text; book.Loaned = 0; book.TotalStock = (short)StockNumericUpDown.Value; book.Language = LanguageTextBox.Text; book.Genre = GenreTextBox.Text; book.BookCost = (float)Double.Parse(BookCostTextBox.Text); if (ShelfComboBox.SelectedValue != null) { book.Shelf = ShelfComboBox.SelectedValue.ToString(); } else { book.Shelf = "1"; } context.BookLists.Add(book); context.SaveChanges(); // Display message MessageBox.Show("Book Added Sucessfully"); DialogResult = DialogResult.OK; this.Close(); }
private void LoadLibrary() { XDocument doc = XDocument.Load(strFilePath); _bookLibrary = from e in doc.Descendants("Book") select new Book() { ID = e.Attribute("ID").Value, Title = e.Element("Title").Value, Author = e.Element("Author").Value, Publisher = e.Element("Publisher").Value, PublishDate = e.Element("PublishDate").Value, Pages = e.Element("Pages").Value, Language = e.Element("Language").Value }; _bookList = _bookLibrary.ToObservableCollection(); SelectedBook = BookList.FirstOrDefault(); }
public ModifyBookForm(String ISBN, String Title) { InitializeComponent(); context = new SA45Team13bLibraryEntities(); SelectedBook = context.BookLists.Single( book => book.ISBN == ISBN && book.BookTitle == Title ); TitleTextBox.Text = SelectedBook.BookTitle; AuthorTextBox.Text = SelectedBook.Author; PublisherTextBox.Text = SelectedBook.Publisher; ISBNTextBox.Text = SelectedBook.ISBN; LanguageTextBox.Text = SelectedBook.Language; GenreTextBox.Text = SelectedBook.Genre; StockNumericUpDown.Value = SelectedBook.TotalStock; StockNumericUpDown.Minimum = SelectedBook.Loaned; BookCostTextBox.Text = SelectedBook.BookCost.ToString(); ShelfComboBox.SelectedIndex = Int32.Parse(SelectedBook.Shelf) - 1; }