/// <summary> /// Save the form. /// </summary> private void SaveDay() { ColourResourcesClass colourResources = ColourResourcesClass.GetInstance(); //bool success = true; Status = "Saving"; List <IJourneyDetailsType> currentDayJourneys = new List <IJourneyDetailsType>(); foreach (IJourneyViewModel journey in this.JnyList) { IJourneyDetailsType converted = JourneyFactory.ToJourneyModel( journey); currentDayJourneys.Add(converted); } DailyInputFactory.SaveDay( this.Year, this.Month, this.Day, currentDayJourneys); this.firstExamples.CheckNewJnyList( currentDayJourneys); this.RaisePropertyChangedOnJnyList(); this.Status = $"Save Completed for {this.Day}/{this.Month}/{this.Year}"; }
/// ---------- ---------- ---------- ---------- ---------- ---------- /// <name>updateArraysBasedOnCls</name> /// <date>15/09/13</date> /// <summary> /// If singleCls is set then use the currentJourney to update all /// location arrays. If not set then update the cls array for the /// current month. /// </summary> /// <param name="classId">class id</param> /// <param name="cls">cls name</param> /// <param name="currentJourneyDetails">current journey details</param> /// <param name="month">month to update</param> /// ---------- ---------- ---------- ---------- ---------- ---------- private static void UpdateArraysBasedOnCls( string vehicleNumber, List <GroupsType> groups, ReportCounterManager <LocationCounter> locations, IJourneyDetailsType currentJourneyDetails, string cls) { if (vehicleNumber == string.Empty) { return; } List <string> classIds = ClassReportFactory.GetClassAndFamilies( groups, vehicleNumber); foreach (string classId in classIds) { if (classId == cls) { locations.AddOne( currentJourneyDetails.To, currentJourneyDetails.From); } } }
/// <summary> /// Convert from a <see cref="IJourneyDetailsType"/> to a <see cref="IJourneyViewModel"/>. /// </summary> /// <param name="input"><see cref="IJourneyDetailsType"/> to convert</param> /// <param name="firstExamples">first examples manager</param> /// <param name="parentNumber">parent unit id</param> /// <returns>converted <see cref="IJourneyViewModel"/></returns> public static IJourneyViewModel ToJourneyViewModel( IJourneyDetailsType input, FirstExampleManager firstExamples, string parentNumber = "") { string unitOne = input.Units.Count > 0 ? input.Units[0] : string.Empty; string unitTwo = input.Units.Count > 1 ? input.Units[1] : string.Empty; string unitThree = input.Units.Count > 2 ? input.Units[2] : string.Empty; string unitFour = input.Units.Count > 3 ? input.Units[3] : string.Empty; JourneyViewModel viewModel = new JourneyViewModel( firstExamples, parentNumber, input.JnyId.JnyNumber, input.From, input.To, input.Via, input.JnyId.Date, input.Distance, unitOne, unitTwo, unitThree, unitFour); viewModel.CalculateStates(); return(viewModel); }
/// <summary> /// Takes a stn and a journey, if the stn and the journey to stn /// match then increase the toLocation arrays. Similar for the /// from stn. /// </summary> /// <param name="stn">stn name</param> /// <param name="currentJourneyDetails">current jny details</param> private static void UpdateArraysForSingleStn( ReportCounterManager <LocationCounter> locations, string stn, IJourneyDetailsType currentJourneyDetails) { if (currentJourneyDetails.To == stn) { locations.AddFrom(currentJourneyDetails.From); } else if (currentJourneyDetails.From == stn) { locations.AddTo(currentJourneyDetails.To); } }
/// <summary> /// Searches for the numbers in journey and see if they are already /// in the list. If they aren't then it adds them. /// </summary> /// <param name="journey">journey details</param> public void SearchLocationsForMatch(IJourneyDetailsType journey) { if (IsCopLocation(journey.From, LocalListType.allPurpose)) { FirstExampleType firstExamples = new FirstExampleType(); firstExamples.Item = journey.From; firstExamples.Date = journey.Date; firstExamples.Index = journey.JnyId.JnyNumber; m_listLocation.Add(firstExamples); firstExamples = null; } if (IsCopLocation(journey.To, LocalListType.allPurpose)) { FirstExampleType firstExamples = new FirstExampleType(); firstExamples.Item = journey.To; firstExamples.Date = journey.Date; firstExamples.Index = journey.JnyId.JnyNumber; m_listLocation.Add(firstExamples); firstExamples = null; } }
/// <date>10/003/19</date> /// <summary> /// Read the contents of a version 2 file. At the point this has been called, the /// first line has been read and is no longer relevant to the decoding process. /// The next line to be read will be the unit id. /// </summary> /// <param name="reader">the open file reader</param> /// <returns>contents of the file being read.</returns> private static IndividualUnitFileContents ReadIndividualUnitFileVersion2( StreamReader reader) { string currentLine = string.Empty; try { // {number} string unitNumber = reader.ReadLine(); // {mileage} //currentLine = reader.ReadLine(); MilesChains unitDistance = new MilesChains(reader.ReadLine()); // {number_entries} int entriesCount = IndividualUnitIOController.ConvertInteger( reader.ReadLine()); IVehicleNumberType formerNumbers = IndividualUnitIOController.GetFormerNumbers( reader.ReadLine()); DateTime lastEntryDate = IndividualUnitIOController.ConvertDate( reader.ReadLine()); DateTime lastCheckDate = IndividualUnitIOController.ConvertDate( reader.ReadLine()); // {Status} VehicleServiceType inService = VehicleServiceType.InService; inService = IndividualUnitIOController.GetServiceStatus(reader.ReadLine()); // {Note} string note = string.Empty; note = reader.ReadLine(); List <IJourneyDetailsType> journeys = new List <IJourneyDetailsType>(); currentLine = reader.ReadLine(); while (currentLine != null) { IJourneyDetailsType journey = IndividualUnitIOController.ConvertJourney( currentLine); if (journey != null) { journeys.Add(journey); } currentLine = reader.ReadLine(); } return(new IndividualUnitFileContents( unitNumber, unitDistance, entriesCount, formerNumbers, inService, lastEntryDate, lastCheckDate, journeys, note)); } catch (Exception ex) { Logger.Instance.WriteLog( $"ERROR: Error reading individual unit file (ver2). Error is {ex}"); return(null); } }
/// <date>10/003/19</date> /// <summary> /// Read the contents of a version 1 file. At the point this has been called, the /// first line has been read and this is the unit id. /// </summary> /// <param name="reader">the open file reader</param> /// <param name="firstLine">contents of the first line/unit id</param> /// <returns>contents of the file being read.</returns> private static IndividualUnitFileContents ReadIndividualUnitFileVersion1( StreamReader reader, string firstLine) { string unitNumber = firstLine; string currentLine = string.Empty; // {mileage} currentLine = reader.ReadLine(); MilesChains unitDistance = new MilesChains(currentLine); // {number_entries} int entriesCount = IndividualUnitIOController.ConvertInteger( reader.ReadLine()); IVehicleNumberType formerNumbers = IndividualUnitIOController.GetFormerNumbers( reader.ReadLine()); DateTime lastCheckDate = IndividualUnitIOController.ConvertDate( reader.ReadLine()); List <IJourneyDetailsType> journeys = new List <IJourneyDetailsType>(); currentLine = reader.ReadLine(); while (currentLine != null) { IJourneyDetailsType journey = IndividualUnitIOController.ConvertJourney(currentLine); if (journey != null) { journeys.Add(journey); } currentLine = reader.ReadLine(); } DateTime lastJourneyDate; { if (journeys.Count > 0) { lastJourneyDate = journeys[journeys.Count - 1].Date; } else { lastJourneyDate = new DateTime(1970, 1, 1); } return(new IndividualUnitFileContents( unitNumber, unitDistance, entriesCount, formerNumbers, VehicleServiceType.InService, lastJourneyDate, lastCheckDate, journeys, string.Empty)); } }
/// <summary> /// Searches for the numbers in journey and see if they are already /// in the list. If they aren't then it adds them. /// </summary> /// <param name="journey">journey details</param> public void SearchNumbersForMatch(IJourneyDetailsType journey) { foreach (string unit in journey.Units) { bool cop = this.IsCopNumber( unit, LocalListType.allPurpose); if (cop) { FirstExampleType firstExamples = new FirstExampleType(); firstExamples.Item = unit; firstExamples.Date = journey.Date; firstExamples.Index = journey.JnyId.JnyNumber; m_listNumber.Add(firstExamples); firstExamples = null; } } //if (IsCopNumber(journey.GetJourneyFirstNumber(), LocalListType.allPurpose)) //{ // FirstExampleType firstExamples = new FirstExampleType(); // firstExamples.Item = journey.GetJourneyFirstNumber(); // firstExamples.Date = journey.GetJourneyDate(); // firstExamples.Index = journey.GetJourneyIndex(); // m_listNumber.Add(firstExamples); // firstExamples = null; //} //if (journey.GetJourneyNumberOfVehicles() >= 2) //{ // if (IsCopNumber(journey.GetJourneySecondNumber(), LocalListType.allPurpose)) // { // FirstExampleType firstExamples = new FirstExampleType(); // firstExamples.Item = journey.GetJourneySecondNumber(); // firstExamples.Date = journey.GetJourneyDate(); // firstExamples.Index = journey.GetJourneyIndex(); // m_listNumber.Add(firstExamples); // firstExamples = null; // } //} //if (journey.GetJourneyNumberOfVehicles() >= 3) //{ // if (IsCopNumber(journey.GetJourneyThirdNumber(), LocalListType.allPurpose)) // { // FirstExampleType firstExamples = new FirstExampleType(); // firstExamples.Item = journey.GetJourneyThirdNumber(); // firstExamples.Date = journey.GetJourneyDate(); // firstExamples.Index = journey.GetJourneyIndex(); // m_listNumber.Add(firstExamples); // firstExamples = null; // } //} //if (journey.GetJourneyNumberOfVehicles() >= 4) //{ // if (IsCopNumber(journey.GetJourneyFourthNumber(), LocalListType.allPurpose)) // { // FirstExampleType firstExamples = new FirstExampleType(); // firstExamples.Item = journey.GetJourneyFourthNumber(); // firstExamples.Date = journey.GetJourneyDate(); // firstExamples.Index = journey.GetJourneyIndex(); // m_listNumber.Add(firstExamples); // firstExamples = null; // } //} }