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 при введенні даних.");
     }
 }
Exemple #2
0
 private static void AddSectionIfNeed(SectionId sectionId,
                                      MainModel model,
                                      Func <DescriptionSection> sectionGetter)
 {
     if (WebSettingsConfig.Instance.IsSectionAllowed(sectionId))
     {
         model.Add(sectionId, sectionGetter());
     }
 }
 private void OnAdd()
 {
     try
     {
         ResetPairList(Model.Add(new NameValuePair {
             Name = PairName, Value = PairValue
         }));
         PairValue   = "";
         PairName    = "";
         FilterValue = "";
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
 }