Beispiel #1
0
 private void Button1_Click(object sender, EventArgs e)
 {
     SQLHandler.Insert(textBox1.Text);
 }
Beispiel #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            var data = new CarModel
            {
                Name = textBox1.Text,

                Mark = textBox4.Text,

                Color = textBox3.Text
            };

            if (data.Mark == "" & data.Name == "")
            {
                MessageBox.Show(
                    "Введіть марку та виробника авто для пошуку.",
                    "Помилка",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);
            }

            SQLHandler search = new SQLHandler();

            if (data.Name != "" & data.Mark != "" & data.Color != "")
            {
                var results = search.SelectCar(data);

                if (results.Count < 1)
                {
                    MessageBox.Show(
                        "Товар не знайдено.",
                        "Помилка",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                }
                else
                {
                    textBox7.Text = ((CarModel)results[0]).Mark.ToString();

                    textBox8.Text = ((CarModel)results[0]).Name.ToString();

                    textBox6.Text = ((CarModel)results[0]).Color.ToString();

                    textBox10.Text = ((CarModel)results[0]).Fuel.ToString();

                    textBox11.Text = ((CarModel)results[0]).EnginePower.ToString();

                    textBox12.Text = ((CarModel)results[0]).EngineVolume.ToString();

                    textBox13.Text = ((CarModel)results[0]).TankVolume.ToString();

                    textBox5.Text = ((CarModel)results[0]).Price.ToString();

                    textBox2.Text = ((CarModel)results[0]).Discount.ToString();

                    switch (data.Name)
                    {
                    case "Cayenne":

                        search.ReadFileFromDatabase("Porsche_Cayenne.jpg");

                        break;

                    case "Q7":

                        search.ReadFileFromDatabase("Audi_Q7.jpg");

                        break;

                    case "X6":

                        search.ReadFileFromDatabase("BMW_X6.jpg");

                        break;

                    case "Kamaro":

                        search.ReadFileFromDatabase("Chevrolet_Camaro.jpg");

                        break;

                    case "Golf":

                        search.ReadFileFromDatabase("Volkswagen_Golf.jpg");

                        break;

                    case "Charger":

                        search.ReadFileFromDatabase("Dodge_Charger.jpg");

                        break;

                    case "Aventador":

                        search.ReadFileFromDatabase("Lamborghini_Aventador.jpg");

                        break;

                    case "Logan XX века":

                        search.ReadFileFromDatabase("Renault_Logan.png");

                        break;

                    case "3000 GT":

                        search.ReadFileFromDatabase("Mitsubishi_3000GT.jpg");

                        break;

                    case "X-Trail":

                        search.ReadFileFromDatabase("Nissan_X-Trail.jpg");

                        break;

                    case "Corolla":

                        search.ReadFileFromDatabase("Toyota_Corolla.jpg");

                        break;
                    }

                    Image image = Image.FromFile(search.Images[0].FileName);

                    pictureBox1.Image = image;
                }
            }
            else if (data.Name != "" & data.Mark != "" & data.Color == "")
            {
                var results = search.SelectCarWithoutColor(data);

                if (results.Count < 1)
                {
                    MessageBox.Show(
                        "Товарів не знайдено.",
                        "Помилка",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                }
                else
                {
                    textBox7.Text = ((CarModel)results[0]).Mark.ToString();

                    textBox8.Text = ((CarModel)results[0]).Name.ToString();

                    textBox6.Text = ((CarModel)results[0]).Color.ToString();

                    textBox10.Text = ((CarModel)results[0]).Fuel.ToString();

                    textBox11.Text = ((CarModel)results[0]).EnginePower.ToString();

                    textBox12.Text = ((CarModel)results[0]).EngineVolume.ToString();

                    textBox13.Text = ((CarModel)results[0]).TankVolume.ToString();

                    textBox5.Text = ((CarModel)results[0]).Price.ToString();

                    textBox2.Text = ((CarModel)results[0]).Discount.ToString();

                    switch (data.Name)
                    {
                    case "Cayenne":

                        search.ReadFileFromDatabase("Porsche_Cayenne.jpg");

                        break;

                    case "Q7":

                        search.ReadFileFromDatabase("Audi_Q7.jpg");

                        break;

                    case "X6":

                        search.ReadFileFromDatabase("BMW_X6.jpg");

                        break;

                    case "Kamaro":

                        search.ReadFileFromDatabase("Chevrolet_Camaro.jpg");

                        break;

                    case "Golf":

                        search.ReadFileFromDatabase("Volkswagen_Golf.jpg");

                        break;

                    case "Charger":

                        search.ReadFileFromDatabase("Dodge_Charger.jpg");

                        break;

                    case "Aventador":

                        search.ReadFileFromDatabase("Lamborghini_Aventador.jpg");

                        break;

                    case "Logan XX века":

                        search.ReadFileFromDatabase("Renault_Logan.png");

                        break;

                    case "3000 GT":

                        search.ReadFileFromDatabase("Mitsubishi_3000GT.jpg");

                        break;

                    case "X-Trail":

                        search.ReadFileFromDatabase("Nissan_X-Trail.jpg");

                        break;

                    case "Corolla":

                        search.ReadFileFromDatabase("Toyota_Corolla.jpg");

                        break;
                    }
                    Image image = Image.FromFile(search.Images[0].FileName);

                    pictureBox1.Image = image;
                }
            }
        }