Esempio n. 1
0
 private void ButtonEdit_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewAutopart.SelectedItems.Count == 1)
         {
             AutopartSet autopart = listViewAutopart.Items[0].Tag as AutopartSet;
             if (textBoxAutoPart.Text == "" || textBoxKol.Text == "" || textBoxPrice.Text == "" ||
                 comboBoxAutoMaker.SelectedItem == null || comboBoxCar.SelectedItem == null)
             {
                 throw new Exception("Обязательные данные не заполнены");
             }
             else
             {
                 autopart.NameAutopart = textBoxAutoPart.Text;
                 autopart.Quantity     = Convert.ToInt32(textBoxKol.Text);
                 autopart.Price        = Convert.ToInt32(textBoxPrice.Text);
                 autopart.IdAutomaker  = Convert.ToInt32(comboBoxAutoMaker.SelectedItem.ToString().Split('.')[0]);
                 autopart.IdCar        = Convert.ToInt32(comboBoxCar.SelectedItem.ToString().Split('.')[0]);
             }
         }
         Program.catalog.SaveChanges();
         ShowAutoPart();
     }
     catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); }
 }
Esempio n. 2
0
 private void ButtonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewAutopart.SelectedItems.Count == 1)
         {
             AutopartSet autopart = listViewAutopart.Items[0].Tag as AutopartSet;
             Program.catalog.AutopartSet.Remove(autopart);
             Program.catalog.SaveChanges();
             ShowAutoPart();
         }
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 3
0
 private void ListViewAutopart_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewAutopart.SelectedItems.Count == 1)
     {
         AutopartSet autopart = listViewAutopart.Items[0].Tag as AutopartSet;
         textBoxAutoPart.Text   = autopart.NameAutopart;
         comboBoxAutoMaker.Text = autopart.IdAutomaker.ToString() + "." + autopart.Automaker.NameAutomaker
                                  + " - " + autopart.Automaker.Country;
         comboBoxCar.Text  = autopart.IdCar.ToString() + "." + autopart.CarSet.CarBrand;
         textBoxKol.Text   = autopart.Quantity.ToString();
         textBoxPrice.Text = autopart.Price.ToString();
     }
     else
     {
         textBoxAutoPart.Text           = "";
         comboBoxAutoMaker.SelectedItem = null;
         comboBoxCar.SelectedItem       = null;
         textBoxKol.Text   = "";
         textBoxPrice.Text = "";
     }
 }