Beispiel #1
0
    public Boolean EsMaster(String IdUsuario)
    {
        Boolean        Respuesta   = false;
        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT UPPER(Nombre) FROM Usuarios WHERE Id_Usuario = '" + DepCom.Depurar(IdUsuario) + "' AND Master = '1' AND Activo = '1';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                Respuesta = true;
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Respuesta = false;
            Transaccion.Rollback();
            conn.Close();
        }

        return(Respuesta);
    }
Beispiel #2
0
    public Boolean ModificarCorreo(List <String> Lista)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String SSL = "0";
            if (Lista[4] != null)
            {
                SSL = "1";
            }
            String     Query   = "UPDATE Correo SET Correo = '" + DepCom.DepurarSinMayus(Lista[0]) + "', Contraseña = '" + DepCom.DepurarSinMayus(Lista[1]) + "', Host = '" + DepCom.DepurarSinMayus(Lista[2]) + "', Puerto = '" + DepCom.DepurarSinMayus(Lista[3]) + "', SSL = '" + SSL + "', Texto = '" + DepCom.DepurarSinMayus(Lista[5]) + "';";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }

        return(Correcto);
    }
Beispiel #3
0
    public Boolean ModificarRFC(String IdUsuario, String RFC)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     Query   = "UPDATE Usuarios SET RFC_Permisos = '" + DepCom.DepurarSinMayus(RFC) + "' WHERE Id_Usuario = '" + DepCom.Depurar(IdUsuario) + "'";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }
        return(Correcto);
    }
Beispiel #4
0
    public Boolean HayCorreo(String IdCliente, String Numero)
    {
        Boolean SiHay = false;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT Id_Correo FROM CorreosCliente WHERE Id_Cliente = '" + DepCom.Depurar(IdCliente) + "' AND Activo = 1 AND Numero_Cliente = '" + DepCom.Depurar(Numero) + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                SiHay = true;
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            SiHay = false;
            String Query = "SELECT Id_Correo FROM CorreosCliente WHERE Id_Cliente = '" + DepCom.Depurar(IdCliente) + "' AND Activo = 1;";
        }

        return(SiHay);;
    }
Beispiel #5
0
    public Boolean BorrarCorreo(String IdCorreo)
    {
        Boolean        Correcto    = true;
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     QueryObtener   = "UPDATE CorreosCliente SET Activo = 0 WHERE Id_Correo = '" + DepCom.Depurar(IdCorreo) + "';";
            SqlCommand ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            ComandoObtener.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }

        return(Correcto);
    }
Beispiel #6
0
    public Boolean ExisteCuenta(String Usuario)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT Id_Usuario FROM Usuarios WHERE UPPER(Usuario) = '" + DepCom.Depurar(Usuario) + "' AND Activo = 1;";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (!Lector.HasRows)
            {
                Correcto = false;
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = true;
            Transaccion.Rollback();
            conn.Close();
        }
        return(Correcto);
    }
Beispiel #7
0
    public Boolean ActualizarNota(String Nota, String IdFactura)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     Query   = "UPDATE Facturas SET Nota = '" + DepCom.Depurar(Nota) + "' WHERE Id_Factura = '" + DepCom.Depurar(IdFactura) + "';";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }

        return(Correcto);
    }
Beispiel #8
0
    public Boolean CrearEmpresa(List <String> Lista)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     Query   = "INSERT INTO Empresa(Razon_Social, RFC) VALUES('" + DepCom.Depurar(Lista[0]) + "', '" + DepCom.DepurarSinMayus(Lista[1]) + "');";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }
        return(Correcto);
    }
Beispiel #9
0
    public Boolean CrearCuenta(List <String> Lista)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     Query   = "INSERT INTO Usuarios(Nombre, Usuario, Password, Administrador, Id_Empresa) VALUES('" + DepCom.Depurar(Lista[0]) + "', '" + DepCom.DepurarSinMayus(Lista[1]) + "', '" + DepCom.DepurarSinMayus(Lista[2]) + "', '" + DepCom.Depurar(Lista[3]) + "', '" + DepCom.Depurar(Lista[4]) + "');";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }
        return(Correcto);
    }
Beispiel #10
0
    public Boolean AgregarCorreo(String IdCliente, String Correo, String Numero)
    {
        Boolean        Correcto    = true;
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     QueryObtener   = "INSERT INTO CorreosCliente(Id_Cliente, Correo, Numero_Cliente) VALUES('" + DepCom.Depurar(IdCliente) + "', '" + DepCom.Depurar(Correo) + "', '" + DepCom.Depurar(Numero) + "');";
            SqlCommand ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            ComandoObtener.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }

        return(Correcto);
    }
Beispiel #11
0
    public Boolean EditarEmpresa(List <String> Lista)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     Query   = "UPDATE Empresa SET Razon_Social = '" + DepCom.Depurar(Lista[0]) + "', RFC = '" + DepCom.Depurar(Lista[1]) + "' WHERE Id_Empresa = '" + DepCom.Depurar(Lista[2]) + "';";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }
        return(Correcto);
    }
Beispiel #12
0
    public Boolean EliminarCuenta(String IdUsuario)
    {
        Boolean Correcto = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String     Query   = "UPDATE Usuarios SET Activo = '0' WHERE Id_Usuario = '" + DepCom.Depurar(IdUsuario) + "'";
            SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Correcto = false;
            Transaccion.Rollback();
            conn.Close();
        }
        return(Correcto);
    }
Beispiel #13
0
    public List <String> DistintosPaises()
    {
        List <String>  Lista       = new List <String>();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        QueryObtener   = "SELECT UPPER(País) FROM Facturas GROUP BY UPPER(País) ORDER BY UPPER(País);";
            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    Lista.Add(LectorObtener.GetString(0).ToUpper());
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }
Beispiel #14
0
    public String ModificarContraseña(List <String> Lista)
    {
        String Error = "";

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            //Primero checo que ñla cotnreaseña sea cporrecta
            Boolean       Existe       = false;
            String        QueryCheca   = "SELECT Id_Usuario FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(Lista[0]) + "' AND Password = '******';";
            SqlCommand    ComandoCheca = new SqlCommand(QueryCheca, conn, Transaccion);
            SqlDataReader LectorCheca  = ComandoCheca.ExecuteReader();
            if (LectorCheca.HasRows)
            {
                Existe = true;
            }
            LectorCheca.Close();

            if (Existe)
            {
                //Si es correcta, inserto
                String     Query   = "UPDATE Usuarios SET Password = '******' WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(Lista[0]) + "';";
                SqlCommand Comando = new SqlCommand(Query, conn, Transaccion);
                Comando.ExecuteNonQuery();
            }
            else
            {
                Error = "Contraseña incorrecta";
            }

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Error = "Error ocurrido durante la operacion";
            Transaccion.Rollback();
            conn.Close();
        }

        return(Error);
    }
Beispiel #15
0
    public List <String> ObtenerResultados(String IdCliente)
    {
        List <String>  Lista       = new List <String>();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        QueryObtener   = "SELECT Id_Factura, Empresa.Razon_Social AS Emisor, Serie, Folio, Nota, Tipo_Comprobante, CONCAT(CONVERT(VARCHAR, Fecha_Emision, 103), ' ', CONVERT(VARCHAR, Fecha_Emision, 108)) , Condiciones_Pago, Metodo_Pago, Moneda, CAST(Tipo_Cambio AS VARCHAR), CAST(Sub_Total AS VARCHAR), CAST(IVA AS VARCHAR), CAST(Total AS VARCHAR) FROM Facturas INNER JOIN Empresa ON Empresa.Id_Empresa = Facturas.Id_Empresa WHERE Facturas.Id_Cliente = '" + DepCom.Depurar(IdCliente) + "';";
            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    Lista.Add(LectorObtener.GetInt32(0).ToString());
                    Lista.Add(LectorObtener.GetString(1).ToUpper());
                    Lista.Add(LectorObtener.GetString(2).ToUpper());
                    Lista.Add(LectorObtener.GetString(3).ToUpper());
                    Lista.Add(LectorObtener.GetString(4).ToUpper());
                    Lista.Add(LectorObtener.GetString(5).ToUpper());
                    Lista.Add(LectorObtener.GetString(6).ToUpper());
                    Lista.Add(LectorObtener.GetString(7).ToUpper());
                    Lista.Add(LectorObtener.GetString(8).ToUpper());
                    Lista.Add(LectorObtener.GetString(9).ToUpper());
                    Lista.Add(LectorObtener.GetString(10).ToUpper());
                    Lista.Add(LectorObtener.GetString(11).ToUpper());
                    Lista.Add(LectorObtener.GetString(12).ToUpper());
                    Lista.Add(LectorObtener.GetString(13).ToUpper());
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }
    public List <int> Iniciar(String Usuario, String Contraseña)
    {
        List <int>     Lista       = new List <int>();
        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT Id_Usuario, CAST(Administrador AS INT), CAST(Master AS INT) FROM Usuarios WHERE Usuario = '" + DepCom.Depurar(Usuario) + "' AND Password = '******' AND Activo = 1;";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Lista.Add(Lector.GetInt32(0));
                    Lista.Add(Lector.GetInt32(1));
                    Lista.Add(Lector.GetInt32(2));
                }
            }
            Lector.Close();



            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            try
            {
                Transaccion.Rollback();
                conn.Close();
            }
            catch
            {
            }
            Lista = null;
        }

        return(Lista);
    }
Beispiel #17
0
    public String NombreCorreo(String IdCorreo)
    {
        String Resultado = "";

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT Correo FROM CorreosCliente WHERE Id_Correo = '" + DepCom.Depurar(IdCorreo) + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Resultado = Lector.GetString(0);
                }
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Resultado = "";

            Transaccion.Rollback();
            conn.Close();
        }

        return(Resultado);
    }
Beispiel #18
0
    public String ObtenerEmpresa(String IdUsuario)
    {
        String         Respuesta   = "";
        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT UPPER(Razon_Social) FROM Usuarios INNER JOIN Empresa ON Empresa.Id_Empresa = Usuarios.Id_Empresa WHERE Id_Usuario = '" + DepCom.Depurar(IdUsuario) + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Respuesta = Lector.GetString(0);
                }
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Respuesta = "";
            Transaccion.Rollback();
            conn.Close();
        }

        return(Respuesta);
    }
Beispiel #19
0
    public List <String> InformacionEmpresa(String IdEmpresa)
    {
        DepuraComilla  DepCom      = new DepuraComilla();
        List <String>  Lista       = new List <String>();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT UPPER(Razon_Social), UPPER(RFC) FROM Empresa WHERE Activo = 1 AND Id_Empresa = '" + DepCom.Depurar(IdEmpresa) + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Lista.Add(Lector.GetString(0));
                    Lista.Add(Lector.GetString(1));
                }
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }
Beispiel #20
0
    public String Redireccionar(String PDFOXML, String IdFactura)
    {
        String Resultado = "";

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT REPLACE(Ruta_" + DepCom.Depurar(PDFOXML) + ", (SELECT Ruta FROM RutaProyecto), '') FROM Facturas WHERE Id_Factura = '" + DepCom.Depurar(IdFactura) + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Resultado = Lector.GetString(0);
                }
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Resultado);
    }
Beispiel #21
0
    public List <String> ObtenerRFC(String IdCliente)
    {
        List <String>  Lista       = new List <String>();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        QueryObtener   = "SELECT RFC, (SELECT TOP(1) Razon_Social FROM Facturas WHERE Facturas.Id_Cliente = Clientes.Id_Cliente GROUP BY Razon_Social ORDER BY COUNT(*) DESC) FROM Clientes WHERE Clientes.Id_Cliente = '" + DepCom.Depurar(IdCliente) + "';";
            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    Lista.Add(LectorObtener.GetString(0).ToUpper());
                    Lista.Add(LectorObtener.GetString(1).ToUpper());
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }
Beispiel #22
0
    public List <String> ObtenerCorreos(String IdCliente, String Numero)
    {
        List <String>  Lista       = new List <String>();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        QueryObtener   = "SELECT Id_Correo, Correo FROM CorreosCliente WHERE Activo = 1 AND Id_Cliente = '" + DepCom.Depurar(IdCliente) + "' AND Numero_Cliente = '" + DepCom.Depurar(Numero) + "';";
            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    Lista.Add(LectorObtener.GetInt32(0).ToString());
                    Lista.Add(LectorObtener.GetString(1).ToUpper());
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }
Beispiel #23
0
    public String ObtenerRFCActual(String IdUsuario)
    {
        String RFC = "";

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            String        Query   = "SELECT RFC_Permisos FROM Usuarios WHERE Id_Usuario = '" + DepCom.Depurar(IdUsuario) + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    RFC = Lector.GetString(0);
                }
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            RFC = null;
            Transaccion.Rollback();
            conn.Close();
        }
        return(RFC);
    }
    public String CrearArchivo(List <String> ListaEntrada, String IdUsuario)
    {
        String         Retorno     = "";
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            String ContenidoArchivo = "";
            //Nombro el archivo
            String NombreArchivo = this.NombrarArchivo();
            //Verifico si el archivo se nombro correctamente
            if (NombreArchivo.Length != 0)
            {
                //Iniciamos con los titulos
                ContenidoArchivo += "RFC Receptor";
                ContenidoArchivo += ",RFC Emisor";
                ContenidoArchivo += ",Razon Social del Receptor";
                ContenidoArchivo += ",N° Interno del Receptor";
                ContenidoArchivo += ",Serie";
                ContenidoArchivo += ",Folio";
                ContenidoArchivo += ",Tipo comprobante";
                ContenidoArchivo += ",Folio Fiscal UUID";
                ContenidoArchivo += ",Fecha de timbrado";
                ContenidoArchivo += ",Moneda";
                ContenidoArchivo += ",Total Bruto";
                ContenidoArchivo += ",Valor IVA";
                ContenidoArchivo += ",Total Neto";
                ContenidoArchivo += ",País";


                //Aqui inicio Querys
                conn.Open();
                Transaccion = conn.BeginTransaction();

                //Checamos si hay serie
                String Condiciones = " WHERE 1 = 1";
                if (ListaEntrada[0] != null)
                {
                    if (ListaEntrada[0].Trim().Length != 0)
                    {
                        Condiciones += " AND Serie = '" + DepCom.Depurar(ListaEntrada[0].Trim()) + "'";
                    }
                }
                //Checo si hay folio
                if (ListaEntrada[1] != null)
                {
                    if (ListaEntrada[1].Trim().Length != 0)
                    {
                        Condiciones += " AND Folio = '" + DepCom.Depurar(ListaEntrada[1].Trim()) + "'";
                    }
                }
                //Ahora el tipo de comprobante
                if (ListaEntrada[2] != null)
                {
                    if (ListaEntrada[2].Trim().Length != 0 && ListaEntrada[2].Trim() != "0")
                    {
                        Condiciones += " AND Tipo_Comprobante = '" + DepCom.Depurar(ListaEntrada[2].Trim()) + "'";
                    }
                }

                //el status
                if (ListaEntrada[6] != null)
                {
                    if (ListaEntrada[6].Trim().Length != 0)
                    {
                        Condiciones += " AND Status = '" + DepCom.Depurar(ListaEntrada[6].Trim()) + "'";
                    }
                }

                //El pais
                if (ListaEntrada[7] != null)
                {
                    if (ListaEntrada[7].Trim().Length != 0)
                    {
                        Condiciones += " AND País = '" + DepCom.Depurar(ListaEntrada[7].Trim()) + "'";
                    }
                }

                //El inicio
                if (ListaEntrada[3] != null)
                {
                    if (ListaEntrada[3].Trim().Length != 0)
                    {
                        Condiciones += " AND Fecha_Emision >= '" + DepCom.Depurar(ListaEntrada[3].Trim()) + "'";
                    }
                }

                //Ahora el fin
                if (ListaEntrada[4] != null)
                {
                    if (ListaEntrada[4].Trim().Length != 0)
                    {
                        Condiciones += " AND Fecha_Emision < DATEADD(DAY, 1, '" + DepCom.Depurar(ListaEntrada[4].Trim()) + "')";
                    }
                }

                //Ahora el receptor
                String Receptor = "";
                if (ListaEntrada[5] != null)
                {
                    if (ListaEntrada[5].Trim().Length != 0 && ListaEntrada[5].Trim() != "0")
                    {
                        Receptor = " AND Facturas.Razon_Social = '" + DepCom.Depurar(ListaEntrada[5].Trim()) + "'";
                    }
                }

                if (Receptor.Length == 0)
                {
                    //Si no hay receptor, entonces checo sus posibles
                    //Checo si es cuenta master Y ADMINISTRADOR
                    String        QueryCheca   = "SELECT CAST(Master AS INT), CAST(Administrador AS INT) FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
                    SqlCommand    ComandoCheca = new SqlCommand(QueryCheca, conn, Transaccion);
                    SqlDataReader LectorCheca  = ComandoCheca.ExecuteReader();
                    int           Master       = 0;
                    int           Admin        = 0;
                    if (LectorCheca.HasRows)
                    {
                        while (LectorCheca.Read())
                        {
                            Master = LectorCheca.GetInt32(0);
                            Admin  = LectorCheca.GetInt32(1);
                        }
                    }
                    LectorCheca.Close();

                    //Si es master, no hago ni merga
                    //Si es admin, agrego un dato nuevo
                    if (Master == 1)
                    {
                        Receptor = "";
                    }
                    else /*if (Admin == 1)
                          * {
                          * Receptor = " AND Facturas.Id_Empresa = (SELECT Usuarios.Id_Empresa FROM Usuarios WHERE Usuarios.Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "')";
                          * }
                          * else*/
                    {
                        Receptor = " AND Facturas.Id_Empresa = (SELECT Usuarios.Id_Empresa FROM Usuarios WHERE Usuarios.Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "')";
                        String        RFC           = "";
                        String        QueryAcceso   = "SELECT RFC_Permisos FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
                        SqlCommand    ComandoAcceso = new SqlCommand(QueryAcceso, conn, Transaccion);
                        SqlDataReader LectorAcceso  = ComandoAcceso.ExecuteReader();
                        if (LectorAcceso.HasRows)
                        {
                            while (LectorAcceso.Read())
                            {
                                RFC = LectorAcceso.GetString(0);
                            }
                        }
                        LectorAcceso.Close();

                        String[] ArregloRFC = RFC.Split(',');
                        RFC = "";
                        for (int i = 0; i < ArregloRFC.Length; i++)
                        {
                            if (RFC.Length == 0)
                            {
                                RFC = "'" + ArregloRFC[i] + "'";
                            }
                            else
                            {
                                RFC += ",'" + ArregloRFC[i] + "'";
                            }
                        }

                        Receptor = " AND Facturas.Serie IN (" + RFC + ")";
                    }
                }

                Condiciones += Receptor + ";";

                String        QueryObtener   = @"SELECT (SELECT TOP(1) Clientes.RFC FROM Facturas WHERE Facturas.Id_Cliente = Clientes.Id_Cliente GROUP BY Razon_Social ORDER BY COUNT(*) DESC) AS RFC_Receptor, Empresa.RFC AS RFC_Emisor, Facturas.Razon_Social, Facturas.Numero_Cliente, Serie, Folio, Tipo_Comprobante, REPLACE((REVERSE(SUBSTRING(REVERSE(Ruta_PDF),0,CHARINDEX('\',REVERSE(Ruta_PDF))))), '.PDF', '') AS UUID, CONCAT(CONVERT(VARCHAR, Fecha_Emision, 103), ' ', CONVERT(VARCHAR, Fecha_Emision, 108)) AS Fecha_Timbrado, Moneda, CAST(Sub_Total AS VARCHAR) AS SubTotal, CAST(IVA AS VARCHAR) AS IVA, CAST(Total AS VARCHAR) AS Total, País FROM Facturas INNER JOIN Empresa ON Empresa.Id_Empresa = Facturas.Id_Empresa INNER JOIN Clientes ON Clientes.Id_Cliente = Facturas.Id_Cliente" + Condiciones;
                SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
                SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
                if (LectorObtener.HasRows)
                {
                    while (LectorObtener.Read())
                    {
                        ContenidoArchivo += "\n" + LectorObtener.GetString(0);
                        ContenidoArchivo += "," + LectorObtener.GetString(1);
                        if (LectorObtener.GetString(2).Contains(","))
                        {
                            ContenidoArchivo += ",\"" + LectorObtener.GetString(2) + "\" ";
                        }
                        else
                        {
                            ContenidoArchivo += "," + LectorObtener.GetString(2);
                        }
                        ContenidoArchivo += "," + LectorObtener.GetString(3);
                        ContenidoArchivo += "," + LectorObtener.GetString(4);
                        ContenidoArchivo += "," + LectorObtener.GetString(5);
                        ContenidoArchivo += "," + LectorObtener.GetString(6);
                        ContenidoArchivo += "," + LectorObtener.GetString(7);
                        ContenidoArchivo += "," + LectorObtener.GetString(8);
                        if (LectorObtener.GetString(9).Contains(","))
                        {
                            ContenidoArchivo += ",\"" + LectorObtener.GetString(9) + "\"";
                        }
                        else
                        {
                            ContenidoArchivo += "," + LectorObtener.GetString(9);
                        }
                        ContenidoArchivo += "," + LectorObtener.GetString(10);
                        ContenidoArchivo += "," + LectorObtener.GetString(11);
                        ContenidoArchivo += "," + LectorObtener.GetString(12);
                        ContenidoArchivo += "," + LectorObtener.GetString(13);
                    }
                }
                LectorObtener.Close();

                Transaccion.Commit();
                conn.Close();

                //Guardo archivo
                var archivo = @"C:\inetpub\wwwroot\EnvioFacturas\Excel\" + NombreArchivo + ".csv";

                using (var fileStream = File.Create(archivo))
                {
                    var texto = new System.Text.UTF8Encoding(true).GetBytes(ContenidoArchivo);
                    fileStream.Write(texto, 0, texto.Length);
                    fileStream.Flush();
                }


                Retorno = "1," + NombreArchivo;
            }
            else
            {
                Retorno = "0,Error ocurrido al nombrar archivo";
            }
        }
        catch (Exception ex)
        {
            Retorno = "0," + ex.Message;
            try
            {
                Transaccion.Rollback();
                conn.Close();
            }
            catch
            {
            }
        }
        return(Retorno);
    }
