/// <summary> /// Button to add or update a bike based on details in the forms /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddBike_Click(object sender, RoutedEventArgs e) { // +1 Because the indexes are being used (0-5) while int bikeToModify = BikeNumCombo.SelectedIndex + 1; int count = 0; bool bikeFound = false; foreach (var bike in bikeList) { // Updating existing bike if (bikeList[count].BikeId == bikeToModify) { ModifyBike(bike, stockList[count]); bikeFound = true; } count++; } // Adding new bike if (!bikeFound) { bikeList.Add(new Bike(Order.OrderId, bikeToModify)); stockList.Add(new BikeStock()); Bike bike = bikeList[bikeList.Count - 1]; BikeStock stock = stockList[stockList.Count - 1]; ModifyBike(bike, stock); } }
// Updates the wheels public void UpdateWheels(string comboBox, BikeStock stock) { double temp = 0; if (stock.WheelCost != 0) { Cost = Cost - stock.WheelCost; } temp = stock.Wheels(comboBox); Cost = Cost + temp; stock.WheelCost = temp; }
// Updates the frame public void UpdateFrame(string firstCombo, string secondCombo, BikeStock stock) { double temp = 0; if (stock.FrameCost != 0) { Cost = Cost - stock.FrameCost; } temp = stock.Frame(firstCombo, secondCombo); Cost = Cost + temp; stock.FrameCost = temp; }
// Updates the finishing set public void UpdateFinishingSet(string firstCombo, string secondCombo, BikeStock stock) { double temp = 0; if (stock.FinishingSetCost != 0) { Cost = Cost - stock.FinishingSetCost; } temp = stock.FinishingSet(firstCombo, secondCombo); Cost += temp; stock.FinishingSetCost = temp; }
/// <summary> /// Updates the display fields /// </summary> /// <param name="bikeToUpdate">Bike to display</param> /// <param name="stockToUpdate">Stock to display</param> private void UpdateText(Bike bikeToUpdate, BikeStock stockToUpdate) { OrderCost.Text = "Order Cost: £" + Orders.OrderCost; OrderIdField.Text = "Order Id: " + Order.OrderId; BikeCost.Text = "Bike Cost: £" + bikeToUpdate.Cost; FrameCost.Text = "Frame Cost: £" + stockToUpdate.FrameCost; WheelCost.Text = "Wheel Cost: £" + stockToUpdate.WheelCost; GroupCost.Text = "Group Set Cost: £" + stockToUpdate.GroupSetCost; FinishingCost.Text = "Finishing Set Cost: £" + stockToUpdate.FinishingSetCost; FrameStock.Text = "Frames Left: " + stockToUpdate.AvailableFrame; WheelStock.Text = "Wheels Left: " + stockToUpdate.AvailableWheels; GroupStock.Text = "Group Sets Left: " + stockToUpdate.AvailableGroupSet; FinishingStock.Text = "Finishing Sets Left: " + stockToUpdate.AvailableFinishingSet; }
/// <summary> /// Modifies a bike with an existing Id /// </summary> private void ModifyBike(Bike bikeToUpdate, BikeStock stockToUpdate) { // Update frame size combo if (FrameSizeCombo.SelectedIndex != -1 && FrameColourCombo.SelectedIndex != -1) { bikeToUpdate.Size = FrameSizeCombo.Text; bikeToUpdate.Colour = FrameColourCombo.Text; bikeToUpdate.UpdateFrame(FrameSizeCombo.Text, FrameColourCombo.Text, stockToUpdate); } // Update wheels from combo if (WheelsCombo.SelectedIndex != -1) { bikeToUpdate.Wheels = WheelsCombo.Text; bikeToUpdate.UpdateWheels(WheelsCombo.Text, stockToUpdate); } // Update gears from combo if (GearCombo.SelectedIndex != -1 && BrakeCombo.SelectedIndex != -1) { bikeToUpdate.Gears = GearCombo.Text; bikeToUpdate.Brakes = BrakeCombo.Text; bikeToUpdate.UpdateGroupSet(GearCombo.Text, BrakeCombo.Text, stockToUpdate); } // Update handlebars from combo if (HandlebarCombo.SelectedIndex != -1 && SaddleCombo.SelectedIndex != -1) { bikeToUpdate.Handlebars = HandlebarCombo.Text; bikeToUpdate.Saddle = SaddleCombo.Text; bikeToUpdate.UpdateFinishingSet(HandlebarCombo.Text, SaddleCombo.Text, stockToUpdate); } // If a warranty has been added if (WarrantyBox.IsChecked == true) { bikeToUpdate.AddWarranty(); } bikeToUpdate.UpdatePrice(); // Updates the display fields UpdateText(bikeToUpdate, stockToUpdate); }