/// <summary> /// Report item generated and ready for reporting /// </summary> /// <param name="e"></param> protected virtual void ReportItemGenerated(HerdReportItemGeneratedEventArgs e) { if (OnReportItemGenerated != null) { OnReportItemGenerated(this, e); } }
private void OnEndOfMonth(object sender, EventArgs e) { RuminantHerd ruminantHerd = Resources.RuminantHerd(); List <Ruminant> herd = ruminantHerd.Herd; // group by breed foreach (var breedGroup in herd.GroupBy(a => a.Breed)) { // group by herd foreach (var herdGroup in breedGroup.GroupBy(a => a.HerdName)) { // group by sex foreach (var sexGroup in herdGroup.GroupBy(a => a.Gender)) { //// sucklings //var sucklings = sexGroup.Where(a => !a.Weaned); //if(sucklings.Count() > 0) //{ //} // weaned foreach (var ageGroup in sexGroup.OrderBy(a => a.Age).GroupBy(a => Math.Truncate(a.Age / 12.0))) { ReportDetails = new HerdReportItemGeneratedEventArgs(); ReportDetails.Breed = breedGroup.Key; ReportDetails.Herd = herdGroup.Key; ReportDetails.Age = Convert.ToInt32(ageGroup.Key); ReportDetails.Sex = sexGroup.Key.ToString().Substring(0, 1); ReportDetails.Number = ageGroup.Sum(a => a.Number); ReportDetails.AverageWeight = ageGroup.Average(a => a.Weight); ReportDetails.AverageWeightGain = ageGroup.Average(a => a.WeightGain); ReportDetails.AverageIntake = ageGroup.Average(a => (a.Intake)); //now daily/30.4; ReportDetails.AdultEquivalents = ageGroup.Sum(a => a.AdultEquivalent); if (sexGroup.Key == Sex.Female) { ReportDetails.NumberPregnant = ageGroup.Cast <RuminantFemale>().Where(a => a.IsPregnant).Count(); ReportDetails.NumberOfBirths = ageGroup.Cast <RuminantFemale>().Where(a => a.BirthDue).Sum(a => a.SucklingOffspring.Count()); } else { ReportDetails.NumberPregnant = 0; ReportDetails.NumberOfBirths = 0; } ReportItemGenerated(ReportDetails); } } } } }
private void OnEndOfMonth(object sender, EventArgs e) { // summary report. RuminantHerd ruminantHerd = Resources.RuminantHerd(); List<Ruminant> herd = ruminantHerd.Herd; // group by breed foreach (var breedGroup in herd.GroupBy(a => a.Breed)) { foreach (var herdGroup in breedGroup.GroupBy(a => a.HerdName)) { foreach (var sexGroup in herdGroup.GroupBy(a => a.Gender)) { //// sucklings //var sucklings = sexGroup.Where(a => !a.Weaned); //if(sucklings.Count() > 0) //{ //} // weaned foreach (var ageGroup in sexGroup.OrderBy(a => a.Age).GroupBy(a => Math.Truncate(a.Age / 12.0))) { ReportDetails = new HerdReportItemGeneratedEventArgs(); ReportDetails.Breed = breedGroup.Key; ReportDetails.Herd = herdGroup.Key; ReportDetails.Age = Convert.ToInt32(ageGroup.Key); ReportDetails.Sex = sexGroup.Key.ToString().Substring(0,1); ReportDetails.Number = ageGroup.Sum(a => a.Number); ReportDetails.AverageWeight = ageGroup.Average(a => a.Weight); ReportDetails.AverageWeightGain = ageGroup.Average(a => a.WeightGain); ReportDetails.AverageIntake = ageGroup.Average(a => (a.Intake))/30.4; ReportDetails.AdultEquivalents = ageGroup.Sum(a => a.AdultEquivalent); if(sexGroup.Key== Sex.Female) { ReportDetails.NumberPregnant = ageGroup.Cast<RuminantFemale>().Where(a => a.IsPregnant).Count(); ReportDetails.NumberOfBirths = ageGroup.Cast<RuminantFemale>().Where(a => a.BirthDue).Sum(a => a.SucklingOffspring.Count()); } else { ReportDetails.NumberPregnant = 0; ReportDetails.NumberOfBirths = 0; } ReportItemGenerated(ReportDetails); } } } } }
/// <summary> /// Report item generated and ready for reporting /// </summary> /// <param name="e"></param> protected virtual void ReportItemGenerated(HerdReportItemGeneratedEventArgs e) { if (OnReportItemGenerated != null) OnReportItemGenerated(this, e); }