public SignUp() { InitializeComponent(); db = new LibraryEntities(); db.Configuration.ProxyCreationEnabled = false; db.User.Load(); }
public AddBook() { InitializeComponent(); db = new LibraryEntities(); //andmebaas db.Configuration.ProxyCreationEnabled = false; db.Book.Load(); //raamatud this.Closing += Window_Closing; }
private void RentBtn_Click(object sender, RoutedEventArgs e)//rent nupp { if (BooksDataGrid.SelectedItems != null) { for (int i = 0; i < BooksDataGrid.SelectedItems.Count; i++) { Book book = BooksDataGrid.SelectedItems[i] as Book; if (book != null && book.Quantity != 0)//raamatute kogus peab olema suurem kui null { Rent r = new Rent(); if (db.Rent.Local.ToBindingList() == null) { r.RentId = 1; } else { r.RentId = db.Rent.Max(k => k.RentId) + 1; } r.Book_Id = book.BookId; r.User_Id = SignUp.userid; r.Rent_date = DateTime.Now; r.Return_date = DateTime.Now.AddDays(21); r.Status = "Rented"; Book b = (from p in db.Book where p.BookId == book.BookId select p).SingleOrDefault(); b.Quantity--; db.Rent.Add(r); db.SaveChanges(); } else { MessageBox.Show("Quantity is 0.", "Error", MessageBoxButton.OK, MessageBoxImage.Information); } } } LibraryEntities db2 = new LibraryEntities(); db2.Book.Load(); db2.RentedBooksInfo.Load(); BooksDataGrid.ItemsSource = null; RentedBooksGrid.ItemsSource = null; BooksDataGrid.ItemsSource = db2.Book.Local.ToBindingList(); var g = db2.RentedBooksInfo. Where(t => t.UserId == SignUp.userid).ToList(); RentedBooksGrid.ItemsSource = g; db2.Dispose(); }
public static int booksdataid;//selekteeritud raamatu id public AdminBooks() { InitializeComponent(); db = new LibraryEntities(); db.Configuration.ProxyCreationEnabled = false; db.Book.Load(); //raamatute andmete datagridisse BooksDataGrid.ItemsSource = db.Book.Local.ToBindingList(); //combobox kategooriad List <String> categories = new List <String> { "All", "ID", "Title", "Author", "Description", "Shelf", "Genre", "Notes" }; CriteriumCombobox.ItemsSource = categories; //trahvi v4lja arvutamine var users = db.User; var rents = db.Rent; var fine = new List <double>(); foreach (User u in users) { foreach (Rent r in rents) { if (r.User_Id == u.UserId) { if (r.Return_date < DateTime.Now) { fine.Clear(); IQueryable <Rent> RB = db.Rent.Where(p => p.User_Id == u.UserId && p.Return_date < DateTime.Now); foreach (Rent m in RB) { m.Status = "Not paid"; if (u.UserId == r.User_Id && r.Status == "Not paid") { fine.Add((DateTime.Now - r.Return_date).TotalDays * 0.14); } } u.ToPay = String.Format("{0:0.##}", fine.Sum()) + "$"; } } } } db.SaveChanges(); this.Closing += Window_Closing; }
public UserControlPanel() { InitializeComponent(); db = new LibraryEntities(); db.Configuration.ProxyCreationEnabled = false; db.User.Load(); db.RentedBooksInfo.Load(); List <String> categories = new List <String> { "All", "Lastname", "Telephone", "Address", "E-mail" }; CriteriumCombobox.ItemsSource = categories; UsersGrid.ItemsSource = db.User.Local.ToBindingList(); this.Closing += Window_Closing; }
private void ReturnBtn_Click(object sender, RoutedEventArgs e)//return nupp { RentInfoTextBlock.Text = String.Empty; if (RentedBooksGrid.SelectedItems != null) { for (int i = 0; i < RentedBooksGrid.SelectedItems.Count; i++) { RentedBooksInfo rbook = RentedBooksGrid.SelectedItems[i] as RentedBooksInfo; if (rbook != null) { Rent r = (from p in db.Rent where p.Book_Id == rbook.BookId && p.User_Id == rbook.User_Id && p.RentId == rbook.RentId select p).SingleOrDefault(); Book b = (from p in db.Book where p.BookId == rbook.BookId select p).SingleOrDefault(); b.Quantity++; db.Rent.Remove(r); db.SaveChanges(); } } } LibraryEntities db2 = new LibraryEntities(); db2.Book.Load(); db2.RentedBooksInfo.Load(); BooksDataGrid.ItemsSource = null; RentedBooksGrid.ItemsSource = null; BooksDataGrid.ItemsSource = db2.Book.Local.ToBindingList(); var g = db2.RentedBooksInfo. Where(t => t.UserId == SignUp.userid).ToList(); RentedBooksGrid.ItemsSource = g; db2.Dispose(); }
public UserBooks() { InitializeComponent(); db = new LibraryEntities(); db.Configuration.ProxyCreationEnabled = false; db.Book.Load(); db.User.Load(); db.RentedBooksInfo.Load(); BooksDataGrid.ItemsSource = db.Book.Local.ToBindingList(); //n4itab useri laenatud raamatuid var g = db.RentedBooksInfo. Where(t => t.UserId == SignUp.userid).ToList(); RentedBooksGrid.ItemsSource = g; //kui raamatu tagastamise aeg on l4bi, siis nuppud "Return" ja "Rent" pole aktiivsed var fine = new List <double>(); if (g != null) { foreach (RentedBooksInfo r in g) { if (r.Return_date < DateTime.Now) { foreach (User u in db.User.Local.ToBindingList()) { if (u.UserId == SignUp.userid) { fine.Clear(); IQueryable <Rent> RB = db.Rent.Where(p => p.User_Id == u.UserId && p.Return_date < DateTime.Now); foreach (Rent m in RB) { m.Status = "Not paid"; if (u.UserId == r.User_Id && r.Status == "Not paid") { fine.Add((DateTime.Now - r.Return_date).TotalDays * 0.14); } } u.ToPay = String.Format("{0:0.##}", fine.Sum()); MessageBox.Show("Rental time is out. Pay " + u.ToPay + "$", "Error", MessageBoxButton.OK, MessageBoxImage.Information); RentBtn.IsEnabled = false; ReturnBtn.IsEnabled = false; } } break; } else { RentBtn.IsEnabled = true; ReturnBtn.IsEnabled = true; } } } //combobox kategooriad List <String> categories = new List <String> { "All", "ID", "Title", "Author", "Description", "Genre", "Notes" }; CriteriumCombobox.ItemsSource = categories; /* List<String> Genres = db.Book.AsEnumerable() * .Select(row => row.Genre.ToString()) * .ToList(); * CriteriumCombobox.ItemsSource = Genres;*/ db.SaveChanges(); this.Closing += UserBooks_Closing; }