Ejemplo n.º 1
0
        // BaseData class will be parent of VehicleData
        public void InsertVehicle(Vehicle vehicle)
        {
            SqlConnection connection = ManageDatabaseConnection("Open");

            try
            {
                using (SqlCommand sqlCommand = new SqlCommand("insert_vehicle", connection))
                {

                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.Add("@NumberPlate", SqlDbType.VarChar).Value = vehicle.NumberPlate;
                    sqlCommand.Parameters.Add("@IdUser", SqlDbType.Int).Value = vehicle.IdUser;  // Hay que arregar esto..!!! Le falta idUser al objeto Vehicle..!!!!
                    sqlCommand.Parameters.Add("@Color", SqlDbType.VarChar).Value = vehicle.Color;
                    sqlCommand.Parameters.Add("@Type", SqlDbType.VarChar).Value = vehicle.Type;
                    sqlCommand.Parameters.Add("@IsApproved", SqlDbType.Bit).Value = vehicle.IsAproved;
                    sqlCommand.Parameters.Add("@IsActive", SqlDbType.Bit).Value = vehicle.HasCertificate;

                    //connection.Open();
                    sqlCommand.ExecuteNonQuery();
                    connection = ManageDatabaseConnection("Close");
                }
            }
            catch (SqlException sqlException)
            {

                throw sqlException;
            }
        }
Ejemplo n.º 2
0
 protected void btnAddCar_Click(object sender, EventArgs e)
 {
     VehicleData vehicleD = new VehicleData();
     UserData user = new UserData();
     User userInSession = user.getUserInSession("email");
     userInSession = user.getUserInSession((string)Session["user"]);
     int idUser = userInSession.Id;
     bool isActive = true;
     string type = ddlType.SelectedItem.Value;
     SiCAP_GrupoCARARA.App_Domain.Vehicle car = new SiCAP_GrupoCARARA.App_Domain.Vehicle(plate.Text, idUser, color.Text, type , false, isActive);
     vehicleD.InsertVehicle(car);
     plate.Text = string.Empty;
     color.Text = string.Empty;
     ddlType.SelectedIndex = -1;
 }
Ejemplo n.º 3
0
        protected void btnAddCar_Click(object sender, EventArgs e)
        {
            VehicleData vehicleD      = new VehicleData();
            UserData    user          = new UserData();
            User        userInSession = user.getUserInSession("email");

            userInSession = user.getUserInSession((string)Session["user"]);
            int    idUser   = userInSession.Id;
            bool   isActive = true;
            string type     = ddlType.SelectedItem.Value;

            SiCAP_GrupoCARARA.App_Domain.Vehicle car = new SiCAP_GrupoCARARA.App_Domain.Vehicle(plate.Text, idUser, color.Text, type, false, isActive);
            vehicleD.InsertVehicle(car);
            plate.Text            = string.Empty;
            color.Text            = string.Empty;
            ddlType.SelectedIndex = -1;
        }
Ejemplo n.º 4
0
        public List<Vehicle> readVehiclesOfUserFromDB(User user)
        {
            SqlConnection connection = ManageDatabaseConnection("Open");
            List<Vehicle> lstVehiclesOfOneUser = new List<Vehicle>();
            Vehicle vehicle;

            try
            {
                using (SqlCommand sqlCommand = new SqlCommand("read_all_Vehicles_underOneUser", connection))
                {

                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.Add("@Username_Email", SqlDbType.VarChar).Value = user.Username;

                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        vehicle = new Vehicle((int)reader["IdVehicle"], (string)reader["NumberPlate"]);
                        lstVehiclesOfOneUser.Add(vehicle);
                    }

                    connection = ManageDatabaseConnection("Close");
                }
            }
            catch (SqlException sqlException)
            {

                throw sqlException;
            }

            return lstVehiclesOfOneUser;
        }