Ejemplo n.º 1
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            if (radioButtonMountain.Checked == true)
            {
                int temp = Convert.ToInt32(textBoxSearch.Text);

                bool         found            = false;
                Mountainbike searchedMountain = new Mountainbike();

                foreach (Mountainbike item in this.Mountainlist)
                {
                    if (item.Sn == temp)
                    {
                        found            = true;
                        searchedMountain = item;
                        break;
                    }
                }

                if (found)
                {
                    MessageBox.Show("Mountianbike Found....\n" + searchedMountain);
                }
                else
                {
                    MessageBox.Show("Mountainbike Not Found");
                }
            }
            else if (radioButtonRoad.Checked == true)
            {
                int temp = Convert.ToInt32(textBoxSearch.Text);

                bool found = false;

                Roadbike searchedRoad = new Roadbike();

                foreach (Roadbike item in this.Roadlist)
                {
                    if (item.Sn == temp)
                    {
                        found        = true;
                        searchedRoad = item;
                        break;
                    }
                }

                if (found)
                {
                    MessageBox.Show("Roadbike Found....\n" + searchedRoad);
                }
                else
                {
                    MessageBox.Show("Roadbike Not Found");
                }
            }
        }
Ejemplo n.º 2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (radioButtonMountain.Checked == true)
            {
                Mountainbike M1 = new Mountainbike();
                M1.Biketype = radioButtonMountain.Text;
                M1.Sn       = (Convert.ToInt32(textBoxSn.Text));
                M1.Model    = textBoxModel.Text;
                M1.Price    = (Convert.ToDouble(textBoxPrice.Text));
                M1.Brand    = textBoxBrand.Text;
                M1.Color    = ((EnumColor)this.comboBoxColor.SelectedItem);
                M1.Style    = ((EnumStyle)this.comboBoxStyle.SelectedItem);
                M1.Speed    = ((EnumSpeed)this.comboBoxColor.SelectedItem);
                M1.Typefs   = ((EnumType)this.comboBoxTypeofsuspension.SelectedItem);
                M1.Heightfg = (Convert.ToDouble(textBoxHeightfromground.Text));

                Date madedate = new Date();
                madedate.Year  = (Convert.ToInt32(textBoxYear.Text));
                madedate.Month = (Convert.ToInt32(textBoxMonth.Text));
                madedate.Day   = (Convert.ToInt32(textBoxDay.Text));

                M1.Madedate = madedate;
                Bike b1 = M1;
                Bikelist.Add(b1);
                Mountainlist.Add(M1);
            }
            else if (radioButtonRoad.Checked == true)
            {
                Roadbike R1 = new Roadbike();
                R1.Biketype   = radioButtonRoad.Text;
                R1.Sn         = (Convert.ToInt32(textBoxSn.Text));
                R1.Model      = textBoxModel.Text;
                R1.Price      = (Convert.ToDouble(textBoxPrice.Text));
                R1.Brand      = textBoxBrand.Text;
                R1.Color      = ((EnumColor)this.comboBoxColor.SelectedItem);
                R1.Style      = ((EnumStyle)this.comboBoxStyle.SelectedItem);
                R1.Speed      = ((EnumSpeed)this.comboBoxColor.SelectedItem);
                R1.Seatheight = (Convert.ToDouble(textBoxSeat.Text));

                Date madedate = new Date();
                madedate.Year  = (Convert.ToInt32(textBoxYear.Text));
                madedate.Month = (Convert.ToInt32(textBoxMonth.Text));
                madedate.Day   = (Convert.ToInt32(textBoxDay.Text));

                R1.Madedate = madedate;
                Bike b2 = R1;
                Bikelist.Add(b2);
                Roadlist.Add(R1);
            }
        }
Ejemplo n.º 3
0
        private void update_Click(object sender, EventArgs e)
        {
            int indexInBikes = GetIndexOfInList(lastSelectedBike,
                                                BikeToObject(bikesList));
            int  indexInType = -1;
            Bike newObj;

            if (lastSelectedBike is Roadbike)
            {
                indexInType = GetIndexOfInList(lastSelectedBike, RoadBikeToObject(roadbikesList));
                newObj      = new Roadbike(long.Parse(serialTextBox.Text), makeInputTextBox.Text,
                                           Convert.ToInt32(speedTextBox.Text), (EnumColor)Enum.Parse(typeof(EnumColor),
                                                                                                     colorComboBox.Text),
                                           new Date(Convert.ToInt32(dayTextBox.Text), Convert.ToInt32(monthTextBox.Text),
                                                    Convert.ToInt32(yearTextBox.Text)), Convert.ToInt32(seatHeightTextBox.Text));
                roadbikesList.RemoveAt(indexInType);
                roadbikesList.Insert(indexInType, (Roadbike)newObj);
            }
            else //if (lastSelectedBike is MountainBike)
            {
                indexInType = GetIndexOfInList(lastSelectedBike, MountainBikeToObject(MountainBikesList));
                newObj      = new MountainBike(long.Parse(serialTextBox.Text), makeInputTextBox.Text,
                                               Convert.ToInt32(speedTextBox.Text), (EnumColor)Enum.Parse(typeof(EnumColor),
                                                                                                         colorComboBox.Text),
                                               new Date(Convert.ToInt32(dayTextBox.Text), Convert.ToInt32(monthTextBox.Text),
                                                        Convert.ToInt32(yearTextBox.Text)),
                                               (EnumSuspension)Enum.Parse(typeof(EnumSuspension), suspensionComboBox.Text));
                MountainBikesList.RemoveAt(indexInType);
                MountainBikesList.Insert(indexInType, (MountainBike)newObj);
            }
            bikesList.RemoveAt(indexInBikes);
            bikesList.Insert(indexInBikes, newObj);
            if (indexInBikes == -1 || indexInType == -1 || newObj == null)
            {
                MessageBox.Show("Cannot  Update..!!");
            }
            else
            {
                MessageBox.Show("Updated successfully..!!");
            }
        }
