public static void Run() { Console.WriteLine($"{Environment.NewLine}*** DECORATOR PATTERN ***{Environment.NewLine}"); // Create Some Bikes MountainBike mBike = new MountainBike("Red", 16, 85, 2); mBike.Display(); RoadBike rBike = new RoadBike("Black", 29, 90, true); rBike.Display(); // Now Decorate both the bikes with brakes Brakes mountainBikeWithBrakes = new Brakes(mBike); mountainBikeWithBrakes.AddBrakes(BrakeType.Disc); mountainBikeWithBrakes.Display(); Brakes roadBikeWithBrakes = new Brakes(rBike); roadBikeWithBrakes.AddBrakes(BrakeType.Rim); roadBikeWithBrakes.Display(); // Now Decorate the mountain bike with shocks Shocks mountainBikeWithShocks = new Shocks(mBike); mountainBikeWithShocks.AddShocks(8); mountainBikeWithShocks.Display(); }
private void buttonAdd_Click(object sender, EventArgs e) { if (this.radioButton1.Checked == true) { Bike aBike = new Bike(); MountainBike mBike = new MountainBike(); mBike.Type = "MBike"; mBike.SerialNumber = Convert.ToInt32(this.textBoxSerialNumber.Text); mBike.Made = (EnumMade)comboBoxMade.SelectedIndex; mBike.Model = (EnumModel)comboBoxModel.SelectedIndex; mBike.Speed = textBoxSpeed.Text; mBike.Color = (EnumColor)comboBoxColor.SelectedIndex; mBike.Day = Convert.ToInt32(textBoxDay.Text); mBike.Month = Convert.ToInt32(textBoxMonth.Text); mBike.Year = Convert.ToInt32(textBoxYear.Text); mBike.Suspension = (EnumSuspension)comboBoxSuspension.SelectedIndex; mBike.Height = textBoxHeight.Text; aBike = (Bike)mBike; this.myBikesList.Add(mBike); this.mountainBikesList.Add(mBike); } else if (this.radioButton2.Checked == true) { Bike aBike = new Bike(); RoadBike rBike = new RoadBike(); rBike.Type = "RBike"; rBike.SerialNumber = Convert.ToInt32(this.textBoxSerialNumber.Text); rBike.Made = (EnumMade)comboBoxMade.SelectedIndex; rBike.Model = (EnumModel)comboBoxModel.SelectedIndex; rBike.Speed = textBoxSpeed.Text; rBike.Color = (EnumColor)comboBoxColor.SelectedIndex; rBike.Day = Convert.ToInt32(textBoxDay.Text); rBike.Month = Convert.ToInt32(textBoxMonth.Text); rBike.Year = Convert.ToInt32(textBoxYear.Text); rBike.SeatHeight = textBoxSeatHeight.Text; aBike = (Bike)rBike; //MessageBox.Show("Bike" + rBike); this.myBikesList.Add(rBike); this.roadBikesList.Add(rBike); } }
private void button_Update_Click(object sender, EventArgs e) { int indexInBikes = GetIndexOfInList(SelectedBike, BikeToObject(bikeList)); int indexInType = -1; Bike newObj; if (SelectedBike is RoadBike) { indexInType = GetIndexOfInList(SelectedBike, RoadBikeToObject(roadBikeList)); newObj = new RoadBike(long.Parse(textBoxSeialNumber.Text), textBoxMake.Text, Convert.ToDouble(textBoxSpeed.Text), (EnumColor)Enum.Parse(typeof(EnumColor), comboBoxColor.Text), new Date(Convert.ToInt32(textBoxDay.Text), Convert.ToInt32(textBoxMonth.Text), Convert.ToInt32(textBoxYear.Text)), Convert.ToInt32(textBoxWarrenty.Text), Convert.ToDouble(textBoxPrice.Text), Convert.ToInt32(textBoxSeatHeight.Text), Convert.ToDouble(textBoxWeight.Text)); roadBikeList.RemoveAt(indexInType); roadBikeList.Insert(indexInType, (RoadBike)newObj); } else { indexInType = GetIndexOfInList(SelectedBike, MountainBikeToObject(mountainBikeList)); newObj = new MountainBike(long.Parse(textBoxSeialNumber.Text), textBoxMake.Text, Convert.ToDouble(textBoxSpeed.Text), (EnumColor)Enum.Parse(typeof(EnumColor), comboBoxColor.Text), new Date(Convert.ToInt32(textBoxDay.Text), Convert.ToInt32(textBoxMonth.Text), Convert.ToInt32(textBoxYear.Text)), Convert.ToInt32(textBoxWarrenty.Text), Convert.ToDouble(textBoxPrice.Text), Convert.ToDouble(textBoxGroundHeight.Text), (EnumSuspension)Enum.Parse(typeof(EnumSuspension), comboBoxSuspensionType.Text), Convert.ToInt32(textBoxGears.Text)); mountainBikeList.RemoveAt(indexInType); mountainBikeList.Insert(indexInType, (MountainBike)newObj); } bikeList.RemoveAt(indexInBikes); bikeList.Insert(indexInBikes, newObj); if (indexInBikes == -1 || indexInType == -1 || newObj == null) { MessageBox.Show("Could not Update..!!"); } else { MessageBox.Show("Updated successfully..!!"); } }
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); }
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); }