private void btnGuardar_Click(object sender, EventArgs e) { int cliente = 0; if (rbtAgregar.Checked) { if (txtCliente.Text != "" && txtApPaterno.Text != "" && txtApMaterno.Text != "" && txtTelefono.Text != "") { _cliente = new ClienteDTO() { nombre = txtCliente.Text, apPaterno = txtApPaterno.Text, apMaterno = txtApMaterno.Text, telefono = txtTelefono.Text }; _clienteManager.InsertarCliente(_cliente); } cliente = _clienteManager.Clientes.Last().idCliente; } else if (rbtBuscar.Checked) { cliente = Convert.ToInt32(cmbCliente.SelectedValue); } _renta = new RentaDTO() { idUsuario = Program.usuario, idTipoUsuario = Program.idTipoUsuario, idCliente = cliente, total = Convert.ToDouble(txtTotal.Text), fechaInicio = dateTimePicker1.Value.ToString(), fechaVencimiento = dateTimePicker2.Value.ToString(), notas = txtNotas.Text }; if (_rentaManager.InsertarRenta(_renta)) { for (int i = 0; i < dgvDetalleVenta.RowCount - 1; i++) { try { _dr = new DetalleRentaDTO() { idRenta = _rentaManager.Rentas.Last().idRenta, idProducto = Convert.ToInt32(cmbProductos.SelectedValue), idProveedor = _prodManager.BuscarProductosPorId(Convert.ToInt32(cmbProductos.SelectedValue)).idProveedor, cantidad = Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[1].Value), total = Convert.ToDouble(dgvDetalleVenta.Rows[i].Cells[2].Value), }; if (_drManager.InsertarDetalleRenta(_dr)) { int stock = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).stockActual; stock -= Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[2].Value); if (_prod == null) { _prod = new ProductoDTO() { idProducto = Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value), nombre = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).nombre, idProveedor = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).idProveedor, idTipoProducto = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).idTipoProducto, precioVenta = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).precioVenta, precioCompra = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).precioCompra, stockActual = stock, stockMax = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).stockMax, stockMin = _prodManager.BuscarProductosPorId(Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[0].Value)).stockMin }; _prodManager.ModificarProducto(_prod); cmbProductos.ResetText(); txtCantidad.Clear(); txtTotal.Clear(); txtNotas.Clear(); cmbProductos.Focus(); } _prod = null; } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, titulo, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } MessageBox.Show("Renta registrada", titulo, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool ModificarRenta(RentaDTO renta) { return(rentaRepository.Modificar(renta)); }
public bool EliminarRenta(RentaDTO renta) { return(rentaRepository.Eliminar(renta)); }
public bool InsertarRenta(RentaDTO renta) { return(rentaRepository.Insertar(renta)); }