public FamilyTree GetFamilyTree(int AnimalId, int Depth, int CurrentLevel) { FamilyTree ins = new FamilyTree(); ins.AnimalId = AnimalId; ins.Level = CurrentLevel; //...Get Father ParentView Father = GetFatherChildRelationship(AnimalId); //...Get Mother ParentView Mother = GetMotherChildRelationship(AnimalId); if (CurrentLevel <= Depth) { if (Father == null) { ins.MaleParentId = 0; } else { ins.MaleParentId = Father.AnimalId; } ins.FatherParents = GetFamilyTree(ins.MaleParentId, Depth, ++CurrentLevel); if (Mother == null) { ins.FemaleParentId = 0; } else { ins.FemaleParentId = Mother.AnimalId; } ins.MotherParents = GetFamilyTree(ins.FemaleParentId, Depth, ++CurrentLevel); } else { ins.FatherParents = new FamilyTree(); ins.MotherParents = new FamilyTree(); } return(ins); }
public ParentView GetMotherChildRelationship(int ChildId) { ParentView ins = new ParentView(); DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI = con.CreateCommand(); cmdI.Connection = con; cmdI.Parameters.Clear(); cmdI.CommandText = CommonStrings.GetAnimalRelationships; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@ChildId", ChildId); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); if (drI.HasRows) { while (drI.Read()) { if (drI["Sex"].ToString().Equals("Female")) { ins.AnimalId = Convert.ToInt32(drI["AnimalId"]); ins.DecriptiveName = drI["DecriptiveName"].ToString(); ins.TagNumber = drI["TagNumber"].ToString(); ins._AnimalType = drI["Species"].ToString(); ins._Sex = drI["Sex"].ToString(); } } } cmdI.Connection.Close(); con.Dispose(); if (ins.AnimalId == 0) { return(null); } else { return(ins); } }
public ParentView GetMotherChildRelationship(int ChildId) { ParentView ins = new ParentView(); DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI = con.CreateCommand(); cmdI.Connection = con; cmdI.Parameters.Clear(); cmdI.CommandText = CommonStrings.GetAnimalRelationships; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@ChildId", ChildId); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); if (drI.HasRows) { while (drI.Read()) { if (drI["Sex"].ToString().Equals("Female")) { ins.AnimalId = Convert.ToInt32(drI["AnimalId"]); ins.DecriptiveName = drI["DecriptiveName"].ToString(); ins.TagNumber = drI["TagNumber"].ToString(); ins._AnimalType = drI["Species"].ToString(); ins._Sex = drI["Sex"].ToString(); } } } cmdI.Connection.Close(); con.Dispose(); if(ins.AnimalId == 0) { return null; } else { return ins; } }