Exemplo n.º 1
0
 private void contextEdit_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedIndex == 2)
     {
         var entity = grdBooks2.SelectedRows.Count > 0 ? grdBooks2.SelectedRows[0].DataBoundItem as Book : null;
         if (entity == null)
         {
             MessageBox.Show("Книга для редактирования не выбрана");
         }
         else
         {
             var form = new FormBook(entity);
             if (form.ShowDialog() == DialogResult.OK)
             {
                 Book.Save();
                 RefreshBooks();
                 SelectFirstRent();
             }
         }
     }
     else if (tabControl1.SelectedIndex == 3)
     {
         var entity = grdReaders.SelectedRows.Count > 0 ? grdReaders.SelectedRows[0].DataBoundItem as Reader : null;
         if (entity == null)
         {
             MessageBox.Show("Читатель для редактирования не выбран");
         }
         else
         {
             var form = new FormReader(entity);
             if (form.ShowDialog() == DialogResult.OK)
             {
                 Reader.Save();
                 RefreshReaders();
                 SelectFirstRent();
             }
         }
     }
     else if (tabControl1.SelectedIndex == 4)
     {
         var entity = grdLibrarians.SelectedRows.Count > 0 ? grdLibrarians.SelectedRows[0].DataBoundItem as Librarian : null;
         if (entity == null)
         {
             MessageBox.Show("Библиотекарь для редактирования не выбран");
         }
         else
         {
             var form = new FormLibrarian(entity);
             if (form.ShowDialog() == DialogResult.OK)
             {
                 Librarian.Save();
                 RefreshLibrarians();
                 SelectFirstRent();
             }
         }
     }
 }
Exemplo n.º 2
0
 private void contextAdd_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedIndex == 2)
     {
         var entity = new Book();
         var form   = new FormBook(entity);
         if (form.ShowDialog() == DialogResult.OK)
         {
             Book.Data.Add(entity);
             Book.Save();
             RefreshBooks();
             UpdateForm();
         }
     }
     else if (tabControl1.SelectedIndex == 3)
     {
         var entity = new Reader();
         var form   = new FormReader(entity);
         if (form.ShowDialog() == DialogResult.OK)
         {
             Reader.Data.Add(entity);
             Reader.Save();
             RefreshReaders();
             UpdateForm();
         }
     }
     else if (tabControl1.SelectedIndex == 4)
     {
         var entity = new Librarian();
         var form   = new FormLibrarian(entity);
         if (form.ShowDialog() == DialogResult.OK)
         {
             Librarian.Data.Add(entity);
             Librarian.Save();
             RefreshLibrarians();
             UpdateForm();
         }
     }
 }