private void SetInteractionsLast() { List<InteractionLog> interactionLog = new List<InteractionLog>(); Interaction ins; int[] aniarr = this.Animals.ToArray(); for (int i = 0; i < aniarr.Length; i++) { InteractionLog animalLog = new InteractionLog(aniarr[i]); animalLog.Interactions = new List<Interaction>(); InteractionDB[] intarr = this.AllInteractionsLast.Where(x => x.AnimalConnected == aniarr[i]).ToArray(); for (int j = 0; j < intarr.Length; j++) { ins = new Interaction(intarr[j].AnimalInProx, intarr[j].NumberInteractions, intarr[j].TimeInteracted); animalLog.Interactions.Add(ins); } animalLog.Interactions = animalLog.Interactions.OrderByDescending(x => x.AverageConnectionTime).ToList(); interactionLog.Add(animalLog); } this.InteractionsLast = interactionLog; }
private void SetInteractionsLastFromDB() { List<InteractionLog> interactionLog = new List<InteractionLog>(); Interaction ins; SqlConnection sqlConn; foreach (int AnimalId in this.Animals) { ////Console.WriteLine("Getting Interactions for Animal: " + AnimalId.ToString()); InteractionLog animalLog = new InteractionLog(AnimalId); animalLog.Interactions = new List<Interaction>(); sqlConn = DataBaseConnection.SqlConn(); using (var con = sqlConn) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec service_GetInteractionsGivenTime @AnimalId, @StartDate, @EndDate", con)) { DateTime EndDate = DateTime.Today; DateTime StartDate = EndDate.AddDays(-3); cmd.Parameters.AddWithValue("@AnimalId", AnimalId); cmd.Parameters.AddWithValue("@StartDate", StartDate); cmd.Parameters.AddWithValue("@EndDate", EndDate); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new Interaction(Convert.ToInt32(drI["AnimalInProximity"]), Convert.ToInt32(drI["Interactions"]), Convert.ToInt32(drI["TimeConnected"])); animalLog.Interactions.Add(ins); } } } con.Close(); con.Dispose(); } sqlConn.Close(); sqlConn.Dispose(); animalLog.Interactions = animalLog.Interactions.OrderBy(x => x.AnimalId).ToList(); interactionLog.Add(animalLog); } this.InteractionsLast = interactionLog; }
private void SetInteractionsFromDB() { List<InteractionLog> interactionLog = new List<InteractionLog>(); Interaction ins; SqlConnection sqlConn; foreach (int AnimalId in this.Animals) { InteractionLog animalLog = new InteractionLog(AnimalId); animalLog.Interactions = new List<Interaction>(); sqlConn = DataBaseConnection.SqlConn(); using (var con = sqlConn) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec service_GetInteractions @AnimalId", con)) { cmd.Parameters.AddWithValue("@AnimalId", AnimalId); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new Interaction(Convert.ToInt32(drI["AnimalInProximity"]), Convert.ToInt32(drI["Interactions"]), Convert.ToInt32(drI["TimeConnected"])); animalLog.Interactions.Add(ins); } } } con.Close(); con.Dispose(); } sqlConn.Close(); sqlConn.Dispose(); animalLog.Interactions = animalLog.Interactions.OrderBy(x => x.AnimalId).ToList(); interactionLog.Add(animalLog); } this.Interactions = interactionLog; }