private void buttonDelete_Click(object sender, EventArgs e)
 {
     using (KochkaDBEntities1 ct = new KochkaDBEntities1())
     {
         var item = ct.Employees.FirstOrDefault(x => x.ServiceNumber.ToString() == labelTabel.Text);
         ct.Employees.Remove(item);
         ct.SaveChanges();
         buttonDelete.Text    = "Удалено!";
         buttonDelete.Enabled = false;
     }
 }
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     if (buttonEdit.Text == "Изменить")
     {
         foreach (Control c in Controls)
         {
             if (c is TextBox t)
             {
                 t.Visible  = true;
                 t.ReadOnly = false;
             }
         }
         buttonEdit.Text = "Сохранить";
     }
     else
     {
         foreach (Control c in Controls)
         {
             if (c is TextBox t)
             {
                 t.Visible  = false;
                 t.ReadOnly = true;
             }
         }
         if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
         {
             return;
         }
         labelFIO.Text        = textBox1.Text;
         labelClubNumber.Text = textBox2.Text;
         labelExp.Text        = textBox3.Text;
         labelPosition.Text   = textBox4.Text;
         using (KochkaDBEntities1 ct = new KochkaDBEntities1())
         {
             Employee empl = ct.Employees.FirstOrDefault(x => x.ServiceNumber.ToString() == labelTabel.Text);
             if (empl != null)
             {
                 empl.EmplyeeSecondName = labelFIO.Text.Split(' ')[0];
                 empl.EmplyeeName       = labelFIO.Text.Split(' ')[1];
                 if (labelFIO.Text.Split(' ').Length > 2)
                 {
                     empl.EmplyeeMiddleName = labelFIO.Text.Split(' ')[2];
                 }
                 empl.Name = labelPosition.Text;
                 ct.SaveChanges();
             }
         }
         buttonEdit.Text = "Изменить";
     }
 }
Exemple #3
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            using (KochkaDBEntities1 ct = new KochkaDBEntities1())
            {
                Employee em = new Employee()
                {
                    EmplyeeSecondName = textBox1.Text.Split(' ')[0],
                    EmplyeeName       = textBox1.Text.Split(' ')[1],
                    EmplyeeMiddleName = (textBox1.Text.Split(' ').Length > 2) ? textBox1.Text.Split(' ')[2] : null,
                    Experience        = Convert.ToInt32(textBox3.Text),
                    NumberOfClub      = Convert.ToInt32(textBox2.Text),
                    Name = textBox4.Text
                };
                em.ServiceNumber = ct.Employees.Where(x => x.NumberOfClub == em.NumberOfClub).Count();
                var item = ct.Clubs.FirstOrDefault(x => x.NumberOfClub == em.NumberOfClub);//типа триггер
                if (item == null)
                {
                    return;
                }
                var item2 = ct.Positions.FirstOrDefault(x => x.Name == em.Name);
                if (item2 == null)
                {
                    return;
                }

                ct.Employees.Add(em);
                ct.SaveChanges();
            }
            buttonAdd.Text = "Добавлено!";
            foreach (Control c in Controls)
            {
                if (c is TextBox t)
                {
                    t.Text = "";
                }
            }
            buttonAdd.Enabled = false;
        }