예제 #1
0
        private void button_Search_Click(object sender, EventArgs e)
        {
            if (textBoxSeialNumber.Text.Equals("") ||
                !RegExValidator.Is12Digit(textBoxSeialNumber.Text))
            {
                MessageBox.Show("Please enter a valid value for serial number..!!");
                return;
            }
            Boolean found = false;

            listBoxDisplay.Items.Clear();
            if (bikeList.Count > 0)
            {
                foreach (Bike bike in bikeList)
                {
                    if (bike.SerialNumber.Equals(long.Parse(textBoxSearchBike.Text)))
                    {
                        listBoxDisplay.Items.Add(bike);
                        found = true;
                        MessageBox.Show("Bike found, Details");
                    }
                }
            }
            else
            {
                MessageBox.Show("\n" + "The list is empty");
            }
            if (!found)
            {
                MessageBox.Show("No Search Results..!!");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            string input;
            long   serNum = 0; string make = "";
            double speed = 0, seatHeight = 0;
            bool   correct = false;

            do
            {
                Console.Write("Please enter serial number: ");
                input = Console.ReadLine();
                if (RegExValidator.Is12Digit(input) && RegExValidator.IsEmpty(input))
                {
                    correct = true;
                }
                if (!correct)
                {
                    Console.WriteLine("\t...The input must not be empty and must be 12 digit. Please try again...\n");
                }
            } while (!correct);

            serNum = long.Parse(input);


            correct = false;
            do
            {
                Console.Write(" Please enter the make:   ");
                input   = Console.ReadLine();
                correct = RegExValidator.IsAlphabetLetter(input);
                if (!correct)
                {
                    Console.WriteLine("\t...Not valid.. the input must be alphabets only. Try again.\n");
                }
            } while (!correct);

            make = input;

            correct = false;
            do
            {
                Console.Write("Please enter top speed:   ");
                input   = Console.ReadLine();
                correct = RegExValidator.IsDigit(input);
                if (!correct)
                {
                    Console.WriteLine("\t...Not valid.. the input must be digit only...\n");
                }
            } while (!correct);

            speed = Convert.ToDouble(input);

            correct = false;
            do
            {
                Console.Write("Please enter seat height(in inches):   ");
                input   = Console.ReadLine();
                correct = RegExValidator.IsDigit(input);
                if (!correct)
                {
                    Console.WriteLine("\t...Not valid. The input must be digits only...\n");
                }
            } while (!correct);

            seatHeight = Convert.ToInt32(input);

            Roadbike rBike = new Roadbike(serNum, make, speed, EnumColor.Black,
                                          new MyBikesStore.Date(1, 1, 1), seatHeight);

            Console.WriteLine("\n\n The Mountain Bike is:\n\t" + rBike);

            Console.ReadKey();
        }
예제 #3
0
        private void button_Add_Click(object sender, EventArgs e)
        {
            int            gearNumber;
            long           serialNumber;
            double         price, warrenty, speed, gheight, sheight, bweight;
            string         make, input, msg = "";
            EnumSuspension suspensionType;
            EnumColor      color;
            bool           correct = false;

            Bike mountainBike = null;
            Bike roadBike     = null;

            if (bikeType.SelectedIndex == -1)
            {
                MessageBox.Show("\t Please Select Bike type \n");
                return;
            }

            input   = textBoxSeialNumber.Text;
            correct = RegExValidator.Is12Digit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t Serial Number must 12 digit \n");
                return;
            }
            serialNumber = long.Parse(input);


            correct = false;
            input   = textBoxMake.Text;
            correct = RegExValidator.IsAlphabetLetter(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t  Must be in LETTER(S) and NOT EMPTY  \n");
                return;
            }
            make = input;

            correct = false;
            input   = textBoxSpeed.Text;
            correct = RegExValidator.IsDigit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t Speed must not be zero AND Must be degit \n");
                return;
            }
            speed = Convert.ToDouble(input);


            Date made_date = new Date();

            made_date.Day   = Convert.ToInt32(textBoxDay.Text);
            made_date.Month = Convert.ToInt32(textBoxMonth.Text);
            made_date.Year  = Convert.ToInt32(textBoxYear.Text);
            suspensionType  = (EnumSuspension)positionsuspensioncombo;
            color           = (EnumColor)positioncolorcombo;
            price           = Convert.ToDouble(textBoxPrice.Text);
            warrenty        = Convert.ToDouble(textBoxWarrenty.Text);
            if (bikeType.SelectedIndex == 1)
            {
                correct = false;
                input   = textBoxSeatHeight.Text;
                correct = RegExValidator.IsDigit(input) &&
                          RegExValidator.IsEmpty(input);
                if (!correct)
                {
                    MessageBox.Show("\t Seat height must not be empty AND Must be degit \n");
                    return;
                }
                sheight  = Convert.ToDouble(input);
                bweight  = Convert.ToDouble(textBoxWeight.Text);
                roadBike = new RoadBike(serialNumber, make, speed, color, made_date, warrenty, price, sheight, bweight);
                bikeList.Add(roadBike);

                msg = "Bike successfully added as a road bike ";
            }
            else
            {
                gheight      = Convert.ToDouble(textBoxGroundHeight.Text);
                gearNumber   = Convert.ToInt32(textBoxGears.Text);
                mountainBike = new MountainBike(serialNumber, make, speed, color, made_date, warrenty, price, gheight, suspensionType, gearNumber);
                bikeList.Add(mountainBike);

                msg = "Bike successfully added as a mountain bike ";
            }


            msg += "with bikelist";
            MessageBox.Show(msg);
        }
