private void btnReject_Click(object sender, EventArgs e) { readerApplication.Status = "O"; dbContext.SaveChanges(); MessageBox.Show("Wniosek odrzucony", "Informacja"); this.Close(); }
public static User AddReader(LibraryDBContainer dbContext, String login, String password, String name, String surname, String mail, String phone, String street, String houseNum, String aptNum, String city, String postal) { var user = AddUser("U", dbContext, login, password, name, surname, mail); if (user != null) { if (!phone.All(Char.IsDigit)) { MessageBox.Show("Telefon nie zawiera tylko cyfr"); dbContext.Users.Remove(user); dbContext.SaveChanges(); return(null); } if (!postal.All(x => Char.IsDigit(x) || x == '-')) { MessageBox.Show("Nieprawidłowy kod pocztowy"); dbContext.Users.Remove(user); dbContext.SaveChanges(); return(null); } if (!houseNum.All(Char.IsDigit)) { MessageBox.Show("Numer domu nie zawiera tylko cyfr"); dbContext.Users.Remove(user); dbContext.SaveChanges(); return(null); } var newReader = new Reader { PhoneNumber = phone, Street = street, HouseNumber = houseNum, ApartmentNumber = aptNum, City = city, PostalCode = postal, Debt = 0, User = user }; user.Reader = newReader; dbContext.Readers.Add(newReader); dbContext.SaveChanges(); } return(user); }
private void buttonSave_Click(object sender, EventArgs e) { List <Author> authors = null; switch (formAction) { case FormAction.Add: if (!AddAuthor()) { return; } break; case FormAction.Edit: if (!EditAuthor()) { return; } break; case FormAction.Search: SearchAuthor(out authors); break; } dbContext.SaveChanges(); authorSaved(this, authors); this.Close(); }
private void buttonSave_Click(object sender, EventArgs e) { List <Book> books = null; switch (formAction) { case FormAction.Add: if (!AddBook()) { return; } break; case FormAction.Edit: if (!EditBook(editedBook)) { return; } break; case FormAction.Search: SearchBook(out books); break; } dbContext.SaveChanges(); bookSaved(this, books); this.Close(); }
private void buttonSave_Click(object sender, EventArgs e) { List <Genre> genres = null; switch (formAction) { case FormAction.Add: if (!AddGenre()) { return; } break; case FormAction.Edit: if (!EditGenre()) { return; } break; case FormAction.Search: SearchGenre(out genres); break; } dbContext.SaveChanges(); genreSaved(this, genres); this.Close(); }
private bool BorrowResource() { if (!DbUtils.HasUserAlreadyBorrowedResource(dbContext, resource, reader)) { List <Reservation> reservations = dbContext.Reservations .Include("Reader") .Include("Resource") .Where(r => r.ReaderId == reader.Id) .Where(r => r.ResourceId == resource.Id) .ToList(); dbContext.Reservations.RemoveRange(reservations); Borrowing borrowing = new Borrowing(); borrowing.BorrowingDate = DateTime.Now; borrowing.ReturnDate = null; borrowing.ReturnTerm = datePicker.Value; borrowing.Reader = reader; borrowing.Resource = resource; borrowing.User = librarian; dbContext.Borrowings.Add(borrowing); dbContext.SaveChanges(); return(true); } MessageBox.Show("Użytkownik już wypożyczył ten zasób!", "Błąd"); return(false); }
public static User AddUser(String type, LibraryDBContainer dbContext, String login, String password, String name, String surname, String mail) { if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(surname) || string.IsNullOrWhiteSpace(mail)) { MessageBox.Show("Pola: Login, Haslo, Email, Imie, Nazwisko nie moga byc puste!"); return(null); } if (dbContext.Users.Any(x => x.Login == login)) { MessageBox.Show("Użytkownik o podanym loginie istnieje!"); return(null); } if (!mail.Contains("@")) { MessageBox.Show("Email nieprawidłowy!"); return(null); } var newUser = new User { Login = login, Password = password, Name = name, Surname = surname, Type = type, E_Mail = mail }; dbContext.Users.Add(newUser); dbContext.SaveChanges(); return(newUser); }
private void btnAccept_Click(object sender, EventArgs e) { reader.Debt = 0; dbContext.SaveChanges(); MessageBox.Show("Wpłacono karę", "Informacja"); this.Close(); }
// Przykład użycia Entity Framework private void dbExample() { using (var db = new LibraryDBContainer()) { // Stworzenie nowego użytkownika var jpUser = new User { Login = "******", Password = "******", Name = "Jakub", Surname = "Plachta", Type = "A", E_Mail = "*****@*****.**" }; db.Users.Add(jpUser); // Dodanie użytkownika do tabeli Users db.SaveChanges(); // Zapisanie zmian do bazy // Zapytanie do bazy pobierające wszystkich użytkowników. var query = from u in db.Users orderby u.Surname, u.Name select u; foreach (var user in query) { dbExampleListBox.Items.Add(user.Surname + " " + user.Name); } } }
private bool ReserveResource() { if (!DbUtils.HasUserAlreadyReservedResource(dbContext, resource, reader) && !DbUtils.HasUserAlreadyBorrowedResource(dbContext, resource, reader)) { Reservation reservation = new Reservation(); reservation.Reader = reader; reservation.Resource = resource; reservation.RealizationDate = datePicker.Value; reservation.ReservationDate = DateTime.Now; dbContext.Reservations.Add(reservation); dbContext.SaveChanges(); } else if (DbUtils.HasUserAlreadyBorrowedResource(dbContext, resource, reader)) { MessageBox.Show("Użytkownik już wypożyczył ten zasób!", "Błąd"); return(false); } else { MessageBox.Show("Użytkownik już zarezerwował ten zasób!", "Błąd"); return(false); } return(true); }
private void buttonSave_Click(object sender, EventArgs e) { List <Publisher> publishers = null; switch (formAction) { case FormAction.Add: if (!AddPublisher()) { return; } break; case FormAction.Edit: if (!EditPublisher()) { return; } break; case FormAction.Search: SearchPublisher(out publishers); break; } dbContext.SaveChanges(); publisherSaved(this, publishers); this.Close(); }
private void buttonSave_Click(object sender, EventArgs e) { List <Position> positions = null; switch (formAction) { case FormAction.Add: if (validate()) { addPosition(); MessageBox.Show("Dodano pozycję", "Informacja"); } break; case FormAction.Edit: if (validate()) { editPosition(editedPosition); MessageBox.Show("Edytowano pozycję", "Informacja"); } break; case FormAction.Search: searchPosition(out positions); break; } dbContext.SaveChanges(); if (positionSaved != null) { positionSaved(this, positions); } this.Close(); }
private void buttonSave_Click(object sender, EventArgs e) { List <Magazine> magazines = null; switch (formAction) { case FormAction.Add: if (!AddMagazine()) { return; } break; case FormAction.Edit: if (!EditMagazine(editedMagazine)) { return; } break; case FormAction.Search: SearchMagazine(out magazines); break; } dbContext.SaveChanges(); magazineSaved(this, magazines); this.Close(); }
public User AddUser(User user) { if (CheckLogin(user.Login)) { db.UserSet.Add(user); db.SaveChanges(); return(user); } return(null); }
private void buttonSave_Click(object sender, EventArgs e) { if (editedUser != null) { editedUser.Password = textBoxPassword.Text; editedUser.E_Mail = textBoxMail.Text; editedUser.Name = textBoxName.Text; editedUser.Surname = textBoxSurname.Text; if (editedUser.Type.Equals("U")) { editedUser.Reader.PhoneNumber = textBoxTel.Text; editedUser.Reader.Street = textBoxStreet.Text; editedUser.Reader.HouseNumber = textBoxStrNum.Text; editedUser.Reader.ApartmentNumber = textBoxApt.Text; editedUser.Reader.City = textBoxCity.Text; editedUser.Reader.PostalCode = textBoxPostal.Text; } dbContext.SaveChanges(); } else { switch (typeSpinner.SelectedIndex) { case 0: editedUser = DbUtils.AddReader(dbContext, textBoxLogin.Text, textBoxPassword.Text, textBoxName.Text, textBoxSurname.Text, textBoxMail.Text, textBoxTel.Text, textBoxStreet.Text, textBoxStrNum.Text, textBoxApt.Text, textBoxCity.Text, textBoxPostal.Text); break; case 1: editedUser = DbUtils.AddUser("L", dbContext, textBoxLogin.Text, textBoxPassword.Text, textBoxName.Text, textBoxSurname.Text, textBoxMail.Text); break; case 2: editedUser = DbUtils.AddUser("A", dbContext, textBoxLogin.Text, textBoxPassword.Text, textBoxName.Text, textBoxSurname.Text, textBoxMail.Text); break; } } if (userSaved != null) { userSaved(this, e); } if (editedUser != null) { this.Close(); } }
private void btnDeleteUser_Click(object sender, EventArgs e) { if (getSelectedUser() != null) { int userToDeleteId = getSelectedUser().Id; var userToDelete = dbContext.Users.Include("Reader").Include("Borrowing") .Where(userSearch => userSearch.Id == userToDeleteId).FirstOrDefault(); dbContext.Users.Remove(userToDelete); dbContext.SaveChanges(); refreshListView(dbContext.Users.ToList()); } }
private void btnNoteReturn_Click(object sender, EventArgs e) { Borrowing borrowing = GuiUtils.GetSelected <Borrowing>(lstViewActions, borrowingTagSet); if (borrowing != null) { borrowing.ReturnDate = DateTime.Now; if (borrowing.ReturnTerm < DateTime.Now) { int penaltyDays = (int)DateTime.Now.Subtract(borrowing.ReturnTerm).TotalDays; int penalty = penaltyDays * 20; Reader reader = borrowing.Reader; reader.Debt += penalty; MessageBox.Show("Naliczono karę w wysokości " + (((double)penalty / 100)).ToString() + " zł.", "Informacja"); } dbContext.SaveChanges(); if (borrowingForUser) { ShowBorrowingsForUser(cachedUser); } else { ShowBorrowingsForResource(cachedResource); } } else { MessageBox.Show("Nie wybrano wypożyczenia!", "Błąd"); return; } MessageBox.Show("Zaksięgowano zwrot.", "Informacja"); }
private void send_Click(object sender, EventArgs e) { if (textBoxName.Text.Count() == 0 || textBoxSurname.Text.Count() == 0 || textBoxTel.Text.Count() == 0 || textBoxStreet.Text.Count() == 0 || textBoxStrNum.Text.Count() == 0 || textBoxCity.Text.Count() == 0 || textBoxPostal.Text.Count() == 0) { MessageBox.Show("Wszystkie pola muszą być uzupełnione"); return; } if (!textBoxTel.Text.All(Char.IsDigit)) { MessageBox.Show("Telefon może zawierać tylko cyfry"); return; } if (!textBoxPostal.Text.All(x => Char.IsDigit(x) || x == '-')) { MessageBox.Show("Nieprawidłowy kod pocztowy"); return; } var applicationData = new ReaderApplicationData { Name = textBoxName.Text, Surname = textBoxSurname.Text, PhoneNumber = textBoxTel.Text, Street = textBoxStreet.Text, HouseNumber = textBoxStrNum.Text, ApartmentNumber = textBoxApt.Text, City = textBoxCity.Text, PostalCode = textBoxPostal.Text }; var application = new ReaderApplication { ApplicationDate = DateTime.Now }; application.ApplicationData.Add(applicationData); user.Application.Add(application); dbContext.SaveChanges(); MessageBox.Show("Wysłano wniosek"); this.Close(); }
public tmpClass() { using (var db = new LibraryDBContainer()) { var query = from u in db.Users where u.Login.Equals("admin") where u.Password.Equals("admin") select u; if (query.ToList().Count < 1) { var jpAdmin = new User { Login = "******", Password = "******", Name = "Jakub", Surname = "Plachta", Type = "A", E_Mail = "*****@*****.**" }; db.Users.Add(jpAdmin); db.SaveChanges(); } } }
private void buttonSave_Click(object sender, EventArgs e) { if (!txtBoxAmount.Text.All(Char.IsDigit)) { MessageBox.Show("Tylko cyfry"); return; } switch (formAction) { case FormAction.Add: AddResource(); MessageBox.Show("Dodano zasób", "Informacja"); break; case FormAction.Edit: EditResource(editedResource); MessageBox.Show("Edytowano zasób", "Informacja"); break; } dbContext.SaveChanges(); this.Close(); }
private void btnReserveResource_Click(object sender, EventArgs e) { if (lstViewBooksAndUsers.SelectedItems.Count > 0) { Resource resource; if (tagSet.TryGetValue(lstViewBooksAndUsers.SelectedItems[0].Tag.ToString(), out resource)) { if (!DbUtils.HasUserAlreadyReservedResource(dbContext, resource, userContext) && !DbUtils.HasUserAlreadyBorrowedResource(dbContext, resource, userContext)) { Reservation reservation = new Reservation(); reservation.Reader = userContext; reservation.Resource = resource; reservation.ReservationDate = DateTime.Now; Borrowing bor = dbContext.Borrowings .Where(b => b.ReturnDate == null) .Where(b => b.ResourceId == resource.Id) .OrderBy(b => b.ReturnTerm) .ToList() .FirstOrDefault(); Reservation res = dbContext.Reservations .Where(r => r.RealizationDate > DateTime.Now) .Where(r => r.ResourceId == resource.Id) .OrderBy(r => r.RealizationDate) .ToList() .FirstOrDefault(); if (bor != null && res != null) { DateTime date = bor.ReturnTerm > res.RealizationDate ? bor.ReturnTerm : res.RealizationDate; reservation.RealizationDate = date.AddMonths(1); } else if (res != null) { reservation.RealizationDate = res.RealizationDate.AddMonths(1); } else if (bor != null) { reservation.RealizationDate = bor.ReturnTerm.AddMonths(1); } else { reservation.RealizationDate = DateTime.Now.AddMonths(1); } dbContext.Reservations.Add(reservation); MessageBox.Show("Twoja rezerwacja trwa do " + reservation.RealizationDate.ToString(), "Informacja"); } else if (DbUtils.HasUserAlreadyBorrowedResource(dbContext, resource, userContext)) { MessageBox.Show("Aktualnie wypożyczasz ten zasób", "Błąd"); } else { MessageBox.Show("Już zarezerwowałeś ten zasób", "Błąd"); } } else { MessageBox.Show("Nie wybrano zasobu", "Błąd"); } } dbContext.SaveChanges(); }