Ejemplo n.º 1
0
 private void FoundUserbutton_Click(object sender, EventArgs e)
 {
     if (IDUsertextbox.Text != "")
     {
         int x = -1;
         try
         {
             x = Convert.ToInt32(IDUsertextbox.Text);
         }
         catch
         {
             MessageBox.Show("ID должен состоять только из цифр", "Неккоректный ввод", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
             IDUsertextbox.Focus();
         }
         if (x <= 0)
         {
             MessageBox.Show("ID не может быть отрицательным или равным нулю.", "Неккоректный ввод", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
             IDUsertextbox.Focus();
         }
         else
         {
             var query = from c in db.GetUsersTable()
                         where c.Id == Convert.ToInt32(IDUsertextbox.Text)
                         select c.Id;
             var a = query.FirstOrDefault();
             if (a == 0)
             {
                 MessageBox.Show("Введен не существующий ID.", "ID не найден", MessageBoxButtons.OK,
                                 MessageBoxIcon.Information);
             }
             else
             {
                 Tableindex = 1;
                 panel3.Show();
                 IDUsertextbox.Enabled = false;
                 dataGrid.DataSource   = from c in db.GetBooksTable()
                                         join author_Book in db.GetAuthor_BooksTable()
                                         on c.Id equals author_Book.IdBooks
                                         join Author in db.GetAuthorsTable()
                                         on author_Book.IdAuthors equals Author.Id
                                         where c.Id == Convert.ToInt32(IDBooktextbox.Text)
                                         select new
                 {
                     c.Id,
                     c.Title,
                     c.Genre,
                     c.Release,
                     c.Count,
                     Author.FirstName,
                     Author.LastName,
                     Current_Count = c.Count - ((from rent in db.GetRentTable()
                                                 where c.Id == rent.IdBooks
                                                 select rent.Count).Sum() ?? 0)
                 };
             }
         }
     }
     else
     {
         MessageBox.Show("Заполните поле \"ID\"", "Неккоректный ввод", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 2
0
 private void FoundUserbutton_Click(object sender, EventArgs e)
 {
     if (IDUsertextbox.Text != "")
     {
         int x = -1;
         try
         {
             x = Convert.ToInt32(IDUsertextbox.Text);
         }
         catch
         {
             MessageBox.Show("ID должен состоять только из цифр", "Неккоректный ввод", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
             IDUsertextbox.Focus();
         }
         if (x <= 0)
         {
             MessageBox.Show("ID не может быть отрицательным или равным нулю.", "Неккоректный ввод", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
             IDUsertextbox.Focus();
         }
         else
         {
             var query = from c in db.GetRentTable()
                         where c.IdUsers == x
                         select c.IdUsers;
             var a = query.FirstOrDefault();
             if (a == 0)
             {
                 MessageBox.Show("Введен не существующий ID.", "ID не найден", MessageBoxButtons.OK,
                                 MessageBoxIcon.Information);
             }
             else
             {
                 index = 0;
                 panel2.Show();
                 IDUsertextbox.Enabled   = false;
                 FoundUserbutton.Enabled = false;
                 dataGrid.DataSource     = from rent in db.GetRentTable()
                                           join book in db.GetBooksTable()
                                           on rent.IdBooks equals book.Id
                                           join staff in db.GetStaffTable()
                                           on rent.IdStaff equals staff.Id
                                           join user in db.GetUsersTable()
                                           on rent.IdUsers equals user.Id
                                           where rent.IdUsers == x
                                           select new
                 {
                     IdBook = book.Id,
                     book.Title,
                     IdUser    = user.Id,
                     UserName  = user.LastName + " " + user.FirstName,
                     IDStaff   = staff.Id,
                     StaffName = staff.LastName + " " + staff.FirstName,
                     RentCount = rent.Count,
                     IssueDate = rent.Issue,
                 };
             }
         }
     }
     else
     {
         MessageBox.Show("Заполните поле \"ID\"", "Неккоректный ввод", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
 }