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(); 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 notacredito (total, subtotal,FK_idFactura, fecha) VALUES ( '" + totall.ToString().Replace(",", ".") + "', '" + subtotall.ToString().Replace(",", ".") + "','" + 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_notacredito (FK_idNotaCredito, FK_idProductos, cantidad, precioUnitario) VALUES ('" + lastid + "','" + idp + "', '" + cantidad + "', '" + precioUni.ToString().Replace(",", ".") + "')"; conexion.operaciones(productostNC); } foreach (var producto in newW.itemsFact) { String sql = "UPDATE productos_has_facturas SET CrNotaCredito = '" + producto.cantidad + "' where FK_idProducto = '" + producto.id + "' and FK_idfactura = '" + idFactura + "'"; conexion.operaciones(sql); } foreach (var item in newW.itemsNC) { String updatestock = "UPDATE productos SET stock = stock -'" + item.cantidad + "' where idProductos = '" + item.id + "'"; conexion.operaciones(updatestock); } String updateestadoOC = "UPDATE ordencompra SET estadoNC = '" + 2 + "' where idOrdenCompra = '" + newW.idOC + "'"; conexion.operaciones(updateestadoOC); LoadDgvNC(); loadLtsNotaCredito(); bandera = false; ltsNC.Items.MoveCurrentToLast(); } }
private void btnModificarNC_Click(object sender, RoutedEventArgs e) { 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_idfactura FROM notacredito WHERE idNotaCredito = '" + ltsNC.SelectedValue + "'"; String idFactura = conexion.ValorEnVariable(idf); String productosFatura = "SELECT DISTINCT t2.nombre,t2.idProductos,t3.cantidad from productos_has_facturas t1, productos_has_notacredito t3 inner join productos t2 where t1.FK_idProducto = t2.idProductos and t1.FK_idFactura = '" + idFactura + "' and t3.FK_idNotaCredito = '" + ltsNC.SelectedValue + "' and t3.FK_idProductos = t2.idProductos"; productos = conexion.ConsultaParametrizada(productosFatura, ltsNC.SelectedValue); for (int i = 0; i < productos.Rows.Count; i++) { producto = new Producto(productos.Rows[i].ItemArray[0].ToString(), (int)productos.Rows[i].ItemArray[1], (int)productos.Rows[i].ItemArray[2]); productosAmodificar.Add(producto); } var newW = new windowAgregarNCFactura(subtotal, total, iva, cambio, productosAmodificar, idFactura, idnotacredito); 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(); String deete = "DELETE FROM productos_has_notacredito WHERE FK_idNotaCredito = '" + idnotaCredito + "' "; conexion.operaciones(deete); 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 notacredito SET total = '" + totalm.ToString().Replace(",", ".") + "', subtotal = '" + subm.ToString().Replace(",", ".") + "' WHERE idNotaCredito = '" + idnotaCredito + "'"; conexion.operaciones(updateNC); String updateProductosNC = "INSERT INTO productos_has_notacredito (FK_idNotaCredito, FK_idProductos, cantidad) VALUES('" + idnotaCredito + "','" + idp + "', '" + cantidad + "')"; conexion.operaciones(updateProductosNC); foreach (var producto in newW.itemsFact) { String sql = "UPDATE productos_has_facturas SET CrNotaCredito = '" + producto.cantidad + "' where FK_idProducto = '" + producto.id + "' and FK_idfactura = '" + idFactura + "'"; conexion.operaciones(sql); } } foreach (var item1 in newW.itemsNCAntiguos) { String updatestock1 = "UPDATE productos SET stock = stock+'" + item1.cantidad + "' where idProductos = '" + item1.id + "'"; conexion.operaciones(updatestock1); } //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(); } }