예제 #1
0
    public DataView getCampos()
    {
        string str_driver = PageCadastroBase.getExcelDriver();

        if (str_driver == "")
        {
            str_driver = "Microsoft Excel Driver (*.xls)";
        }

        string conexao = "Driver={" + str_driver + "};DriverId=790;DBQ=" +
                         this.CaminhoExcel + ";ReadOnly= true ; ";

        //conn.ConnectionString = conexao;


        ConnODBC OdbcConn = null;

        try
        {
            IDbPersist oTmp = FactoryConn.getConn("odbc", conexao, "odbc");
            OdbcConn = (ConnODBC)oTmp;
            //conn.Open();
        }
        catch (Exception exp)
        {
            Trace.Write("Erro ao tentar conectar o banco de dados de filtro via ODBC: " +
                        exp.Message + " - Arquivo em formato inválido! - String de Conexão:" + conexao);

            //Alert("Erro ao tentar conectar o banco de dados de filtro via ODBC: " +
            //  exp.Message + " - Arquivo em formato inválido! ");


            return(null);
        }

        OdbcConnection conn = (OdbcConnection)OdbcConn.getConn();

        string[] restrictions = new string[4];
        restrictions[3] = "Table";

        DataTable userTables = conn.GetSchema("Tables");

        string my_tabela = this.Tabela;

        for (int i = 0; i < userTables.Rows.Count; i++)
        {
            string tab_col = userTables.Rows[i][2].ToString();

            if (userTables.Rows[i][3].ToString().IndexOf("TABLE") > -1 && tab_col == this.Tabela + "$")
            {
                my_tabela = userTables.Rows[i][2].ToString();
                break;
            }
        }


        DataTable dt_campos =
            ConnAccess.fetchData(OdbcConn, "select * from [" +
                                 my_tabela + "] where visivel = 'True' order by tipo desc, ordem asc, label asc ");

        //primaryKey desc, label,
        conn.Close();
        conn.Dispose();

        string add_filtro = string.Empty;

        if (dt_campos.Columns.Contains("filtro"))
        {
            add_filtro += " and filtro = '1' ";
        }

        DataView dw = dt_campos.DefaultView;

        return(dw);
    }