Example #1
0
 private void buttonCalculate_Click(object sender, EventArgs e)
 {
     try
     {
         double MPG;
         MPG = double.Parse(boxMiles.Text) / double.Parse(boxGas.Text);
         labelMPGOutput.Text = MPG.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void LoadAvailableVehicles()
        {
            List <VehicleManager> vehiclesAvailable = new List <VehicleManager>();
            string   manufacturer, model, SIPPCodeStr, currency;
            double   MPG, basePrice;
            long     locationID = 0;
            SIPPCode sizeOfVehicleSIPPCode, noOfDoorsSIPPCode, transmissionAndDriveSIPPCode, fuelAndACSIPPCode;
            Button   bookVehicle;
            TableRow row;

            if (locationDdl.SelectedValue != "")
            {
                locationID = Convert.ToInt32(locationDdl.SelectedValue.Split(',')[0]);

                //Filter by using the ID from the location ddl
                vehiclesAvailable = VehicleManager.GetAvailableVehicles(locationID).Where(x => x.Active == true).ToList();
            }

            foreach (VehicleManager vehicle in vehiclesAvailable)
            {
                row = new TableRow();
                Image vehicleImg = new Image();

                TableCell cell = new TableCell();

                vehicleImg.ImageUrl      = vehicle.ImageLoc;
                vehicleImg.AlternateText = vehicle.Manufacturer + " " + vehicle.Model;

                //make standard size of car images 270x150
                vehicleImg.Width  = Variables.STANDARDWIDTH;
                vehicleImg.Height = Variables.STANDARDHEIGHT;

                cell.Controls.Add(vehicleImg);

                row.Cells.Add(cell);
                vehiclesAvailableTbl.Rows.Add(row);

                manufacturer = vehicle.Manufacturer;
                model        = vehicle.Model;
                MPG          = vehicle.MPG;
                SIPPCodeStr  = vehicle.SIPPCode;
                currency     = vehicle.Currency;
                AddCell(row, manufacturer + " " + model + "<br />MPG: " + MPG.ToString() + "<br />SIPP: " + SIPPCodeStr);

                //Gets SIPP Code descriptions for all letters of SIPP code for this car
                sizeOfVehicleSIPPCode        = SIPPCode.GetSIPPCodeDesc(Variables.SIZEOFVEHICLE, vehicle.SIPPCode[0].ToString());
                noOfDoorsSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.NOOFDOORS, vehicle.SIPPCode[1].ToString());
                transmissionAndDriveSIPPCode = SIPPCode.GetSIPPCodeDesc(Variables.TRANSMISSIONANDDRIVE, vehicle.SIPPCode[2].ToString());
                fuelAndACSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.FUELANDAC, vehicle.SIPPCode[3].ToString());

                cell = new TableCell();
                Label label = new Label();
                label.Text = sizeOfVehicleSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = noOfDoorsSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = transmissionAndDriveSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = fuelAndACSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                row.Cells.Add(cell);

                basePrice = vehicle.BasePrice;
                AddCell(row, currency + ": " + basePrice.ToString());

                //Book button to book selected car
                bookVehicle          = new Button();
                bookVehicle.ID       = locationID + "_" + vehicle.VehicleAvailableID + "_BookBtn";
                bookVehicle.Text     = "Book";
                bookVehicle.CssClass = "btn btn-primary";
                bookVehicle.Click   += new EventHandler(BookVehicleBtn_Click);
                if (Session["LoggedInType"] != null)
                {
                    if (Session["LoggedInType"].ToString() == "")
                    {
                        bookVehicle.OnClientClick = "return alert('Please login to continue');";
                    }
                }
                else
                {
                    bookVehicle.OnClientClick = "return alert('Please login to continue');";
                }
                cell = new TableCell();
                cell.Controls.Add(bookVehicle);
                row.Cells.Add(cell);

                vehiclesAvailableTbl.Rows.Add(row);
            }
        }
Example #3
0
        /// <summary>
        ///  Load vehicles and put them into a table.
        /// </summary>
        private void LoadVehicles()
        {
            string   manufacturer, model, SIPPCodeStr;
            double   MPG;
            SIPPCode sizeOfVehicleSIPPCode, noOfDoorsSIPPCode, transmissionAndDriveSIPPCode, fuelAndACSIPPCode;
            TableRow row;
            List <VehicleManager> vehicles;
            List <CompanyManager> companies;
            CompanyManager        company;

            vehicles  = VehicleManager.GetVehicles().Where(x => x.Active == true).ToList();
            companies = CompanyManager.GetCompanies();

            //Only get cars with 50 MPG or more
            if (ecoFriendlyChk.Checked == true)
            {
                vehicles = vehicles.Where(x => x.MPG >= Variables.ECOFRIENDLY && x.Active == true).ToList();
            }

            if (manufacturerDdl.SelectedValue.Equals("All"))
            {
                //Get all the cars on the list
            }
            else if (modelDdl.SelectedValue.Equals("All"))
            {
                vehicles = vehicles.Where(x => x.Manufacturer == manufacturerDdl.SelectedValue && x.Active == true).ToList();
            }
            else
            {
                if (vehicles.Any(x => x.Manufacturer == manufacturerDdl.SelectedValue && x.Model == modelDdl.SelectedValue))
                {
                    vehicles = vehicles.Where(x => x.Manufacturer == manufacturerDdl.SelectedValue && x.Model == modelDdl.SelectedValue && x.Active == true).ToList();
                }
                //If selected another manufacturer while model of different manufacturer is selected the models are cleared
                else
                {
                    vehicles = vehicles.Where(x => x.Manufacturer == manufacturerDdl.SelectedValue && x.Active == true).ToList();
                }
            }

            foreach (VehicleManager vehicle in vehicles)
            {
                row = new TableRow();
                Image vehicleImg = new Image();

                TableCell cell = new TableCell();

                vehicleImg.ImageUrl      = vehicle.ImageLoc;
                vehicleImg.AlternateText = vehicle.Manufacturer + " " + vehicle.Model;

                //make standard size of car images 270x150
                vehicleImg.Width  = Variables.STANDARDWIDTH;
                vehicleImg.Height = Variables.STANDARDHEIGHT;

                cell.Controls.Add(vehicleImg);

                row.Cells.Add(cell);
                VehiclesTbl.Rows.Add(row);

                manufacturer = vehicle.Manufacturer;
                model        = vehicle.Model;
                AddCell(row, manufacturer + " " + model);

                SIPPCodeStr = vehicle.SIPPCode;
                AddCell(row, SIPPCodeStr);

                MPG = vehicle.MPG;

                //Gets SIPP Code descriptions for all letters of SIPP code for this car
                sizeOfVehicleSIPPCode        = SIPPCode.GetSIPPCodeDesc(Variables.SIZEOFVEHICLE, vehicle.SIPPCode[0].ToString());
                noOfDoorsSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.NOOFDOORS, vehicle.SIPPCode[1].ToString());
                transmissionAndDriveSIPPCode = SIPPCode.GetSIPPCodeDesc(Variables.TRANSMISSIONANDDRIVE, vehicle.SIPPCode[2].ToString());
                fuelAndACSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.FUELANDAC, vehicle.SIPPCode[3].ToString());

                cell = new TableCell();
                Label label = new Label();
                label.Text = "MPG: " + MPG.ToString() + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = sizeOfVehicleSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = noOfDoorsSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = transmissionAndDriveSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                label      = new Label();
                label.Text = fuelAndACSIPPCode.Description + "<br />";
                cell.Controls.Add(label);

                row.Cells.Add(cell);

                company = companies.Where(x => x.CompanyID == vehicle.UserID).SingleOrDefault();
                AddCell(row, company.CompanyName);

                VehiclesTbl.Rows.Add(row);
            }
        }
Example #4
0
        /// <summary>
        ///  Load vehicles and put into table but make table invisible until a manufacturer and model are selected.
        /// </summary>
        private void LoadVehicles()
        {
            string   manufacturer, model, SIPPCodeStr;
            double   MPG;
            SIPPCode sizeOfVehicleSIPPCode, noOfDoorsSIPPCode, transmissionAndDriveSIPPCode, fuelAndACSIPPCode;
            TableRow row;
            List <VehicleManager> vehicles;

            vehicles = VehicleManager.GetVehicles().Where(x => x.UserID == Variables.GetUser(Session["UserID"].ToString())).ToList();

            VehiclesTbl.Visible = false;

            //Only populate table when model and manufacturer selected
            if (vehicles.Any(x => x.Manufacturer == manufacturerDdl.SelectedValue && x.Model == modelDdl.SelectedValue))
            {
                vehicles = vehicles.Where(x => x.Manufacturer == manufacturerDdl.SelectedValue && x.Model == modelDdl.SelectedValue).ToList();
                AddHeaderRow();
                //Only make table visible when a model is selected
                //The car table always needs to exist otherwise update button from the table to text boxes WILL NOT WORK
                VehiclesTbl.Visible = true;

                foreach (VehicleManager vehicle in vehicles)
                {
                    row = new TableRow();
                    Image vehicleImg = new Image();

                    TableCell cell = new TableCell();

                    vehicleImg.ImageUrl      = vehicle.ImageLoc;
                    vehicleImg.AlternateText = vehicle.Manufacturer + " " + vehicle.Model;

                    //make standard size of car images 270x150
                    vehicleImg.Width  = Variables.STANDARDWIDTH;
                    vehicleImg.Height = Variables.STANDARDHEIGHT;

                    cell.Controls.Add(vehicleImg);

                    row.Cells.Add(cell);
                    VehiclesTbl.Rows.Add(row);

                    manufacturer = vehicle.Manufacturer;
                    model        = vehicle.Model;
                    AddCell(row, manufacturer + " " + model);

                    SIPPCodeStr = vehicle.SIPPCode;
                    AddCell(row, SIPPCodeStr);

                    MPG = vehicle.MPG;

                    //Gets SIPP Code descriptions for all letters of SIPP code for this car
                    sizeOfVehicleSIPPCode        = SIPPCode.GetSIPPCodeDesc(Variables.SIZEOFVEHICLE, vehicle.SIPPCode[0].ToString());
                    noOfDoorsSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.NOOFDOORS, vehicle.SIPPCode[1].ToString());
                    transmissionAndDriveSIPPCode = SIPPCode.GetSIPPCodeDesc(Variables.TRANSMISSIONANDDRIVE, vehicle.SIPPCode[2].ToString());
                    fuelAndACSIPPCode            = SIPPCode.GetSIPPCodeDesc(Variables.FUELANDAC, vehicle.SIPPCode[3].ToString());

                    cell = new TableCell();
                    Label label = new Label();
                    label.Text = "MPG: " + MPG.ToString() + "<br />";
                    cell.Controls.Add(label);

                    label      = new Label();
                    label.Text = sizeOfVehicleSIPPCode.Description + "<br />";
                    cell.Controls.Add(label);

                    label      = new Label();
                    label.Text = noOfDoorsSIPPCode.Description + "<br />";
                    cell.Controls.Add(label);

                    label      = new Label();
                    label.Text = transmissionAndDriveSIPPCode.Description + "<br />";
                    cell.Controls.Add(label);

                    label      = new Label();
                    label.Text = fuelAndACSIPPCode.Description + "<br />";
                    cell.Controls.Add(label);

                    row.Cells.Add(cell);

                    VehiclesTbl.Rows.Add(row);

                    //Add an update button to each vehicle
                    Button updateBtn = new Button();
                    updateBtn.Click   += new EventHandler(SelectToUpdateBtn_Click);
                    updateBtn.Text     = "Select";
                    updateBtn.ID       = vehicle.VehicleID.ToString() + vehicle.Model;
                    updateBtn.CssClass = "btn btn-primary";

                    cell = new TableCell();
                    cell.Controls.Add(updateBtn);
                    cell.CssClass = "h4";
                    row.Cells.Add(cell);

                    cell         = new TableCell();
                    cell.ID      = vehicle.VehicleID.ToString();
                    cell.Visible = false;
                    row.Cells.Add(cell);

                    VehiclesTbl.Rows.Add(row);
                }
            }
            //If selected another manufacturer while model of different manufacturer is selected the models are cleared
            else
            {
                vehicles = vehicles.Where(x => x.Manufacturer == manufacturerDdl.SelectedValue).ToList();
            }
        }