Beispiel #1
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         SpareSet spareSet = new SpareSet();
         if (comboBoxCar.SelectedItem != null)
         {
             spareSet.IdCar = Convert.ToInt32(comboBoxCar.SelectedItem.ToString().Split('.')[0]);
         }
         if (textBoxNameSpare.Text != "")
         {
             spareSet.Name = textBoxNameSpare.Text;
         }
         if (textBoxMaker.Text != "")
         {
             spareSet.Maker = textBoxMaker.Text;
         }
         if (textBoxCount.Text != "")
         {
             spareSet.Count = Convert.ToInt32(textBoxCount.Text);
         }
         if (textBoxPrice.Text != "")
         {
             spareSet.Price = Convert.ToDouble(textBoxPrice.Text);
         }
         Program.OilerDb.SpareSet.Add(spareSet);
         Program.OilerDb.SaveChanges();
         ShowSpare();
     }
     catch
     { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); }
 }
Beispiel #2
0
 void Deductions()
 {
     textBoxPrice.Clear();
     if (comboBoxSpare.SelectedItem != null)
     {
         SpareSet spareSet = Program.OilerDb.SpareSet.Find(Convert.ToInt32(comboBoxSpare.SelectedItem.ToString().Split('.')[0]));
         double   Price    = spareSet.Price * 1.5;
         textBoxPrice.Text = Price.ToString();
         if (textBoxDate.Text == "")
         {
             textBoxDate.Text = DateTime.Now.ToString("dd.MM.yyyy");
         }
     }
 }
Beispiel #3
0
 private void listViewSpare_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewSpare.SelectedItems.Count == 1)
     {
         SpareSet spareSet = listViewSpare.SelectedItems[0].Tag as SpareSet;
         comboBoxCar.SelectedIndex = comboBoxCar.FindString(spareSet.IdCar.ToString());
         textBoxNameSpare.Text     = spareSet.Name;
         textBoxMaker.Text         = spareSet.Maker;
         textBoxCount.Text         = spareSet.Count.ToString();
         textBoxPrice.Text         = spareSet.Price.ToString();
     }
     else
     {
         comboBoxCar.SelectedItem = null;
         textBoxNameSpare.Text    = "";
         textBoxMaker.Text        = "";
         textBoxCount.Text        = "";
         textBoxPrice.Text        = "";
     }
 }
Beispiel #4
0
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     if ((comboBoxCar.SelectedItem != null) && (textBoxNameSpare.Text != "") && (textBoxMaker.Text != "") &&
         (textBoxCount.Text != "") && (textBoxPrice.Text != ""))
     {
         if (listViewSpare.SelectedItems.Count == 1)
         {
             SpareSet spareSet = listViewSpare.SelectedItems[0].Tag as SpareSet;
             spareSet.IdCar = Convert.ToInt32(comboBoxCar.SelectedItem.ToString().Split('.')[0]);
             spareSet.Name  = textBoxNameSpare.Text;
             spareSet.Maker = textBoxMaker.Text;
             spareSet.Count = Convert.ToInt32(textBoxCount.Text);
             spareSet.Price = Convert.ToDouble(textBoxPrice.Text);
             Program.OilerDb.SaveChanges();
             ShowSpare();
         }
     }
     else
     {
         MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Beispiel #5
0
 private void buttonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewSpare.SelectedItems.Count == 1)
         {
             SpareSet spareSet = listViewSpare.SelectedItems[0].Tag as SpareSet;
             Program.OilerDb.SpareSet.Remove(spareSet);
             Program.OilerDb.SaveChanges();
             ShowSpare();
         }
         comboBoxCar.SelectedItem = null;
         textBoxNameSpare.Text    = "";
         textBoxMaker.Text        = "";
         textBoxCount.Text        = "";
         textBoxPrice.Text        = "";
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }