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);
        }
        public int BuscaClaveArt(string Desc)
        {
            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 Clave FROM Articulo WHERE Descripcion LIKE'" + Desc + "'";

            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 Clave = Convert.ToInt32(Lector.GetValue(0).ToString());
                    Con.Close();
                    return(Clave);
                }
            }
            Con.Close();
            return(-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();
        }
        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();
        }
Пример #5
0
        private void cmbProveedores_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 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();
                    txtClave.Text = Clave;
                }
            }
            Conecta.Close();
        }
Пример #6
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;
        }
        public int BuscaFacturaClave(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 Factura 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());
                    return(Art);
                }
            }
            Con.Close();
            return(-1);
        }
        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();
        }
Пример #9
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();
        }
        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;
            }
        }
Пример #11
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();
        }
Пример #12
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 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();
        }
Пример #14
0
        public int DetallesPorFactura(int ClaveFactura)
        {
            string        strConexion = Rutinas.GetConnectionString();
            int           Cantidad    = 0;
            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(Cantidad);
            }
            SqlDataReader Lector = null;

            string strComandoC = "SELECT COUNT (Factura) FROM DetalleFactura WHERE Factura=" + ClaveFactura;

            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(Cantidad);
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Cantidad = Convert.ToInt32(Lector.GetValue(0).ToString());
                }
            }
            Con.Close();
            return(Cantidad);
        }
Пример #15
0
        public bool DetalleRepetido(int ClaveFactura, int ClaveArt)
        {
            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 * from DetalleFactura where Factura = " + ClaveFactura + "and Articulo = " + ClaveArt;

            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)
            {
                return(true);
            }
            Con.Close();
            return(false);
        }
        public string getNombreProveedor(int clave)
        {
            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(null);
            }
            string        Query  = "select nombre from Proveedor where clave = " + clave;
            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(null);
            }
            if (!Lector.HasRows)
            {
                Conecta.Close();
                return(null);
            }
            while (Lector.Read())
            {
                return(Lector.GetValue(0).ToString());
            }
            return(null);
        }
        public void AgregaProveedor(int Clave, String RFC, String nombre, String domicilio)
        {
            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 Query = "insert into Proveedor(Clave,Nombre,RFC,Domicilio,Saldo)";

            Query += " values(@Clave,@Nombre,@RFC,@Domicilio,@Saldo)";
            SqlCommand cmd = new SqlCommand(Query, Conecta);

            cmd.Parameters.AddWithValue("@Clave", Clave);
            cmd.Parameters.AddWithValue("@Nombre", nombre);
            cmd.Parameters.AddWithValue("@RFC", RFC);
            cmd.Parameters.AddWithValue("@Domicilio", domicilio);
            cmd.Parameters.AddWithValue("@Saldo", 0);
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (SqlException Ex)
            {
                foreach (SqlError item in Ex.Errors)
                {
                    MessageBox.Show(item.Message);
                }
                Conecta.Close();
                return;
            }
            Conecta.Close();
        }
        private void frmConsultaProvedor_Load(object sender, EventArgs e)
        {
            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        Query  = "select Nombre 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;
            }
            if (Lector.HasRows)
            {
                cmbProveedores.Items.Clear();
                while (Lector.Read())
                {
                    cmbProveedores.Items.Add(Lector.GetValue(0).ToString());
                }
            }
            Conecta.Close();
        }
        public bool ClaveExistente(int clave)
        {
            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(true);
            }
            string        Query  = "select Clave from Proveedor where Clave= " + clave;
            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(true);
            }
            if (Lector.HasRows)
            {
                return(true);
            }

            return(false);
        }
        private void cmbFactura_SelectedIndexChanged(object sender, EventArgs e)
        {
            lvDetalleFactura.Items.Clear();

            if (cmbFactura.SelectedIndex < 0)
            {
                return;
            }

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

            if (Con == 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);
                }
                Con.Close();
                return;
            }

            string        Fact   = cmbFactura.SelectedItem.ToString();
            string        Query  = "SELECT P.Nombre,P.Clave FROM Factura F INNER JOIN Proveedor P ON F.Provedor=P.Clave WHERE F.Clave=" + Fact;
            SqlDataReader Lector = null;

            Lector = UsoBD.Consulta(Query, Con);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL REALIZAR CONSULTA");
                foreach (SqlError Error in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(Error.Message);
                }
                Con.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    string Nombre = Lector.GetValue(0).ToString();
                    string Clave  = Lector.GetValue(1).ToString();
                    txtProveedor.Text = Nombre;
                    txtClaveP.Text    = Clave;
                }
            }
            Con.Close();

            string CA = "", Art = "", Cant = "", Pre = "";
            string Conexion = Rutinas.GetConnectionString();

            SqlConnection Con2 = UsoBD.ConectaBD(Conexion);

            if (Con2 == 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 Lector2 = null;

            string strComando = "SELECT A.Clave,A.Descripcion,DF.Cantidad,DF.Precio FROM DetalleFactura DF ";

            strComando += "INNER JOIN Articulo A ON DF.Articulo = A.Clave WHERE DF.Factura = " + Fact + "ORDER BY DF.Factura";

            Lector2 = UsoBD.Consulta(strComando, Con2);

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

                Con2.Close();
                return;
            }
            if (Lector2.HasRows)
            {
                while (Lector2.Read())
                {
                    CA   = Lector2.GetValue(0).ToString();
                    Art  = Lector2.GetValue(1).ToString();
                    Cant = Lector2.GetValue(2).ToString();
                    Pre  = Lector2.GetValue(3).ToString();

                    ListViewItem Registro = new ListViewItem(Fact);
                    Registro.SubItems.Add(CA);
                    Registro.SubItems.Add(Art);
                    Registro.SubItems.Add(Cant);
                    Registro.SubItems.Add(Pre);

                    lvDetalleFactura.Items.Add(Registro);
                }
            }
            Con2.Close();
        }
