public static Trip ToTrip(this TripHeaderViewModel thvm) { if (null == thvm) { return null; } Trip trip = null; switch (thvm.GearCode) { case "S": trip = new PurseSeineTrip(); break; case "L": trip = new LongLineTrip(); break; case "P": trip = new PoleAndLineTrip(); break; default: // Don't know what kind of trip this is... break; } // It's not correct to assume that DepartureDate and ReturnDate have values. // Yes, they are required, but the caller may pass us an invalid structure // here. Bleah! if (null != trip) { trip.DepartureDate = thvm.DepartureDate; if (trip.DepartureDate.HasValue) { trip.DepartureTimeOnly = trip.DepartureDate.Value.ToString("HHmm"); trip.DepartureDateOnly = thvm.DepartureDate.Value.Subtract(thvm.DepartureDate.Value.TimeOfDay); } trip.ReturnDate = thvm.ReturnDate; if (trip.ReturnDate.HasValue) { trip.ReturnTimeOnly = trip.ReturnDate.Value.ToString("HHmm"); trip.ReturnDateOnly = thvm.ReturnDate.Value.Subtract(thvm.ReturnDate.Value.TimeOfDay); } trip.TripNumber = thvm.TripNumber; if (Enum.IsDefined(typeof(ObserverProgram), thvm.ProgramCode)) { trip.ProgramCode = (ObserverProgram)Enum.Parse(typeof(ObserverProgram), thvm.ProgramCode); } trip.CountryCode = thvm.CountryCode; if (Enum.IsDefined(typeof(WorkbookVersion), thvm.Version)) { trip.Version = (WorkbookVersion)Enum.Parse(typeof(WorkbookVersion), thvm.Version); } } return trip; }
internal ReportResult Summary(LongLineTrip trip) { return new ReportResult(new Report()); }
internal ReportResult AllSamples(LongLineTrip trip) { var repo = TubsDataService.GetRepository<LongLineCatch>(MvcApplication.CurrentSession); var samples = repo.FilterBy(s => s.FishingSet.Trip.Id == trip.Id).OrderBy(s => s.FishingSet.SetNumber); // It would be cool if I could use LINQ like I do for Purse Seine, but NHibernate doesn't like the // cool LINQ project necessary to find the Lat/Lon for the start of set // Latitude = s.FishingSet.EventList.Where(sh => sh.ActivityType == Spc.Ofp.Tubs.DAL.Common.HaulActivityType.StartOfSet).First().Latitude IList<LengthSampleLineItem> items = new List<LengthSampleLineItem>(samples.Count()); foreach (var sample in samples) { string latitude = String.Empty; string longitude = String.Empty; string eez = String.Empty; var startOfSet = sample.FishingSet.EventList.Where(sh => sh.ActivityType == Spc.Ofp.Tubs.DAL.Common.HaulActivityType.StartOfSet).FirstOrDefault(); if (null != startOfSet) { latitude = startOfSet.Latitude; longitude = startOfSet.Longitude; eez = startOfSet.EezCode; } items.Add(new LengthSampleLineItem() { SetDate = sample.FishingSet.SetDate, Latitude = latitude, Longitude = longitude, Eez = eez, SetNumber = sample.FishingSet.SetNumber.HasValue ? sample.FishingSet.SetNumber.Value : -1, SequenceNumber = sample.SampleNumber.HasValue ? sample.SampleNumber.Value : -1, // All 1 for obstrip_id 4177? SpeciesCode = sample.SpeciesCode, Length = sample.Length.HasValue ? sample.Length.Value : -1 }); } var report = new Report(items.ToReportSource()); report.TextFields.Title = string.Format("Length frequency summary for trip {0}", trip.SpcTripNumber); return new ReportResult(report); }
internal void Validate(LongLineTrip trip, LongLineSetViewModel svm) { // The delta between Ship's date and UTC date shouldn't be more than +/- 1 day DateTime? shipStartOfSet = svm.ShipsDate.Merge(svm.ShipsTime); DateTime? utcStartOfSet = svm.UtcDate.Merge(svm.UtcTime); if (shipStartOfSet.HasValue && utcStartOfSet.HasValue) { var deltaT = shipStartOfSet.Value.Subtract(utcStartOfSet.Value); if (Math.Abs(deltaT.TotalDays) > 1.0d) { var msg = string.Format("Difference of {0} days between ship's and local time too large", Math.Abs(deltaT.TotalDays)); ModelState["UtcDate"].Errors.Add(msg); } } if (shipStartOfSet.HasValue && shipStartOfSet.Value.CompareTo(trip.DepartureDate) < 0) { ModelState["ShipsDate"].Errors.Add("Start of set can't be before the trip departure date"); } }