Beispiel #25
0
    public List <ObjetoFactura> ObtenerResultadosEspecificos(DatosEnviar Datos, String IdUsuario)
    {
        List <ObjetoFactura> Lista       = new List <ObjetoFactura>();
        SqlConnection        conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction       Transaccion = null;
        DepuraComilla        DepCom      = new DepuraComilla();

        try
        {
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }

            Transaccion = conn.BeginTransaction();

            //Checamos si hay serie
            String Condiciones = " WHERE 1 = 1";
            if (Datos.Serie != null)
            {
                if (Datos.Serie.Trim().Length != 0)
                {
                    Condiciones += " AND Serie = '" + DepCom.Depurar(Datos.Serie.Trim()) + "'";
                }
            }
            //Checo si hay folio
            if (Datos.Folio != null)
            {
                if (Datos.Folio.Trim().Length != 0)
                {
                    Condiciones += " AND Folio = '" + DepCom.Depurar(Datos.Folio.Trim()) + "'";
                }
            }
            //Ahora el tipo de comprobante
            if (Datos.TipoComprobante != null)
            {
                if (Datos.TipoComprobante.Trim().Length != 0 && Datos.TipoComprobante.Trim() != "0")
                {
                    Condiciones += " AND Tipo_Comprobante = '" + DepCom.Depurar(Datos.TipoComprobante.Trim()) + "'";
                }
            }

            //el status
            if (Datos.Status != null)
            {
                if (Datos.Status.Trim().Length != 0)
                {
                    Condiciones += " AND Status = '" + DepCom.Depurar(Datos.Status.Trim()) + "'";
                }
            }

            //El inicio
            if (Datos.Inicio != null)
            {
                if (Datos.Inicio.Trim().Length != 0)
                {
                    Condiciones += " AND Fecha_Emision >= '" + DepCom.Depurar(Datos.Inicio.Trim()) + "'";
                }
            }

            //Ahora el fin
            if (Datos.Fin != null)
            {
                if (Datos.Fin.Trim().Length != 0)
                {
                    Condiciones += " AND Fecha_Emision < DATEADD(DAY, 1, '" + DepCom.Depurar(Datos.Fin.Trim()) + "')";
                }
            }

            //El pais
            if (Datos.Pais != null)
            {
                if (Datos.Pais.Trim().Length != 0)
                {
                    Condiciones += " AND País = '" + DepCom.Depurar(Datos.Pais.Trim()) + "'";
                }
            }

            //Ahora el receptor
            String Receptor = "";
            if (Datos.Receptor != null)
            {
                if (Datos.Receptor.Trim().Length != 0 && Datos.Receptor.Trim() != "0")
                {
                    //Buscamos el rfc para ver que no sea extranjero
                    String        QueryExtra    = "SELECT TOP(1) Facturas.Id_Cliente, RFC FROM Facturas INNER JOIN Clientes ON Clientes.Id_Cliente = Facturas.Id_Cliente WHERE UPPER(Razon_Social) = '" + DepCom.Depurar(Datos.Receptor.Trim()) + "' GROUP BY Facturas.Id_Cliente, RFC;";
                    SqlCommand    ComandoExtra  = new SqlCommand(QueryExtra, conn, Transaccion);
                    SqlDataReader LectorExtra   = ComandoExtra.ExecuteReader();
                    int           IdClienteTemp = -1;
                    String        RFCTemp       = "";
                    if (LectorExtra.HasRows)
                    {
                        while (LectorExtra.Read())
                        {
                            IdClienteTemp = LectorExtra.GetInt32(0);
                            RFCTemp       = LectorExtra.GetString(1);
                        }
                    }
                    LectorExtra.Close();

                    if (RFCTemp.EndsWith("010101000"))
                    {
                        Receptor = " AND Facturas.Razon_Social = '" + DepCom.Depurar(Datos.Receptor.Trim()) + "'";
                    }
                    else
                    {
                        Receptor = " AND Facturas.Id_Cliente = '" + IdClienteTemp + "'";
                    }
                }
            }


            if (Receptor.Length == 0)
            {
                //Si no hay receptor, entonces checo sus posibles
                //Checo si es cuenta master Y ADMINISTRADOR
                String        QueryCheca   = "SELECT CAST(Master AS INT), CAST(Administrador AS INT) FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
                SqlCommand    ComandoCheca = new SqlCommand(QueryCheca, conn, Transaccion);
                SqlDataReader LectorCheca  = ComandoCheca.ExecuteReader();
                int           Master       = 0;
                int           Admin        = 0;
                if (LectorCheca.HasRows)
                {
                    while (LectorCheca.Read())
                    {
                        Master = LectorCheca.GetInt32(0);
                        Admin  = LectorCheca.GetInt32(1);
                    }
                }
                LectorCheca.Close();

                //Si es master, no hago ni merga
                //Si es admin, agrego un dato nuevo
                if (Master == 1)
                {
                    Receptor = "";
                }
                else
                {
                    Receptor = " AND Facturas.Id_Empresa = (SELECT Usuarios.Id_Empresa FROM Usuarios WHERE Usuarios.Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "')";
                    String        RFC           = "";
                    String        QueryAcceso   = "SELECT RFC_Permisos FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
                    SqlCommand    ComandoAcceso = new SqlCommand(QueryAcceso, conn, Transaccion);
                    SqlDataReader LectorAcceso  = ComandoAcceso.ExecuteReader();
                    if (LectorAcceso.HasRows)
                    {
                        while (LectorAcceso.Read())
                        {
                            RFC = LectorAcceso.GetString(0);
                        }
                    }
                    LectorAcceso.Close();

                    String[] ArregloRFC = RFC.Split(',');
                    RFC = "";
                    for (int i = 0; i < ArregloRFC.Length; i++)
                    {
                        if (RFC.Length == 0)
                        {
                            RFC = "'" + ArregloRFC[i] + "'";
                        }
                        else
                        {
                            RFC += ",'" + ArregloRFC[i] + "'";
                        }
                    }

                    Receptor = " AND Facturas.Serie IN (" + RFC + ")";
                }
            }

            Condiciones += Receptor + ";";


            String        QueryObtener   = "SELECT Id_Factura, Empresa.Razon_Social AS Emisor, Facturas.Razon_Social, Serie, Folio, Tipo_Comprobante, CONCAT(CONVERT(VARCHAR, Fecha_Emision, 103), ' ', CONVERT(VARCHAR, Fecha_Emision, 108)) , Condiciones_Pago, Metodo_Pago, Moneda, CAST(Tipo_Cambio AS VARCHAR), CAST(Sub_Total AS VARCHAR), CAST(IVA AS VARCHAR), CAST(Total AS VARCHAR), CAST(Facturas.Id_Cliente AS VARCHAR), Nota, Numero_Cliente, País, Enviada FROM Facturas INNER JOIN Empresa ON Empresa.Id_Empresa = Facturas.Id_Empresa INNER JOIN Clientes ON Clientes.Id_Cliente = Facturas.Id_Cliente" + Condiciones;
            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    ObjetoFactura ObjFac = new ObjetoFactura();
                    ObjFac.IdFactura       = LectorObtener.GetInt32(0);
                    ObjFac.Emisor          = LectorObtener.GetString(1);
                    ObjFac.RazonSocial     = LectorObtener.GetString(2);
                    ObjFac.Serie           = LectorObtener.GetString(3);
                    ObjFac.Folio           = LectorObtener.GetString(4);
                    ObjFac.TipoComprobante = LectorObtener.GetString(5);
                    ObjFac.FechaEmision    = LectorObtener.GetString(6);
                    ObjFac.CondicionesPago = LectorObtener.GetString(7);
                    ObjFac.MetodoPago      = LectorObtener.GetString(8);
                    ObjFac.Moneda          = LectorObtener.GetString(9);
                    ObjFac.TipoCambio      = LectorObtener.GetString(10);
                    ObjFac.SubTotal        = LectorObtener.GetString(11);
                    ObjFac.IVA             = LectorObtener.GetString(12);
                    ObjFac.Total           = LectorObtener.GetString(13);
                    ObjFac.IdCliente       = LectorObtener.GetString(14);
                    ObjFac.Nota            = LectorObtener.GetString(15);
                    ObjFac.NumeroCliente   = LectorObtener.GetString(16);
                    ObjFac.Pais            = LectorObtener.GetString(17);
                    ObjFac.Enviada         = LectorObtener.GetInt32(18);
                    Lista.Add(ObjFac);
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
        }
        catch
        {
            Transaccion.Rollback();
        }
        finally
        {
            if (conn.State != ConnectionState.Closed)
            {
                conn.Close();
            }
        }

        return(Lista);
    }
Beispiel #26
0
    public List <String> ObtenerSeries(String IdUsuario)
    {
        List <String>  Lista       = new List <String>();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;
        DepuraComilla  DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            //Checo si es cuenta master Y ADMINISTRADOR
            String        QueryCheca   = "SELECT CAST(Master AS INT), CAST(Administrador AS INT) FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
            SqlCommand    ComandoCheca = new SqlCommand(QueryCheca, conn, Transaccion);
            SqlDataReader LectorCheca  = ComandoCheca.ExecuteReader();
            int           Master       = 0;
            int           Admin        = 0;
            if (LectorCheca.HasRows)
            {
                while (LectorCheca.Read())
                {
                    Master = LectorCheca.GetInt32(0);
                    Admin  = LectorCheca.GetInt32(1);
                }
            }
            LectorCheca.Close();

            String QueryObtener = "";

            if (Master == 1)
            {
                QueryObtener = "SELECT Serie FROM Facturas INNER JOIN Empresa ON Empresa.Id_Empresa = Facturas.Id_Empresa WHERE Empresa.Activo = 1 GROUP BY Serie ORDER BY Serie;";
            }
            else if (Admin == 1)
            {
                QueryObtener = "SELECT Serie FROM Facturas INNER JOIN Empresa ON Empresa.Id_Empresa = Facturas.Id_Empresa WHERE Empresa.Activo = 1 AND Facturas.Id_Empresa = (SELECT Id_Empresa FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "') GROUP BY Serie ORDER BY Serie;";
            }
            else
            {
                //Obtengo RFC de acceso
                String        RFC           = "";
                String        QueryAcceso   = "SELECT RFC_Permisos FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
                SqlCommand    ComandoAcceso = new SqlCommand(QueryAcceso, conn, Transaccion);
                SqlDataReader LectorAcceso  = ComandoAcceso.ExecuteReader();
                if (LectorAcceso.HasRows)
                {
                    while (LectorAcceso.Read())
                    {
                        RFC = LectorAcceso.GetString(0);
                    }
                }
                LectorAcceso.Close();

                String[] ArregloRFC = RFC.Split(',');

                RFC = "";
                for (int i = 0; i < ArregloRFC.Length; i++)
                {
                    if (RFC.Length == 0)
                    {
                        RFC = "'" + ArregloRFC[i] + "'";
                    }
                    else
                    {
                        RFC += ",'" + ArregloRFC[i] + "'";
                    }
                }
                RFC = RFC.ToUpper();

                QueryObtener = "SELECT Serie FROM Facturas INNER JOIN Empresa ON Empresa.Id_Empresa = Facturas.Id_Empresa WHERE Empresa.Activo = 1 AND Facturas.Serie IN(" + RFC + ") GROUP BY Serie ORDER BY Serie;";
            }



            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    Lista.Add(LectorObtener.GetString(0).ToUpper());
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }
Beispiel #27
0
    public Boolean Manda(String IdFactura)
    {
        Boolean Mando = true;

        DepuraComilla  DepCom      = new DepuraComilla();
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();


            //Primero obtengo las credenciales
            String        Correo              = "";
            String        Contraseña          = "";
            String        Host                = "";
            String        Puerto              = "";
            Boolean       SSL                 = false;
            String        QueryCredenciales   = "SELECT Correo, Contraseña, Host, Puerto, SSL FROM Correo WHERE Activo = 1;";
            SqlCommand    ComandoCredenciales = new SqlCommand(QueryCredenciales, conn, Transaccion);
            SqlDataReader LectorCredenciales  = ComandoCredenciales.ExecuteReader();
            if (LectorCredenciales.HasRows)
            {
                while (LectorCredenciales.Read())
                {
                    Correo     = LectorCredenciales.GetString(0);
                    Contraseña = LectorCredenciales.GetString(1);
                    Host       = LectorCredenciales.GetString(2);
                    Puerto     = LectorCredenciales.GetString(3);
                    SSL        = LectorCredenciales.GetBoolean(4);
                }
            }
            else
            {
                Mando = false;
            }
            LectorCredenciales.Close();

            if (Mando)
            {
                String      XML   = "";
                MailMessage email = new MailMessage();
                //Ahora obtengo los correos del cliente
                String        QueryCorreos   = "SELECT Correo, Ruta_XML FROM Facturas INNER JOIN CorreosCliente ON CorreosCliente.Id_Cliente = Facturas.Id_Cliente WHERE Id_Factura = '" + DepCom.Depurar(IdFactura) + "' AND CorreosCliente.Activo = 1  AND CorreosCliente.Numero_Cliente = (SELECT Numero_Cliente FROM Facturas WHERE Facturas.Id_Factura = '" + DepCom.Depurar(IdFactura) + "');";
                SqlCommand    ComandoCorreos = new SqlCommand(QueryCorreos, conn, Transaccion);
                SqlDataReader LectorCorreos  = ComandoCorreos.ExecuteReader();
                if (LectorCorreos.HasRows)
                {
                    while (LectorCorreos.Read())
                    {
                        email.To.Add(new MailAddress(LectorCorreos.GetString(0)));
                        XML = LectorCorreos.GetString(1);
                    }
                }
                LectorCorreos.Close();

                String        Texto        = "";
                String        QueryTexto   = "SELECT Texto FROM Correo;";
                SqlCommand    ComandoTexto = new SqlCommand(QueryTexto, conn, Transaccion);
                SqlDataReader LectorTexto  = ComandoTexto.ExecuteReader();
                if (LectorTexto.HasRows)
                {
                    while (LectorTexto.Read())
                    {
                        Texto = LectorTexto.GetString(0);
                    }
                }
                LectorTexto.Close();

                String[] ArregloFactura = XML.Split('\\');

                email.From    = new MailAddress(Correo);
                email.Subject = "Reenvio de Factura " + ArregloFactura[ArregloFactura.Length - 1].Replace(".xml", "");
                //Adjunto los archivos
                //email.Attachments.Add(new Attachment(XML));
                //email.Attachments.Add(new Attachment(XML.Replace(".xml", ".pdf")));
                email.Body       = Texto;
                email.IsBodyHtml = false;
                email.Priority   = MailPriority.Normal;

                //Definimos credenciales
                SmtpClient smtp = new SmtpClient();
                smtp.Host                  = Host;
                smtp.Port                  = Convert.ToInt32(Puerto);
                smtp.EnableSsl             = SSL;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential(Correo, Contraseña);

                smtp.Send(email);

                //eliminamos el objeto
                smtp.Dispose();

                //Ahora marcamos como enviado
                String     Query   = "UPDATE Facturas SET Enviada = 1 where Id_Factura = '" + IdFactura + "';";
                SqlCommand Comando = new SqlCommand(Query, conn);
                conn.Open();
                Comando.ExecuteNonQuery();
                conn.Close();
            }

            Transaccion.Commit();
            conn.Close();
        }
        catch (Exception ex)
        {
            Mando = false;
            Transaccion.Rollback();
            conn.Close();
        }

        return(Mando);
    }
