コード例 #1
0
ファイル: Functions.cs プロジェクト: Gilluminati/Ose-V_113
        /// <summary>
        /// funcao - carrega os menus 
        /// </summary>
        /// <param name="filtrar"></param>
        /// <param name="pesquisar"></param>
        public static void CarregarMenus(Filtrar filtrar,
                                         Pesquisar pesquisar)
        {
            if (_connection.State != ConnectionState.Closed)
            {
                _connection.Close();
                _connection.Dispose();
            }
            try
            {
                ArrayList.Clear();
                using (_connection = new MySqlConnection(MainWindow.Interface.ConnectionString))
                {

                    _connection.Open();
                    var comandosql = @"SELECT `MOD.TIPO`," +
                                     "`MOD.NOME`," +
                                     "`MOD.DESCRICAO`," +
                                     "`MOD.PRIVILEGIO`" +
                                     "FROM   `v101_tab_modulo`";
                    switch (filtrar)
                    {

                        case Filtrar.Todos:
                            if (LikeByText != string.Empty)
                            {
                                switch (pesquisar)
                                {
                                    case Pesquisar.Modulo:
                                        comandosql = string.Concat(comandosql,
                                        " WHERE `MOD.NOME` LIKE '%" + LikeByText + "%'");
                                        break;
                                    case Pesquisar.Descricao:
                                        comandosql = string.Concat(comandosql,
                                        " WHERE `MOD.DESCRICAO` LIKE '%" + LikeByText + "%'");
                                        break;
                                    case Pesquisar.Privilegio:
                                        comandosql = string.Concat(comandosql,
                                        " WHERE `MOD.PRIVILEGIO` LIKE '%" + LikeByText + "%'");
                                        break;
                                }
                            }
                            break;
                        case Filtrar.Aplicacao:
                            comandosql = string.Concat(comandosql,
                            " WHERE `MOD.TIPO` = 'APLICACAO'");
                            break;
                        case Filtrar.Modulo:
                            comandosql = string.Concat(comandosql,
                            " WHERE `MOD.TIPO` = 'MENU'");
                            break;
                    }
                    switch (pesquisar)
                    {
                       case Pesquisar.Modulo:
                            if (LikeByText != string.Empty && filtrar != Filtrar.Todos)
                            {
                                comandosql = string.Concat(comandosql,
                                " AND `MOD.NOME` LIKE '%" + LikeByText + "%'");
                            }
                            break;
                       case Pesquisar.Descricao:
                            if (LikeByText != string.Empty && filtrar != Filtrar.Todos)
                            {
                                comandosql = string.Concat(comandosql,
                                " AND `MOD.DESCRICAO` LIKE '%" + LikeByText + "%'");
                            }
                            break;
                       case Pesquisar.Privilegio:
                            if (LikeByText != string.Empty && filtrar != Filtrar.Todos)
                            {
                                comandosql = string.Concat(comandosql,
                                " AND `MOD.PRIVILEGIO` LIKE '%" + LikeByText + "%'");
                            }
                            break;
                    }
                    using (MySqlCommand command = new MySqlCommand(comandosql,_connection))
                    {
                        MySqlDataReader sqlDataReader = command.ExecuteReader();
                        while (sqlDataReader.Read())
                        {
                            if (sqlDataReader.GetString(1) != @"MNU000")
                            {
                                var t = new UiMenu()
                                {
                                    Tipo = sqlDataReader.GetString(0),
                                    Modulo = sqlDataReader.GetString(1),
                                    Descricao = sqlDataReader.GetString(2),
                                    Privilegio = sqlDataReader.GetString(3)
                                };
                                ArrayList.Add(t);
                            }
                        }
                    }
                }
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                if (_connection.State != ConnectionState.Closed)
                {
                    _connection.Close();
                    _connection.Dispose();
                }
            }
        }
コード例 #2
0
ファイル: Functions.cs プロジェクト: Gilluminati/Ose-V_113
        /// <summary>
        /// funcao - carrega os menus
        /// </summary>
        /// <param name="filtrar"></param>
        /// <param name="pesquisar"></param>
        public static void CarregarMenus(Filtrar filtrar,
                                         Pesquisar pesquisar)
        {
            if (_connection.State != ConnectionState.Closed)
            {
                _connection.Close();
                _connection.Dispose();
            }
            try
            {
                ArrayList.Clear();
                using (_connection = new MySqlConnection(MainWindow.Interface.ConnectionString))
                {
                    _connection.Open();
                    var comandosql = @"SELECT `MOD.TIPO`," +
                                     "`MOD.NOME`," +
                                     "`MOD.DESCRICAO`," +
                                     "`MOD.PRIVILEGIO`" +
                                     "FROM   `v101_tab_modulo`";
                    switch (filtrar)
                    {
                    case Filtrar.Todos:
                        if (LikeByText != string.Empty)
                        {
                            switch (pesquisar)
                            {
                            case Pesquisar.Modulo:
                                comandosql = string.Concat(comandosql,
                                                           " WHERE `MOD.NOME` LIKE '%" + LikeByText + "%'");
                                break;

                            case Pesquisar.Descricao:
                                comandosql = string.Concat(comandosql,
                                                           " WHERE `MOD.DESCRICAO` LIKE '%" + LikeByText + "%'");
                                break;

                            case Pesquisar.Privilegio:
                                comandosql = string.Concat(comandosql,
                                                           " WHERE `MOD.PRIVILEGIO` LIKE '%" + LikeByText + "%'");
                                break;
                            }
                        }
                        break;

                    case Filtrar.Aplicacao:
                        comandosql = string.Concat(comandosql,
                                                   " WHERE `MOD.TIPO` = 'APLICACAO'");
                        break;

                    case Filtrar.Modulo:
                        comandosql = string.Concat(comandosql,
                                                   " WHERE `MOD.TIPO` = 'MENU'");
                        break;
                    }
                    switch (pesquisar)
                    {
                    case Pesquisar.Modulo:
                        if (LikeByText != string.Empty && filtrar != Filtrar.Todos)
                        {
                            comandosql = string.Concat(comandosql,
                                                       " AND `MOD.NOME` LIKE '%" + LikeByText + "%'");
                        }
                        break;

                    case Pesquisar.Descricao:
                        if (LikeByText != string.Empty && filtrar != Filtrar.Todos)
                        {
                            comandosql = string.Concat(comandosql,
                                                       " AND `MOD.DESCRICAO` LIKE '%" + LikeByText + "%'");
                        }
                        break;

                    case Pesquisar.Privilegio:
                        if (LikeByText != string.Empty && filtrar != Filtrar.Todos)
                        {
                            comandosql = string.Concat(comandosql,
                                                       " AND `MOD.PRIVILEGIO` LIKE '%" + LikeByText + "%'");
                        }
                        break;
                    }
                    using (MySqlCommand command = new MySqlCommand(comandosql, _connection))
                    {
                        MySqlDataReader sqlDataReader = command.ExecuteReader();
                        while (sqlDataReader.Read())
                        {
                            if (sqlDataReader.GetString(1) != @"MNU000")
                            {
                                var t = new UiMenu()
                                {
                                    Tipo       = sqlDataReader.GetString(0),
                                    Modulo     = sqlDataReader.GetString(1),
                                    Descricao  = sqlDataReader.GetString(2),
                                    Privilegio = sqlDataReader.GetString(3)
                                };
                                ArrayList.Add(t);
                            }
                        }
                    }
                }
            }
            catch (MySqlException e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                if (_connection.State != ConnectionState.Closed)
                {
                    _connection.Close();
                    _connection.Dispose();
                }
            }
        }