Ejemplo n.º 4
0
        private void add_Click(object sender, EventArgs e)
        {
            string input;
            long   serNum = 0;
            string make = "";
            double speed = 0, seatHeight = 0;

            MyBikesStore.Date date;
            bool correct = false;

            if (bikeTypeDropDown.SelectedIndex == -1)
            {
                MessageBox.Show("\t...Not valid.. The input must be 12 digits only...\n");
                return;
            }

            //-------------validation for serial number
            input   = serialTextBox.Text;
            correct = MyBikesStore.Bus.RegExValidator.Is12Digit(input) &&
                      MyBikesStore.Bus.RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...Not valid. The input must be digits and 12 digits only.. PLease try again...\n");
                return;
            }
            serNum = long.Parse(input);

            correct = false;
            input   = makeInputTextBox.Text;
            correct = MyBikesStore.Bus.RegExValidator.IsAlphabetLetter(input) &&
                      MyBikesStore.Bus.RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\tThe input must not be empty and must be alphabets only\n");
                return;
            }
            make = input;

            correct = false;
            input   = speedTextBox.Text;
            correct = MyBikesStore.Bus.RegExValidator.IsDigit(input) &&
                      MyBikesStore.Bus.RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\tThe input must not be empty and must be alphabets only. Please try again \n");
                return;
            }
            speed = Convert.ToDouble(input);


            correct = false;
            input   = speedTextBox.Text;
            correct = MyBikesStore.Bus.RegExValidator.IsDigit(dayTextBox.Text) &&
                      MyBikesStore.Bus.RegExValidator.IsDigit(monthTextBox.Text) &&
                      MyBikesStore.Bus.RegExValidator.IsDigit(yearTextBox.Text) &&
                      MyBikesStore.Bus.RegExValidator.IsEmpty(dayTextBox.Text) &&
                      MyBikesStore.Bus.RegExValidator.IsEmpty(monthTextBox.Text) &&
                      MyBikesStore.Bus.RegExValidator.IsEmpty(yearTextBox.Text);
            if (!correct)
            {
                MessageBox.Show("\t...The input must not be empty and must be digits only. Please try again...\n");
                return;
            }
            while (!correct)
            {
                ;
            }

            date = new Date(Convert.ToInt32(dayTextBox.Text),
                            Convert.ToInt32(monthTextBox.Text),
                            Convert.ToInt32(yearTextBox.Text));
            Bike   bike;
            string successMsg = "";

            if (bikeTypeDropDown.SelectedIndex == 1)
            {
                correct = false;
                input   = seatHeightTextBox.Text;
                correct = MyBikesStore.Bus.RegExValidator.IsDigit(input) &&
                          MyBikesStore.Bus.RegExValidator.IsEmpty(input);
                if (!correct)
                {
                    MessageBox.Show("\t...The input must not be empty and must be digits only. Please try again..\n");
                    return;
                }
                seatHeight = Convert.ToInt32(input);
                Roadbike rbike = new Roadbike(serNum, make, speed,
                                              (EnumColor)Enum.Parse(typeof(EnumColor), colorComboBox.Text),
                                              date, seatHeight);
                roadbikesList.Add(rbike);
                bike       = (Bike)rbike;
                successMsg = "Bike successfully added as a road bike and ";
            }
            else
            {
                MountainBike mbike = new MountainBike(serNum, make, speed,
                                                      (EnumColor)Enum.Parse(typeof(EnumColor), colorComboBox.Text),
                                                      date, (EnumSuspension)Enum.Parse(typeof(EnumSuspension), suspensionComboBox.Text));
                MountainBikesList.Add(mbike);
                bike       = (Bike)mbike;
                successMsg = "Bike successfully added as a mountain bike and ";
            }
            bikesList.Add(bike);
            successMsg += "a bike";
            MessageBox.Show(successMsg);
        }