/// <summary> /// initializes view components /// </summary> public EditTimeTrialViewModel(IFrameNavigationService navigationService) { _navigationService = navigationService; timeTrial = navigationService.Parameter as TimeTrial; selectedModel = timeTrial.Model; modelText = timeTrial.Model.Base; date = timeTrial.Date; salesOrder = timeTrial.SalesOrder; productionNum = timeTrial.ProductionNumber; driveTime = timeTrial.DriveTime; AVTime = timeTrial.AVTime; numOptions = timeTrial.NumOptions; foreach (TimeTrialsOptionTime TTOption in timeTrial.TTOptionTimes) { TTOptions.Add(TTOption); } cancelCommand = new RelayCommand(cancel); // loadedCommand = new RelayCommand(loaded); //addTTCommand = new RelayCommand(addTT); //submitCommand = new RelayCommand(submit); }
/// <summary> /// Checks to see if all necessary fields are filled out with correct formatting /// before the time trial can be added. /// </summary> /// <returns> true if the form is complete, otherwise false </returns> private bool checkComplete() { informationText = ""; bool complete = true; _haveOptionTimes = true; if (string.IsNullOrWhiteSpace(modelText) || selectedModel == null) { complete = false; modelText = ""; informationText = "Please select a valid model."; } else if (date == null || salesOrder == null || salesOrder <= 0 || productionNum == null || productionNum <= 0) { complete = false; informationText = "Fill out all fields before adding time trial."; } else { //Check that options are filled out foreach (TimeTrialsOptionTime option in TTOptions) { if (!complete) { break; } else { if (string.IsNullOrWhiteSpace(option.OptionCode)) { complete = false; informationText = "Fill out all options before adding time trial."; } else if (option.OptionCode.Length != 2) { informationText = "Invalid Option Code Format. Must be 2 letters"; complete = false; } else { if (!option.OptionCode.ElementAt(0).Equals('P') && !option.OptionCode.ElementAt(0).Equals('T') && !option.OptionCode.ElementAt(0).Equals('p') && !option.OptionCode.ElementAt(0).Equals('t')) { informationText = "Option Code must start with a 'P' or 'T'"; complete = false; } else if (option.OptionCode.ElementAt(1).Equals('P') || option.OptionCode.ElementAt(1).Equals('T') || option.OptionCode.ElementAt(1).Equals('p') || option.OptionCode.ElementAt(1).Equals('t')) { informationText = "Option Code cannot end with a 'P' or 'T'"; complete = false; } } } if (option.Time <= 0) { _haveOptionTimes = false; } } //Check for duplicate options if (complete && TTOptions.GroupBy(n => n.OptionCode).Any(c => c.Count() > 1)) { complete = false; informationText = "Invalid Options. Duplicate option exists in list."; } } if (complete) { //If the AV time, Drive time, or all options times are not filled out, then the total time needs to be filled out if (!_haveOptionTimes || driveTime == null || driveTime <= 0 || AVTime == null || AVTime <= 0) { if (totalTime == null || totalTime <= 0) { complete = false; informationText = "Enter the total time or fill out the drive time, av time, and all option times."; } else if (driveTime != null || AVTime != null) { if (totalTime < ((driveTime == null ? 0 : driveTime) + (AVTime == null ? 0 : AVTime))) { complete = false; informationText = "Total time cannot be less than drive time plus av time."; } } } } return(complete); }