private void button2_Click(object sender, EventArgs e) { using (LibraryDBEntities dbContext = new LibraryDBEntities()) { Reader reader = new Reader(); List <Reader> readers = dbContext.Readers.ToList(); string loginPattern = @"[A-Z]{2}[-]{1}\b\d{6}\b"; string phoneNumberPattern = @"[+]{1}\b\d{12}\b"; bool isLoginExhist = false; bool isPasswordMatches = true; foreach (Reader match in readers) { if (match.CardNumber == textBox6.Text) { isLoginExhist = true; } } if (!Regex.IsMatch(textBox1.Text, phoneNumberPattern)) { MessageBox.Show("Incorect form of phone number", "Sign up error"); return; } if (!Regex.IsMatch(textBox6.Text, loginPattern)) { MessageBox.Show("Invalid readers card identification", "Sign up error"); return; } if (isLoginExhist) { MessageBox.Show("This readers card is already registered", "Sign up error"); return; } if (textBox3.Text != textBox4.Text) { MessageBox.Show("Passwords aren`t matches", "Sign up error"); isPasswordMatches = false; return; } if (isLoginExhist == false && isPasswordMatches == true && Regex.IsMatch(textBox6.Text, loginPattern)) { reader.Name = textBox2.Text; reader.PhoneNumber = textBox1.Text; DateTime birthDate = DateTime.Parse(comboBoxDate.Text + " " + comboBoxMonth.Text + " " + comboBoxYear.Text); reader.BirthDate = birthDate; reader.CardNumber = textBox6.Text; reader.Password = textBox4.Text; reader.DateOfSigningIn = DateTime.Now; dbContext.Readers.Add(reader); dbContext.SaveChanges(); textBox2.Clear(); textBox1.Clear(); textBox6.Clear(); textBox4.Clear(); textBox3.Clear(); MessageBox.Show("You were registered successfully", "Congratulations!", MessageBoxButtons.OK); } } }
private void ViewAllButton_Click(object sender, EventArgs e) { using (LibraryDBEntities dbContext = new LibraryDBEntities()) { List <Book> books = dbContext.Books.ToList(); SearchResultGrid.DataSource = books; int cellcount = SearchResultGrid.ColumnCount - 1; SearchResultGrid.Columns.Remove(SearchResultGrid.Columns[cellcount]); } }
public ScheduleWindow() { InitializeComponent(); using (LibraryDBEntities dbContext = new LibraryDBEntities()) { foreach (Schedule schedule in dbContext.Schedules) { foreach (Employee employee in dbContext.Employees) { if (employee.Employee_Id == schedule.Employee_Id) { ScheduleGridView.Rows.Add(schedule.DayName, employee.Name, schedule.WorkTime, schedule.Day_Id); } } } } }
private void FindPersoneButton_Click(object sender, EventArgs e) { using (LibraryDBEntities dbContext = new LibraryDBEntities()) { if (ReaderRadioButton.Checked) { ReaderGridView.Rows.Clear(); foreach (Reader reader in dbContext.Readers) { if (UpdateLoginTextbox.Text == null || UpdateLoginTextbox.Text.Trim().Length == 0) { return; } if (reader.CardNumber.Contains(UpdateLoginTextbox.Text)) { ReaderGridView.Rows.Add(reader.Name, reader.PhoneNumber, reader.CardNumber, reader.BirthDate.ToShortDateString(), reader.DateOfSigningIn.ToShortDateString()); } } } if (LibrarianRadioButton.Checked) { LibrarianGridView.Rows.Clear(); foreach (Employee employee in dbContext.Employees) { if (UpdateLoginTextbox.Text == null || UpdateLoginTextbox.Text.Trim().Length == 0) { return; } if (employee.Login.Contains(UpdateLoginTextbox.Text)) { string position = "Unknown"; switch (employee.Job_Id) { case 1: position = "Head Librarian"; break; case 2: position = "Librarian"; break; } LibrarianGridView.Rows.Add(employee.Name, employee.Login, employee.PhoneNumber, employee.BirthDate.ToShortDateString(), employee.HireDate.ToShortDateString(), position, employee.Salary); } } } } }
private void ChangeWInfoButton_Click(object sender, EventArgs e) { bool isChanged = false; string newName = ChangeWNameTextbox.Text; string newPhone = ChangeWPhoneTextbox.Text; DateTime newBirthDate = DateTime.Parse(ChangeWDateBox.Text + " " + ChangeWMonthBox.Text + " " + ChangeWYearBox.Text); string phoneNumberPattern = @"[+]{1}\b\d{12}\b"; using (LibraryDBEntities dbContext = new LibraryDBEntities()) { Employee employee = dbContext.Employees.SingleOrDefault(w => w.Employee_Id == ActiveUserId); if (employee != null) { if (newName != null && newName.Trim().Length > 0) { employee.Name = newName; } if (newPhone != null && newPhone.Trim().Length > 0) { if (Regex.IsMatch(newPhone, phoneNumberPattern)) { employee.PhoneNumber = newPhone; } else { MessageBox.Show("Incorrect form of phone number", "Error"); return; } } if (newBirthDate != null) { employee.BirthDate = newBirthDate; } } dbContext.SaveChanges(); WorkerNameLabel.Text = employee.Name; WorkerPhoneLabel.Text = employee.PhoneNumber; WorkerBirtdateLabel.Text = "Date of birth " + employee.BirthDate.ToShortDateString(); isChanged = true; } if (isChanged) { MessageBox.Show("Information changed successfuly", "Success", MessageBoxButtons.OK); } ChangeWNameTextbox.Clear(); ChangeWPhoneTextbox.Clear(); }
private void EditScheduleButton_Click(object sender, EventArgs e) { bool isChanged = false; if (ScheduleGridView.SelectedRows.Count == 0) { return; } if (WorkersComboBox.Text.Trim().Length == 0 || WorkersComboBox.Text == null) { return; } if (WorkTimeTextbox.Text.Trim().Length == 0 || WorkTimeTextbox.Text == null) { return; } using (LibraryDBEntities dbContext = new LibraryDBEntities()) { int day_IdCell = ScheduleGridView.ColumnCount - 1; int name_Cell = ScheduleGridView.ColumnCount - 3; int day_Id = Convert.ToInt32(ScheduleGridView.SelectedRows[0].Cells[day_IdCell].Value); string[] arr = WorkersComboBox.Text.Split('-'); int workerID = Convert.ToInt32(arr[0].Trim()); Schedule day = dbContext.Schedules.SingleOrDefault(d => d.Day_Id == day_Id); foreach (Employee employee in dbContext.Employees) { if (employee.Employee_Id == workerID) { day.Employee_Id = workerID; day.WorkTime = WorkTimeTextbox.Text; } } dbContext.SaveChanges(); isChanged = true; Employee newScheduleLibrarian = dbContext.Employees.SingleOrDefault(w => w.Employee_Id == workerID); ScheduleGridView.SelectedRows[0].Cells[name_Cell].Value = newScheduleLibrarian.Name; ScheduleGridView.SelectedRows[0].Cells[name_Cell + 1].Value = WorkTimeTextbox.Text; ScheduleGridView.Refresh(); if (isChanged) { MessageBox.Show("Schedule was edited", "Success", MessageBoxButtons.OK); } } }
private void ChangeInfoButton_Click(object sender, EventArgs e) { bool isChanged = false; string newName = ChangeNameTextbox.Text; string newPhoneNumber = ChangePhonetextbox.Text; DateTime newBirthDate = DateTime.Parse(ChangeDateBox.Text + " " + ChangeMonthBox.Text + " " + ChangeYearBox.Text); string phoneNumberPattern = @"[+]{1}\b\d{12}\b"; using (LibraryDBEntities dbContext = new LibraryDBEntities()) { Reader reader = dbContext.Readers.SingleOrDefault(r => r.Reader_Id == ActiveUserId); if (reader != null) { if (newName != null && newName.Trim().Length > 0) { reader.Name = newName; } if (newPhoneNumber != null && newPhoneNumber.Trim().Length > 0 && Regex.IsMatch(newPhoneNumber, phoneNumberPattern)) { reader.PhoneNumber = newPhoneNumber; } else { MessageBox.Show("Incorect form of phone number", "Error"); return; } if (newBirthDate != null) { reader.BirthDate = newBirthDate; } } dbContext.SaveChanges(); NameLabel.Text = reader.Name; PhoneNumberLabel.Text = reader.PhoneNumber; BirthDateLabel.Text = "Date of birth " + reader.BirthDate.ToShortDateString(); isChanged = true; } if (isChanged) { MessageBox.Show("Information changed successfuly", "Success", MessageBoxButtons.OK); } ChangeNameTextbox.Clear(); ChangePhonetextbox.Clear(); }
private void ShowMyBooksButton_Click(object sender, EventArgs e) { UsersBooksGrid.Rows.Clear(); using (LibraryDBEntities dbContext = new LibraryDBEntities()) { List <ReaderOrder> readerOrders = new List <ReaderOrder>(); foreach (ReaderOrder order in dbContext.ReaderOrders) { if (order.Reader_Id == ActiveUserId) { readerOrders.Add(order); } } List <Order> orders = new List <Order>(); foreach (ReaderOrder readerOrder in readerOrders) { foreach (Order order in dbContext.Orders) { if (readerOrder.Order_Id == order.ReaderOrder_Id) { TimeSpan expireTime = DateTime.Now - order.OrderDate; if (expireTime.Days > 14 && order.IsReturned == false) { order.IsExpired = true; } orders.Add(order); } } } dbContext.SaveChanges(); foreach (Order order in orders) { foreach (Book book in dbContext.Books) { if (order.Book_Id == book.Book_Id) { UsersBooksGrid.Rows.Add(book.Name, book.Autor, book.Genre, order.OrderDate.ToShortDateString(), order.IsExpired, order.IsReturned); } } } } }
private void SearchBooksButton_Click(object sender, EventArgs e) { List <Book> searchedBooks = new List <Book>(); using (LibraryDBEntities dbContext = new LibraryDBEntities()) { List <Book> books = dbContext.Books.ToList(); foreach (var book in books) { if ((book.Name.Contains(BookNameTextBox.Text) && BookNameTextBox.Text != null && BookNameTextBox.Text != "") || (book.Autor.Contains(BookAutorTextBox.Text) && BookAutorTextBox.Text != null && BookAutorTextBox.Text != "") || (book.Genre.Contains(BookGenreTextBox.Text)) && BookGenreTextBox.Text != null && BookGenreTextBox.Text != "") { searchedBooks.Add(book); } } } SearchResultGrid.DataSource = searchedBooks; int cellcount = SearchResultGrid.ColumnCount - 1; SearchResultGrid.Columns.Remove(SearchResultGrid.Columns[cellcount]); }
private void RemoveBookButton_Click(object sender, EventArgs e) { if (BooksToEditGrid.SelectedRows.Count == 0) { return; } using (LibraryDBEntities dBContext = new LibraryDBEntities()) { List <Book> books = dBContext.Books.ToList(); int id = Convert.ToInt32(BooksToEditGrid.SelectedRows[0].Cells[5].Value); foreach (Book book in books) { if (book.Book_Id == id) { dBContext.Books.Remove(book); } } dBContext.SaveChanges(); DataGridViewRow rowToDelete = BooksToEditGrid.SelectedRows[0]; BooksToEditGrid.Rows.Remove(rowToDelete); BooksToEditGrid.ClearSelection(); } }
private void MarkAsReadButton_Click(object sender, EventArgs e) { if (OrdersViewGrid.SelectedRows.Count == 0) { return; } int itemCell = OrdersViewGrid.ColumnCount - 1; int bookId = Convert.ToInt32(OrdersViewGrid.SelectedRows[0].Cells[itemCell].Value); using (LibraryDBEntities dbContext = new LibraryDBEntities()) { foreach (Order order in dbContext.Orders) { if (order.LineItem == bookId) { order.IsReturned = true; } } dbContext.SaveChanges(); OrdersViewGrid.SelectedRows[0].Cells[itemCell - 1].Value = true; OrdersViewGrid.Refresh(); } }
private void button1_Click(object sender, EventArgs e) { using (LibraryDBEntities dbContext = new LibraryDBEntities()) { List <Reader> readers = dbContext.Readers.ToList(); List <Employee> employees = dbContext.Employees.ToList(); Employee currentEmployee = null; Reader currentReader = null; if (!checkBox3.Checked) { foreach (Reader reader in readers) { if (textBox2.Text == reader.CardNumber && textBox1.Text == reader.Password) { currentReader = reader; } } } if (checkBox3.Checked) { foreach (Employee employee in employees) { if (textBox2.Text == employee.Login && textBox1.Text == employee.Password) { currentEmployee = employee; } } } if (currentReader != null) { User user = new User(); user.UsersNameLable.Text = currentReader.Name; User.ActiveUserId = currentReader.Reader_Id; user.UsersCardNumberLable.Text = "Readers card number: " + currentReader.CardNumber; user.NameLabel.Text = currentReader.Name; user.CardNumberLabel.Text = currentReader.CardNumber; user.PhoneNumberLabel.Text = currentReader.PhoneNumber; user.BirthDateLabel.Text = "Date of birth " + currentReader.BirthDate.ToShortDateString(); user.DateOfSignupLabel.Text = "Date of Sign up " + currentReader.DateOfSigningIn.ToShortDateString(); user.StatusLabel.Text = "Reader"; user.ChangeDateBox.Text = currentReader.BirthDate.Day.ToString(); user.ChangeMonthBox.Text = currentReader.BirthDate.Month.ToString(); user.ChangeYearBox.Text = currentReader.BirthDate.Year.ToString(); for (int i = 0; i < 4; i++) { TabPage pageToDelete = user.MyCabinetPage.TabPages[2]; user.MyCabinetPage.TabPages.Remove(pageToDelete); } user.Show(); this.Hide(); } else if (!checkBox3.Checked) { MessageBox.Show("Such reader does not exhist", "Reader not found"); } else if (currentEmployee != null) { User user = new User(); user.UsersNameLable.Text = currentEmployee.Name; if (currentEmployee.Job_Id == 2) { user.UsersCardNumberLable.Text = "Librarian"; } if (currentEmployee.Job_Id == 1) { user.UsersCardNumberLable.Text = "Head Librarian"; } User.ActiveUserId = currentEmployee.Employee_Id; user.WorkerNameLabel.Text = currentEmployee.Name; user.WorkerPhoneLabel.Text = currentEmployee.PhoneNumber; if (currentEmployee.Job_Id == 2) { user.WorkerStatusLabel.Text = "Librarian"; } if (currentEmployee.Job_Id == 1) { user.WorkerStatusLabel.Text = "Head Librarian"; } user.WorkerBirtdateLabel.Text = "Date of birth " + currentEmployee.BirthDate.ToShortDateString(); user.WorkerHiredateLabel.Text = "Hired " + currentEmployee.HireDate.ToShortDateString(); user.ChangeWDateBox.Text = currentEmployee.BirthDate.Day.ToString(); user.ChangeWMonthBox.Text = currentEmployee.BirthDate.Month.ToString(); user.ChangeWYearBox.Text = currentEmployee.BirthDate.Year.ToString(); TabPage pageToDelete1 = user.MyCabinetPage.TabPages[1]; user.MyCabinetPage.TabPages.Remove(pageToDelete1); if (currentEmployee.Job_Id == 2) { for (int i = 0; i < 3; i++) { TabPage pageToDelete = user.MyCabinetPage.TabPages[2]; user.MyCabinetPage.TabPages.Remove(pageToDelete); } } user.AddToListButton.Enabled = false; user.RemoveFromListButton.Enabled = false; user.SendOrderButton.Enabled = false; user.OrderListGrid.Enabled = false; user.label3.Enabled = false; user.Show(); this.Hide(); } else { MessageBox.Show("Such worker does not exhist", "Worker not found"); } } }
private void ChangePersonInfoButton_Click(object sender, EventArgs e) { bool isChanged = false; using (LibraryDBEntities dbContext = new LibraryDBEntities()) { if (ReaderRadioButton.Checked) { if (ReaderGridView.SelectedRows.Count == 0) { return; } string cardNumber = ReaderGridView.SelectedRows[0].Cells[2].Value.ToString(); string loginPattern = @"[A-Z]{2}[-]{1}\b\d{6}\b"; if (!Regex.IsMatch(UpdateLoginTextbox.Text, loginPattern)) { MessageBox.Show("Invalid readers card identification", "Sign up error"); return; } foreach (Reader readerOld in dbContext.Readers) { if (readerOld.CardNumber == UpdateLoginTextbox.Text) { MessageBox.Show("Such card already registered", "Error", MessageBoxButtons.OK); return; } } Reader reader = dbContext.Readers.SingleOrDefault(r => r.CardNumber == cardNumber); if (reader != null) { reader.CardNumber = UpdateLoginTextbox.Text; dbContext.SaveChanges(); isChanged = true; } ReaderGridView.SelectedRows[0].Cells[2].Value = UpdateLoginTextbox.Text; ReaderGridView.Refresh(); if (isChanged) { MessageBox.Show("Login changed successfuly", "Success", MessageBoxButtons.OK); } UpdateLoginTextbox.Clear(); } if (LibrarianRadioButton.Checked) { if (LibrarianGridView.SelectedRows.Count == 0) { return; } string contractNumber = LibrarianGridView.SelectedRows[0].Cells[1].Value.ToString(); foreach (Employee employeeOld in dbContext.Employees) { if (employeeOld.Login == UpdateLoginTextbox.Text) { MessageBox.Show("Such contract already registered", "Error", MessageBoxButtons.OK); return; } } Employee employee = dbContext.Employees.SingleOrDefault(emp => emp.Login == contractNumber); if (employee != null) { if (UpdateSalaryTextbox.Text != null && UpdateSalaryTextbox.Text.Trim().Length > 0) { Job job = dbContext.Jobs.SingleOrDefault(j => j.Job_Id == 2); if (Convert.ToInt32(UpdateSalaryTextbox.Text) < job.Min_Salary) { MessageBox.Show("Sallary is too small", "Error", MessageBoxButtons.OK); return; } else if (Convert.ToInt32(UpdateSalaryTextbox.Text) > job.Max_Salary) { MessageBox.Show("Sallary is too big", "Error", MessageBoxButtons.OK); return; } else { employee.Salary = Convert.ToInt32(UpdateSalaryTextbox.Text); LibrarianGridView.SelectedRows[0].Cells[6].Value = UpdateSalaryTextbox.Text; dbContext.SaveChanges(); } } if (UpdateLoginTextbox.Text == null || UpdateLoginTextbox.Text.Trim().Length == 0) { return; } employee.Login = UpdateLoginTextbox.Text; LibrarianGridView.SelectedRows[0].Cells[1].Value = UpdateLoginTextbox.Text; dbContext.SaveChanges(); isChanged = true; LibrarianGridView.Refresh(); if (isChanged) { MessageBox.Show("Information changed successfuly", "Success", MessageBoxButtons.OK); } UpdateSalaryTextbox.Clear(); UpdateLoginTextbox.Clear(); } } } }
private void NewWorkerAddButton_Click(object sender, EventArgs e) { bool IsNameOk = false; bool IsPhoneOk = false; bool IsContractOk = false; bool IsSalaryOk = false; int num; string newLibrarianName = LibrarianFullNameTextbox.Text; string newLibrarianPhone = PhoneNumberTextbox.Text; string phoneNumberPattern = @"[+]{1}\b\d{12}\b"; DateTime newLibrarianBirthDate = DateTime.Parse(DayCombobox.Text + " " + MonthCombobox.Text + " " + YearCombobox.Text); string newLibrarianContractNumber = ContractNumberTextbox.Text; string newLibrarianSalary = SalaryTextbox.Text; using (LibraryDBEntities dbContext = new LibraryDBEntities()) { Employee employee = new Employee(); Job job = dbContext.Jobs.SingleOrDefault(j => j.Job_Id == 2); if (newLibrarianName != null && newLibrarianName.Trim().Length > 0) { employee.Name = newLibrarianName; IsNameOk = true; } if (newLibrarianPhone != null && newLibrarianPhone.Trim().Length > 0) { if (!Regex.IsMatch(newLibrarianPhone, phoneNumberPattern)) { MessageBox.Show("Wrong mobile phone number", "Error", MessageBoxButtons.OK); return; } employee.PhoneNumber = newLibrarianPhone; IsPhoneOk = true; } if (newLibrarianContractNumber != null && newLibrarianContractNumber.Trim().Length > 0) { Employee employExist = dbContext.Employees.SingleOrDefault(emp => emp.Login == newLibrarianContractNumber); if (employExist == null) { employee.Login = newLibrarianContractNumber; IsContractOk = true; } else { MessageBox.Show("Such contract is already registered", "Error", MessageBoxButtons.OK); return; } } if (newLibrarianSalary != null && newLibrarianSalary.Trim().Length > 0) { if (!int.TryParse(newLibrarianSalary, out num)) { MessageBox.Show("Wrong characters in 'Salary' field", "Error", MessageBoxButtons.OK); return; } if (Convert.ToInt32(newLibrarianSalary) < job.Min_Salary) { MessageBox.Show("Sallary is too small", "Error", MessageBoxButtons.OK); return; } else if (Convert.ToInt32(newLibrarianSalary) > job.Max_Salary) { MessageBox.Show("Sallary is too big", "Error", MessageBoxButtons.OK); return; } else { employee.Salary = Convert.ToInt32(newLibrarianSalary); IsSalaryOk = true; } } if (!(IsNameOk && IsPhoneOk && IsContractOk && IsSalaryOk)) { MessageBox.Show("Some fields are empty. Please check your information", "Error", MessageBoxButtons.OK); return; } employee.BirthDate = newLibrarianBirthDate; employee.HireDate = DateTime.Now; employee.Job_Id = 2; employee.Password = "******"; dbContext.Employees.Add(employee); dbContext.SaveChanges(); LibrarianFullNameTextbox.Clear(); PhoneNumberTextbox.Clear(); ContractNumberTextbox.Clear(); SalaryTextbox.Clear(); MessageBox.Show("New Librarian added", "Error", MessageBoxButtons.OK); } }
private void UpdateBookButton_Click(object sender, EventArgs e) { bool isChanged = false; string newBookTitle = EditBookTitleTextbox.Text; string newBookAutor = EditAutorTextbox.Text; string newBookGenre = EditGenreTextbox.Text; string newBookYear = EditYearTextbox.Text; string newBookPublication = EditPublicationTextbox.Text; using (LibraryDBEntities dbContex = new LibraryDBEntities()) { if (BooksToEditGrid.SelectedRows.Count == 0) { return; } int id = Convert.ToInt32(BooksToEditGrid.SelectedRows[0].Cells[5].Value); Book book = dbContex.Books.SingleOrDefault(b => b.Book_Id == id); if (book != null) { if (newBookTitle != null && newBookTitle.Trim().Length > 0) { book.Name = newBookTitle; BooksToEditGrid.SelectedRows[0].Cells[0].Value = newBookTitle; } if (newBookAutor != null && newBookAutor.Trim().Length > 0) { book.Autor = newBookAutor; BooksToEditGrid.SelectedRows[0].Cells[1].Value = newBookAutor; } if (newBookGenre != null && newBookGenre.Trim().Length > 0) { book.Genre = newBookGenre; BooksToEditGrid.SelectedRows[0].Cells[2].Value = newBookGenre; } if (newBookYear != null && newBookYear.Trim().Length > 0) { int num; if (!int.TryParse(EditYearTextbox.Text, out num)) { MessageBox.Show("Incorrect year!", "Error"); return; } book.Year = newBookYear; BooksToEditGrid.SelectedRows[0].Cells[3].Value = newBookYear; } if (newBookPublication != null && newBookPublication.Trim().Length > 0) { book.Publication = newBookPublication; BooksToEditGrid.SelectedRows[0].Cells[4].Value = newBookPublication; } isChanged = true; dbContex.SaveChanges(); } BooksToEditGrid.Refresh(); EditBookTitleTextbox.Clear(); EditAutorTextbox.Clear(); EditGenreTextbox.Clear(); EditYearTextbox.Clear(); EditPublicationTextbox.Clear(); if (isChanged) { MessageBox.Show("Information changed successfuly", "Success", MessageBoxButtons.OK); } } }
private void ShowOrderButton_Click(object sender, EventArgs e) { OrdersViewGrid.Rows.Clear(); using (LibraryDBEntities dbContext = new LibraryDBEntities()) { List <ReaderOrder> readerOrders = new List <ReaderOrder>(); int num; if (OrderIDTextbox.Text != null && OrderIDTextbox.Text.Trim().Length > 0 && int.TryParse(OrderIDTextbox.Text, out num)) { foreach (ReaderOrder readerOrder in dbContext.ReaderOrders) { if (readerOrder.Order_Id == Convert.ToInt32(OrderIDTextbox.Text)) { readerOrders.Add(readerOrder); } } } else if (OrderIDTextbox.Text == null || OrderIDTextbox.Text.Trim().Length == 0) { foreach (ReaderOrder readerOrder in dbContext.ReaderOrders) { readerOrders.Add(readerOrder); } } List <Order> orders = new List <Order>(); foreach (ReaderOrder readerOrder in readerOrders) { foreach (Order order in dbContext.Orders) { if (readerOrder.Order_Id == order.ReaderOrder_Id) { TimeSpan expireTime = DateTime.Now - order.OrderDate; if (expireTime.Days > 14 && order.IsReturned == false) { order.IsExpired = true; } orders.Add(order); } } } dbContext.SaveChanges(); foreach (Order order in orders) { foreach (Book book in dbContext.Books) { if (order.Book_Id == book.Book_Id) { foreach (ReaderOrder readerOrder in readerOrders) { if (readerOrder.Order_Id == order.ReaderOrder_Id) { foreach (Reader reader in dbContext.Readers) { if (readerOrder.Reader_Id == reader.Reader_Id) { OrdersViewGrid.Rows.Add(order.ReaderOrder_Id, reader.Name, reader.CardNumber, book.Name, book.Autor, order.OrderDate.ToShortDateString(), order.IsExpired, order.IsReturned, order.LineItem); } } } } } } } } }