Пример #1
0
        /// <summary>
        ///  Checks fields entered are valid then adds vehicle to database.
        /// </summary>
        protected void VehicleAddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string manufacturer, model, SIPPCodeStr, imageLoc;
                double mpg    = 0;
                int    userID = 0;

                //If any conditions fail then do not add vehicle
                bool insertVehicle = true;

                imageLoc = null;

                SIPPCodeStr  = SIPPCodeTxt.Text.ToUpper();
                manufacturer = manufacturerTxt.Text;
                model        = modelTxt.Text;

                #region checkValidity
                insertVehicle = PictureUpload();

                //Upload selected image (check further down if upload failed)
                if (noImageChk.Checked == false)
                {
                    //If no image is selected save null location in database
                    if (imgViewFile.ImageUrl != "")
                    {
                        imageLoc = imgViewFile.ImageUrl;
                    }
                    else
                    {
                        imageLoc = null;
                    }
                }
                //If no file is being uploaded then set there to be no file to look at
                else if (noImageChk.Checked == true)
                {
                    imageLoc = null;
                }

                if (Variables.CheckDecimal(MPGTxt.Text) == false)
                {
                    MPGFailLbl.Text = "MPG - Please enter either a number or decimal number";
                    insertVehicle   = false;
                }
                else
                {
                    mpg = Convert.ToDouble(MPGTxt.Text);
                }
                if (SIPPCode.CheckSIPPCode(SIPPCodeStr) == false)
                {
                    SIPPCodeFailLbl.Text = "Please enter a valid 4 digit SIPP code";
                    insertVehicle        = false;
                }
                if (model == "")
                {
                    modelFailLbl.Text = "Please enter a model";
                    insertVehicle     = false;
                }
                if (manufacturer == "")
                {
                    manufacturerFailLbl.Text = "Please enter a manufacturer";
                    insertVehicle            = false;
                }

                userID = Variables.GetUser(Session["UserID"].ToString());
                if (userID == 0)
                {
                    insertVehicle        = false;
                    generalErrorLbl.Text = "Not logged in. Please login to continue";
                }
                #endregion

                if (insertVehicle == true)
                {
                    VehicleManager.InsertNewVehicle(manufacturer, model, SIPPCodeStr, mpg, imageLoc, userID, (int)UserAccess.UserType.company);

                    addCompleteLbl.Text = "Car Added Successfully";

                    //Send user to the list of all vehicles.
                    HtmlMeta meta = new HtmlMeta();
                    meta.HttpEquiv = "Refresh";
                    meta.Content   = "2;url=" + Variables.URL + "Vehicles";
                    this.Page.Controls.Add(meta);
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
        /// <summary>
        ///  Adds a new vehicle to be listed against this location as available to book.
        /// </summary>
        protected void AddAvailableVehiclesBtn_Click(object sender, EventArgs e)
        {
            try
            {
                List <VehicleManager> vehiclesAvailable = new List <VehicleManager>();
                bool   validEntries  = true;
                long   vehicleID     = 0;
                long   locationID    = 0;
                int    totalVehicles = 0;
                int    userID        = 0;
                double basePrice     = 0;
                string currency;

                #region checkValidity
                if (locationDdl.SelectedValue != "")
                {
                    locationID        = Convert.ToInt32(locationDdl.SelectedValue.Split(',')[0]);
                    vehiclesAvailable = VehicleManager.GetAvailableVehicles(locationID);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please select a location. <br />";
                }
                if (vehicleDdl.SelectedValue != "")
                {
                    vehicleID = Convert.ToInt32(vehicleDdl.SelectedValue.Split(',')[0]);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please select a vehicle. <br />";
                }

                if (Regex.IsMatch(totalVehiclesTxt.Text, @"^[0-9]*$"))
                {
                    totalVehicles = Convert.ToInt32(totalVehiclesTxt.Text);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please enter a whole number for total vehicles. <br />";
                }

                if (currencyDdl.SelectedValue != "")
                {
                    currency = currencyDdl.SelectedValue;
                }
                else
                {
                    currency           = "";
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please enter a currency. <br />";
                }
                if (Variables.CheckDecimal(basePriceTxt.Text))
                {
                    basePrice = Convert.ToDouble(basePriceTxt.Text);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "Please enter a base price in currency format. <br />";
                }

                foreach (VehicleManager vehicle in vehiclesAvailable)
                {
                    if (vehicle.VehicleID == vehicleID)
                    {
                        validEntries       = false;
                        inputErrorLbl.Text = inputErrorLbl.Text + "This vehicle is already assigned to this location. Please select another. <br />";
                    }
                }

                if (Response.Cookies["UserID"].Value != null)
                {
                    userID = Convert.ToInt32(Response.Cookies["UserID"].Value);
                }
                else if (Session["UserID"] != null)
                {
                    userID = Convert.ToInt32(Session["UserID"]);
                }
                else
                {
                    validEntries       = false;
                    inputErrorLbl.Text = "Not logged in. Please login to continue";
                }
                #endregion

                if (validEntries == true)
                {
                    VehicleManager.InsertNewAvailableVehicle(vehicleID, locationID, totalVehicles, currency, basePrice, userID, (int)UserAccess.UserType.company);
                    vehicleAddedLbl.Text = "New available vehicle added.";
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
Пример #3
0
        /// <summary>
        ///  Checks fields entered are valid then updates vehicle in database.
        /// </summary>
        protected void VehicleUpdateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateInputVisible();

                string manufacturer, model, SIPPCodeStr, imageLoc, vehicleID;
                double mpg    = 0;
                int    userID = 0;
                bool   active;

                //If any conditions fail then do not update vehicle
                bool updateCar = true;

                SIPPCodeStr = SIPPCodeTxt.Text.ToUpper();

                updateCar = PictureUpload();

                manufacturer = manufacturerTxt.Text;
                model        = modelTxt.Text;
                vehicleID    = (string)Session["VehicleID"];

                //If no image is selected and a file is going to be uploaded then
                //use the image currently in use for that vehicle
                if (imgViewFile.ImageUrl == "" && noImageChk.Checked == false)
                {
                    if ((string)Session["OldImageURL"] != "")
                    {
                        imageLoc = (string)Session["OldImageURL"];
                    }
                    else
                    {
                        imageLoc = null;
                    }
                }
                //If no file is being uploaded then set there to be no file to look at
                else if (noImageChk.Checked == true)
                {
                    imageLoc = null;
                }
                //Otherwise use image selected for vehicle
                else
                {
                    imageLoc = imgViewFile.ImageUrl;
                }


                if (Variables.CheckDecimal(MPGTxt.Text) == false)
                {
                    MPGFailLbl.Text = "MPG - Please enter either a number or decimal number";
                    updateCar       = false;
                }
                else
                {
                    mpg = Convert.ToDouble(MPGTxt.Text);
                }
                if (SIPPCode.CheckSIPPCode(SIPPCodeStr) == false)
                {
                    SIPPCodeFailLbl.Text = "Please enter a valid 4 digit SIPP code";
                    updateCar            = false;
                }
                if (model == "")
                {
                    modelFailLbl.Text = "Please enter a model";
                    updateCar         = false;
                }
                if (manufacturer == "")
                {
                    manufacturerFailLbl.Text = "Please enter a manufacturer";
                    updateCar = false;
                }

                active = activeChk.Checked;

                userID = Variables.GetUser(Session["UserID"].ToString());
                if (userID == 0)
                {
                    updateCar            = false;
                    generalErrorLbl.Text = "Not logged in. Please login to continue";
                }

                if (updateCar == true)
                {
                    VehicleManager.UpdateVehicle(vehicleID, manufacturer, model, SIPPCodeStr, mpg, imageLoc, active, userID, (int)UserAccess.UserType.company);

                    VehiclesTbl.Visible = false;

                    updateCompleteLbl.Text = "Car Updated Successfully";
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }