Exemplo n.º 1
0
        public List <Car> SelectCars()
        {
            using (SqlCommand command = new SqlCommand("SELECT * FROM Car ", CarConnection.GetInstance().SqlConnection))
            {
                //
                // Add new SqlParameter to the command.
                //
                //command.Parameters.Add(new SqlParameter("Name", dogName));
                //
                // Read in the SELECT results.
                //
                List <Car>    carsList = new List <Car>();
                SqlDataReader reader   = command.ExecuteReader();
                while (reader.Read())
                {
                    Car newCar = new Car(reader.GetInt32(0), reader.GetString(2), reader.GetInt32(1), reader.GetInt32(3), reader.GetString(4));

                    carsList.Add(newCar);

                    //ListViewItem lvi = new ListViewItem();
                    //lvi.Text = newCar.Id.ToString() ;
                    //lvi.SubItems.Add(newCar.Company);
                    //lvi.SubItems.Add(newCar.Comments);
                    //lvi.SubItems.Add(newCar.Size.ToString());
                    //lvi.SubItems.Add(newCar.Color.ToString());
                    //listView1.Items.Add(lvi);
                }
                return(new List <Car>());
            }
        }
Exemplo n.º 2
0
        public List <Driver> SelectDrivers()
        {
            using (SqlCommand command = new SqlCommand("SELECT * FROM Driver ", CarConnection.GetInstance().SqlConnection))
            {
                //
                // Add new SqlParameter to the command.
                //
                //command.Parameters.Add(new SqlParameter("Name", dogName));
                //
                // Read in the SELECT results.
                //
                List <Driver> driverList = new List <Driver>();
                SqlDataReader reader     = command.ExecuteReader();
                while (reader.Read())
                {
                    Driver newDriver = new Driver(reader.GetInt32(0), reader.GetString(2), reader.GetInt32(1), reader.GetString(3), reader.GetInt32(4));

                    driverList.Add(newDriver);
                }
                return(new List <Driver>());
            }
        }
Exemplo n.º 3
0
        public void UpdateCar(Car car)
        {
            SqlCommand sqlCommand = new SqlCommand(@"Update Cars set CarSize = @CarSize, CarCompany=@CarCompany, CarColor= @CarColor, Comments=@Comments where Id = @Id", CarConnection.GetInstance().SqlConnection);

            SqlParameter sqlParameter = new SqlParameter("ID", car.Id);

            sqlCommand.Parameters.Add(sqlParameter);

            SqlParameter sqlParameter1 = new SqlParameter("CarSize", car.Size);

            sqlCommand.Parameters.Add(sqlParameter1);
            SqlParameter sqlParameter2 = new SqlParameter("CarCompany", car.Company);

            sqlCommand.Parameters.Add(sqlParameter2);
            SqlParameter sqlParameter3 = new SqlParameter("CarColor", car.Color);

            sqlCommand.Parameters.Add(sqlParameter3);
            SqlParameter sqlParameter4 = new SqlParameter("Comments", car.Comments);

            sqlCommand.Parameters.Add(sqlParameter4);



            sqlCommand.ExecuteScalar();
        }
Exemplo n.º 4
0
        public void InsertCar(Car car)
        {
            //SqlCommand sqlCommand = new SqlCommand(@"INSERT INTO Car VALUES (+" + txtId.Text + ", "+ txtSize.Text + ",'" + txtCompany.Text +  "', '" + txtComments.Text +"')", cnn);
            SqlCommand sqlCommand = new SqlCommand(@"INSERT INTO Car VALUES @ID, @CarSize, @CarCompany, @CarColor, Comments", CarConnection.GetInstance().SqlConnection);

            SqlParameter sqlParameter = new SqlParameter("ID", car.Id);

            sqlCommand.Parameters.Add(sqlParameter);

            SqlParameter sqlParameter1 = new SqlParameter("CarSize", car.Size);

            sqlCommand.Parameters.Add(sqlParameter1);
            SqlParameter sqlParameter2 = new SqlParameter("CarCompany", car.Company);

            sqlCommand.Parameters.Add(sqlParameter2);
            SqlParameter sqlParameter3 = new SqlParameter("CarColor", car.Color);

            sqlCommand.Parameters.Add(sqlParameter3);
            SqlParameter sqlParameter4 = new SqlParameter("Comments", car.Comments);

            sqlCommand.Parameters.Add(sqlParameter4);

            sqlCommand.ExecuteScalar();
        }
Exemplo n.º 5
0
        public void DeleteCar(Car car)
        {
            SqlCommand   sqlCommand   = new SqlCommand(@"Delete * from Cars where Id = @Id", CarConnection.GetInstance().SqlConnection);
            SqlParameter sqlParameter = new SqlParameter("ID", car.Id);

            sqlCommand.Parameters.Add(sqlParameter);
        }
Exemplo n.º 6
0
        public void UpdateDriver(Driver driver)
        {
            SqlCommand sqlCommand = new SqlCommand(@"Update Drivers set DriverName = @DriverName, Age=@Age, Adress= @Adress, DriversLessonType=@DriversLessonType where Id = @Id", CarConnection.GetInstance().SqlConnection);

            SqlParameter sqlParameter = new SqlParameter("ID", driver.Id);

            sqlCommand.Parameters.Add(sqlParameter);

            SqlParameter sqlParameter1 = new SqlParameter("DriverName", driver.DriverName);

            sqlCommand.Parameters.Add(sqlParameter1);
            SqlParameter sqlParameter2 = new SqlParameter("Age", driver.Age);

            sqlCommand.Parameters.Add(sqlParameter2);
            SqlParameter sqlParameter3 = new SqlParameter("Adress", driver.Address);

            sqlCommand.Parameters.Add(sqlParameter3);
            SqlParameter sqlParameter4 = new SqlParameter("DriversLessonType", driver.DriversLessonType);

            sqlCommand.Parameters.Add(sqlParameter4);
        }
Exemplo n.º 7
0
        public void InsertDriver(Driver driver)
        {
            SqlCommand sqlCommand = new SqlCommand(@"INSERT INTO Drivers VALUES @ID, @DriverName, @Age, @Address, @DriversLessonType", CarConnection.GetInstance().SqlConnection);


            SqlParameter sqlParameter = new SqlParameter("ID", driver.Id);

            sqlCommand.Parameters.Add(sqlParameter);

            SqlParameter sqlParameter1 = new SqlParameter("DriverName", driver.DriverName);

            sqlCommand.Parameters.Add(sqlParameter1);
            SqlParameter sqlParameter2 = new SqlParameter("Age", driver.Age);

            sqlCommand.Parameters.Add(sqlParameter2);
            SqlParameter sqlParameter3 = new SqlParameter("Adress", driver.Address);

            sqlCommand.Parameters.Add(sqlParameter3);
            SqlParameter sqlParameter4 = new SqlParameter("DriversLessonType", driver.DriversLessonType);

            sqlCommand.Parameters.Add(sqlParameter4);

            sqlCommand.ExecuteScalar();
        }
Exemplo n.º 8
0
        public bool CheckDriverExists(Driver driver)
        {
            using (SqlCommand command = new SqlCommand("SELECT * FROM Driver where id= @ID ", CarConnection.GetInstance().SqlConnection))
            {
                SqlParameter sqlParameter = new SqlParameter("ID", driver.Id);
                command.Parameters.Add(sqlParameter);

                List <Driver> driverList = new List <Driver>();
                SqlDataReader reader     = command.ExecuteReader();
                while (reader.Read())
                {
                    return(true);
                }
                return(false);
            }
        }