Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            DbCars db = new DbCars();

            WindowsFormsApplication1.Car w = new WindowsFormsApplication1.Car();
            try
            {
                w.Id       = int.Parse(textBox1.Text);
                w.Kind     = textBox3.Text;
                w.Color    = textBox2.Text;
                w.ClientId = int.Parse(textBox4.Text);
                w.History  = int.Parse(textBox5.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Invalid parameters", "Error");
                return;
            }


            DbClients cdb = new DbClients();

            if (!cdb.ClientExist(w.ClientId))
            {
                MessageBox.Show("Invalid Client", "Error");
                return;
            }



            db.insertCar(w);
            MessageBox.Show("add Car Success");
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                WindowsFormsApplication1.Car w = new WindowsFormsApplication1.Car();
                DbCars db = new DbCars();
                w.Id       = int.Parse(textBox1.Text);
                w.Kind     = textBox3.Text;
                w.Color    = textBox2.Text;
                w.ClientId = int.Parse(textBox4.Text);
                w.History  = int.Parse(textBox5.Text);

                DbClients cdb = new DbClients();


                if (!cdb.ClientExist(w.ClientId))
                {
                    MessageBox.Show("Client Does not exist");
                    return;
                }

                db.UpdateCar(w);
                MessageBox.Show("Successfully updated Car");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            DbCars db = new DbCars();

            WindowsFormsApplication1.Car w = new WindowsFormsApplication1.Car();
            try
            {
                w.Id = int.Parse(textBox1.Text);
                if (db.CarExist(w.Id) == true)
                {
                    DialogResult dialogResult = MessageBox.Show("Are You Sure To Delete Car?", "Delete", MessageBoxButtons.YesNoCancel);
                    if (dialogResult == DialogResult.Yes)
                    {
                        db.DeleteCar(w);
                        MessageBox.Show("Car was deleted Successfully");
                    }
                }
                else
                {
                    MessageBox.Show("Car with similar ID was not found , try again", "Error");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Example #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            WindowsFormsApplication1.Car w = new WindowsFormsApplication1.Car();
            DbCars  db = new DbCars();
            DataSet ds = new DataSet();

            try
            {
                w.Id = int.Parse(textBox1.Text);
                if (db.CarExist(w.Id) == true)
                {
                    ds            = db.getCarInfo(w);
                    textBox1.Text = ds.Tables[0].Rows[0]["ProductCode"].ToString();
                    textBox3.Text = ds.Tables[0].Rows[0]["Kind"].ToString();
                    textBox2.Text = ds.Tables[0].Rows[0]["Color"].ToString();
                    textBox4.Text = ds.Tables[0].Rows[0]["ClientId"].ToString();
                    textBox5.Text = ds.Tables[0].Rows[0]["History"].ToString();
                }
                else
                {
                    textBox1.Text = "Car not found ";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            DbCars db = new DbCars();

            try
            {
                WindowsFormsApplication1.Car w = new WindowsFormsApplication1.Car();
                w.Id = int.Parse(textBox1.Text);

                if (comboBox1.SelectedIndex == 0)
                {
                    dataGridView1.DataSource = db.SearchCarByProductCode(w.Id).Tables[0];
                }
                else
                {
                    dataGridView1.DataSource = db.SearchCarByClientId(w.Id).Tables[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }