Ejemplo n.º 1
0
        private bool vehicleValidation()
        {
            bool progress = true;

            string rego      = this.carRegoTb.Text;
            string Make      = this.carMakeTb.Text;
            string Model     = this.carModeltb.Text;
            string Year      = this.carYeartb.Text;
            string Cclass    = this.carClasscb.Text;
            string seats     = this.carSeatstb.Text;
            string trans     = this.carTranscb.Text;
            string Fuel      = this.carFuelcb.Text;
            bool   gps       = this.carGpscb.Checked;
            bool   Sroof     = this.carSunRoofcb.Checked;
            string Colour    = this.carColourtb.Text;
            string Dailyrate = this.carDratetb.Text;

            this.clientErrorProvider.Clear();
            int drate;

            if (!int.TryParse(Dailyrate, out drate))
            {
                this.clientErrorProvider.SetError(this.carDratetb, "results not Valid");
                progress = false;
            }
            else
            {
                if (drate < 1)
                {
                    this.clientErrorProvider.SetError(this.carDratetb, "results not Valid");
                    progress = false;
                }
            }

            if (Colour == "")
            {
                this.clientErrorProvider.SetError(this.carColourtb, "results not Valid");
                progress = false;
            }
            if (Fuel == "Petrol" || Fuel == "Diesel")
            {
            }
            else
            {
                this.clientErrorProvider.SetError(this.carFuelcb, "results not Valid");
                progress = false;
            }

            int sts;

            if (int.TryParse(seats, out sts))
            {
                if (sts < 2 || sts > 10)
                {
                    this.clientErrorProvider.SetError(this.carSeatstb, "results not Valid");
                    progress = false;
                }
            }
            else
            {
                this.clientErrorProvider.SetError(this.carSeatstb, "results not Valid");
                progress = false;
            }

            if (trans == "Automatic" || trans == "Manual")
            {
            }
            else
            {
                this.clientErrorProvider.SetError(this.carTranscb, "results not Valid");
                progress = false;
            }

            if (Cclass == "Luxury" || Cclass == "Commercial" || Cclass == "Economy" || Cclass == "Family")
            {
            }
            else
            {
                this.clientErrorProvider.SetError(this.carClasscb, "Car Class not Valid");
                progress = false;
            }
            if (Make == "")
            {
                this.clientErrorProvider.SetError(this.carMakeTb, "Car Make cannot be blank");
                progress = false;
            }

            if (Model == "")
            {
                this.clientErrorProvider.SetError(this.carModeltb, "car Model cannot be blank");
                progress = false;
            }
            int yr;

            if (int.TryParse(Year, out yr))
            {
                if (yr < 1900 || yr > 2018)
                {
                    this.clientErrorProvider.SetError(this.carYeartb, "Year of car must be a valid year");
                    progress = false;
                }
            }

            if (Year == "")
            {
                this.clientErrorProvider.SetError(this.carYeartb, "Year of car must be a valid year");
                progress = false;
            }

            if (rego == "")
            {
                this.clientErrorProvider.SetError(this.carRegoTb, "Registration cannot be blank");
                progress = false;
            }

            if (fleetMan.Exists(rego))
            {
                this.clientErrorProvider.SetError(this.carRegoTb, "This car registration already exists");
                progress = false;
            }
            return(progress);
        }