Esempio n. 1
0
        public void EditData()
        {
            if (edit.textBoxNameEdit.Text == null || edit.textBoxAuthorEdit.Text == null ||
                edit.textBoxNameEdit.Text.Equals("") || edit.textBoxAuthorEdit.Text.Equals(""))
            {
                MessageBox.Show("Поля \"Назва\" та \"Автор\" повинні бути заповнені");
                return;
            }
            try
            {
                int    id          = Convert.ToInt32(edit.textBoxIdEdit.Text.ToString());
                string name        = edit.textBoxNameEdit.Text.ToString();
                string author      = edit.textBoxAuthorEdit.Text.ToString();
                int    yearOfBook  = Convert.ToInt32(edit.textBoxYearEdit.Text.ToString());
                int    location    = Convert.ToInt32(edit.textBoxLocationEdit.Text.ToString());
                Book   currentBook = new TSPP2.model.Book(id, author, yearOfBook, name, location);
                Remover();

                model.Add(currentBook);
                edit.Visible        = false;
                libraryForm.Visible = true;
                libraryForm.dataGridView1.Rows.Insert(libraryForm.dataGridView1.SelectedRows[0].Index,
                                                      id, name,
                                                      author, yearOfBook, location);
                libraryForm.dataGridView1.Rows.RemoveAt(libraryForm.dataGridView1.SelectedRows[0].Index);

                edit.Visible        = false;
                libraryForm.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Помилки при введенні даних ");
            }
        }
Esempio n. 2
0
 public void AddBook()
 {
     if (addForm.textBoxNameAdd.Text == null || addForm.textBoxAuthorAdd.Text == null ||
         addForm.textBoxNameAdd.Text.Equals("") || addForm.textBoxAuthorAdd.Text.Equals(""))
     {
         MessageBox.Show("Поля \"Назва\" та \"Автор\" повинні бути заповнені.");
         return;
     }
     try
     {
         int    id          = Convert.ToInt32(addForm.textBoxIdAdd.Text.ToString());
         string name        = addForm.textBoxNameAdd.Text.ToString();
         string author      = addForm.textBoxAuthorAdd.Text.ToString();
         int    yearOfBook  = Convert.ToInt32(addForm.textBoxYearAdd.Text.ToString());
         int    location    = Convert.ToInt32(addForm.textBoxLocationAdd.Text.ToString());
         Book   currentBook = new TSPP2.model.Book(id, author, yearOfBook, name, location);
         model.Add(currentBook);
         if (libraryForm.dataGridView1.Rows.Count < 10)
         {
             int remainingCount = 10 - libraryForm.dataGridView1.Rows.Count;
             MessageBox.Show("Кількість записів повинна бути більше 10. Додайте ще " + remainingCount + " записів.");
             libraryForm.dataGridView1.Rows.Add(currentBook.Id, currentBook.Name, currentBook.Author, currentBook.YearOfBook, currentBook.Location);
             return;
         }
         addForm.Visible     = false;
         libraryForm.Visible = true;
         libraryForm.dataGridView1.Rows.Add(currentBook.Id, currentBook.Name, currentBook.Author, currentBook.YearOfBook, currentBook.Location);
     }
     catch
     {
         MessageBox.Show("Помилкa при введенні даних.");
     }
 }