Пример #21
0
        private void btnRealizarPago_Click(object sender, EventArgs e)
        {
            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;
            }
            DialogResult result = MessageBox.Show("¿DESEA REALIZAR EL PAGO?", "PAGO", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                string   Proveedor = Convert.ToString(cmbProveedores.SelectedItem);
                string   importeTexto = txtImporte.Text;
                float    importe, saldo = 0;
                int      claveProveedor;
                DateTime Fecha = DateTime.Now;

                if (cmbProveedores.SelectedIndex == -1)
                {
                    MessageBox.Show("PROVEEDOR NO ENCONTRADO", "PROVEEDOR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Limpiar();
                    return;
                }
                try
                {
                    importe = float.Parse(importeTexto);
                }
                catch (Exception)
                {
                    MessageBox.Show("IMPORTE INVALIDO", "PAGO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (importe < 1)
                {
                    MessageBox.Show("IMPORTE INVALIDO", "PAGO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                claveProveedor = proveedores.GetClave(Proveedor);
                string        Query  = "select Saldo from Proveedor where Clave = " + claveProveedor;
                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())
                    {
                        try
                        {
                            saldo = float.Parse(Lector.GetValue(0).ToString());
                        }
                        catch (Exception Ex)
                        {
                            MessageBox.Show("ERROR DE FORMATO", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
                Conecta.Close();
                if ((saldo - importe) < 0)
                {
                    MessageBox.Show("EL IMPORTE A PAGAR DEBE SER IGUAL O MENOR QUE EL SALDO ACTUAL", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                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 PagoProveedor(Proveedor,Fecha,Importe)";
                strComando += "VALUES(@ClaveProv,@Fecha,@Monto)";

                SqlCommand Insert = new SqlCommand(strComando, Con);

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

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

                    Con.Close();
                    return;
                }
                Con.Close();
                MessageBox.Show("PAGO REALIZADO CORRECTAMENTE", "PAGO REALIZADO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Limpiar();
            }
        }
Пример #22
0
        private void btnAgregarArticulo_Click(object sender, EventArgs e)
        {
            string ClaveF = Convert.ToString(txtClaveFactura), ClaveP = Convert.ToString(cmbProveedores.SelectedItem); string Articulo = Convert.ToString(cmbArticulo.SelectedItem);
            int    ClaveArticulo;

            if (ClaveF.Length == 0)
            {
                MessageBox.Show("NO PUEDE AGREGAR ARTICULOS SI NO TIENE UNA FACTURA", "SIN FACTURA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (cmbProveedores.SelectedIndex == -1)
            {
                MessageBox.Show("SELECCIONE UN PROVEEDOR", "PROVEEDOR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (cmbArticulo.SelectedIndex == -1)
            {
                MessageBox.Show("SELECCIONE UN ARTÍCULO", "ARTÍCULO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int CantArt = lvArticulos.Items.Count;

            if (CantArt >= 3)
            {
                MessageBox.Show("NO SE PUEDE AGRGAR MÁS DE 3 TIPOS DIFERENTES DE ARTICULOS", "ARTICULOS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ClaveArticulo = AdmA.BuscaClaveArt(Articulo);
            if (ClaveArticulo == -1)
            {
                MessageBox.Show("EL ARTICULO NO SE ENCONTRO EN EL SISTEMA", "ARTICULO INEXISTENTE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            float  ArtP = 0; int ArtC = 0; string ArtD = "", ArtM = "";
            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 Precio,Cantidad,Descripcion, Marca FROM Articulo WHERE Clave=" + ClaveArticulo;

            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())
                {
                    ArtP = Convert.ToSingle(Lector.GetValue(0).ToString());
                    ArtC = Convert.ToInt32(Lector.GetValue(1).ToString());
                    ArtD = Lector.GetValue(2).ToString();
                    ArtM = Lector.GetValue(3).ToString();
                }
            }
            Con.Close();

            int   Cant        = Convert.ToInt32(numUpCantidad.Value);
            float PrecioTotal = Cant * ArtP;

            for (int i = 0; i < lvArticulos.Items.Count; i++) //BUSCA SI EL ARTICULO YA ESTA AGREGADO EN EL LIST VIEW
            {
                if (lvArticulos.Items[i].Text.Trim() == ClaveArticulo.ToString())
                {
                    int rc      = Convert.ToInt32(lvArticulos.Items[i].SubItems[4].Text); //CANTIDAD DEL ARTICULO REGISTRADO
                    int SumCant = ArtC - (rc + Cant);
                    if (SumCant < 0)
                    {
                        MessageBox.Show("LA EXISTENCIA DEL ARTICULO NO ES LA SUFICIENTE PARA LA CANTIDAD INGRESADA", "EXISTENCIA INSUFICIENTE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    int cf = rc + Cant; //CANTIDAD FINAL
                    lvArticulos.Items[i].SubItems[4].Text = cf.ToString();
                    float rp = Convert.ToSingle(lvArticulos.Items[i].SubItems[5].Text);
                    float pf = PrecioTotal + rp; //PRECIO FINAL
                    lvArticulos.Items[i].SubItems[5].Text = pf.ToString();
                    CalculaImporte();
                    return;
                }
            }
            //SI EL ARTICULO A AGREGAR NO SE ENCUENTRA EN LA LIST VIEW
            int DifCant = ArtC - Cant;

            if (DifCant < 0)
            {
                MessageBox.Show("LA EXISTENCIA DEL ARTICULO NO ES LA SUFICIENTE PARA LA CANTIDAD INGRESADA", "EXISTENCIA INSUFICIENTE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //AGREGA LOS DATOS DEL ARTICULO EN UNA LISTA
            ListViewItem Registro = new ListViewItem(ClaveArticulo.ToString());

            Registro.SubItems.Add(ArtD);
            Registro.SubItems.Add(ArtM);
            Registro.SubItems.Add(ArtP.ToString());
            Registro.SubItems.Add(Cant.ToString());
            Registro.SubItems.Add(PrecioTotal.ToString());
            //AGREGA LA LISTA CON TODOS LOS DATOS DEL ARTICULO EN EL LIST VIEW
            lvArticulos.Items.Add(Registro);
            CalculaImporte();
        }
Пример #23
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show("¿DESEA GUARDAR LOS CAMBIOS?", "PREGUNTA", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

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

            if (cmbArticulos.SelectedIndex == -1)
            {
                MessageBox.Show("NO HA SELECCIONADO NINGUN ARTICULO", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string Articulo = Convert.ToString(cmbArticulos.SelectedItem); int Cant = Convert.ToInt32(nudCantidad.Value);

            if (Cant < 1)
            {
                MessageBox.Show("LA CANTIDAD NO PUEDE SER MENOR A 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Limpiar();
                return;
            }

            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 = "UPDATE Articulo SET Cantidad=Cantidad+@Cant WHERE Descripcion LIKE'" + Articulo + "'";

            SqlCommand Update = new SqlCommand(strComando, Con);

            Update.Parameters.AddWithValue("@Cant", Cant);

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

                Con.Close();
                return;
            }
            Con.Close();

            MessageBox.Show("MODIFICACION EXITOSA", "INFORMACION", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Limpiar();
        }
Пример #24
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            DialogResult D = MessageBox.Show("¿DESEA AGREGAR LA FACTURA?", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (D == DialogResult.Yes)
            {
                string ClaveF = Convert.ToString(txtClaveFactura.Text); string Proveedor = Convert.ToString(cmbProveedores.SelectedItem);
                string ClaveA = Convert.ToString(cmbArticulo.SelectedItem);
                int    ClaveFactura; int ClaveProveedor;

                if (ClaveF.Length == 0)
                {
                    MessageBox.Show("CLAVE DE FACTURA VACÍA", "CAMPO VACÍO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (!Rutinas.ValidaTextoNum(ClaveF))
                {
                    MessageBox.Show("CLAVE DE FACTURA NO VÁLIDA", "SÓLO NÚMEROS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                try
                {
                    ClaveFactura = int.Parse(ClaveF);
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("CLAVE DE FACTURA NO VÁLIDA", "ERROR FORMATO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (mF.BuscaFacturaClave(ClaveFactura) > 0)
                {
                    MessageBox.Show("LA FACTURA YA EXISTE", "CLAVE FACTURA DUPLICADA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ClaveProveedor = proveedores.BuscarPosNombre(Proveedor);
                int CantArt = lvArticulos.Items.Count;
                if (ClaveProveedor == -1)
                {
                    MessageBox.Show("EL PROVEEDOR NO SE ENCUENTRA EN EL SISTEMA", "PROVEEDOR INEXISTENTE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (CantArt == 0)
                {
                    MessageBox.Show("NO SE PUEDE GUARDAR LA FACTURA, NO HAY ARTICULOS SELECCIONADOS", "SIN ARTICULOS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                DateTime fecha = DateTime.Now;
                mF.AgregarFactura(ClaveFactura, ClaveProveedor, fecha, 0);

                //CREA DETALLE FACTURA POR CADA DIFERENTE TIPO DE ARTICULO
                for (int i = 0; i < lvArticulos.Items.Count; i++)
                {
                    int    ClaveArt     = Convert.ToInt32(lvArticulos.Items[i].Text);
                    int    Cant         = Convert.ToInt32(lvArticulos.Items[i].SubItems[4].Text);
                    string strConexion1 = Rutinas.GetConnectionString();

                    SqlConnection Con1 = UsoBD.ConectaBD(strConexion1);

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

                        foreach (SqlError E in UsoBD.ESalida.Errors)
                        {
                            MessageBox.Show(E.Message);
                        }
                        return;
                    }
                    mD.AgregarDetalle(ClaveFactura, ClaveArt, Cant);
                }

                MessageBox.Show("FACTURA CREADA CORRECTAMENTE CON SUS " + CantArt + " DETALLES DE FACTURA", "FACTURA", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Limpiar();
            }
        }
        private void cmbClaveFactura_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbClaveFactura.SelectedIndex < 0)
            {
                return;
            }
            string clave = cmbClaveFactura.SelectedItem.ToString();
            int    claveFactura;

            try
            {
                claveFactura = int.Parse(clave);
            }
            catch (Exception)
            {
                return;
            }
            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,Provedor,format(Fecha	,'dd/MM/yyyy'),monto FROM FACTURA where clave = " + 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)
            {
                int proveedor = 0, factura = 0;
                while (Lector.Read())
                {
                    try
                    {
                        proveedor = int.Parse(Lector.GetValue(1).ToString());
                        factura   = int.Parse(Lector.GetValue(0).ToString());
                    }
                    catch (Exception)
                    {
                    }
                    txtClaveProveedor.Text = String.Format(" " + proveedor);
                    txtImporte.Text        = Lector.GetValue(3).ToString();
                    txtProveedor.Text      = proveedores.getNombreProveedor(proveedor);
                    txtFecha.Text          = Lector.GetValue(2).ToString();
                    txtCantDetalles.Text   = String.Format(" " + mD.DetallesPorFactura(factura));
                    Con.Close();
                    return;
                }
            }
        }