private void addRecordButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (choose == 0)
         {
             var editform = new Edit(null, connectionString);
             editform.FormClosed += Edit_FormClosed;
             editform.ShowDialog(this);
         }
         if (choose == 1)
         {
             Author a    = null;
             var    form = new Table(a, connectionString);
             form.FormClosed += Edit_FormClosed;
             form.ShowDialog(this);
             choose = 0;
         }
         if (choose == 2)
         {
             StatusSight a    = null;
             var         form = new Table(a, connectionString);
             form.FormClosed += Edit_FormClosed;
             form.ShowDialog(this);
             choose = 0;
         }
         if (choose == 3)
         {
             TransportStop a    = null;
             var           form = new Table(a, connectionString);
             form.FormClosed += Edit_FormClosed;
             form.ShowDialog(this);
             choose = 0;
         }
         if (choose == 4)
         {
             Category a    = null;
             var      form = new Table(a, connectionString);
             form.FormClosed += Edit_FormClosed;
             form.ShowDialog(this);
             choose = 0;
         }
         if (choose == 5)
         {
             KindOfTransport a    = null;
             var             form = new Table(a, connectionString);
             form.FormClosed += Edit_FormClosed;
             form.ShowDialog(this);
             choose = 0;
         }
     }
     catch (DbUpdateException)
     {
         MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
     }
 }
 public Table(KindOfTransport kt, string con, bool view = false)
 {
     try
     {
         if (!view)
         {
             if (kt == null)
             {
                 kintr            = new KindOfTransport();
                 choose           = 5;
                 connectionString = con;
                 InitializeComponent();
                 this.Text            = "Создание";
                 HeaderLabel.Text     = "Вид транспорта";
                 DeleteButton.Visible = false;
                 NoVisible();
             }
             else
             {
                 kintr            = kt;
                 choose           = 5;
                 connectionString = con;
                 InitializeComponent();
                 this.Text        = "Изменение";
                 HeaderLabel.Text = "Вид транспорта";
                 NameTextBox.Text = kt.NameKind;
                 NoVisible();
             }
         }
         else
         {
             kintr            = kt;
             choose           = 5;
             connectionString = con;
             InitializeComponent();
             this.Text                = "Просмотр";
             HeaderLabel.Text         = "Вид транспорта";
             NameTextBox.Text         = kt.NameKind;
             NameTextBox.Enabled      = false;
             DeleteButton.Visible     = false;
             CreateEditButton.Visible = false;
             NoVisible();
         }
     }
     catch (DbUpdateException)
     {
         MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
     }
 }
 private void CreateEditButton_Click(object sender, EventArgs e)
 {
     try
     {
         using (SightOfOneCityEntities context = new SightOfOneCityEntities(connectionString))
         {
             if (ChekField())
             {
                 if (this.Text == "Изменение")
                 {
                     if (choose == 1)
                     {
                         Author a = context.Author.Find(auth.ID);
                         a.FamilyAuthor     = FamilyTextBox.Text;
                         a.NameAuthor       = NameTextBox.Text;
                         a.PatronymicAuthor = PatronymicTextBox.Text;
                         if (ManCheckBox.Checked)
                         {
                             a.Gender = true;
                         }
                         else
                         {
                             a.Gender = false;
                         }
                         a.DateBirthday = (short)YearNumericUpDown.Value;
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 2)
                     {
                         StatusSight ss = context.StatusSight.Find(stsi.ID);
                         ss.NameStatus = NameTextBox.Text;
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 3)
                     {
                         TransportStop ts = context.TransportStop.Find(trst.ID);
                         ts.NameStop = NameTextBox.Text;
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 4)
                     {
                         Category c = context.Category.Find(cat.ID);
                         c.NameCategory = NameTextBox.Text;
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 5)
                     {
                         KindOfTransport kt = context.KindOfTransport.Find(kintr.ID);
                         kt.NameKind = NameTextBox.Text;
                         context.SaveChanges();
                         this.Close();
                     }
                 }
                 else
                 {
                     if (choose == 1)
                     {
                         context.Author.Add(new Author(auth.FamilyAuthor, auth.NameAuthor,
                                                       auth.PatronymicAuthor, auth.Gender, auth.DateBirthday));
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 2)
                     {
                         context.StatusSight.Add(new StatusSight(stsi.NameStatus));
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 3)
                     {
                         context.TransportStop.Add(new TransportStop(trst.NameStop));
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 4)
                     {
                         context.Category.Add(new Category(cat.NameCategory));
                         context.SaveChanges();
                         this.Close();
                     }
                     if (choose == 5)
                     {
                         context.KindOfTransport.Add(new KindOfTransport(kintr.NameKind));
                         context.SaveChanges();
                         this.Close();
                     }
                 }
             }
             else
             {
                 MessageBox.Show("Не все обязательные поля заполнены. Проверьте данные.", "Внимание");
             }
         }
     }
     catch (DbUpdateException)
     {
         MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
     }
 }