public void RegistrarPesaje(Pesaje objPesaje) { BDParacasEntities context = new BDParacasEntities(); context.Pesaje.Add(objPesaje); context.SaveChanges(); }
public void EliminarPesaje(int PesajeId) { BDParacasEntities context = new BDParacasEntities(); Pesaje objPesajeOri = context.Pesaje.FirstOrDefault(X => X.PesajeId == PesajeId); context.Pesaje.Remove(objPesajeOri); context.SaveChanges(); }
public void EditarPesaje(Pesaje objPesaje) { BDParacasEntities context = new BDParacasEntities(); Pesaje objPesajeOri = context.Pesaje.FirstOrDefault(X => X.PesajeId == objPesaje.PesajeId); // creo que no se edita context.SaveChanges(); }
public override void UpdateList() { switch (_current_action) { case molAction.Add: case molAction.Copy: if (_entity == null) { return; } List.AddItem(_entity.GetInfo(false)); if (FilterType == IFilterType.Filter) { PesajeList listA = PesajeList.GetList(_filter_results); listA.AddItem(_entity.GetInfo(false)); _filter_results = listA.GetSortedList(); } break; case molAction.Edit: case molAction.Lock: case molAction.Unlock: case molAction.ChangeStateAnulado: if (_entity == null) { return; } ActiveItem.CopyFrom(_entity); break; case molAction.Delete: if (ActiveItem == null) { return; } List.RemoveItem(ActiveOID); if (FilterType == IFilterType.Filter) { PesajeList listD = PesajeList.GetList(_filter_results); listD.RemoveItem(ActiveOID); _filter_results = listD.GetSortedList(); } break; } RefreshSources(); if (_entity != null) { Select(_entity.Oid); } _entity = null; }
public OrdenBuilder WithPesaje(bool existe) { if (existe) { Pesaje _pesaje = new Pesaje(); ICollection <Pesaje> _pesajes = new List <Pesaje>(); _pesajes.Add(_pesaje); _orden.Pesaje = _pesajes; } else { _orden.Pesaje = null; } return(this); }
public async Task <IActionResult> Finalizar(int?id, [Bind("Tag,asistencia,vacunado,peso,padecimientos,glosa")] List <FormResultado> results) { Orden orden = _context.Orden.Where(x => x.IdOrden == id).First(); if (ModelState.IsValid) { using (var transaccion = _context.Database.BeginTransaction()) { try { var queryPes = _context.Pesaje.Where(x => x.IdOrden == orden.IdOrden); var queryVac = _context.Vacunacion.Where(x => x.IdOrden == orden.IdOrden); var queryInsp = _context.Inspeccion.Where(x => x.IdOrden == orden.IdOrden); var queryCont = _context.Conteo.Where(x => x.IdOrden == orden.IdOrden); Pesaje pes = null; Vacunacion vac = null; Inspeccion insp = null; Conteo cont = null; if (queryPes.Count() != 0) { pes = queryPes.First(); } if (queryVac.Count() != 0) { vac = queryVac.First(); } if (queryInsp.Count() != 0) { insp = queryInsp.First(); } if (queryCont.Count() != 0) { cont = queryCont.First(); } foreach (FormResultado r in results) { Ganado vaca = _context.Ganado.Where(x => x.Tag == r.Tag).First(); if (pes != null) { orden.Pesaje.Add(pes); } if (vac != null) { orden.Vacunacion.Add(vac); } if (insp != null) { orden.Inspeccion.Add(insp); } if (cont != null) { orden.Conteo.Add(cont); } ResultadoConteo resultCont = new ResultadoConteo(); ResultadoPesaje resultPes = new ResultadoPesaje(); ResultadoVacunacion resultVac = new ResultadoVacunacion(); ResultadoInspeccion resultInsp = new ResultadoInspeccion(); // Encargandose del conteo; resultCont.Asistencia = r.asistencia; resultCont.IdGanado = vaca.IdGanado; resultCont.IdConteo = orden.Conteo.First().IdConteo; _context.Add(resultCont); //Encargandose del Pesaje if (resultCont.Asistencia == 1 && orden.Pesaje.Count() > 0) { resultPes.Peso = r.peso; resultPes.IdGanado = vaca.IdGanado; resultPes.IdPesaje = orden.Pesaje.First().IdPesaje; _context.Add(resultPes); } //Encargandose de la Vacunacion if (resultCont.Asistencia == 1 && orden.Vacunacion.Count() > 0) { List <VacunaAplicada> aplicaciones = new List <VacunaAplicada>(); var queryPlanificacion = _context.PlanificacionVacunacion.Where(x => x.IdVacunacion == orden.Vacunacion.First().IdVacunacion); foreach (PlanificacionVacunacion plan in queryPlanificacion) { VacunaAplicada aplicacion = new VacunaAplicada(); aplicacion.IdVacuna = plan.IdVacuna; aplicaciones.Add(aplicacion); } orden.Vacunacion.First().PlanificacionVacunacion = queryPlanificacion.ToList(); resultVac.IdGanado = vaca.IdGanado; resultVac.IdVacunacion = orden.Vacunacion.First().IdVacunacion; _context.Add(resultVac); foreach (VacunaAplicada ap in aplicaciones) { ap.IdResultadoVacunacion = resultVac.IdResultadoVacunacion; _context.Add(ap); } } //Encargandose de la Inspeccion if (resultCont.Asistencia == 1 && orden.Inspeccion.Count() > 0) { List <InspeccionPadecimiento> inspad_list = new List <InspeccionPadecimiento>(); resultInsp.Glosa = r.glosa; resultInsp.IdGanado = vaca.IdGanado; resultInsp.IdInspeccion = orden.Inspeccion.First().IdInspeccion; foreach (int num in r.padecimientos) { InspeccionPadecimiento inspad = new InspeccionPadecimiento(); inspad.IdPadecimiento = num; inspad_list.Add(inspad); } resultInsp.InspeccionPadecimiento = inspad_list; _context.Add(resultInsp); foreach (InspeccionPadecimiento ip in inspad_list) { ip.IdResultadoInspeccion = resultInsp.IdResultadoInspeccion; _context.Add(ip); } //orden.Estado='desactivado' _context.Update(orden); } } transaccion.Commit(); } catch { transaccion.Rollback(); return(View("~/Views/Shared/Error.cshtml")); throw; } await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } return(View(orden)); }
public async void Generar() { for (int i = 2006; i <= 2019; i++) { List <int> vacunaciones = new List <int>() { _rand.Next(2, 4), _rand.Next(5, 7), _rand.Next(10, 13) }; // Todos se dan entre el dia 05 - 25 for (int j = 1; j <= 12; j++) { var inicio = DateTime.Parse(string.Format("05/{0}/{1}", j, i)); var fin = DateTime.Parse(string.Format("25/{0}/{1}", j, i)); var fecha = FechaAleatoria(inicio, fin); bool existeInspeccion = false; bool existeVacunacion = false; bool existePesaje = false; using (SCGContext context = new SCGContext()) { using (var transaction = context.Database.BeginTransaction()) { var ganado = await context.Ganado.Where(x => x.Estado == Ganado.Estados.Activo && x.FechaIngreso <= fecha).ToListAsync(); var orden = new Orden() { FechaPlanificacion = fecha, Razon = string.Empty }; context.Orden.Add(orden); await context.SaveChangesAsync(); var conteo = new Conteo() { IdOrden = orden.IdOrden }; context.Conteo.Add(conteo); await context.SaveChangesAsync(); var inspeccion = new Inspeccion() { IdOrden = orden.IdOrden }; if (_rand.NextDouble() < ProbabilidadInspeccion) { context.Inspeccion.Add(inspeccion); await context.SaveChangesAsync(); existeInspeccion = true; } var pesaje = new Pesaje() { IdOrden = orden.IdOrden }; if (_rand.NextDouble() < ProbabilidadPesaje) { context.Pesaje.Add(pesaje); await context.SaveChangesAsync(); existePesaje = true; } // Mes de vacunacion Vacunacion vacunacion = new Vacunacion() { IdOrden = orden.IdOrden }; int vacunasMax = _rand.Next(2, 5); var listaVacunas = vacunasRandom(vacunasMax); if (vacunaciones.Exists(x => x == j)) { context.Vacunacion.Add(vacunacion); await context.SaveChangesAsync(); for (int k = 0; k < listaVacunas.Count; k++) { PlanificacionVacunacion pv = new PlanificacionVacunacion() { IdVacunacion = vacunacion.IdVacunacion }; pv.IdVacuna = listaVacunas[k]; context.PlanificacionVacunacion.Add(pv); await context.SaveChangesAsync(); } existeVacunacion = true; } /// A PARTIR DE ACA SE COMPLETAN LAS ACTIVIDADES foreach (var val in ganado) { ResultadoConteo rc = new ResultadoConteo() { IdConteo = conteo.IdConteo, IdGanado = val.IdGanado, Asistencia = 0 }; if (_rand.NextDouble() < ProbabilidadAsistencia) { rc.Asistencia = 1; } else { rc.Asistencia = 0; } context.ResultadoConteo.Add(rc); await context.SaveChangesAsync(); if (existeInspeccion) { if (_rand.NextDouble() < ProbabilidadPadecimiento) { var ri = new ResultadoInspeccion() { IdInspeccion = inspeccion.IdInspeccion, IdGanado = val.IdGanado }; context.ResultadoInspeccion.Add(ri); await context.SaveChangesAsync(); InspeccionPadecimiento ip = new InspeccionPadecimiento() { IdResultadoInspeccion = ri.IdResultadoInspeccion }; ip.IdPadecimiento = Padecimientos[_rand.Next(0, Padecimientos.Count)]; context.InspeccionPadecimiento.Add(ip); await context.SaveChangesAsync(); } } if (existePesaje) { bool invierno = false; var rp = new ResultadoPesaje() { IdGanado = val.IdGanado, IdPesaje = pesaje.IdPesaje }; int edad = (int)Math.Round((fecha - val.FechaNacimiento).Value.TotalDays / 365); if (fecha.Month > 4 && fecha.Month < 9) { invierno = true; } rp.Peso = calcularPeso(edad, invierno); context.ResultadoPesaje.Add(rp); await context.SaveChangesAsync(); } if (existeVacunacion) { var rv = new ResultadoVacunacion() { IdGanado = val.IdGanado, IdVacunacion = vacunacion.IdVacunacion }; context.ResultadoVacunacion.Add(rv); await context.SaveChangesAsync(); for (int k = 0; k < listaVacunas.Count; k++) { var va = new VacunaAplicada() { IdResultadoVacunacion = rv.IdResultadoVacunacion, IdVacuna = listaVacunas[k] }; context.VacunaAplicada.Add(va); await context.SaveChangesAsync(); } } } transaction.Commit(); } } } } }