private void btnAgregar_Click(object sender, RoutedEventArgs e) { bandera = true; itemsNC.Clear(); int index = ltsNC.SelectedIndex; Console.WriteLine("idindex parametro " + index); var newW = new windowAgregarNCFactura(1); newW.ShowDialog(); DateTime hoy = DateTime.Today; if (newW.DialogResult == true) { idFactura = newW.idFactura; String totall = newW.txtTotal.Text; String subtotall = newW.txtSubtotal.Text; String insertNC = "INSERT INTO notacreditosalida (total, subtotal,FK_idFacturas, fecha) VALUES ( '" + totall + "', '" + subtotall + "','" + idFactura + "','" + hoy.ToString("yyyy/MM/dd") + "')"; conexion.operaciones(insertNC); string ultimoId = "Select last_insert_id()"; lastid = conexion.ValorEnVariable(ultimoId); foreach (Producto p in newW.itemsNC) { String nombre = p.nombre; int cantidad = p.cantidad; float totalp = p.total; float precioUni = p.precioUnitario; int idp = p.id; Producto pr = new Producto(nombre, idp, cantidad, totalp, precioUni); itemsNC.Add(p); String productostNC = "INSERT INTO productos_has_notacreditosalida (FK_idNotaCredito, FK_idProductos, cantidad, precioUnitario) VALUES ('" + lastid + "','" + idp + "', '" + cantidad + "', '" + precioUni + "')"; conexion.operaciones(productostNC); String updatestock = "UPDATE productos SET stock = stock+'" + p.cantidad + "' where idProductos = '" + p.id + "'"; conexion.operaciones(updatestock); } foreach (var producto in newW.itemsFact) { String sql = "UPDATE productos_has_facturassalida SET CrNotaCredito = '" + producto.cantidad + "' where FK_idProductos = '" + producto.id + "' and FK_idfacturas = '" + idFactura + "'"; conexion.operaciones(sql); } String updateestadoOC = "UPDATE ordencomprasalida SET estadoNC = '" + 2 + "' where idOrdenCompra = '" + newW.idOC + "'"; conexion.operaciones(updateestadoOC); LoadDgvNC(); loadLtsNotaCredito(); bandera = false; MessageBox.Show("Se agrego correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information); ltsNC.SelectedIndex = -1; ltsNC.SelectedIndex = 0; } }
private void btnModificarNC_Click(object sender, RoutedEventArgs e) { try { bandera = true; int idnotacredito = (int)ltsNC.SelectedValue; productosAmodificar.Clear(); String iva = txtIVA.Text; String subtotal = txtSubtotal.Text; String cambio = txtTipoCambio.Text; String total = txtTotal.Text; String idf = "SELECT FK_idfacturas FROM notacreditosalida WHERE idNotaCredito = '" + ltsNC.SelectedValue + "'"; String idFactura = conexion.ValorEnVariable(idf); String productosFatura = "SELECT DISTINCT t1.subtotal, t2.nombre ,t2.precioUnitario,t2.idProductos,t3.cantidad from productos_has_facturassalida t1, productos_has_notacreditosalida t3 inner join productos t2 where t1.FK_idProductos = t2.idProductos and t1.FK_idfacturas = '" + idFactura + "' and t3.FK_idNotaCredito = '" + ltsNC.SelectedValue + "'"; productos = conexion.ConsultaParametrizada(productosFatura, ltsNC.SelectedValue); for (int i = 0; i < productos.Rows.Count; i++) { producto = new Producto(productos.Rows[i].ItemArray[1].ToString(), (int)productos.Rows[i].ItemArray[3], (int)productos.Rows[i].ItemArray[4], (float)productos.Rows[i].ItemArray[0], (float)productos.Rows[i].ItemArray[2]); productosAmodificar.Add(producto); } var newW = new windowAgregarNCFactura(subtotal, total, iva, cambio, productosAmodificar, idFactura, idnotacredito, 1); newW.Title = "Modificar Nota de Crédito"; newW.ShowDialog(); if (newW.DialogResult == true) { String subm = newW.subtotalmodificar; String totalm = newW.totalmodificar; int idnotaCredito = newW.idnota; itemsNC.Clear(); foreach (Producto p in newW.itemsNC) { String nombre = p.nombre; int cantidad = p.cantidad; float totalp = p.total; float precioUni = p.precioUnitario; int idp = p.id; Producto pr = new Producto(nombre, idp, cantidad, totalp, precioUni); itemsNC.Add(p); String updateNC = "UPDATE notacreditosalida SET total = '" + totalm + "', subtotal = '" + subm + "' WHERE idNotaCredito = '" + idnotaCredito + "'"; conexion.operaciones(updateNC); String updateProductosNC = "UPDATE productos_has_notacreditosalida SET FK_idNotaCredito = '" + idnotaCredito + "', FK_idProductos = '" + idp + "', cantidad = '" + cantidad + "', precioUnitario = '" + precioUni + "' WHERE FK_idNotaCredito = '" + idnotaCredito + "' AND FK_idProductos = '" + idp + "'"; conexion.operaciones(updateProductosNC); foreach (var producto in newW.itemsFact) { String sql = "UPDATE productos_has_facturassalida SET CrNotaCredito = '" + producto.cantidad + "' where FK_idProductos = '" + producto.id + "' and FK_idfacturas = '" + idFactura + "'"; conexion.operaciones(sql); } foreach (var item in newW.itemsNCAntiguos) { String updatestock = "UPDATE productos SET stock = stock-'" + item.cantidad + "' where idProductos = '" + item.id + "'"; conexion.operaciones(updatestock); } //update stock foreach (var item in newW.itemsNC) { String updatestock = "UPDATE productos SET stock = stock +'" + item.cantidad + "' where idProductos = '" + item.id + "'"; conexion.operaciones(updatestock); } } LoadDgvNC(); loadLtsNotaCredito(); bandera = false; ltsNC.Items.MoveCurrentToLast(); MessageBox.Show("Se modifico correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (NullReferenceException) { MessageBox.Show("Seleccione una factura a modificar", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }