Ejemplo n.º 1
0
        private void Vpagar_Load(object sender, EventArgs e)
        {
            string        peticion_id_ultima_factura = "select max (id_factura) from tabla_facturas";
            clase_lectura leer      = new clase_lectura();
            string        ultimo_id = leer.leer_un_dato(database, peticion_id_ultima_factura);
            string        id_actual = Convert.ToString((Convert.ToInt64(ultimo_id) + 1));

            textBox5.Text    = id_actual;
            textBox5.Enabled = false;
        }
Ejemplo n.º 2
0
        private void Vproducto_Load(object sender, EventArgs e)
        {
            textBox1.Text = "0";
            textBox2.Text = "0";
            textBox3.Text = "0";
            textBox4.Text = "0";

            //Todo lo de este evento  se ejecuta apenas el formulario se carga

            textBox5.Focus();

            // cargo todos los productos de la base de datos en el combobox1 apenas se carga el fomulario

            string        peticion_lectura = "select Codigo,Nombre from tabla_productos";
            SqlConnection conexion         = new SqlConnection(database);

            clase_lectura lectura   = new clase_lectura();
            SqlDataReader registros = lectura.leer_varios_datos(database, peticion_lectura);

            while (registros.Read())
            {
                string nombre_producto = registros["Nombre"].ToString();
                comboBox1.Items.Add(nombre_producto);
            }

            registros.Close();
            conexion.Close();



            //Creo el datatable que me va a almacenar los datos del datagridview_tabla
            dt = new DataTable();
            dt.Columns.Add("Codigo");
            dt.Columns.Add("Detalle");
            dt.Columns.Add("Valor Unitario");
            dt.Columns.Add("Cantidad");
            dt.Columns.Add("Valor Total");
            dataGridView_tabla.DataSource = dt;


            //Borro la ultima factura

            string          borrar_ultima_factura = "delete from tabla_factura";
            clase_escritura consulta = new clase_escritura();

            consulta.escribir(database, borrar_ultima_factura);

            string        peticion_id_ultima_factura = "select max (id_factura) from tabla_facturas";
            clase_lectura leer      = new clase_lectura();
            string        ultimo_id = leer.leer_un_dato(database, peticion_id_ultima_factura);
            string        id_actual = Convert.ToString((Convert.ToInt64(ultimo_id) + 1));

            textBox7.Text    = "FAC-0" + id_actual;
            textBox7.Enabled = false;
        }
Ejemplo n.º 3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string producto_elegido        = comboBox1.Text;
            string peticion_lectura_codigo = "select Codigo from tabla_productos where Nombre = '" + producto_elegido + "' ";

            clase_lectura leer            = new clase_lectura();
            string        codigo_producto = leer.leer_un_dato(database, peticion_lectura_codigo);

            textBox5.Text = codigo_producto;
            textBox6.Text = "1";
        }
Ejemplo n.º 4
0
        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
            string peticion_lectura_producto = "select Nombre from tabla_productos where Codigo = '" + textBox5.Text + "' ";


            if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != (char)Keys.Back) && (e.KeyChar != (char)Keys.Enter))
            {
                MessageBox.Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Handled = true;
                return;
            }



            if ((int)e.KeyChar == (int)Keys.Enter)
            {
                try {
                    clase_lectura leer            = new clase_lectura();
                    string        nombre_producto = leer.leer_un_dato(database, peticion_lectura_producto);
                    comboBox1.Text = nombre_producto;
                    textBox6.Focus();
                }

                catch
                {
                    clase_lectura leer      = new clase_lectura();
                    int           verificar = leer.verificar_existencia(database, peticion_lectura_producto);

                    if (verificar == 0)
                    {
                        MessageBox.Show("No se encontraron productos con el codigo ingresado intente con otro", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        textBox5.Text  = "";
                        textBox6.Text  = "";
                        comboBox1.Text = "";
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void Iniciar_Click(object sender, EventArgs e)
        {
            //definición de las texbox para el usuario y clave

            string Usuario, Clave;

            Usuario = textboxUser.Text;
            Clave   = textboxClave.Text;

            //Logica para comprobar si tengo los campos de usuario y contraseña
            //vacios o si el usuario y la contraseña son incorrectos

            if (Usuario == "" || Clave == "")
            {
                MessageBox.Show("Tiene campos vacios", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                //Conexion a la base de datos para traerme el usuario y contraseña con el criterio ingresado desde la base de datos

                SqlConnection conexion = new SqlConnection(database);
                string        peticion_lectura_usuario = "select Usuario,Contraseña from tabla_usuarios where Usuario = '" + Usuario + "' ";

                clase_lectura leer      = new clase_lectura();
                SqlDataReader registros = leer.leer_varios_datos(database, peticion_lectura_usuario);

                //la contraseña ingresada la paso por la funcion hash de sha 1
                string hash_clave_introducida = hash.EncodePassword(Clave);


                while (registros.Read())
                {
                    string usuario_registrado    = registros["Usuario"].ToString();
                    string hash_clave_registrada = registros["Contraseña"].ToString();



                    //Verificaciòn de el usuario y la contraseña con su hash para mas seguridad

                    if (usuario_registrado == Usuario & hash_clave_introducida == hash_clave_registrada)
                    {
                        MessageBox.Show("Inicio de sesiòn correctamente", "Bienvenido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textboxUser.Clear();
                        textboxClave.Clear();
                        this.Hide();
                        Vproducto Ventas_ventana = new Vproducto();
                        Ventas_ventana.Show();
                    }

                    else
                    {
                        MessageBox.Show("Usuario o contraseña incorectos", "Error inicio de sesiòn", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        textboxUser.Text  = "";
                        textboxClave.Text = "";
                    }
                }

                registros.Close();
                conexion.Close();
            }
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataRow fila in source.Rows)
            {
                string codigo_producto             = fila["Codigo"].ToString();
                string cantidad_productos_vendidos = fila["Cantidad"].ToString();
                //MessageBox.Show(codigo_producto);

                string peticion_stock_actual = "Select Stock from tabla_productos where Codigo=" + codigo_producto + "";

                clase_lectura leer         = new clase_lectura();
                string        stock_actual = leer.leer_un_dato(database, peticion_stock_actual);

                int stock_nuevo = Convert.ToInt32(stock_actual) - Convert.ToInt32(cantidad_productos_vendidos);

                string          peticion_modificar_stock = "update tabla_productos set Stock = " + Convert.ToString(stock_nuevo) + " where Codigo= " + codigo_producto + " ";
                clase_escritura consulta  = new clase_escritura();
                int             resultado = consulta.escribir(database, peticion_modificar_stock);
            }


            SqlConnection conexion = new SqlConnection(database);

            conexion.Open();
            string     inserta_producto_vendidos = "insert into tabla_Ventas(id_factura,Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values(@id_factura,@Codigo,@Detalle,@ValorUnitario,@Cantidad,@ValorTotal) ";
            SqlCommand comando           = new SqlCommand(inserta_producto_vendidos, conexion);
            Vproducto  v                 = new Vproducto();
            string     actual_id_factura = textBox5.Text;

            foreach (DataRow fila in source.Rows)
            {
                comando.Parameters.Clear();
                comando.Parameters.AddWithValue("@id_factura", actual_id_factura);
                comando.Parameters.AddWithValue("@Codigo", fila["Codigo"].ToString());
                comando.Parameters.AddWithValue("@Detalle", fila["Detalle"].ToString());
                comando.Parameters.AddWithValue("@ValorUnitario", fila["Valor Unitario"].ToString());
                comando.Parameters.AddWithValue("@Cantidad", fila["Cantidad"].ToString());
                comando.Parameters.AddWithValue("@ValorTotal", fila["Valor Total"].ToString());
                comando.ExecuteNonQuery();
            }
            conexion.Close();


            string          inserta_totales = "insert into tabla_facturas(id_factura,Subtotal,Impuesto,Descuento,Totalpago) values( " + actual_id_factura + " ," + Subtotal + "," + Impuesto + "," + Descuento + "," + Totalpago + ")";
            clase_escritura consulta2       = new clase_escritura();

            consulta2.escribir(database, inserta_totales);

            DialogResult eleccion = MessageBox.Show("Desea Imprimir una factura", "Factura", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (eleccion == DialogResult.Yes)
            {
                SqlConnection conexion3 = new SqlConnection(database);
                conexion3.Open();
                string     inserta_factura = "insert into tabla_factura(Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values(@Codigo,@Detalle,@ValorUnitario,@Cantidad,@ValorTotal) ";
                SqlCommand comando3        = new SqlCommand(inserta_factura, conexion3);

                foreach (DataRow fila in source.Rows)
                {
                    comando3.Parameters.Clear();
                    comando3.Parameters.AddWithValue("@Codigo", fila["Codigo"].ToString());
                    comando3.Parameters.AddWithValue("@Detalle", fila["Detalle"].ToString());
                    comando3.Parameters.AddWithValue("@ValorUnitario", fila["Valor Unitario"].ToString());
                    comando3.Parameters.AddWithValue("@Cantidad", fila["Cantidad"].ToString());
                    comando3.Parameters.AddWithValue("@ValorTotal", fila["Valor Total"].ToString());
                    comando3.ExecuteNonQuery();
                }
                conexion.Close();

                string          inserta_totales2 = "insert into tabla_totales(Subtotal,Impuesto,Descuento,Totalpago) values(" + Subtotal + "," + Impuesto + "," + Descuento + "," + Totalpago + ") ";
                clase_escritura consulta         = new clase_escritura();
                consulta.escribir(database, inserta_totales2);

                Vreporte ventanareporte = new Vreporte();
                ventanareporte.Show();
                this.Close();
            }



            else
            {
                this.Close();
            }

            Vproducto ventana = new Vproducto();

            ventana.Hide();
            ventana.Show();
        }
Ejemplo n.º 7
0
        private void button6_Click(object sender, EventArgs e)
        {
            double descuento = (Convert.ToDouble(textBox3.Text)) / 100;


            //Verificación si los espacios de codigo, cantidad y nombre de productos estaban vacios

            if (textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "")
            {
                MessageBox.Show("Tiene campos vacios", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            string        producto_elegido        = comboBox1.Text;
            string        peticion_lectura_precio = "select Precio from tabla_productos where Nombre = '" + producto_elegido + "' ";
            clase_lectura leer            = new clase_lectura();
            string        precio_producto = leer.leer_un_dato(database, peticion_lectura_precio);

            Int32 numero_filas = dataGridView_tabla.Rows.Count;
            int   numero_fila  = 0;
            int   bandera      = 0;

            //Este for recorre toda las filas de el datagridview_tabla y me busca si el ultimo
            //producto que agrege ya existe en la tabla , para asi solo sumar sus cantidades

            for (int a = 0; a < numero_filas; a++)
            {
                string codigo_actual = (string)dataGridView_tabla.Rows[a].Cells[0].Value;

                if (codigo_actual == textBox5.Text)
                {
                    //MessageBox.Show("El articulo ya existe en la tabla");
                    numero_fila = a;
                    bandera     = 1;
                }
            }

            if (bandera == 1)
            {
                //Logica para sumar cantidades de productos iguales
                dataGridView_tabla.Rows[numero_fila].Cells[3].Value = Convert.ToString(Convert.ToInt32((string)dataGridView_tabla.Rows[numero_fila].Cells[3].Value) + Convert.ToInt32(textBox6.Text));
                double aux3       = Convert.ToDouble(dataGridView_tabla.Rows[numero_fila].Cells[3].Value);
                double aux4       = Convert.ToDouble(precio_producto);
                double valortotal = aux3 * aux4;
                dataGridView_tabla.Rows[numero_fila].Cells[4].Value = Convert.ToString(valortotal);


                //Clase que me entrega el total, subtotal, impuesto ,descuento
                Totalizar resultado = new Totalizar(dt);
                textBox1.Text = resultado.subtotal(impuesto);
                textBox2.Text = resultado.impuesto(impuesto);
                textBox4.Text = resultado.sumatotal(descuento);
                label25.Text  = resultado.sumatotal(descuento);
                textBox5.Focus();

                //Visualización de el subtotal , el impuesto y el total a pagar en los textboxs

                textBox5.Focus();
                textBox5.Clear();
                textBox6.Clear();
                comboBox1.Text = "";
            }

            else if (bandera != 1)
            {
                //MessageBox.Show("El articulo se agrega por primera vez");

                double aux2, aux3;
                aux2 = Convert.ToDouble(textBox6.Text);
                aux3 = Convert.ToDouble(precio_producto);
                double valortotal = aux2 * aux3;

                DataRow row = dt.NewRow();
                row["Codigo"]         = textBox5.Text;
                row["Detalle"]        = comboBox1.Text;;
                row["Valor Unitario"] = precio_producto;;
                row["Cantidad"]       = textBox6.Text;;
                row["Valor Total"]    = Convert.ToString(valortotal);;
                dt.Rows.Add(row);

                //Refresco las textbox para ingresar nuevo datos
                textBox5.Clear();
                textBox6.Clear();
                comboBox1.Text = "";

                //Clase que me entrega el total a pagar

                Totalizar resultado = new Totalizar(dt);
                textBox1.Text = resultado.subtotal(impuesto);
                textBox2.Text = resultado.impuesto(impuesto);
                textBox4.Text = resultado.sumatotal(descuento);
                label25.Text  = resultado.sumatotal(descuento);
                textBox5.Focus();



                //Visualización de el subtotal , el impuesto y el total a pagar en los textboxs
            }
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            try {
                clase_escritura borrar          = new clase_escritura();
                string          peticion_borrar = "delete from tabla_factura";
                borrar.escribir(database, peticion_borrar);


                int    fila_seleccionada       = dataGridView_facturas.SelectedRows[0].Index;
                string id_factura_seleccionada = dataGridView_facturas.Rows[fila_seleccionada].Cells[0].Value.ToString();
                //MessageBox.Show(id_factura_seleccionada);
                string peticion_lectura = "select Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal from tabla_ventas where Id_factura = '" + Convert.ToString(id_factura_seleccionada) + "' ";


                clase_lectura leer      = new clase_lectura();
                SqlDataReader registros = leer.leer_varios_datos(database, peticion_lectura);
                SqlConnection conexion  = new SqlConnection(database);

                while (registros.Read())
                {
                    string Codigo1        = registros["Codigo"].ToString();
                    string Detalle1       = registros["Detalle"].ToString();
                    string ValorUnitario1 = registros["ValorUnitario"].ToString();
                    string Cantidad1      = registros["Cantidad"].ToString();
                    string ValorTotal1    = registros["ValorTotal"].ToString();

                    string          inserta_factura = "insert into tabla_factura(Codigo,Detalle,ValorUnitario,Cantidad,ValorTotal) values('" + Codigo1 + "','" + Detalle1 + "','" + ValorUnitario1 + "','" + Cantidad1 + "','" + ValorTotal1 + "') ";
                    clase_escritura escritura       = new clase_escritura();
                    int             confirmar       = escritura.escribir(database, inserta_factura);
                }
                registros.Close();
                conexion.Close();

                string        peticion_lectura_totales = "select Subtotal,Impuesto,Descuento,Totalpago from tabla_facturas where Id_factura = '" + Convert.ToString(id_factura_seleccionada) + "' ";
                clase_lectura leer2      = new clase_lectura();
                SqlDataReader registros2 = leer.leer_varios_datos(database, peticion_lectura_totales);
                SqlConnection conexion2  = new SqlConnection(database);

                while (registros2.Read())
                {
                    string Subtotal  = registros2["Subtotal"].ToString();
                    string Impuesto  = registros2["Impuesto"].ToString();
                    string Descuento = registros2["Descuento"].ToString();
                    string Totalpago = registros2["Totalpago"].ToString();

                    string          inserta_totales2 = "insert into tabla_totales(Subtotal,Impuesto,Descuento,Totalpago) values(" + Subtotal + "," + Impuesto + "," + Descuento + "," + Totalpago + ") ";
                    clase_escritura consulta         = new clase_escritura();
                    consulta.escribir(database, inserta_totales2);
                }
                registros2.Close();
                conexion2.Close();

                //Vfacturas_todas ventanareporte = new Vfacturas_todas();
                //ventanareporte.Show();

                Vreporte ventanareporte = new Vreporte();
                ventanareporte.Show();
            }
            catch
            {
                MessageBox.Show("Seleccione toda la fila para visualizar la factura", "Informaciòn", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }