private string GetBestNIMale() { var grouped = this.BirthHistories .GroupBy(s => s.FatherId) .Select(g => new { MaleId = g.Key, Count = g.Count() }).ToList(); var ordered = grouped.OrderByDescending(x => x.Count).ToList(); int Best = ordered.First().MaleId; BirthHistory Selected = this.BirthHistories.Where(x => x.FatherId == Best).ToList().First(); return(Selected.MaleTag); }
private void SetBirthHistory() { this.BirthHistories = new List <BirthHistory>(); BirthHistory ins; SqlConnection sqlConn = DataBaseConnection.SqlConn(); using (var con = sqlConn) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec " + StoredProcedures.GetBirthHistory + " @AnimalId", con)) { cmd.Parameters.AddWithValue("@AnimalId", this.AnimalId); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new BirthHistory(); if (drI["BirthDate"].Equals(DBNull.Value)) { ins.BirthDate = DateTime.MinValue; } else { ins.BirthDate = Convert.ToDateTime(drI["BirthDate"]); } ins.FatherId = Convert.ToInt32(drI["MaleParentId"]); ins.Success = Convert.ToBoolean(drI["Success"]); ins.TubeUsed = Convert.ToInt32(drI["TubeId"]); ins.WasNatural = Convert.ToBoolean(drI["WasNatural"]); ins.MaleTag = drI["TagNumber"].ToString(); this.BirthHistories.Add(ins); } } } con.Close(); con.Dispose(); } }
private void SetBirthHistory() { this.BirthHistories = new List<BirthHistory>(); BirthHistory ins; SqlConnection sqlConn = DataBaseConnection.SqlConn(); using (var con = sqlConn) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec " + StoredProcedures.GetBirthHistory + " @AnimalId", con)) { cmd.Parameters.AddWithValue("@AnimalId", this.AnimalId); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new BirthHistory(); if(drI["BirthDate"].Equals(DBNull.Value)) { ins.BirthDate = DateTime.MinValue; } else { ins.BirthDate = Convert.ToDateTime(drI["BirthDate"]); } ins.FatherId = Convert.ToInt32(drI["MaleParentId"]); ins.Success = Convert.ToBoolean(drI["Success"]); ins.TubeUsed = Convert.ToInt32(drI["TubeId"]); ins.WasNatural = Convert.ToBoolean(drI["WasNatural"]); ins.MaleTag = drI["TagNumber"].ToString(); this.BirthHistories.Add(ins); } } } con.Close(); con.Dispose(); } }