Exemple #1
0
        public bool AgregarDetalle(int ClaveFact, int ClaveArt, int Cant)
        {
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return(false);
            }
            SqlDataReader Lector = null;

            string strComandoC = "exec InsertarDetalleFactura " + ClaveFact + "," + ClaveArt + "," + Cant;

            Lector = UsoBD.Consulta(strComandoC, Con);
            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return(false);
            }
            Con.Close();
            return(false);
        }
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            if (lvDetalleFactura.SelectedItems.Count == 0)
            {
                MessageBox.Show("NO HA SELECCIONADO NINGUN DETALLE DE FACTURA", "SIN SELECCIONAR", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DialogResult R = MessageBox.Show("¿DESEA ELIMINAR EL DETALLE SELECCIONADO?", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (R == DialogResult.Yes)
            {
                string Fac, Art, Cant, Pre;
                for (int i = 0; i < lvDetalleFactura.Items.Count; i++)
                {
                    if (lvDetalleFactura.SelectedItems.Contains(lvDetalleFactura.Items[i]))
                    {
                        Fac  = lvDetalleFactura.Items[i].SubItems[0].Text;
                        Art  = lvDetalleFactura.Items[i].SubItems[1].Text;
                        Cant = lvDetalleFactura.Items[i].SubItems[3].Text;
                        Pre  = lvDetalleFactura.Items[i].SubItems[4].Text;

                        string        strConexion = Rutinas.GetConnectionString();
                        SqlConnection Con         = UsoBD.ConectaBD(strConexion);

                        if (Con == null)
                        {
                            MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                            foreach (SqlError E in UsoBD.ESalida.Errors)
                            {
                                MessageBox.Show(E.Message);
                            }
                            return;
                        }
                        SqlDataReader Lector = null;

                        string strComandoC = "EXEC EliminaDetalleFactura " + Fac + "," + Art + "," + Cant + "," + Pre;

                        Lector = UsoBD.Consulta(strComandoC, Con);
                        if (Lector == null)
                        {
                            MessageBox.Show("ERROR AL HACER LA CONSULTA");
                            foreach (SqlError E in UsoBD.ESalida.Errors)
                            {
                                MessageBox.Show(E.Message);
                            }

                            Con.Close();
                            return;
                        }
                        Con.Close();
                        lvDetalleFactura.Items[i].Remove();
                        MessageBox.Show("LA ELIMINACION DEL DETALLE DE FACTURA SE HA REALIZADO CORRECTAMENTE", "ELIMINACION REALIZADA", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show("¿DESEA GUARDAR LA INFORMACION?", "PREGUNTA", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (Result == DialogResult.No)
            {
                return;
            }

            string Desc = txtDescripcion.Text, Prec = txtPrecio.Text, Marca = txtMarca.Text;; float Precio; int Cant = Convert.ToInt32(nudCantidad.Value);

            if (Rutinas.IsEmpty(Desc))
            {
                MessageBox.Show("FAVOR DE ESCRIBIR UNA DESCRIPCION", "CAMPO VACIO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (Rutinas.IsEmpty(Marca))
            {
                MessageBox.Show("FAVOR DE ESCRIBIR EL MODELO", "CAMPO VACIO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!(Rutinas.validadDecimal(Prec)))
            {
                MessageBox.Show("SOLO SE ACEPTAN NUMEROS EN FORMATO (0.00)", "FORMATO INCORRECTO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                Precio = Convert.ToSingle(txtPrecio.Text);
            }
            catch (FormatException E)
            {
                MessageBox.Show("EL PRECIO NO PUEDE ESTAR VACIO", "CAMPO VACIO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Precio < 1)
            {
                MessageBox.Show("EL PRECIO NO PUEDE SER MENOR A 1", "VALOR FUERA DE RANGO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (Cant < 1)
            {
                MessageBox.Show("LA CANTIDAD DE ARTICULOS A INGRESAR NO PUEDE SER MENOR A 1", "VALOR FUERA DE RANGO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (AdmA.BuscaClaveArt(Desc) > -1)
            {
                MessageBox.Show("EL ARTICULO YA FUE REGISTRADO", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!AdmA.AgregaArt(Desc, Marca, Precio, Cant))
            {
                MessageBox.Show("NO SE PUDO GUARDAR EL ARTICULO", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            MessageBox.Show("ARTICULO AGREGADO EXITOSAMENTE", "INFORMACION", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Limpiar();
        }
        private void cmbArticulos_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbArticulos.SelectedIndex == 0)
            {
                lblDescripcion.Text = "";
                lblMarca.Text       = "";
                lblPrecio.Text      = "";
                lblCantidad.Text    = "";
            }
            else
            {
                string strConexion = Rutinas.GetConnectionString();

                SqlConnection Con = UsoBD.ConectaBD(strConexion);
                if (Con == null)
                {
                    MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                SqlDataReader Lector = null;

                string Desc = cmbArticulos.SelectedItem.ToString();

                string strComando = "SELECT Descripcion,Marca,Precio,Cantidad FROM Articulo WHERE Descripcion LIKE'" + Desc + "'";

                Lector = UsoBD.Consulta(strComando, Con);

                if (Lector == null)
                {
                    MessageBox.Show("ERROR AL HACER LA CONSULTA");
                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }

                    Con.Close();
                    return;
                }
                if (Lector.HasRows)
                {
                    while (Lector.Read())
                    {
                        lblDescripcion.Text = Lector.GetValue(0).ToString();
                        lblMarca.Text       = Lector.GetValue(1).ToString();
                        lblPrecio.Text      = Lector.GetValue(2).ToString();
                        lblCantidad.Text    = Lector.GetValue(3).ToString();
                    }
                }
                Con.Close();
            }
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("¿DESEA GUARDAR?", "GUARDAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                String domicilio, RFC, nombre, claveTexto;
                domicilio  = txtDomicilio.Text;
                RFC        = txtRFC.Text;
                nombre     = txtNombre.Text;
                claveTexto = txtClave.Text;
                if (!ValidaTexto(claveTexto) || !ValidaTexto(nombre) || !ValidaTexto(domicilio) || !ValidaTexto(RFC))
                {
                    MessageBox.Show("CAMPO VACÍO", "AGREGAR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (!validadRFC(RFC))
                {
                    MessageBox.Show("RFC INCORRECTO", "AGREGAR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                int clave = 0;
                try
                {
                    clave = int.Parse(txtClave.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("CLAVE INVÁLIDA", "AGREGAR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (!(Rutinas.ValidaTexto(Rutinas.CadenaSinEspacios(nombre.Trim()))))
                {
                    MessageBox.Show("NOMBRE ESCRITO CON FORMATO NO PERMITIDOO", "AGREGAR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (proveedores.ClaveExistente(clave) || clave < 1)
                {
                    MessageBox.Show("CLAVE INVÁLIDA", "AGREGAR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (proveedores.NombreExistente(nombre))
                {
                    MessageBox.Show("NOMBRE YA EXISTENTE", "AGREGAR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                proveedores.AgregaProveedor(clave, RFC, nombre, domicilio);
                MessageBox.Show("PROVEEDOR AGREGADO EXITOSAMENTE", "PROVEEDOR", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Clear();
            }
            if (result == DialogResult.No)
            {
                return;
            }
        }
Exemple #6
0
        private void cmbClaveFactura_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbClaveFactura.SelectedIndex < 0)
            {
                return;
            }
            string        claveFactura = cmbClaveFactura.SelectedItem.ToString();
            string        strConexion  = Rutinas.GetConnectionString();
            SqlConnection Con          = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "select p.clave,p.Nombre,f.monto,format(f.fecha,'dd/MM/yyyy') from Factura f inner join Proveedor p on f.provedor=p.Clave where f.clave =" + claveFactura;

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    txtClaveProveedor.Text = Lector.GetValue(0).ToString();
                    txtProveedor.Text      = Lector.GetValue(1).ToString();
                    txtImporte.Text        = Lector.GetValue(2).ToString();
                    txtFecha.Text          = Lector.GetValue(3).ToString();
                }
            }
            Con.Close();
            int factura = int.Parse(claveFactura);

            txtCantDetalles.Text = String.Format("" + mD.DetallesPorFactura(factura));
        }
        private void cmbArticulo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbArticulo.SelectedIndex < 0)
            {
                return;
            }
            string descripcion = cmbArticulo.SelectedItem.ToString();

            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "SELECT * from articulo where descripcion = '" + descripcion + "'";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    txtClaveArt.Text   = Lector.GetValue(0).ToString();
                    txtPrecio.Text     = Lector.GetValue(3).ToString();
                    txtExistencia.Text = Lector.GetValue(4).ToString();
                    Con.Close();
                    return;
                }
            }
            Con.Close();
        }
        private void cmbNombre_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbProveedores.SelectedIndex < 0)
            {
                return;
            }
            string        Conexion = Rutinas.GetConnectionString();
            SqlConnection Conecta  = UsoBD.ConectaBD(Conexion);

            if (Conecta == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return;
            }
            string        Nom    = cmbProveedores.SelectedItem.ToString();
            string        Query  = "select Clave,RFC,Domicilio,Saldo from Proveedor where Nombre = " + "'" + Nom + "'";
            SqlDataReader Lector = null;

            Lector = UsoBD.Consulta(Query, Conecta);
            if (Lector == null)
            {
                MessageBox.Show("ERROR AL REALIZAR CONSULTA");
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    string Clave     = Lector.GetValue(0).ToString();
                    string RFC       = Lector.GetValue(1).ToString();
                    string Domicilio = Lector.GetValue(2).ToString();
                    string Saldo     = Lector.GetValue(3).ToString();

                    txtClave.Text     = Clave;
                    txtRFC.Text       = RFC;
                    txtDomicilio.Text = Domicilio;
                    txtSueldo.Text    = Saldo;
                }
            }
            Conecta.Close();
        }
        private void txtNombre_Validated(object sender, EventArgs e)
        {
            string M = txtNombre.Text;

            if (!Rutinas.ValidaTexto(Rutinas.CadenaSinEspacios(M)))
            {
                errorProviderProveedores.SetError(txtNombre, "NOMBRE ESCRITO EN FORMA INCORRECTA");
                txtNombre.Focus();
            }
            else
            {
                errorProviderProveedores.SetError(txtNombre, "");
            }
        }
        private void txtClave_Validated(object sender, EventArgs e)
        {
            string P = txtClave.Text;

            if (!(Rutinas.ValidaTextoNum(P)))
            {
                errorProviderProveedores.SetError(txtClave, "SOLO DEBE TENER NÚMEROS");
                txtClave.Focus();
            }
            else
            {
                errorProviderProveedores.SetError(txtClave, "");
            }
        }
Exemple #11
0
        private void txtClaveFactura_Validated(object sender, EventArgs e)
        {
            string ClaveFactura = txtClaveFactura.Text;

            if (!Rutinas.ValidaTextoNum(ClaveFactura))
            {
                errorP.SetError(txtClaveFactura, "CLAVE DE FACTURA NO VÁLIDA");
                txtClaveFactura.Focus();
            }
            else
            {
                errorP.SetError(txtClaveFactura, "");
            }
        }
        private void txtPrecio_Validated(object sender, EventArgs e)
        {
            string P = txtPrecio.Text;

            if (!(Rutinas.validadDecimal(P)))
            {
                Error.SetError(txtPrecio, "PRECIO ESCRITO EN FORMA INCORRECTA, FORMATO (0.00)");
                txtPrecio.Focus();
            }
            else
            {
                Error.SetError(txtPrecio, "");
            }
        }
Exemple #13
0
        private void txtImporte_Validated(object sender, EventArgs e)
        {
            string P = txtImporte.Text;

            if (!(Rutinas.validadDecimal(P)))
            {
                errorProviderProveedores.SetError(txtImporte, "SOLO DEBE TENER NÚMEROS,  FORMATO (0.00)");
                txtImporte.Focus();
            }
            else
            {
                errorProviderProveedores.SetError(txtImporte, "");
            }
        }
        public int Count()
        {
            int           Count    = 0;
            string        Conexion = Rutinas.GetConnectionString();
            SqlConnection Conecta  = UsoBD.ConectaBD(Conexion);

            if (Conecta == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return(Count);
            }
            string        Query  = "select count(*) from Proveedor";
            SqlDataReader Lector = null;

            Lector = UsoBD.Consulta(Query, Conecta);
            if (Lector == null)
            {
                MessageBox.Show("ERROR AL REALIZAR CONSULTA");
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return(Count);
            }
            if (!Lector.HasRows)
            {
                Conecta.Close();
                return(Count);
            }
            while (Lector.Read())
            {
                try
                {
                    Count = Convert.ToInt32(Lector.GetValue(0));
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("ERRORR AL CONVERTIR", "ERROR FORMATO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(Count);
                }
            }
            return(Count);
        }
        public bool BuscaRep(string Desc, string Marca)
        {
            string strConexion = Rutinas.GetConnectionString();

            SqlConnection Con = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return(false);
            }
            SqlDataReader Lector = null;

            string strComandoC = "SELECT COUNT(Clave) FROM Articulo WHERE Descripcion LIKE'" + Desc + "' AND Marca LIKE'" + Marca + "'";

            Lector = UsoBD.Consulta(strComandoC, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return(false);
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    if (Convert.ToInt32(Lector.GetValue(0).ToString()) > 0)
                    {
                        Con.Close();
                        return(true);
                    }
                }
            }
            Con.Close();
            return(false);
        }
        public int BuscarPosNombre(String nombre)
        {
            int           P        = -1;
            string        Conexion = Rutinas.GetConnectionString();
            SqlConnection Conecta  = UsoBD.ConectaBD(Conexion);

            if (Conecta == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return(P);
            }
            string        Query  = "select Clave from Proveedor where Nombre= " + "'" + nombre + "'";
            SqlDataReader Lector = null;

            Lector = UsoBD.Consulta(Query, Conecta);
            if (Lector == null)
            {
                MessageBox.Show("ERROR AL REALIZAR CONSULTA");
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return(P);
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    try
                    {
                        P = int.Parse(Lector.GetValue(0).ToString());
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show("ERRORR CONVIRTIENDO LA CLAVE", "ERROR FORMATO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(P);
                    }
                }
            }
            return(P);
        }
Exemple #17
0
        public void cargarDataGridViewFacturas()
        {
            dtgvFacturas.Rows.Clear();
            string        nombre      = cmbProveedores.SelectedItem.ToString();
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "select f.clave,p.clave,p.Nombre,f.monto,format(f.fecha,'dd/MM/yyyy') from Factura f inner join Proveedor p on f.provedor=p.Clave where p.Nombre ='" + nombre + "'";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            int clave = 0;

            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    clave = int.Parse(Lector.GetValue(1).ToString());
                    dtgvFacturas.Rows.Add(Lector.GetValue(0).ToString(), Lector.GetValue(1).ToString(), Lector.GetValue(2).ToString(), Lector.GetValue(3).ToString(), Lector.GetValue(4).ToString());
                }
            }
            Con.Close();
        }
Exemple #18
0
        public void cargarCmbFacturas()
        {
            cmbFacturas.Items.Clear();
            string        nombre      = cmbProveedores.SelectedItem.ToString();
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "SELECT F.CLAVE FROM FACTURA  F INNER JOIN Proveedor P ON P.Clave=f.provedor where P.Nombre='" + nombre + "'";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    cmbFacturas.Items.Add(Lector.GetValue(0).ToString());
                }
                Con.Close();
                return;
            }
            cmbFacturas.SelectedIndex = -1;
        }
        private void cmbClaveFactura_SelectedIndexChanged(object sender, EventArgs e)
        {
            dvgBuscaDetalles.Rows.Clear();
            string        claveFactura = cmbClaveFactura.SelectedItem.ToString();
            string        strConexion  = Rutinas.GetConnectionString();
            SqlConnection Con          = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "select a.clave,a.descripcion,d.Precio,d.Cantidad,(d.Precio*d.Cantidad),f.monto from DetalleFactura d inner join Articulo a on d.Articulo=a.clave inner join Factura f on f.clave = d.Factura where d.Factura = " + claveFactura;

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    dvgBuscaDetalles.Rows.Add(Lector.GetValue(0).ToString(), Lector.GetValue(1).ToString(), Lector.GetValue(2).ToString(), Lector.GetValue(3).ToString(), Lector.GetValue(4).ToString());
                    lblImporteTexto.Text = "Importe total para la factura: $" + Lector.GetValue(5).ToString();
                }
            }
            Con.Close();
        }
        public int BuscaArt(int Clave)
        {
            string strConexion = Rutinas.GetConnectionString();

            SqlConnection Con = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return(-1);
            }
            SqlDataReader Lector = null;

            string strComandoC = "SELECT COUNT (Clave) FROM Articulo WHERE Clave=" + Clave;

            Lector = UsoBD.Consulta(strComandoC, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return(-1);
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    int Art = Convert.ToInt32(Lector.GetValue(0).ToString());
                    Con.Close();
                    return(Art);
                }
            }
            Con.Close();
            return(-1);
        }
        public bool AgregaArt(string Desc, string Marca, float Precio, int Cant)
        {
            string strConexion = Rutinas.GetConnectionString();

            SqlConnection Con = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return(false);
            }

            string strComando = "INSERT INTO Articulo(Descripcion,Marca,Precio,Cantidad)";

            strComando += " VALUES(@Descripcion, @Marca, @Precio, @Cantidad)";

            SqlCommand Insert = new SqlCommand(strComando, Con);

            Insert.Parameters.AddWithValue("@Descripcion", Desc.Trim());
            Insert.Parameters.AddWithValue("@Marca", Marca.Trim());
            Insert.Parameters.AddWithValue("@Precio", Precio);
            Insert.Parameters.AddWithValue("@Cantidad", Cant);

            try
            {
                Insert.ExecuteNonQuery();
            }
            catch (SqlException Ex)
            {
                foreach (SqlError item in Ex.Errors)
                {
                    MessageBox.Show(item.Message);
                }

                Con.Close();
                return(false);
            }
            Con.Close();
            return(true);
        }
Exemple #22
0
        private void frmConsultaProveedores_Load(object sender, EventArgs e)
        {
            dtgvProveedores.Rows.Clear();
            string        Conexion = Rutinas.GetConnectionString();
            SqlConnection Conecta  = UsoBD.ConectaBD(Conexion);

            if (Conecta == null)
            {
                MessageBox.Show("ERROR CONECTANDO CON LA BASE DE DATOS");
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return;
            }
            string        Query  = "select Clave,Nombre,RFC,Domicilio,Saldo from Proveedor";
            SqlDataReader Lector = null;

            Lector = UsoBD.Consulta(Query, Conecta);
            if (Lector == null)
            {
                MessageBox.Show("ERROR REALIZANDO CONSULTA");
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Conecta.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    string Clave     = Lector.GetValue(0).ToString();
                    string Nombre    = Lector.GetValue(1).ToString();
                    string RFC       = Lector.GetValue(2).ToString();
                    string Domicilio = Lector.GetValue(3).ToString();
                    string Saldo     = Lector.GetValue(4).ToString();

                    dtgvProveedores.Rows.Add(Clave, Nombre, RFC, Domicilio, Saldo);
                }
            }
            Conecta.Close();
        }
        private void frmConsultaArticulo_Load(object sender, EventArgs e)
        {
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "SELECT Descripcion FROM Articulo ORDER BY Descripcion ASC";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    cmbArticulos.Items.Add(Lector.GetValue(0).ToString());
                }

                Con.Close();
                return;
            }
            Con.Close();
        }
        public void AgregarFactura(int Clave, int ClaveProv, DateTime Fecha, float Monto)
        {
            string strConexion = Rutinas.GetConnectionString();

            SqlConnection Con = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            string strComando = "INSERT INTO Factura(Clave,Provedor,Fecha,Monto)";

            strComando += "VALUES(@Clave,@ClaveProv,@Fecha,@Monto)";

            SqlCommand Insert = new SqlCommand(strComando, Con);

            Insert.Parameters.AddWithValue("@Clave", Clave);
            Insert.Parameters.AddWithValue("@ClaveProv", ClaveProv);
            Insert.Parameters.AddWithValue("@Fecha", Fecha);
            Insert.Parameters.AddWithValue("@Monto", Monto);

            try
            {
                Insert.ExecuteNonQuery();
            }
            catch (SqlException Ex)
            {
                foreach (SqlError item in Ex.Errors)
                {
                    MessageBox.Show(item.Message);
                }

                Con.Close();
                return;
            }
            Con.Close();
        }
Exemple #25
0
        public void cargarDataGridViewDetalles()
        {
            dtgvDetalles.Rows.Clear();
            string        factura     = cmbFacturas.SelectedItem.ToString();
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "select d.Factura,d.Articulo,a.descripcion,a.marca,d.Cantidad,d.Precio,(d.Cantidad*d.Precio)  from DetalleFactura d inner join Articulo a on a.clave = d.Articulo where d.Factura = " + factura;

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    dtgvDetalles.Rows.Add(Lector.GetValue(0).ToString(), Lector.GetValue(1).ToString(), Lector.GetValue(2).ToString(), Lector.GetValue(3).ToString(), Lector.GetValue(4).ToString(), Lector.GetValue(5).ToString(), Lector.GetValue(6).ToString());
                }
            }
            Con.Close();
        }
Exemple #26
0
        public void cargarCmbProveedores()
        {
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "SELECT nombre FROM proveedor ORDER BY nombre ASC";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    cmbProveedores.Items.Add(Lector.GetValue(0).ToString());
                }
                Con.Close();
                return;
            }
            cmbProveedores.SelectedIndex = -1;
        }
Exemple #27
0
        private void frmMostrarDetalles_Load(object sender, EventArgs e)
        {
            dgvDetalles.Rows.Clear();
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "select d.Factura,a.clave,a.descripcion,d.Precio,d.Cantidad,(d.Precio*d.Cantidad) from DetalleFactura d inner join Articulo a on d.Articulo=a.clave";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    dgvDetalles.Rows.Add(Lector.GetValue(0).ToString(), Lector.GetValue(1).ToString(), Lector.GetValue(2).ToString(), Lector.GetValue(3).ToString(), Lector.GetValue(4).ToString(), Lector.GetValue(5).ToString());
                }
            }
            Con.Close();
        }
        public void cargarCmbFacturas()
        {
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "SELECT CLAVE FROM FACTURA ORDER BY CLAVE ASC";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    cmbClaveFactura.Items.Add(Lector.GetValue(0).ToString());
                }
                Con.Close();
                return;
            }
        }
Exemple #29
0
        private void frmMostrarFacturas_Load(object sender, EventArgs e)
        {
            dgvFacturas.Rows.Clear();
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector = null;

            string strComando = "select f.clave,p.clave,p.Nombre,f.monto,format(f.fecha,'dd/MM/yyyy') from Factura f inner join Proveedor p on f.provedor=p.Clave";

            Lector = UsoBD.Consulta(strComando, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    dgvFacturas.Rows.Add(Lector.GetValue(0).ToString(), Lector.GetValue(1).ToString(), Lector.GetValue(2).ToString(), Lector.GetValue(3).ToString(), Lector.GetValue(4).ToString());
                }
            }
            Con.Close();
        }
        public void cargarCmbArticulos()
        {
            string        strConexion = Rutinas.GetConnectionString();
            SqlConnection Con         = UsoBD.ConectaBD(strConexion);

            if (Con == null)
            {
                MessageBox.Show("NO SE PUDO CONECTAR A LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            string strComando = "SELECT Descripcion FROM ARTICULO ORDER BY Descripcion ASC";

            SqlDataReader Lector2 = UsoBD.Consulta(strComando, Con);

            if (Lector2 == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Con.Close();
                return;
            }
            if (Lector2.HasRows)
            {
                while (Lector2.Read())
                {
                    cmbArticulo.Items.Add(Lector2.GetValue(0).ToString());
                }
                Con.Close();
                return;
            }
            Con.Close();
        }