Beispiel #1
0
        //-----------------------------------------------------------------------------------------------------------
        private void addTypeButton_Click(object sender, EventArgs e)
        {
            TypeTruckForm typeForm = new TypeTruckForm();
            DialogResult  result   = typeForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }
            else
            {
                try
                {
                    TypeTruck typeTruck = new TypeTruck();
                    typeTruck.Name = typeForm.textBox1.Text;
                    db.TypeTrucks.Add(typeTruck);
                    db.SaveChanges();
                    PlaySound(Application.StartupPath + "\\exclamationtone.wav", 0, 1);
                    MessageBox.Show("Новый тип грузовика добавлен");
                }
                catch
                {
                    PlaySound(Application.StartupPath + "\\errortone.wav", 0, 1);
                    MessageBox.Show("Не получилось добавить новый объект");
                }
            }
        }
Beispiel #2
0
 private void chTypeButton_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count > 0)
     {
         int  index     = dataGridView1.SelectedRows[0].Index;
         int  id        = 0;
         bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
         if (converted == false)
         {
             return;
         }
         TypeTruck     typeTruck     = db.TypeTrucks.Find(id);
         TypeTruckForm typeTruckForm = new TypeTruckForm();
         typeTruckForm.textBox1.Text = typeTruck.Name;
         List <TypeTruck> typeTrucks = db.TypeTrucks.ToList();
         DialogResult     result     = typeTruckForm.ShowDialog(this);
         if (result == DialogResult.Cancel)
         {
             return;
         }
         typeTruck.Name            = typeTruckForm.textBox1.Text;
         db.Entry(typeTruck).State = EntityState.Modified;
         db.SaveChanges();
         PlaySound(Application.StartupPath + "\\strarttone.wav", 0, 1);
         MessageBox.Show("Объект обновлен");
     }
 }
Beispiel #3
0
 private void typeTruckButton_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count > 0)
     {
         int  index     = dataGridView1.SelectedRows[0].Index;
         int  id        = 0;
         bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
         if (converted == false)
         {
             return;
         }
         TypeTruck typeTruck = db.TypeTrucks.Find(id);
         listBox1.DataSource    = typeTruck.Trucks.ToList();
         listBox1.DisplayMember = "Model";
     }
 }
Beispiel #4
0
 private void delTypeButton_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count > 0)
     {
         int  index     = dataGridView1.SelectedRows[0].Index;
         int  id        = 0;
         bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
         if (converted == false)
         {
             return;
         }
         TypeTruck typeTruck = db.TypeTrucks.Find(id);
         db.TypeTrucks.Remove(typeTruck);
         db.SaveChanges();
         PlaySound(Application.StartupPath + "\\stoptone.wav", 0, 1);
         MessageBox.Show("Тип грузовика удалён");
     }
 }