Exemple #1
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewCars.SelectedItems.Count == 1)
                {
                    CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet;

                    if (textBoxModel.Text == "" || textBoxPrice.Text == "" || textBoxNumberState.Text == "" || textBoxYear.Text == "")
                    {
                        throw new Exception("Обязательные данные не заполнены");
                    }
                    else
                    {
                        carsSet.Price       = Convert.ToInt32(textBoxPrice.Text);
                        carsSet.Model       = textBoxModel.Text;
                        carsSet.NumberState = textBoxNumberState.Text;
                        carsSet.Year        = textBoxYear.Text;
                    }

                    if (comboBoxColor.SelectedItem != null)
                    {
                        carsSet.Color = Convert.ToString(comboBoxColor.SelectedItem.ToString().Split('.')[0]);
                    }
                    else
                    {
                        throw new Exception("Обязательные данные не заполнены");
                    }

                    Program.cGG.SaveChanges();
                    ShowCars();
                }
            }
            catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); }
        }
Exemple #2
0
        private void listViewCars_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewCars.SelectedItems.Count == 1)
            {
                CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet;

                textBoxPrice.Text       = carsSet.Price.ToString();
                comboBoxColor.Text      = carsSet.Color.ToString();
                textBoxModel.Text       = carsSet.Model;
                textBoxNumberState.Text = carsSet.NumberState;
                textBoxYear.Text        = carsSet.Year;
            }
            else
            {
                comboBoxColor.SelectedItem = null;
                textBoxModel.Text          = "";
                textBoxNumberState.Text    = "";
                textBoxPrice.Text          = "";
                textBoxYear.Text           = "";
            }
        }
Exemple #3
0
        private void buttonDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewCars.SelectedItems.Count == 1)
                {
                    CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet;
                    Program.cGG.CarsSet.Remove(carsSet);
                    Program.cGG.SaveChanges();
                    ShowCars();
                }

                comboBoxColor.SelectedItem = null;
                textBoxModel.Text          = "";
                textBoxNumberState.Text    = "";
                textBoxPrice.Text          = "";
                textBoxYear.Text           = "";
            }
            catch
            {
                MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);;
            }
        }