private bool CreateClient() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Models.Client newclient = new Models.Client { Name = txtName_Client.Text, Surname = txtSurname_Client.Text, Email = txtEmail_Client.Text, Phone = txtPhone_Client.Text }; db.Clients.Add(newclient); db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private void buttonReserve_Click(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); List <int> books = new List <int>(); foreach (DataGridViewRow row in dataGridViewBooks.SelectedRows) { if (row.Cells[0].Value != null) { books.Add(Convert.ToInt32(row.Cells[0].Value)); } } if (books.Count > 0) { var client = (from c in context.Clients where c.ClientID == id select c).SingleOrDefault(); foreach (LibraryReader.ClientsBook cBook in client.ClientsBooks) { if (books.Contains(cBook.BookID)) { cBook.Reservation = true; MessageBox.Show("Резервирането е успешно!"); } } context.SaveChanges(); } }
private void EditClick(object sender, RoutedEventArgs e) { Tenant tenant = TenantGrid.SelectedItem as Tenant; db.Tenant.Remove(tenant); db.SaveChanges(); TenantGrid.ItemsSource = db.Tenant.ToList(); }
private void checkBoxRejection_CheckedChanged(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); Book book = GetBookByID(context, id); book.Rejection = true; context.SaveChanges(); }
private void AddAuthor(object sender, EventArgs e) { if (saveBtn.Text == "Save") { Regex letters = new Regex(@"^[A-Za-z ]+$"); Match nameMatch = letters.Match(nameBox.Text); Match surnameMatch = letters.Match(surnameBox.Text); if (nameMatch.Success && surnameMatch.Success) { Models.Authors a1 = new Models.Authors(); a1.Id = ab.AuthorId; a1.Name = nameBox.Text; a1.Surname = surnameBox.Text; using (LibraryEntities db = new LibraryEntities()) { db.Authors.Add(a1); db.SaveChanges(); } FillAuthors(); nameBox.Clear(); surnameBox.Clear(); } else { MessageBox.Show("Surname and name contain only letters"); } } else { using (LibraryEntities db = new LibraryEntities()) { int authorId = Convert.ToInt32(authorTable.SelectedRows[0].Cells[0].Value); Models.Authors newAuthor = db.Authors.Where(a => a.Id == authorFound.Id).FirstOrDefault(); newAuthor.Id = authorId; Regex letters = new Regex(@"^[A-Za-z ]+$"); Match nameMatch = letters.Match(nameBox.Text); Match surnameMatch = letters.Match(surnameBox.Text); if (nameMatch.Success && surnameMatch.Success) { newAuthor.Name = nameBox.Text; newAuthor.Surname = surnameBox.Text; } else { MessageBox.Show("Surname and name contain only letters"); } db.SaveChanges(); FillAuthors(); } } }
private void buttonAdd_Click(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); Author newAuthor = new Author() { FName = textBoxFName.Text, LName = textBoxLName.Text }; context.Author.AddObject(newAuthor); context.SaveChanges(); }
private void buttonAdd_Click(object sender, EventArgs e) { int i = dataGridViewCategories.CurrentRow.Index; string cat = dataGridViewCategories.Rows[i].Cells[1].Value.ToString(); LibraryEntities context = new LibraryEntities(); Category newCategory = new Category() { Name = cat }; context.Category.AddObject(newCategory); context.SaveChanges(); }
private void DeleteClient(object sender, EventArgs e) { using (LibraryEntities db = new LibraryEntities()) { int clientId = Convert.ToInt32(clientTable.SelectedRows[0].Cells[0].Value); Models.Clients c1 = db.Clients.Where(c => c.Id == clientId).FirstOrDefault(); db.Clients.Remove(c1); db.SaveChanges(); } FIllClients(); Reset(); }
private void buttonAdd_Click(object sender, EventArgs e) { int i = dataGridViewLanguages.CurrentRow.Index; string lang = dataGridViewLanguages.Rows[i].Cells[1].Value.ToString(); LibraryEntities context = new LibraryEntities(); Language newLanguage = new Language() { Name = lang }; context.Language.AddObject(newLanguage); context.SaveChanges(); }
private void buttonAdd_Click(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); Author newAuthor = new Author() { FName = textBoxFName.Text, LName = textBoxLName.Text }; context.Author.AddObject(newAuthor); context.SaveChanges(); }
private void DeleteAuthor(object sender, EventArgs e) { using (LibraryEntities db = new LibraryEntities()) { int authorId = Convert.ToInt32(authorTable.SelectedRows[0].Cells[0].Value); Models.Authors a1 = db.Authors.Where(a => a.Id == authorId).FirstOrDefault(); db.Authors.Remove(a1); db.SaveChanges(); } FillAuthors(); Reset(); }
private void AddCategory(object sender, EventArgs e) { if (saveBtn.Text == "Save") { Regex letters = new Regex(@"^[A-Za-z ]+$"); Match categoryNameMatch = letters.Match(categoryBox.Text); if (!categoryNameMatch.Success) { MessageBox.Show("Category contains only letters"); } else { Models.Categories c1 = new Models.Categories(); c1.Name = categoryBox.Text; using (LibraryEntities db = new LibraryEntities()) { db.Categories.Add(c1); db.SaveChanges(); } FillCategories(); categoryBox.Clear(); } } else { using (LibraryEntities db = new LibraryEntities()) { int categoryId = Convert.ToInt32(categoryTable.SelectedRows[0].Cells[0].Value); Models.Categories newCat = db.Categories.Where(c => c.Id == categoryFound.Id).FirstOrDefault(); newCat.Id = categoryId; Regex letters = new Regex(@"^[A-Za-z ]+$"); Match categoryNameMatch = letters.Match(categoryBox.Text); if (!categoryNameMatch.Success) { MessageBox.Show("Category contains only letters"); } else { newCat.Name = categoryBox.Text; } db.SaveChanges(); FillCategories(); } } }
private void buttonAdd_Click(object sender, EventArgs e) { int i = dataGridViewCategories.CurrentRow.Index; string cat = dataGridViewCategories.Rows[i].Cells[1].Value.ToString(); LibraryEntities context = new LibraryEntities(); Category newCategory = new Category() { Name = cat }; context.Category.AddObject(newCategory); context.SaveChanges(); }
private void buttonAdd_Click(object sender, EventArgs e) { int i = dataGridViewLanguages.CurrentRow.Index; string lang = dataGridViewLanguages.Rows[i].Cells[1].Value.ToString(); LibraryEntities context = new LibraryEntities(); Language newLanguage = new Language() { Name = lang }; context.Language.AddObject(newLanguage); context.SaveChanges(); }
private void DeleteCategory(object sender, EventArgs e) { using (LibraryEntities db = new LibraryEntities()) { int bookId = Convert.ToInt32(bookTable.SelectedRows[0].Cells[0].Value); Models.Books b1 = db.Books.Where(b => b.Id == bookId).FirstOrDefault(); db.Books.Remove(b1); db.SaveChanges(); } FillBooks(); Reset(); }
private void OrderBtn_Click(object sender, EventArgs e) { int clientID = Convert.ToInt32(userTable.SelectedRows[0].Cells[0].Value); int bookID = Convert.ToInt32(bookTable.SelectedRows[0].Cells[0].Value); Models.Orders order = new Models.Orders(); order.ClientId = clientID; order.BookId = bookID; order.OrderDate = DateTime.Now; order.ReturnDate = DateTime.Now.AddMonths(1); using (LibraryEntities db = new LibraryEntities()) { db.Orders.Add(order); db.SaveChanges(); } }
private bool DeleteAuthor() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Author newStu = db.Authors.Where(s => s.Id == authorGlobal.Id).FirstOrDefault(); db.Authors.Remove(newStu); affectedRows = db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private bool DeleteCategori() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Category newCat = db.Categories.Where(s => s.Id == globalCateg.Id).FirstOrDefault(); db.Categories.Remove(newCat); affectedRows = db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private bool DeleteClient() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Client newcly = db.Clients.Where(s => s.Id == globalClient.Id).FirstOrDefault(); db.Clients.Remove(newcly); affectedRows = db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private bool UpdateAuthor() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Author newAut = db.Authors.Where(a => a.Id == authorGlobal.Id).FirstOrDefault(); newAut.Name = txtName_Author.Text; newAut.Surname = txtSurname_Author.Text; db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private bool UpdateCategori() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Category newCat = db.Categories.Where(a => a.Id == globalCateg.Id).FirstOrDefault(); newCat.Name = txtNameCategori.Text; db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private void InsertClick(object sender, RoutedEventArgs e) { if (FirstName != null && LastName != null && MiddleName != null && PhoneNumber != null && NumberList != null) { Tenant Tenant = new Tenant(); Tenant.FirstName = FirstName.Text; Tenant.LastName = LastName.Text; Tenant.MiddleName = MiddleName.Text; Tenant.PhoneNumber = PhoneNumber.Text; Tenant.LibraryCard = int.Parse(NumberList.Text); db.Tenant.Add(Tenant); db.SaveChanges(); MessageBox.Show("Создание прошло успешно"); ReaderList op = new ReaderList(); op.Show(); this.Close(); } else { MessageBox.Show("Неправильно введены "); } }
static void CreateNewBook(string invn, string isbn, string title,int authorID, string descr, int categID, int yearpubl, int langID, int price) { LibraryEntities context = new LibraryEntities(); Author author = context.Author.FirstOrDefault(p => p.ID == authorID); Book newBook = new Book() { InvNum = invn, ISBN = isbn, Title = title, Description = descr, CategoryID = categID, YearPubl = yearpubl, LanguageID = langID, Price = price, Rejection = false }; newBook.Author.Add(author); context.Book.AddObject(newBook); context.SaveChanges(); //return newBook.ID; }
static void CreateNewBook(string invn, string isbn, string title, int authorID, string descr, int categID, int yearpubl, int langID, int price) { LibraryEntities context = new LibraryEntities(); Author author = context.Author.FirstOrDefault(p => p.ID == authorID); Book newBook = new Book() { InvNum = invn, ISBN = isbn, Title = title, Description = descr, CategoryID = categID, YearPubl = yearpubl, LanguageID = langID, Price = price, Rejection = false }; newBook.Author.Add(author); context.Book.AddObject(newBook); context.SaveChanges(); //return newBook.ID; }
private bool CreateCategori() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Models.Category newcategori = new Models.Category { Name = txtNameCategori.Text }; db.Categories.Add(newcategori); db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private bool CreateAuthor() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Models.Author newauthor = new Models.Author { Name = txtName_Author.Text, Surname = txtSurname_Author.Text }; db.Authors.Add(newauthor); db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private bool UpdateClient() { int affectedRows = 0; using (LibraryEntities db = new LibraryEntities()) { Client newcly = db.Clients.Where(a => a.Id == globalClient.Id).FirstOrDefault(); newcly.Name = txtName_Client.Text; newcly.Surname = txtSurname_Client.Text; newcly.Email = txtEmail_Client.Text; newcly.Phone = txtPhone_Client.Text; db.SaveChanges(); } if (affectedRows > 0) { return(true); } else { return(false); } }
private void checkBoxRejection_CheckedChanged(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); Book book = GetBookByID(context, id); book.Rejection = true; context.SaveChanges(); }
private void AddClient(object sender, EventArgs e) { if (saveBtn.Text == "Save") { Regex letters = new Regex(@"^[A-Za-z ]+$"); Match nameMatch = letters.Match(nameBox.Text); Match surnameMatch = letters.Match(surnameBox.Text); Regex email = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match emailMatch = email.Match(emailBox.Text); Regex phone = new Regex(@"^[+0-9]*$"); Match phoneMatch = phone.Match(phoneBox.Text); if (!nameMatch.Success || !surnameMatch.Success) { MessageBox.Show("Name and surname contain only letters"); } else if (!emailMatch.Success) { MessageBox.Show("Please , enter a valid email"); } else if (!phoneMatch.Success) { MessageBox.Show("Please , enter a valid phone number"); } else { Models.Clients c1 = new Models.Clients { Name = nameBox.Text, Surname = surnameBox.Text, Email = emailBox.Text, Phone = phoneBox.Text }; using (LibraryEntities db = new LibraryEntities()) { db.Clients.Add(c1); db.SaveChanges(); } FIllClients(); nameBox.Clear(); surnameBox.Clear(); emailBox.Clear(); phoneBox.Clear(); } } else { using (LibraryEntities db = new LibraryEntities()) { int clientId = Convert.ToInt32(clientTable.SelectedRows[0].Cells[0].Value); Models.Clients newClient = db.Clients.Where(c => c.Id == clientFound.Id).FirstOrDefault(); newClient.Id = clientId; Regex letters = new Regex(@"^[A-Za-z ]+$"); Match nameMatch = letters.Match(nameBox.Text); Match surnameMatch = letters.Match(surnameBox.Text); Regex email = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match emailMatch = email.Match(emailBox.Text); Regex phone = new Regex(@"^[+0-9]*$"); Match phoneMatch = phone.Match(phoneBox.Text); if (!nameMatch.Success || !surnameMatch.Success) { MessageBox.Show("Name and surname contain only letters"); } else if (!emailMatch.Success) { MessageBox.Show("Please , enter a valid email"); } else if (!phoneMatch.Success) { MessageBox.Show("Please , enter a valid phone number"); } else { newClient.Name = nameBox.Text; newClient.Surname = surnameBox.Text; newClient.Email = emailBox.Text; newClient.Phone = phoneBox.Text; } db.SaveChanges(); FIllClients(); } } }
private void AddBook(object sender, EventArgs e) { if (saveBtn.Text == "Save") { Regex letters = new Regex(@"^[A-Za-z ]+$"); Match bookNameMatch = letters.Match(nameBox.Text); Regex price = new Regex(@"^[0-9.]*$"); Match priceMatch = price.Match(priceBox.Text); Regex numbers = new Regex(@"^[0-9]*$"); Match quantityMatch = numbers.Match(quantityBox.Text); if (!bookNameMatch.Success) { MessageBox.Show("Book name contains only letters"); } else if (!priceMatch.Success) { MessageBox.Show("Price contains only numbers and dot"); } else if (!quantityMatch.Success) { MessageBox.Show("Quantity contains only numbers"); } else { using (LibraryEntities db = new LibraryEntities()) { Models.AuthorsBooks ab = new AuthorsBooks(); int categoryId = (db.Categories.Where(c => c.Name == categoryDrop.SelectedItem.ToString()).FirstOrDefault()).Id; int authorId = (db.Authors.Where(a => a.Name + " " + a.Surname == authorDrop.SelectedItem.ToString()).FirstOrDefault()).Id; Models.Books b1 = new Models.Books(); b1.Name = nameBox.Text; ab.BookId = b1.Id; ab.AuthorId = authorId; db.AuthorsBooks.Add(ab); b1.Price = Convert.ToDecimal(priceBox.Text); b1.CategoryId = categoryId; b1.Quantity = Convert.ToInt32(quantityBox.Text); db.Books.Add(b1); db.SaveChanges(); } FillBooks(); nameBox.Clear(); priceBox.Clear(); quantityBox.Clear(); categoryDrop.SelectedIndex = -1; authorDrop.SelectedIndex = -1; } } else { using (LibraryEntities db = new LibraryEntities()) { int bookId = Convert.ToInt32(bookTable.SelectedRows[0].Cells[0].Value); Models.Books newBook = db.Books.Where(b => b.Id == bookFound.Id).FirstOrDefault(); newBook.Id = bookId; Regex letters = new Regex(@"^[A-Za-z ]+$"); Match bookNameMatch = letters.Match(nameBox.Text); Regex price = new Regex(@"^[0-9.]*$"); Match priceMatch = price.Match(priceBox.Text); Regex numbers = new Regex(@"^[0-9]*$"); Match quantityMatch = numbers.Match(quantityBox.Text); if (!bookNameMatch.Success) { MessageBox.Show("Book name contains only letters"); } else if (!priceMatch.Success) { MessageBox.Show("Price contains only numbers and dot"); } else if (!quantityMatch.Success) { MessageBox.Show("Quantity contains only numbers"); } else { newBook.Name = nameBox.Text; newBook.Categories.Name = (db.Categories.Where(c => c.Name == categoryDrop.SelectedItem.ToString()).FirstOrDefault()).Name; newBook.Price = Convert.ToDecimal(priceBox.Text); newBook.Quantity = Convert.ToInt32(quantityBox.Text); } db.SaveChanges(); FillBooks(); Reset(); } } }