private void ObtenerDatosCalculados() { try { var animalBL = new AnimalPL(); var lotePL = new LotePL(); if (Contexto.LoteProyeccion != null) { if (Contexto.Lote.FechaDisponibilidad.Date.Year > 2000) { Contexto.FechaDisponible = Contexto.Lote.FechaDisponibilidad; } else { Contexto.FechaDisponible = Contexto.Lote.FechaInicio.AddDays(Contexto.LoteProyeccion.DiasEngorda); } } else { Contexto.FechaDisponible = DateTime.Now; } modificacionCodigo = true; dtpFechaDisponible.SelectedDate = Contexto.FechaDisponible; var animalesLote = animalBL.ObtenerAnimalesPorLote(Contexto.Corral.Organizacion.OrganizacionID, Contexto.Lote.LoteID); if (animalesLote == null) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ConfiguracionReimplante_LoteSinAnimales, MessageBoxButton.OK, MessageImage.Warning); return; } var count = animalesLote.Count; double temp = 0D; for (int i = 0; i < count; i++) { temp += animalesLote[i].FechaEntrada.Ticks / (double)count; } var average = new DateTime((long)temp); Contexto.PesoOrigen = Convert.ToInt32(animalesLote.Average(ani => ani.PesoCompra)); Contexto.TipoGanado = lotePL.ObtenerTipoGanadoCorral(Contexto.Lote); Contexto.DiasEngorda = Convert.ToInt32((DateTime.Now - average).TotalDays); if (Contexto.Lote.AplicaCierreLote && Contexto.DiasEngorda < 21) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ConfiguracionReimplante_LoteMenor21, MessageBoxButton.OK, MessageImage.Warning); Limpiar(); } } catch (Exception ex) { Logger.Error(ex); SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ConfiguracionReimplante_ErrorCalcularDatos, MessageBoxButton.OK, MessageImage.Error); } }