private void txtBuscar_TextChanged(object sender, EventArgs e) { DetallePrestamo FDP = new DetallePrestamo(); string buscar = '%' + txtBuscar.Text + '%'; dgvReportePersonal.DataSource = FDP.filtrarPP(buscar); }
public void Guardar(PrestamoEditDto prestamoDto) { var listaDetalles = new List <DetallePrestamo>(); foreach (var itemDto in prestamoDto.DetallePrestamo)//falta validar los datos del socio { var item = new DetallePrestamo() { DetallePedidoId = itemDto.DetallePrestamoId, Libro = new Libro { LibroId = itemDto.Libro.LibroId, Titulo = itemDto.Libro.Titulo }, //cantidad = itemDto.Cantidad cantidad = 1 }; listaDetalles.Add(item); } var prestamo = new Prestamo { PrestamoId = prestamoDto.PrestamoId, Socio = new Socio { SocioId = prestamoDto.NombreSocio.SocioId, NroDoc = prestamoDto.NombreSocio.NroDoc }, FechaPrestamo = prestamoDto.FechaPrestamo, detallePrestamo = listaDetalles }; _conexionBd = new ConexionBd(); SqlTransaction tran = null; try { SqlConnection cn = _conexionBd.AbrirConexion(); tran = cn.BeginTransaction();//Comienza la transacción _repositorio = new RepositorioPrestamos(cn, tran); _repositorioLibros = new RepositorioLibros(cn, tran); _repositorioDetalle = new RepositorioDetallePrestamos(cn, tran); _repositorio.Guardar(prestamo);//sigue deberia irse a guardar foreach (var detallePrestamo in prestamo.detallePrestamo) { detallePrestamo.Prestamo = prestamo; _repositorioDetalle.Guardar(detallePrestamo); _repositorioLibros.ActualizarPrestamos(detallePrestamo.Libro, -detallePrestamo.cantidad); } tran.Commit();//persiste los datos prestamoDto.PrestamoId = prestamo.PrestamoId; } catch (Exception e) { tran.Rollback(); throw new Exception(e.Message); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,idPrestamo,idLibro")] DetallePrestamo detallePrestamo) { if (id != detallePrestamo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(detallePrestamo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DetallePrestamoExists(detallePrestamo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(detallePrestamo)); }
private void txtBuscar_TextChanged(object sender, EventArgs e) { DetallePrestamo DPEP = new DetallePrestamo(); string buscar = '%' + txtBuscar.Text + '%'; dgvDetalleprestamo.DataSource = DPEP.filtrarPrestamo(buscar); }
public ActionResult DeleteConfirmed(int id) { DetallePrestamo detallePrestamo = db.DetallePrestamo.Find(id); db.DetallePrestamo.Remove(detallePrestamo); db.SaveChanges(); return(RedirectToAction("Index")); }
// Operaciones CRUD public bool insert(DetallePrestamo oDetallePrestamo) { string sql = @"INSERT INTO DetallePrestamo (idPrestamo,idEstadoDetallePrestamo,idEjemplar, idLibro,fechaDevolucion,)" + "VALUES (" + oDetallePrestamo.IdPrestamo + "," + oDetallePrestamo.IdEstadoDetallePrestamo + "," + oDetallePrestamo.IdEjemplar + "," + oDetallePrestamo.IdLibro + "," + oDetallePrestamo.FechaDevolucion + ")"; return((DBConexion.GetDBConexion().ExecuteSQL(sql)) == 1); }
public async Task <IActionResult> Create([Bind("Id,idPrestamo,idLibro")] DetallePrestamo detallePrestamo) { if (ModelState.IsValid) { _context.Add(detallePrestamo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(detallePrestamo)); }
public ActionResult Edit([Bind(Include = "idDetPre,idPrestamo,idRepuesto,Cantidad,Estado")] DetallePrestamo detallePrestamo) { if (ModelState.IsValid) { db.Entry(detallePrestamo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idPrestamo = new SelectList(db.Prestamo, "idPrestamo", "Descripcion", detallePrestamo.idPrestamo); ViewBag.idRepuesto = new SelectList(db.Repuesto, "idRepuesto", "Nombre", detallePrestamo.idRepuesto); return(View(detallePrestamo)); }
public ActionResult Edit([Bind(Include = "PrestamoID,DetallePrestamoID,FechaVencimiento,FechaDevolucion,CantidadEjemplares,LibroID,Estado")] DetallePrestamo detallePrestamo) { if (ModelState.IsValid) { db.Entry(detallePrestamo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LibroID = new SelectList(db.Libro, "LibroID", "NroDocumento", detallePrestamo.LibroID); ViewBag.PrestamoID = new SelectList(db.Prestamo, "PrestamoID", "NroDocumento", detallePrestamo.PrestamoID); return(View(detallePrestamo)); }
public ActionResult DetallesVentaAgregar(int?cantidad, int?idLibro, string titulo, string genero) { Libros_maestro.Models.DetallePrestamo daux = new DetallePrestamo(); daux.Libros = db.Libros.Find(idLibro); daux.libro_id = idLibro; daux.cantidad = cantidad; aux.Add(daux); ViewBag.listaDetalles = aux; return(PartialView()); }
internal bool Update(DetallePrestamo oDetallePrestamo) { //SIN PARAMETROS string str_sql = "UPDATE DetallePrestamo " + " SET idPrestamo=" + oDetallePrestamo.IdPrestamo + "," + " idEstadoDetallePrestamo=" + oDetallePrestamo.IdEstadoDetallePrestamo + "," + " idEjemplar=" + oDetallePrestamo.IdEjemplar + "," + " idLibro=" + oDetallePrestamo.IdLibro + "," + " fechaDevolucion=" + oDetallePrestamo.FechaDevolucion + " WHERE idDetallePrestamo=" + oDetallePrestamo; return(DBConexion.GetDBConexion().ExecuteSQL(str_sql) == 1); }
// GET: DetallePrestamoes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DetallePrestamo detallePrestamo = db.DetallePrestamo.Find(id); if (detallePrestamo == null) { return(HttpNotFound()); } return(View(detallePrestamo)); }
public static string Insertar(DataTable dtDetalle) { List <DetallePrestamo> detalle = new List <DetallePrestamo>(); DetallePrestamo Detalle = new DetallePrestamo(); foreach (DataRow raw in dtDetalle.Rows) { DetallePrestamo detail = new DetallePrestamo(); detail.IdPrestamo = Convert.ToInt32(raw["idPrestamo"].ToString()); detail.ClaveLibro = Convert.ToString(raw["claveLibro"].ToString()); detalle.Add(detail); } return(Detalle.InsertarDetalle(detalle)); }
// GET: DetallePrestamoes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DetallePrestamo detallePrestamo = db.DetallePrestamo.Find(id); if (detallePrestamo == null) { return(HttpNotFound()); } ViewBag.LibroID = new SelectList(db.Libro, "LibroID", "NroDocumento", detallePrestamo.LibroID); ViewBag.PrestamoID = new SelectList(db.Prestamo, "PrestamoID", "NroDocumento", detallePrestamo.PrestamoID); return(View(detallePrestamo)); }
// GET: DetallePrestamo/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DetallePrestamo detallePrestamo = db.DetallePrestamo.Find(id); if (detallePrestamo == null) { return(HttpNotFound()); } ViewBag.idPrestamo = new SelectList(db.Prestamo, "idPrestamo", "Descripcion", detallePrestamo.idPrestamo); ViewBag.idRepuesto = new SelectList(db.Repuesto, "idRepuesto", "Nombre", detallePrestamo.idRepuesto); return(View(detallePrestamo)); }
public void Guardar(DetallePrestamo detalle) { try { string cadenaComando = "INSERT INTO DetallesPrestamos (LibroId, Cantidad, PrestamoId) " + "VALUES(@libro, @cantidad, @prestamoid)"; var comando = new SqlCommand(cadenaComando, _sqlConnection, _tran); comando.Parameters.AddWithValue("@libro", detalle.Libro.LibroId); comando.Parameters.AddWithValue("@cantidad", detalle.cantidad); comando.Parameters.AddWithValue("@prestamoid", detalle.Prestamo.PrestamoId); comando.ExecuteNonQuery(); } catch (Exception) { throw new Exception("Error al intentar guardar un detalle de prestamos"); } }
public DetallePrestamo mapping(DataRow row) { DetallePrestamo oDetallePrestamo = new DetallePrestamo(); //Validamos que la fecha este cargada antes de mapear, la fecha de devolucion //es la fecha en la que se devolvio el libro y no la fecha limite por eso es //null al principio if (row["fechaDevolucion"] != DBNull.Value) { oDetallePrestamo.FechaDevolucion = Convert.ToDateTime(row["fechaDevolucion"].ToString()); } Console.WriteLine("El numero de ejemplar es : " + Convert.ToInt32(row["idEjemplar"].ToString())); oDetallePrestamo.IdEjemplar = Convert.ToInt32(row["idEjemplar"].ToString()); oDetallePrestamo.IdPrestamo = Convert.ToInt32(row["idPrestamo"].ToString()); oDetallePrestamo.IdLibro = Convert.ToInt32(row["idLibro"].ToString()); oDetallePrestamo.IdEstadoDetallePrestamo = Convert.ToInt32(row["idEstadoDetallePrestamo"].ToString()); return(oDetallePrestamo); }
public async Task <Unit> Handle(InsertarDetallePrestamo request, CancellationToken cancellationToken) { var detallePrestamo = new DetallePrestamo { Cantidad = request.Cantidad, IdPrestamo = request.IdPrestamo, IdLibro = request.IdLibro }; _context.tblDetallePrestamo.Add(detallePrestamo); var valor = await _context.SaveChangesAsync(); if (valor > 0) { return(Unit.Value); } throw new Exception("No se pudo apregar el detalle de préstamo"); }
protected void CacularButton_Click(object sender, EventArgs e) { Prestamo prestamo = new Prestamo(); DetallePrestamo detalle = new DetallePrestamo(); List <DetallePrestamo> detallePrestamolista = new List <DetallePrestamo>(); decimal capital = Utils.ToDecimal(CapitalTextBox.Text); decimal interes = Utils.ToDecimal(InteresTextBox.Text) / 100; int meses = Utils.ToInt(TiempoMesesTextBox.Text); decimal total; int cuota = 0; for (int i = 0; i < meses; i++) { detalle.InteresMensual = interes * capital / meses; detalle.CapitalMensual = capital / meses; total = detalle.InteresMensual * meses + capital; prestamo.Total = detalle.InteresMensual + detalle.CapitalMensual; cuota = cuota += 1; if (i == 0) { detalle.Balance = total - (detalle.InteresMensual + detalle.CapitalMensual); } else { detalle.Balance = detalle.Balance - (detalle.InteresMensual + detalle.CapitalMensual); } if (i == 0) { detallePrestamolista.Add(new DetallePrestamo(cuota, 0, detalle.Fecha, Utils.ToInt(PrestamoIdTextBox.Text), detalle.InteresMensual, detalle.CapitalMensual, detalle.Balance)); } else { detallePrestamolista.Add(new DetallePrestamo(cuota, 0, detalle.Fecha, Utils.ToInt(PrestamoIdTextBox.Text), detalle.InteresMensual, detalle.CapitalMensual, detalle.Balance)); } } ViewState["Cuotas"] = detallePrestamolista; PrestamoGridView.DataSource = ViewState["Cuotas"]; PrestamoGridView.DataBind(); }
private void cargarPrestamo() { oPrestamoSelected.FechaPrestamo = System.DateTime.Today; oPrestamoSelected.FechaLimite = dtFechaLimite.Value; oPrestamoSelected.IdEstadoPrestamo = Convert.ToInt32(cboEstado.SelectedValue); switch (Convert.ToInt32(cboCantLibros.SelectedItem)) { case 1: DetallePrestamo oDetallePrestamo1 = new DetallePrestamo(); oDetallePrestamo1.IdEjemplar = Convert.ToInt32(cboNumeroDeEjemplar1.SelectedItem.ToString()); oDetallePrestamo1.IdEstadoDetallePrestamo = Convert.ToInt32(cboEstadoDetallePrestamo1.SelectedValue.ToString()); oDetallePrestamo1.IdLibro = Convert.ToInt32(txtCodigoLibro1.Text); oDetallePrestamo1.IdPrestamo = oPrestamoSelected.IdPrestamo; oPrestamoSelected.ListaDeDetalles = new List <DetallePrestamo>(); oPrestamoSelected.ListaDeDetalles.Add(oDetallePrestamo1); break; case 2: DetallePrestamo oDetallePrestamo2 = new DetallePrestamo(); oDetallePrestamo2.IdEjemplar = Convert.ToInt32(cboNumeroDeEjemplar2.SelectedItem.ToString()); oDetallePrestamo2.IdEstadoDetallePrestamo = Convert.ToInt32(cboEstadoDetallePrestamo2.SelectedValue.ToString()); oDetallePrestamo2.IdLibro = Convert.ToInt32(txtCodigoLibro2.Text); oDetallePrestamo2.IdPrestamo = oPrestamoSelected.IdPrestamo; oPrestamoSelected.ListaDeDetalles.Add(oDetallePrestamo2); goto case 1; case 3: DetallePrestamo oDetallePrestamo3 = new DetallePrestamo(); oDetallePrestamo3.IdEjemplar = Convert.ToInt32(cboNumeroDeEjemplar3.SelectedItem.ToString()); oDetallePrestamo3.IdEstadoDetallePrestamo = Convert.ToInt32(cboEstadoDetallePrestamo3.SelectedValue.ToString()); oDetallePrestamo3.IdLibro = Convert.ToInt32(txtCodigoLibro3.Text); oDetallePrestamo3.IdPrestamo = oPrestamoSelected.IdPrestamo; oPrestamoSelected.ListaDeDetalles.Add(oDetallePrestamo3); goto case 2; } }
public void Guardar(DetallePrestamo detalle) { throw new NotImplementedException(); }
public void listarPP() { DetallePrestamo DP = new DetallePrestamo(); dgvReportePersonal.DataSource = DP.ListarPP(); }
public void ListarDetallePrestamo() { DetallePrestamo LDP = new DetallePrestamo(); dgvDetalleprestamo.DataSource = LDP.ListarDetallePrestamo(); }
public ActionResult NuevoPedido(VistaPedido pedidoVista) { pedidoVista = Session["pedidoVista"] as VistaPedido; var idDerechoLinea = int.Parse(Request["idDerechoLinea"]); var idChofer = Request["idChofer"].ToString(); var idEncargado = Request["idEncargado"].ToString(); if (idDerechoLinea == 0 || idChofer == "" || idEncargado == "") { var lista = db.DerechoLinea.ToList(); lista.Add(new DerechoLinea { idDerechoLinea = 0, idDueño = "[seleccione un derecho de linea...]" }); lista = lista.OrderBy(c => c.idDueño).ToList(); ViewBag.idDerechoLinea = new SelectList(lista, "idDerechoLinea", "idDueño"); var listb = db.Personal.ToList(); listb.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Chofer...]" }); listb = listb.OrderBy(c => c.Login).ToList(); ViewBag.idChofer = new SelectList(listb, "Login", "nombreCompleto"); var listc = db.Personal.ToList(); listc.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Encargado...]" }); listc = listc.OrderBy(c => c.Login).ToList(); ViewBag.idEncargado = new SelectList(listc, "Login", "nombreCompleto"); ViewBag.Error = "Debe Elegir un Encargado, Chofer y Derecho de Linea"; return(View(pedidoVista)); } if (pedidoVista.Repuestos.Count == 0) { var lista = db.DerechoLinea.ToList(); lista.Add(new DerechoLinea { idDerechoLinea = 0, idDueño = "[seleccione un derecho de linea...]" }); lista = lista.OrderBy(c => c.idDueño).ToList(); ViewBag.idDerechoLinea = new SelectList(lista, "idDerechoLinea", "idDueño"); var listb = db.Personal.ToList(); listb.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Chofer...]" }); listb = listb.OrderBy(c => c.Login).ToList(); ViewBag.idChofer = new SelectList(listb, "Login", "nombreCompleto"); var listc = db.Personal.ToList(); listc.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Encargado...]" }); listc = listc.OrderBy(c => c.Login).ToList(); ViewBag.idEncargado = new SelectList(listc, "Login", "nombreCompleto"); ViewBag.Error = "Deben Elegir un Producto"; return(View(pedidoVista)); } int prestamoID = 0; int cantRepuesto = 0; //Prueba de Transaccion int i = 0; using (var transaction = db.Database.BeginTransaction()) //using (TransactionScope scope = new TransactionScope()) { try { DateTime fecLim = DateTime.Now.AddDays(3); var prestamo = new Prestamo { idDerechoLinea = idDerechoLinea, fechaInicio = DateTime.Now, fechaLimite = fecLim, idChofer = idChofer.ToString(), idEncargado = idEncargado.ToString(), Descripcion = Request["Descripcion"].ToString() }; db.Prestamo.Add(prestamo); db.SaveChanges(); prestamoID = db.Prestamo.ToList().Select(o => o.idPrestamo).Max(); foreach (var item in pedidoVista.Repuestos) { var detallePedido = new DetallePrestamo { idPrestamo = prestamoID, idRepuesto = item.idRepuesto, Cantidad = int.Parse(item.MontoCantidad.ToString()), Estado = "Prestado" }; cantRepuesto = db.Repuesto.Where(r => r.idRepuesto == detallePedido.idRepuesto).FirstOrDefault().Cantidad; if (cantRepuesto - detallePedido.Cantidad <= 0) { transaction.Rollback(); ViewBag.Error = "Error: El repuesto pedido excede la cantidad de Inventario"; var listt1 = db.DerechoLinea.ToList(); listt1.Add(new DerechoLinea { idDerechoLinea = 0, idDueño = "[seleccione un derecho de linea...]" }); listt1 = listt1.OrderBy(c => c.idDueño).ToList(); ViewBag.idDerechoLinea = new SelectList(listt1, "idDerechoLinea", "idDueño"); var listt2 = db.Personal.ToList(); listt2.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Chofer...]" }); listt2 = listt2.OrderBy(c => c.Login).ToList(); ViewBag.idChofer = new SelectList(listt2, "Login", "nombreCompleto"); var listt3 = db.Personal.ToList(); listt3.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Encargado...]" }); listt3 = listt3.OrderBy(c => c.Login).ToList(); ViewBag.idEncargado = new SelectList(listt3, "Login", "nombreCompleto"); pedidoVista = new VistaPedido(); pedidoVista.DerechoLinea = new DerechoLinea(); pedidoVista.Encargado = new Personal(); pedidoVista.Chofer = new Personal(); pedidoVista.Repuestos = new List <OrdenRepuesto>(); Session["pedidoVista"] = pedidoVista; return(View(pedidoVista)); } else { db.DetallePrestamo.Add(detallePedido); db.SaveChanges(); //Prueba de Transaccion //i++; //if (i > 2) //{ // int a = 0; // i /= a; //} } } transaction.Commit(); //scope.Complete(); } catch (Exception ex) { ViewBag.Error = "Error: " + ex.Message; transaction.Rollback(); var listt1 = db.DerechoLinea.ToList(); listt1.Add(new DerechoLinea { idDerechoLinea = 0, idDueño = "[seleccione un derecho de linea...]" }); listt1 = listt1.OrderBy(c => c.idDueño).ToList(); ViewBag.idDerechoLinea = new SelectList(listt1, "idDerechoLinea", "idDueño"); var listt2 = db.Personal.ToList(); listt2.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Chofer...]" }); listt2 = listt2.OrderBy(c => c.Login).ToList(); ViewBag.idChofer = new SelectList(listt2, "Login", "nombreCompleto"); var listt3 = db.Personal.ToList(); listt3.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Encargado...]" }); listt3 = listt3.OrderBy(c => c.Login).ToList(); ViewBag.idEncargado = new SelectList(listt3, "Login", "nombreCompleto"); return(View(pedidoVista)); } } ViewBag.Message = string.Format("La orden: {0}, Grabada Exitosamente", prestamoID); var list = db.DerechoLinea.ToList(); list.Add(new DerechoLinea { idDerechoLinea = 0, idDueño = "[seleccione un derecho de linea...]" }); list = list.OrderBy(c => c.idDueño).ToList(); ViewBag.idDerechoLinea = new SelectList(list, "idDerechoLinea", "idDueño"); var list1 = db.Personal.ToList(); list1.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Chofer...]" }); list1 = list1.OrderBy(c => c.Login).ToList(); ViewBag.idChofer = new SelectList(list1, "Login", "nombreCompleto"); var list2 = db.Personal.ToList(); list2.Add(new Personal { Login = "", nombreCompleto = "[seleccione un Encargado...]" }); list2 = list2.OrderBy(c => c.Login).ToList(); ViewBag.idEncargado = new SelectList(list2, "Login", "nombreCompleto"); pedidoVista = new VistaPedido(); pedidoVista.DerechoLinea = new DerechoLinea(); pedidoVista.Encargado = new Personal(); pedidoVista.Chofer = new Personal(); pedidoVista.Repuestos = new List <OrdenRepuesto>(); Session["pedidoVista"] = pedidoVista; return(View(pedidoVista)); }