/// <summary> /// Initialises a new instance of the <see cref="UnitViewModel"/> class. /// </summary> /// <param name="individualUnitIoController">Unit IO manager</param> /// <param name="className">name of the parent class.</param> public UnitViewModel( Func <IUnitViewModel, string, bool> saveAction, FirstExampleManager firstExamples, string className, IndividualUnitFileContents rawData, bool isFirst, bool isLast, string imagePath, string alphaIdentifier) : base(rawData, firstExamples) { this.saveAction = saveAction; this.firstExamples = firstExamples; this.OpenWindowCmd = new CommonCommand(this.OpenWindow, () => true); this.PreviousUnitCmd = new CommonCommand(this.PreviousUnit, this.PreviousUnitAvailable); this.NextUnitCmd = new CommonCommand(this.NextUnit, this.NextUnitAvailable); this.UpdateUnitCmd = new CommonCommand(this.UpdateUnit, this.UpdateCmdAvailable); this.RefreshUnitCmd = new CommonCommand(this.RefreshUnit, () => true); this.SaveUnitCmd = new CommonCommand(this.SaveUnit, () => true); this.CloseWindowCmd = new CommonCommand(this.CloseWindow, () => true); this.FirstUnit = isFirst; this.LastUnit = isLast; this.SubClassImagePath = imagePath; this.AlphaIdentifier = alphaIdentifier; this.className = className; this.CompleteUpdate(); }
/// <date>12/08/2018</date> /// <summary> /// Initialises a new instance of the <see cref="VehicleDetailsViewModel"/> class. /// </summary> /// <param name="rawData"> raw data, read from the file.</param> public VehicleDetailsViewModel( IndividualUnitFileContents rawData, FirstExampleManager firstExamples) { this.UnitNumber = rawData.UnitNumber; this.FormerNumbers = new VehicleNumberTypeViewModel(); this.m_lastCheckDate = rawData.LastCheckDate; this.FormerNumbers = rawData.FormerNumbers; this.Notes = rawData.Notes; foreach (IJourneyDetailsType jny in rawData.Journeys) { IJourneyViewModel journey = JourneyFactory.ToJourneyViewModel( jny, firstExamples, this.UnitNumber); this.AddJourney(journey); } this.origMilage = UnitDistance; for (int index = 0; index < this.ServiceTypeList.Count; ++index) { if (this.ServiceTypeList[index] == rawData.InService) { this.serviceIndex = index; break; } } }
public static ObservableCollection <SubClassViewModel> CreateSubClasses( FirstExampleManager firstExamples, ObservableCollection <SubClassDataTypeViewModel> modelSubClasses, ClassFunctionalViewModel parent) { Random r = new Random(); ObservableCollection <SubClassViewModel> subClasses = new ObservableCollection <SubClassViewModel>(); foreach (SubClassDataTypeViewModel modelSubClass in modelSubClasses) { ObservableCollection <IUnitViewModel> units = new ObservableCollection <IUnitViewModel>(); for (int index = 0; index < modelSubClass.VehicleNumbersList.Count; ++index) { // Read raw data from the file and used to create a new unit. IndividualUnitFileContents unitRaw = IndividualUnitIOController.ReadIndividualUnitFile( parent.ClassId, modelSubClass.VehicleNumbersList[index].VehicleNumber.ToString()); if (unitRaw == null) { Logger.Instance.WriteLog($"Failed to read unit from file, data missing: {modelSubClass.VehicleNumbersList[index].VehicleNumber}"); } else { int imageIndex = r.Next(0, modelSubClass.SubClassImageList.Count); IUnitViewModel newUnit = new UnitViewModel( IndividualUnitIOController.WriteIndividualUnitFile, firstExamples, parent.ClassId, unitRaw, index == 0, index == modelSubClass.VehicleNumbersList.Count - 1, modelSubClass.GetImagePath(imageIndex), parent.ClassData.AlphaIdentifier); units.Add(newUnit); } } SubClassViewModel newSubClass = new SubClassViewModel( parent.ClassData.AlphaIdentifier, units); subClasses.Add(newSubClass); } return(subClasses); }