예제 #4
0
        private void Button_Add_Click(object sender, EventArgs e)
        {
            long           serialNumber;
            double         warrenty, speed, gheight, sheight, bweight;
            string         make, input, msg = "";
            EnumSuspension suspensionType;
            EnumColor      color;
            bool           correct = false;

            Bike mountainBike = null;
            Bike roadBike     = null;

            //Bike bike;
            if (bikeType.SelectedIndex == -1)
            {
                MessageBox.Show("\t...BAD INPUT..No bike type selected\n");
                return;
            }

            input   = textBoxSeialNumber.Text;
            correct = RegExValidator.Is12Digit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...BAD INPUT..Serial cant be empty and should be of 12 digits\n");
                return;
            }
            serialNumber = long.Parse(input);


            correct = false;
            input   = textBoxMake.Text;
            correct = RegExValidator.IsAlphabetLetter(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...BAD INPUT..Make cannot be empty and should contain\n");
                return;
            }
            make = input;

            correct = false;
            input   = textBoxSpeed.Text;
            correct = RegExValidator.IsDigit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...BAD INPUT..Speed cannot be empty and should contain only digits\n");
                return;
            }
            speed = Convert.ToDouble(input);


            Date made_date = new Date();

            made_date.Day   = Convert.ToInt32(textBoxDay.Text);
            made_date.Month = Convert.ToInt32(textBoxMonth.Text);
            made_date.Year  = Convert.ToInt32(textBoxYear.Text);
            suspensionType  = (EnumSuspension)positionsuspensioncombo;
            color           = (EnumColor)positioncolorcombo;

            warrenty = Convert.ToDouble(textBoxWarrenty.Text);
            if (bikeType.SelectedIndex == 1)
            {
                correct = false;
                input   = textBoxSeatHeight.Text;
                correct = RegExValidator.IsDigit(input) &&
                          RegExValidator.IsEmpty(input);
                if (!correct)
                {
                    MessageBox.Show("\t...BAD INPUT..Seat height cannot be empty and should contain only digits\n");
                    return;
                }
                sheight  = Convert.ToDouble(input);
                bweight  = Convert.ToDouble(textBoxWeight.Text);
                roadBike = new RoadBike(serialNumber, make, speed, color, made_date, warrenty, sheight, bweight);
                bikeList.Add(roadBike);

                msg = "Bike successfully added as a road bike ";
            }
            else
            {
                gheight      = Convert.ToDouble(textBoxGroundHeight.Text);
                mountainBike = new MountainBike(serialNumber, make, speed, color, made_date, warrenty, gheight, suspensionType);
                bikeList.Add(mountainBike);

                msg = "Bike successfully added as a mountain bike ";
            }


            msg += "with bikelist";
            MessageBox.Show(msg);
        }