Well I'm making an invoice which is that the invoice consists of two tables detail purchase and purchase she keeps and everything perfect! My problem is that when I save correctly if I want to return an invoice without closing the form, the products that were made in the previous invoice are still there, I have a button to add the product if they are in the textbox, the product will add it to the grid I use linq to place the columns in the datagrid and I want to know if there is any way.
private void ActualizarLista()
{
//Nventas gestionproduucto = new Nventas();
//listaventas = gestionproduucto.obtenerlistventa();
}
private void ActualizarLista2()
{
//Ndetalleventa gestiondetalle = new Ndetalleventa();
//listadetalle = gestiondetalle.obtenerlistdetalle();
var lista = (from d in compra.listadetalle
select new
{
//d.ventas.idventas,
d.producto.Codproducto,
d.producto.Producto,
d.producto.Precio,
d.Cantidad,
d.Total
}).ToList();
dgvventas.DataSource = lista;
}
private void frmCompra_Load(object sender, EventArgs e)
{
try
{
ActualizarLista2();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnagregar_Click(object sender, EventArgs e)
{
try
{
EdetalleCompra nuevas = new EdetalleCompra();
nuevas.Cantidad = Convert.ToInt32(txtCantidad.Text);
nuevas.producto.Codproducto = Convert.ToInt32(txtproducto.Text);
nuevas.producto.Precio = Convert.ToDecimal(txtprecio.Text);
nuevas.Total = Convert.ToDecimal(nuevas.Cantidad * nuevas.producto.Precio);
nuevas.producto.Producto = txtnombre.Text;
compra.listadetalle.Add(nuevas);
ActualizarLista2();
calculartotal();
Deshabilitar();
txtCantidad.Enabled = true;
btnGuardar.Enabled = true;
btnCancelar.Enabled = true;
btnNuevo.Enabled = true;
txtdescuento.Enabled = true;
txtproducto.Text = "";
txtprecio.Text = "";
txtnombre.Text = "";
txtCantidad.Text = "";
txtprecio.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
radioButton2.Enabled = true;
rbtEfectivo.Enabled = true;
}
private void btnGuardar_Click(object sender, EventArgs e)
{
try
{
compra.Proveedor.idProveedor = Convert.ToInt32(txtbuscaridproveedor.Text);
compra.Usuario.idUsuario = Convert.ToInt32(txtbuscarusuario.Text);
compra.FechaFactura = dtpfecha.Value;
compra.HoraFactura = dtpHora.Value;
if (rbtEfectivo.Checked == true)
{
compra.Tipopago = "Efectivo";
}
else
{
compra.Tipopago = "Tarjeta";
}
compra.Subtotal = Convert.ToDecimal(txtsubtotal.Text);
compra.Descuento = Convert.ToDecimal(txtdescuento.Text);
compra.TotalCordobas = Convert.ToDecimal(txttotalCordobas.Text);
compra.TotalDolares = Convert.ToDecimal(txtTotalDolares.Text);
Ncompra gestionventas = new Ncompra();
gestionventas.agregarcompra(compra);
MessageBox.Show("Se agrego la compra correctamente", "COMPRA", MessageBoxButtons.OK, MessageBoxIcon.Information);
ActualizarLista2();
Limpiar();
Deshabilitar();
btnagregar.Enabled = false;
btnbuscarcliente.Enabled = false;
Btnbuscarusuario.Enabled = false;
txttotalCordobas.Enabled = false;
txttotalCordobas.Clear();
txtsubtotal.Clear();
dgvventas.DataSource = null;
btnagregar.Enabled = false;
btnGuardar.Enabled = false;
btnCancelar.Enabled = false;
btnNuevo.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Limpiar();
}