public static bool Editar(T_GUQ_PRESUPUESTO presupuesto, List <T_GUQ_PARTIDA> listaPartidas, List <double> listaMontos) { bool exito = false; try { RicardoPalmaEntities db = new RicardoPalmaEntities(); T_GUQ_PRESUPUESTO_PARTIDA PresupuestoPartida; db.Database.ExecuteSqlCommand( "DELETE FROM T_GUQ_PRESUPUESTO_PARTIDA WHERE idPresupuesto = @idPer", new SqlParameter[] { new SqlParameter("idPer", presupuesto.idPresupuesto) } ); presupuesto.estado = "Generado"; presupuesto.monto = 0; for (int i = 0; i < listaPartidas.Count(); i++) { PresupuestoPartida = new T_GUQ_PRESUPUESTO_PARTIDA(); PresupuestoPartida.idPartida = listaPartidas[i].idPartida; PresupuestoPartida.idPresupuesto = presupuesto.idPresupuesto; PresupuestoPartida.montoPartida = listaMontos[i]; presupuesto.idPresupuesto = presupuesto.idPresupuesto; presupuesto.monto = presupuesto.monto + listaMontos[i]; db.Database.ExecuteSqlCommand( "InSERT INTO T_GUQ_PRESUPUESTO_PARTIDA VALUES(@P1,@P2,@P3)", new SqlParameter[] { new SqlParameter("P1", PresupuestoPartida.idPresupuesto), new SqlParameter("P2", PresupuestoPartida.idPartida), new SqlParameter("P3", PresupuestoPartida.montoPartida) } ); } db.Database.ExecuteSqlCommand( "UPDATE T_GUQ_PRESUPUESTO SET monto = @p1 WHERE idPresupuesto = @p2", new SqlParameter[] { new SqlParameter("P1", presupuesto.monto), new SqlParameter("P2", presupuesto.idPresupuesto) } ); db.SaveChanges(); exito = true; } catch (Exception ex) { exito = false; Bitacora.CrearLog("Error al editar el presupuesto", TipoLog.Error, ex); } return(exito); }
public string Edit(T_GUQ_PRESUPUESTO presupuesto) { string mensaje = "Error al grabar los datos"; if (listaPartidas.Count() == 0) { mensaje = "Error : No puede grabar presupuesto sin partida"; return(mensaje); } T_GUQ_PRESUPUESTO oPresupuesto = TGUQPresupuesto.Obtener(presupuesto.idPresupuesto); List <T_GUQ_PARTIDA> lisPartidas = new List <T_GUQ_PARTIDA>(); T_GUQ_PARTIDA oPartida; List <double> listaMontos = new List <double>(); double montoTotal = 0; for (int i = 0; i < listaPartidas.Count(); i++) { montoTotal = montoTotal + listaPartidas[i].monto; oPartida = new T_GUQ_PARTIDA(); oPartida.idPartida = listaPartidas[i].idPartida; oPartida.dscPartida = listaPartidas[i].descripcion; lisPartidas.Add(oPartida); listaMontos.Add(listaPartidas[i].monto); } bool exito = TGUQPresupuesto.Editar(oPresupuesto, lisPartidas, listaMontos); if (exito) { mensaje = "Los datos se grabaron con exito"; } return(mensaje); }
public string Create(T_GUQ_PRESUPUESTO presupuesto) { string mensaje = "Error al grabar los datos"; if (DateTime.Now.Year != presupuesto.anio) { mensaje = "Error : No puede grabar presupuesto en ese año: " + presupuesto.anio; return(mensaje); } if (listaPartidas.Count() == 0) { mensaje = "Error : No puede grabar presupuesto sin partida"; return(mensaje); } foreach (var item in TGUQPresupuesto.ListarTodos()) { if (item.anio == presupuesto.anio && item.idArea == presupuesto.idArea) { mensaje = "Error : Ya existe presupuesto para este año y esa área"; return(mensaje); } } List <T_GUQ_PARTIDA> lisPartidas = new List <T_GUQ_PARTIDA>(); T_GUQ_PARTIDA oPartida; List <double> listaMontos = new List <double>(); double montoTotal = 0; for (int i = 0; i < listaPartidas.Count(); i++) { montoTotal = montoTotal + listaPartidas[i].monto; oPartida = new T_GUQ_PARTIDA(); oPartida.idPartida = listaPartidas[i].idPartida; oPartida.dscPartida = listaPartidas[i].descripcion; lisPartidas.Add(oPartida); listaMontos.Add(listaPartidas[i].monto); } bool exito = TGUQPresupuesto.Crear(presupuesto, lisPartidas, listaMontos); if (exito) { mensaje = "Los datos se grabaron con exito"; } return(mensaje); }
public ActionResult AgregarPartida(T_GUQ_PRESUPUESTO presupuesto, int partida) { foreach (var item in listaPartidas) { if (item.idPartida == partida) { return(Json("Error", JsonRequestBehavior.AllowGet)); } } double monto = presupuesto.monto; var Partida = TGUQPartida.Obtener(partida); Partida oPartida = new Partida(); oPartida.monto = Math.Round(monto, 2); oPartida.idPartida = partida; oPartida.descripcion = Partida.dscPartida; listaPartidas.Add(oPartida); return(Json(listaPartidas, JsonRequestBehavior.AllowGet)); }
public static bool Crear(T_GUQ_PRESUPUESTO presupuesto, List <T_GUQ_PARTIDA> listaPartidas, List <double> listaMontos) { bool exito = false; try { RicardoPalmaEntities db = new RicardoPalmaEntities(); T_GUQ_PRESUPUESTO_PARTIDA PresupuestoPartida; presupuesto.estado = "Generado"; for (int i = 0; i < listaPartidas.Count(); i++) { PresupuestoPartida = new T_GUQ_PRESUPUESTO_PARTIDA(); PresupuestoPartida.idPartida = listaPartidas[i].idPartida; PresupuestoPartida.montoPartida = listaMontos[i]; presupuesto.monto = presupuesto.monto + listaMontos[i]; presupuesto.T_GUQ_PRESUPUESTO_PARTIDA.Add(PresupuestoPartida); } db.Entry(presupuesto).State = EntityState.Added; // db.T_GUQ_PRESUPUESTO.Add(presupuesto); for (int i = 0; i < listaPartidas.Count(); i++) { db.Entry(listaPartidas[i]).State = EntityState.Unchanged; } db.SaveChanges(); exito = true; } catch (Exception ex) { exito = false; Bitacora.CrearLog("Error al crear el presupuesto", TipoLog.Error, ex); } return(exito); }