Beispiel #28
0
    public List <ObjetoClientes> ObtenerResultados(String IdUsuario)
    {
        List <ObjetoClientes> Lista       = new List <ObjetoClientes>();
        SqlConnection         conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction        Transaccion = null;
        DepuraComilla         DepCom      = new DepuraComilla();

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            //Checo si es cuenta master Y ADMINISTRADOR
            String        QueryCheca   = "SELECT CAST(Master AS INT), CAST(Administrador AS INT) FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
            SqlCommand    ComandoCheca = new SqlCommand(QueryCheca, conn, Transaccion);
            SqlDataReader LectorCheca  = ComandoCheca.ExecuteReader();
            int           Master       = 0;
            int           Admin        = 0;
            if (LectorCheca.HasRows)
            {
                while (LectorCheca.Read())
                {
                    Master = LectorCheca.GetInt32(0);
                    Admin  = LectorCheca.GetInt32(1);
                }
            }
            LectorCheca.Close();


            String Condiciones = "";
            if (Master == 1)
            {
                Condiciones += "";
                //QueryObtener = "SELECT Clientes.RFC, Facturas.Razon_Social FROM FACTURAS INNER JOIN Clientes ON Clientes.Id_Cliente = Facturas.Id_Cliente GROUP BY Razon_Social, Clientes.RFC ORDER BY Razon_Social;";
            }
            else if (Admin == 1)
            {
                Condiciones += " AND A.Id_Empresa = (SELECT Id_Empresa FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "')";
            }
            else
            {
                //Obtengo RFC de acceso
                String        RFC           = "";
                String        QueryAcceso   = "SELECT RFC_Permisos FROM Usuarios WHERE Id_Usuario = '" + DepCom.DepurarSinMayus(IdUsuario) + "';";
                SqlCommand    ComandoAcceso = new SqlCommand(QueryAcceso, conn, Transaccion);
                SqlDataReader LectorAcceso  = ComandoAcceso.ExecuteReader();
                if (LectorAcceso.HasRows)
                {
                    while (LectorAcceso.Read())
                    {
                        RFC = LectorAcceso.GetString(0);
                    }
                }
                LectorAcceso.Close();

                String[] ArregloRFC = RFC.Split(',');

                RFC = "";
                for (int i = 0; i < ArregloRFC.Length; i++)
                {
                    if (RFC.Length == 0)
                    {
                        RFC = "'" + ArregloRFC[i] + "'";
                    }
                    else
                    {
                        RFC += ",'" + ArregloRFC[i] + "'";
                    }
                }
                RFC = RFC.ToUpper();

                Condiciones += " AND A.Serie IN(" + RFC + ")";
            }

            String        QueryObtener   = "SELECT B.RFC, (SELECT TOP(1) UPPER(C.Razon_Social) FROM Facturas AS C WHERE C.Id_Cliente = B.Id_Cliente GROUP BY C.Razon_Social ORDER BY COUNT(*) DESC) AS Razon_Social FROM Facturas AS A INNER JOIN Clientes AS B ON B.Id_Cliente = A.Id_Cliente WHERE B.RFC NOT LIKE '%010101000'" + Condiciones + " GROUP BY B.Id_Cliente, B.RFC UNION SELECT B.RFC, UPPER(A.Razon_Social) FROM Facturas AS A INNER JOIN Clientes AS B ON B.Id_Cliente = A.Id_Cliente WHERE B.RFC LIKE '%010101000'" + Condiciones + " GROUP BY A.Razon_Social, B.RFC;";
            SqlCommand    ComandoObtener = new SqlCommand(QueryObtener, conn, Transaccion);
            SqlDataReader LectorObtener  = ComandoObtener.ExecuteReader();
            if (LectorObtener.HasRows)
            {
                while (LectorObtener.Read())
                {
                    ObjetoClientes ObjCli = new ObjetoClientes();
                    ObjCli.RazonSocial = LectorObtener.GetString(1);
                    ObjCli.RFC         = LectorObtener.GetString(0);
                    Lista.Add(ObjCli);
                }
            }
            LectorObtener.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            Transaccion.Rollback();
            conn.Close();
        }

        return(Lista);
    }