Esempio n. 1
0
 private void chMarkTruckButton_Click(object sender, EventArgs e)
 {
     if (dataGridView2.SelectedRows.Count > 0)
     {
         int  index     = dataGridView2.SelectedRows[0].Index;
         int  id        = 0;
         bool converted = Int32.TryParse(dataGridView2[0, index].Value.ToString(), out id);
         if (converted == false)
         {
             return;
         }
         Mark          mark          = db.Marks.Find(id);
         MarkTruckForm markTruckForm = new MarkTruckForm();
         markTruckForm.textBox1.Text = mark.Name;
         List <Mark>  marks  = db.Marks.ToList();
         DialogResult result = markTruckForm.ShowDialog(this);
         if (result == DialogResult.Cancel)
         {
             return;
         }
         mark.Name            = markTruckForm.textBox1.Text;
         db.Entry(mark).State = EntityState.Modified;
         db.SaveChanges();
         PlaySound(Application.StartupPath + "\\strarttone.wav", 0, 1);
         MessageBox.Show("Объект обновлен");
     }
 }
Esempio n. 2
0
        private void addMarkTruckButton_Click(object sender, EventArgs e)
        {
            MarkTruckForm markForm = new MarkTruckForm();
            DialogResult  result   = markForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }
            else
            {
                try
                {
                    Mark markTruck = new Mark();
                    markTruck.Name = markForm.textBox1.Text;
                    db.Marks.Add(markTruck);
                    db.SaveChanges();
                    PlaySound(Application.StartupPath + "\\exclamationtone.wav", 0, 1);
                    MessageBox.Show("Новая марка грузовика добавлена");
                }
                catch
                {
                    PlaySound(Application.StartupPath + "\\errortone.wav", 0, 1);
                    MessageBox.Show("Не получилось добавить новый объект");
                }
            }
        }