private void btVolver_Click(object sender, EventArgs e) { ventas fr = new ventas(); fr.Show(); this.Close(); }
private void btVentas_Click(object sender, EventArgs e) { ventas fr = new ventas(); fr.Show(); }
private void btFinalizarVenta_Click(object sender, EventArgs e) { DateTime fecha; fecha = dateTimePicker1.Value; MessageBox.Show(session.UserID.ToString()); string numero = session.UserID.ToString(); conexion.ConnectionString = strconexion; cmdLeer2.CommandType = CommandType.Text; cmdLeer2.CommandText = "INSERT INTO ventas values ('" + idVenta + "','" + txtPrecio.Text + "' ,'" + fecha + "' )"; cmdLeer2.Connection = conexion; cmdLeer5.CommandType = CommandType.Text; cmdLeer5.CommandText = "insert into ventasCliente values((select isnull(MAX(idVentaCliente), 0)+1 from ventasCliente),'" + idVenta + "', '" + numero + "')"; cmdLeer5.Connection = conexion; cmdLeer6.CommandType = CommandType.Text; cmdLeer6.CommandText = "update clientes set gastos = (gastos + (select precio from ventas where IdVenta = '" + idVenta + "' )) where idCliente='" + numero + "'"; cmdLeer6.Connection = conexion; cmdLeer7.CommandType = CommandType.Text; cmdLeer7.CommandText = "update cuentas set dinero = dinero - (select precio from ventas where IdVenta = '" + idVenta + "' )" + "where idCuenta=(select idCuenta from clientesCuenta where idCliente='" + numero + "')"; cmdLeer7.Connection = conexion; conexion.Open(); string file = @"C:\Users\igorberistain\Dropbox\&DAM\&&Ignacio\deberes\casa\factura" + session.Nombre + ".txt"; //string file = @"C:\Users\igor\Dropbox\&DAM\&&Ignacio\deberes\casa\factura"+session.Nombre+".txt"; using (StreamWriter outputFile = new StreamWriter(file, true)) { // conexion.ConnectionString = strconexion; cmdFactura.CommandType = CommandType.Text; cmdFactura.Connection = conexion; cmdFactura.CommandText = "select 'numero factura: '"; outputFile.WriteLine(cmdFactura.ExecuteScalar().ToString()); cmdFactura4.CommandType = CommandType.Text; cmdFactura4.Connection = conexion; cmdFactura4.CommandText = "select " + idVenta; outputFile.WriteLine(cmdFactura4.ExecuteScalar().ToString()); cmdFactura5.CommandType = CommandType.Text; cmdFactura5.Connection = conexion; cmdFactura5.CommandText = "select 'precio total: '"; outputFile.WriteLine(cmdFactura5.ExecuteScalar().ToString()); cmdFactura2.CommandType = CommandType.Text; cmdFactura2.Connection = conexion; cmdFactura2.CommandText = "select " + txtPrecio.Text; //Execute command and write output to file outputFile.WriteLine(cmdFactura2.ExecuteScalar().ToString()); cmdFactura6.CommandType = CommandType.Text; cmdFactura6.Connection = conexion; cmdFactura6.CommandText = "select 'productos: '"; outputFile.WriteLine(cmdFactura6.ExecuteScalar().ToString()); cmdFactura7.CommandType = CommandType.Text; cmdFactura7.Connection = conexion; cmdFactura7.CommandText = "select nombre,precioVenta from productos inner join ventasProductos on productos.idProducto = ventasProductos.idProducto " + "where ventasProductos.IdVenta = " + idVenta; SqlDataReader myReader; myReader = cmdFactura7.ExecuteReader(); while (myReader.Read()) { //Write logic to process data for the first result. string colValue = myReader[0].ToString(); string colValue2 = myReader[1].ToString(); outputFile.WriteLine(colValue); outputFile.WriteLine(colValue2); } myReader.Close(); cmdFactura8.CommandType = CommandType.Text; cmdFactura8.Connection = conexion; cmdFactura8.CommandText = "select '-----------------------------------------------'"; //Execute command and write output to file outputFile.WriteLine(cmdFactura8.ExecuteScalar().ToString()); conexion.Close(); // } try { conexion.Open(); trans = conexion.BeginTransaction(); cmdLeer2.Transaction = trans; cmdLeer2.ExecuteNonQuery(); cmdLeer5.Transaction = trans; cmdLeer5.ExecuteNonQuery(); cmdLeer6.Transaction = trans; cmdLeer6.ExecuteNonQuery(); /* cmdLeer7.Transaction = trans; * cmdLeer7.ExecuteNonQuery(); */ label1.Text = "venta realizada"; MessageBox.Show("Venta realizada"); } catch (SqlException ex) { trans.Rollback(); label1.Text = ex.Message; } finally { trans.Commit(); ventas ft = new ventas(); ft.Show(); this.Close(); conexion.Close(); } }