Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            sesion fl = new sesion();

            fl.Show();
        }
Пример #2
0
        private void btVenta_Click(object sender, EventArgs e)
        {
            //autoincrement sql
            cmdLeer3.CommandType = CommandType.Text;
            cmdLeer3.CommandText = "INSERT INTO ventasProductos values ((select isnull(MAX(idVentaProducto),0)+1 from ventasProductos),'" + idVenta + "','" + dataGridView1.CurrentCell.Value.ToString() + "')";
            cmdLeer3.Connection  = conexion;



            cmdLeer4.CommandType = CommandType.Text;
            cmdLeer4.CommandText = " UPDATE departamentoProductos SET cantidad = cantidad - 1 WHERE departamentoProductos.idProducto = '" + dataGridView1.CurrentCell.Value.ToString() + "'";
            cmdLeer4.Connection  = conexion;

            cmdCantidad.CommandType = CommandType.Text;
            cmdCantidad.CommandText = "Select cantidad from departamentoProductos WHERE departamentoProductos.idProducto = '" + dataGridView1.CurrentCell.Value.ToString() + "'";
            cmdCantidad.Connection  = conexion;



            // Carro compra


            cmdCompra.Connection = conexion;


            conexion.ConnectionString = strconexion;
            cmdCompra.CommandType     = CommandType.Text;
            cmdCompra.CommandText     = "select nombre from productos where idProducto='" + dataGridView1.CurrentCell.Value.ToString() + "'";

            conexion.Open();
            cmdCompra.ExecuteNonQuery();


            nombreProducto = cmdCompra.ExecuteScalar().ToString();
            lblCompra.Items.Add(nombreProducto);
            conexion.Close();
            //


            // Carro precios


            cmdPrecios.Connection = conexion;


            conexion.ConnectionString = strconexion;
            cmdPrecios.CommandType    = CommandType.Text;
            cmdPrecios.CommandText    = "select precioVenta from productos where idProducto='" + dataGridView1.CurrentCell.Value.ToString() + "'";

            conexion.Open();
            cmdPrecios.ExecuteNonQuery();


            precioVenta = cmdPrecios.ExecuteScalar().ToString();
            lblPrecios.Items.Add(precioVenta);


            double suma = 0;

            foreach (object item in lblPrecios.Items)
            {
                double val = Convert.ToDouble(item);

                suma += val;
            }

            txtPrecio.Text = suma.ToString();



            cmdFactura3.Connection = conexion;

            //Mostrar dinero del cliente
            cmdFactura3.CommandType = CommandType.Text;
            cmdFactura3.CommandText = "select dinero from cuentas inner join clientesCuenta on cuentas.idCuenta = clientesCuenta.idCuenta inner join clientes on clientes.idCliente = clientesCuenta.idCliente " +
                                      "where clientes.idCliente =" + session.UserID.ToString() + "";


            // Parar si saldo 0

            saldo         = cmdFactura3.ExecuteScalar().ToString();
            lblSaldo.Text = saldo;


            if (float.Parse(saldo) <= 0)
            {
                MessageBox.Show("Saldo insuficiente ingresa mas dinero");

                sesion fr = new sesion();
                fr.Show();
                this.Close();
            }

            conexion.Close();
            //



            try
            {
                conexion.Open();

                cmdLeer4.ExecuteNonQuery();

                //Cantidad de producto

                /*   cantidad = cmdCantidad.ExecuteScalar().ToString();
                 *
                 *
                 * if (int.Parse(cantidad) <= 0)
                 * {
                 *    MessageBox.Show("Cantidad insuficiente del producto pide mas al almacen");
                 *    cmdLeer3b.Connection = conexion;
                 *    cmdLeer3b.CommandType = CommandType.Text;
                 *    cmdLeer3b.CommandText = "DELETE  from ventasProductos where idVentaProducto=(select top 1 idVentaProducto  from ventasProductos order by idVentaProducto desc)";
                 *    cmdLeer3b.Connection = conexion;
                 *    cmdLeer3b.ExecuteNonQuery();
                 *
                 *    visualizarActualizarDepartamentos fr = new visualizarActualizarDepartamentos();
                 *
                 *    fr.Show();
                 *    this.Close();
                 *
                 * }
                 *
                 */

                cmdLeer3.ExecuteNonQuery();

                //Cantidad
                label1.Text = "producto añadido a la compra";
                MessageBox.Show("Producto añadido a la compra");
            }
            catch (SqlException ex)
            {
                label1.Text = ex.Message;
            }
            finally
            {
                conexion.Close();
            }
        }