Beispiel #1
0
 public EditCar(int id)
 {
     InitializeComponent();
     using (CWMEntities cwm = new CWMEntities(EnCon))
     {
         var r = (from p in cwm.CAR
                  where p.ID == id
                  select p).First();
         textBox1.Text = ((CAR)r).CNAME;
         car           = new CAR();
         car.ID        = ((CAR)r).ID;
         car.CNAME     = ((CAR)r).CNAME;
         car.IDCLASS   = ((CAR)r).IDCLASS;
         if (car.IDCLASS == 1)
         {
             radioButton1.Checked = true;
         }
         if (car.IDCLASS == 2)
         {
             radioButton2.Checked = true;
         }
         if (car.IDCLASS == 3)
         {
             radioButton3.Checked = true;
         }
         if (car.IDCLASS == 4)
         {
             radioButton4.Checked = true;
         }
         if (car.IDCLASS == 5)
         {
             radioButton5.Checked = true;
         }
     }
 }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Введите название автомобиля!");
                return;
            }
            CAR e1 = new CAR();

            e1.CNAME = textBox1.Text;
            if (radioButton1.Checked)
            {
                e1.IDCLASS = 1;
            }
            if (radioButton2.Checked)
            {
                e1.IDCLASS = 2;
            }
            if (radioButton3.Checked)
            {
                e1.IDCLASS = 3;
            }
            if (radioButton4.Checked)
            {
                e1.IDCLASS = 4;
            }
            if (radioButton5.Checked)
            {
                e1.IDCLASS = 5;
            }

            try
            {
                using (CWMEntities cwm = new CWMEntities(EnCon))
                {
                    cwm.AddToCAR(e1);
                    cwm.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка при добавлении автомобиля!", ex.Message);
                return;
            }
            MessageBox.Show("Автомобиль успешно добавлен!");
            Close();
        }