Exemplo n.º 1
0
 public Table(Author a, string con, bool view = false)
 {
     try
     {
         if (!view)
         {
             if (a == null)
             {
                 auth             = new Author();
                 choose           = 1;
                 connectionString = con;
                 InitializeComponent();
                 this.Text            = "Создание";
                 HeaderLabel.Text     = "Автор";
                 DeleteButton.Visible = false;
             }
             else
             {
                 auth             = a;
                 choose           = 1;
                 connectionString = con;
                 InitializeComponent();
                 this.Text               = "Изменение";
                 HeaderLabel.Text        = "Автор";
                 NameTextBox.Text        = a.NameAuthor;
                 PatronymicTextBox.Text  = a.PatronymicAuthor;
                 FamilyTextBox.Text      = a.FamilyAuthor;
                 YearNumericUpDown.Value = a.DateBirthday;
                 if (a.Gender)
                 {
                     ManCheckBox.Checked = true;
                 }
             }
         }
         else
         {
             auth             = a;
             choose           = 1;
             connectionString = con;
             InitializeComponent();
             this.Text                 = "Просмотр";
             HeaderLabel.Text          = "Автор";
             NameTextBox.Text          = a.NameAuthor;
             NameTextBox.Enabled       = false;
             PatronymicTextBox.Text    = a.PatronymicAuthor;
             PatronymicTextBox.Enabled = false;
             FamilyTextBox.Text        = a.FamilyAuthor;
             FamilyTextBox.Enabled     = false;
             YearNumericUpDown.Value   = a.DateBirthday;
             YearNumericUpDown.Enabled = false;
             if (a.Gender)
             {
                 ManCheckBox.Checked = true;
             }
             ManCheckBox.Enabled      = false;
             DeleteButton.Visible     = false;
             CreateEditButton.Visible = false;
         }
     }
     catch (DbUpdateException)
     {
         MessageBox.Show(text: "У вас нет прав на это действие.", caption: "Error", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
 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);
     }
 }