private void btnAgregar_Click(object sender, RoutedEventArgs e) { var newW = new WindowAgregarNCRemito(); newW.ShowDialog(); DateTime dtp2 = System.DateTime.Now; if (newW.DialogResult == true) { String insertNCR = "INSERT INTO notacredito (FK_idremitos, fecha) VALUES ('" + newW.idRemito + "','" + dtp2.ToString("yyyy/MM/dd") + "')"; conexion.operaciones(insertNCR); 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(pr); String productostNCR = "INSERT INTO productos_has_notacredito (FK_idNotaCredito, FK_idProductos, cantidad) VALUES ('" + lastid + "','" + idp + "', '" + cantidad + "')"; conexion.operaciones(productostNCR); } foreach (var producto in newW.productosparametro) { String updateCRremito = "UPDATE productos_has_remitos SET CrNotaCredito = '" + producto.cantidad + "' where FK_idProducto = '" + producto.id + "' and FK_idRemito = '" + newW.idRemito + "'"; conexion.operaciones(updateCRremito); } 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 = '" + 1 + "' where idOrdenCompra = '" + newW.idOC + "'"; conexion.operaciones(updateestadoOC); loadLtsNCRemitos(); MessageBox.Show("La nota de crédito se agrego correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void btnModificar_Click(object sender, RoutedEventArgs e) { try { int idnotacredito = (int)ltsRemitos.SelectedValue; productosAmodificar.Clear(); String idr = "SELECT FK_idremitos FROM notacredito WHERE idNotaCredito = '" + idnotacredito + "'"; String idRem = conexion.ValorEnVariable(idr); String productosRemito = "SELECT DISTINCT t2.nombre,t2.idProductos,t3.cantidad from productos_has_remitos t1, productos_has_notacredito t3 inner join productos t2 where t1.FK_idProducto = t2.idProductos and t1.FK_idRemito = '" + idRem + "' and t3.FK_idNotaCredito = '" + ltsRemitos.SelectedValue + "' and t3.FK_idProductos = t2.idProductos"; productos = conexion.ConsultaParametrizada(productosRemito, ltsRemitos.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 WindowAgregarNCRemito(productosAmodificar, int.Parse(idRem), idnotacredito); newW.Title = "Modificar Nota de Crédito"; newW.ShowDialog(); if (newW.DialogResult == true) { int idRemito = newW.idRemito; itemsNC.Clear(); foreach (Producto p in newW.itemsNC) { String nombre = p.nombre; int cantidad = p.cantidad; MessageBox.Show("cabtudad" + 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 deete = "DELETE FROM productos_has_notacredito WHERE FK_idNotaCredito = '" + newW.idNotaCred + "' AND FK_idProductos = '" + idp + "'"; conexion.operaciones(deete); String updateProductosNC = "INSERT INTO productos_has_notacredito (FK_idNotaCredito, FK_idProductos, cantidad) VALUES('" + newW.idNotaCred + "','" + idp + "', '" + cantidad + "')"; conexion.operaciones(updateProductosNC); foreach (var producto in newW.productosparametro) { String sql = "UPDATE productos_has_remitos SET CrNotaCredito = '" + producto.cantidad + "' where FK_idProducto = '" + producto.id + "' and FK_idRemito = '" + idRemito + "'"; 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); } loadLtsNCRemitos(); } } catch (NullReferenceException) { MessageBox.Show("Seleccione una Nota de crédito a modificar", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }