private void Button_Click_DELETE(object sender, RoutedEventArgs e) { int delbookid = Int32.Parse(TextBoxBookIdDelete.Text); book = db.books.Where(w => w.Idbook == delbookid).FirstOrDefault(); db.books.Remove(book); db.SaveChanges(); MessageBox.Show("Kniga ydalena"); }
private void Button_Click(object sender, RoutedEventArgs e) { int fromtextbox = Int32.Parse(AssignBookId.Text); int fromtexboxAssignstudid = Int32.Parse(AssignStudId.Text); book = db.books.Where(w => w.Idbook == fromtextbox).FirstOrDefault(); assign.BookId = book.Idbook; stud = db.Students.Where(w => w.IdStudent == fromtexboxAssignstudid).FirstOrDefault(); assign.StudentId = stud.IdStudent; assign.StartDate = DateTime.Now; assign.EndDate = DateTime.Now.AddDays(30); // assign.Penality = (assign.EndDate - DateTime.Now) * 5 ; db.AssignBooks.Add(assign); db.SaveChanges(); MessageBox.Show(string.Format("student id:{0} assign to ", assign.StudentId.ToString())); }
private void Button_Click_UPDATE(object sender, RoutedEventArgs e) { int id = Int32.Parse(TextBoxBookIdEdit.Text); bookupd = db.books.FirstOrDefault(f => f.Idbook == id); if (bookupd != null) { bookupd.BookName = TextBoxBookNameEdit.Text; bookupd.BookPublisherName = TextBoxBookPublisherNameEdit.Text; bookupd.BookPublisheredYear = Int32.Parse(TextBoxBookPublisherYearEdit.Text); bookupd.BookPrice = Int32.Parse(TextBoxBookPriceEdit.Text); bookupd.BookQuantity = Int32.Parse(TextBoxBookQantityEdit.Text); db.Entry(bookupd).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Izmeniniya po knige vipolneni"); } else { MessageBox.Show("Knigi s takim ID net v baze"); } }
private void Button_Click_ADD(object sender, RoutedEventArgs e) { Module.books newbook = new Module.books(); newbook.Idbook = Int32.Parse(TextBoxBookId.Text); newbook.BookName = TextBoxBookName.Text; newbook.BookPublisherName = TextBoxBookPublisherName.Text; newbook.BookPublisheredYear = Int32.Parse(TextBoxBookPublisherYear.Text); newbook.BookPrice = Int32.Parse(TextBoxBookPrice.Text); newbook.BookQuantity = Int32.Parse(TextBoxBookQantity.Text); db.books.Add(newbook); try { db.SaveChanges(); MessageBox.Show("Kniga dobavlena"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }