Example #1
0
 protected Vehicle CreateVehicle()
 {
     try
     {
         //Creating the vehicle
         Vehicle vehicle = new Vehicle();
         VehicleType vehicleType = new VehicleType();
         vehicle.VehiclePlate = textboxLicense.Value;
         if (hiddenTypeValue.Value.Equals(string.Empty))
         {
             vehicleType.Id = Convert.ToInt32(selectType.Items[0].Value);
             vehicleType.Name = selectType.Items[0].Text;
         }
         else
         {
             vehicleType.Id = Convert.ToInt32(hiddenTypeValue.Value);
             vehicleType.Name = selectType.Items.FindByValue(hiddenTypeValue.Value).Text;
         }
         vehicle.Type = vehicleType;
         return vehicle;
     }
     catch (FormatException)
     {
         return null;
     }
 }
Example #2
0
 protected void UpdateVehicle(Vehicle vehicle)
 {
     if (vehicle != null)
     {
         switch (vehicleRules.UpdateVehicle(vehicle))
         {
             case 0:
                 textboxLicense.Value = "";
                 buttonStyle.buttonStyleBlue(buttonErrors, "Vehicle updated successful.");
                 break;
             case 1:
                 buttonStyle.buttonStyleWhite(buttonErrors, "Vehicle plate field is empty.");
                 break;
             case 2:
                 buttonStyle.buttonStyleRed(buttonErrors, "An error ocurred updating the vehicle, please check data or contact we us.");
                 break;
         }
     }
 }
Example #3
0
        protected void InsertVehicle(Vehicle vehicle)
        {
            VehicleTypeData vehicleTypeData = new VehicleTypeData();
            VehicleBussinessRules vehicleBussinessRules = new VehicleBussinessRules();

            if (vehicle != null)
            {
                int insertResult = vehicleBussinessRules.InsertVehicle(vehicle, Session["User-UserName"].ToString());
                switch (insertResult)
                {
                    case 0:
                        buttonStyle.buttonStyleBlue(buttonErrors, "Vehicle added sucessful.");
                        FillTable();
                        break;
                    case 1:
                        buttonStyle.buttonStyleWhite(buttonErrors, "The license field is empty.");
                        break;
                    case 2:
                        buttonStyle.buttonStyleRed(buttonErrors, "The license can only contain seven characters.");
                        break;
                }
            }
            else
            {
                buttonStyle.buttonStyleRed(buttonErrors, "Invalid data, please check it.");
            }
        }
        protected Reservation CreateReservation()
        {
            Reservation reservation = new Reservation();
            Space space = new Space();
            User user = new User();
            Vehicle vehicle = new Vehicle();
            DateTime checkIn = DateTime.Now;
            DateTime checkOut = DateTime.Now;
            TimeSpan initialHour = new TimeSpan();
            TimeSpan finalHour = new TimeSpan();
            try
            {
                if (hiddenCampusValue.Value.Equals(string.Empty))
                    space.ParkingCampusId = Convert.ToInt32(selectCampus.Items[0].Value);
                else
                    space.ParkingCampusId = Convert.ToInt32(hiddenCampusValue.Value);
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "The campus select is empty.");
                return null;
            }

            try
            {
                if (hiddenParkingValue.Value.Equals(string.Empty))
                    space.ParkingId = Convert.ToInt32(selectParking.Items[0].Value);
                else
                    space.ParkingId = Convert.ToInt32(hiddenParkingValue.Value);
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "The parking select is empty.");
                return null;
            }

            try
            {
                space.Id = Convert.ToInt32(hiddenSpaceValue.Value);
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "Please, select a space.");
                return null;
            }

            try
            {
                if (hiddenVehicleValue.Value.Equals(string.Empty))
                    vehicle.VehiclePlate = selectVehicle.Items[0].Value;
                else
                    vehicle.VehiclePlate = hiddenVehicleValue.Value;
            }
            catch (FormatException)
            {
                buttonStyle.buttonStyleRed(buttonErrors, "The vehicle select is empty.");
                return null;
            }

            user.Username = Session["User-UserName"].ToString();
            reservation.Space = space;
            reservation.User = user;
            reservation.Vehicle = vehicle;
            initialHour = CreateCheckIn(initialHour);
            finalHour = CreateCheckOut(finalHour);
            checkIn = checkIn.Date + initialHour;
            checkOut = checkOut.Date + finalHour;
            reservation.CheckIn = checkIn;
            reservation.CheckOut = checkOut;

            return reservation;
        }
Example #5
0
 public void UpdateVehicle(Vehicle vehicle)
 {
     connection = ManageDatabaseConnection("Open");
     using (SqlCommand update = new SqlCommand(@"UpdateVehicle", connection))
     {
         update.CommandType = CommandType.StoredProcedure;
         update.Parameters.Add("@VehiclePlate", SqlDbType.Int).Value = vehicle.VehiclePlate;
         update.Parameters.Add("@VehicleTypeId", SqlDbType.Int).Value = vehicle.Type.Id;
         update.Parameters.Add("@VehicleTypeName", SqlDbType.VarChar).Value = vehicle.Type.Name;
         update.ExecuteNonQuery();
     }
     connection = ManageDatabaseConnection("Close");
 }
Example #6
0
 public void InsertVehicle(Vehicle vehicle, string userName)
 {
     connection = ManageDatabaseConnection("Open");
     using (SqlCommand insert = new SqlCommand(@"InsertVehicle", connection))
     {
         insert.CommandType = CommandType.StoredProcedure;
         insert.Parameters.Add("@UserName", SqlDbType.VarChar).Value = userName;
         insert.Parameters.Add("@VehiclePlate", SqlDbType.VarChar).Value = vehicle.VehiclePlate;
         insert.Parameters.Add("@VehicleTypeId", SqlDbType.Int).Value = vehicle.Type.Id;
         insert.Parameters.Add("@VehicleTypeName", SqlDbType.VarChar).Value = vehicle.Type.Name;
         insert.ExecuteNonQuery();
     }
     connection = ManageDatabaseConnection("Close");
 }