void ShowManutencaoFromItem()
        {
            if (ListView.SelectedItem == null)
            {
                return;
            }
            Manutencao manutencao = new Manutencao
            {
                ShowTitleBar = false,
                GlowBrush    = new SolidColorBrush(Colors.DodgerBlue),
                //UiMenu = {Novo = false}
            };

            Manutencao.UiMenu.Novo = false;

            var item = ListView.SelectedItem as UiMenu ?? new UiMenu();

            manutencao.InicializarComboBox(false, OseFunctions.GetNameFromModulo(item.Modulo));
            Manutencao.UiMenu.Tipo       = item.Tipo == @"APLICACAO" ? ManutencaoUiMenu.IsType.Aplicacao : ManutencaoUiMenu.IsType.Menu;
            Manutencao.UiMenu.Modulo     = item.Modulo;
            Manutencao.UiMenu.Descricao  = item.Descricao;
            Manutencao.UiMenu.Privilegio = item.Privilegio;
            Manutencao.UiMenu.ModuloPai  = OseFunctions.GetPaiFrom(item.Modulo);

            manutencao.ShowDialog();

            // Atualizar - manutencao.close()
            CallFilterAndLike();
            InicializarListView();
        }
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            Interface.Carregar_Config();
            MySql.DoWork += (o, args) =>
            {
                Interface.IsConnectMySql();
            };
            MySql.RunWorkerCompleted += (o, args) =>
            {
                if (!Interface.SMySql.IsOnline)
                {
                    // Offline
                    Label.Content    = @"MDM100" + @" - Offline";
                    Label.Foreground = Color.Red;
                    return;
                }
                // Online
                Label.Content    = @"MDM100" + @" - Online";
                Label.Foreground = Color.DodgerBlue;

                // Contar total de modulos,menus,aplicacao
                string modulos, menus, aplicacao;
                OseFunctions.ContarTotalModulos(out modulos, out menus, out aplicacao);

                LblModCad.Content     = modulos;
                LblMenuTotal.Content  = menus;
                LblAplicTotal.Content = aplicacao;

                CallFilterAndLike();
                InicializarListView();
            };
            MySql.RunWorkerAsync();
        }
        private async void CmdDeletar_OnClick(object sender, RoutedEventArgs e)
        {
            if (TextBox.Text == @"MNU00")
            {
                return;
            }
            var result = await this.ShowMessageAsync(@"Exluir", @"Deseja realmente exluir modulo :" + TextBox.Text, MessageDialogStyle.AffirmativeAndNegative);

            if (result == MessageDialogResult.Affirmative)
            {
                OseFunctions.DeleteModulo(TextBox.Text);
                await this.ShowMessageAsync(@"Sucesso", @"Modulo excluido com sucesso . . .");

                this.Close();
            }
        }
        void CallFilterAndLike()
        {
            //  LIKE
            if (RadModulo.IsChecked != null && RadModulo.IsChecked.Value)
            {
                Pesquisar = OseFunctions.Pesquisar.Modulo;
            }
            else if (RadDescricao.IsChecked != null && RadDescricao.IsChecked.Value)
            {
                Pesquisar = OseFunctions.Pesquisar.Descricao;
            }
            else if (RadPrivilegio.IsChecked != null && RadPrivilegio.IsChecked.Value)
            {
                Pesquisar = OseFunctions.Pesquisar.Privilegio;
            }

            // FILTRAR MENU OR APLICACAO
            if (RadFilTodos.IsChecked != null && RadFilTodos.IsChecked.Value)
            {
                Filtrar = OseFunctions.Filtrar.Todos;
            }

            if (RadApenasAplic.IsChecked != null && RadApenasAplic.IsChecked.Value)
            {
                Filtrar = OseFunctions.Filtrar.Aplicacao;
            }

            if (RadApenasModulo.IsChecked != null && RadApenasModulo.IsChecked.Value)
            {
                Filtrar = OseFunctions.Filtrar.Modulo;
            }
            OseFunctions.LikeByText = TextBox.Text;
            OseFunctions.CarregarMenus(Filtrar, Pesquisar);

            //GetAllModules()
            string modules, menus, aplicacoes;

            OseFunctions.ContarTotalModulos(out modules, out menus, out aplicacoes);
            LblModCad.Content     = modules;
            LblMenuTotal.Content  = menus;
            LblAplicTotal.Content = aplicacoes;
        }
        public void InicializarComboBox(bool isDefault,
                                        string isMod = null)
        {
            if (!isDefault)
            {
                ComboBox.Items.Clear();
                if (ComboBox.Items.Count == 0)
                {
                    var result = OseFunctions.GetModulos();
                    foreach (var i in result)
                    {
                        ComboBox.Items.Add(i);
                    }
                }
                if (isMod != null)
                {
                    var result = OseFunctions.GetPaiFrom(isMod.Substring(0, 6));
                    foreach (var i in ComboBox.Items)
                    {
                        if (result == i.ToString().Substring(0, 6))
                        {
                            ComboBox.SelectedItem = i;
                        }
                    }
                }
                return;
            }

            if (ComboBox.Items.Count == 0)
            {
                ComboBox.Items.Clear();
                var getmods = OseFunctions.GetModulos();
                foreach (var i in getmods)
                {
                    ComboBox.Items.Add(i);
                }
            }
        }
        private async void ItemExcluir_OnClick(object sender, RoutedEventArgs e)
        {
            var item = ListView.SelectedItem as UiMenu ?? new UiMenu();

            if (item.Modulo != null)
            {
                var result = await this.ShowMessageAsync(@"Exluir", @"Deseja realmente exluir modulo :" +
                                                         item.Modulo, MessageDialogStyle.AffirmativeAndNegative);

                if (result == MessageDialogResult.Affirmative)
                {
                    OseFunctions.DeleteModulo(item.Modulo);
                    await this.ShowMessageAsync(@"Sucesso",
                                                @"Modulo excluido com sucesso . . .");

                    //this.Close();

                    // Atualizar - manutencao.close()
                    CallFilterAndLike();
                    InicializarListView();
                }
            }
        }
        private async void CmdConfirma_OnClick(object sender, RoutedEventArgs e)
        {
            if (RadMenu.IsChecked != null && !RadMenu.IsChecked.Value && RadAplic.IsChecked != null && !RadAplic.IsChecked.Value)
            {
                _campoembranco = string.Concat(_campoembranco, "Tipo \n");
            }
            /*EstiloTextBlock(true);*/
            if (TextBox.Text.Length == 0 || TextBox.Text.Length != 6)
            {
                _campoembranco = string.Concat(_campoembranco, "Modulo \n");
                /*BlockObrigatorioModulo.Visibility = Visibility.Visible;*/
            }
            if (TextBoxDescricao.Text.Length == 0)
            {
                _campoembranco = string.Concat(_campoembranco, "Descricao \n");
                /*BlockObrigatorioDescricao.Visibility = Visibility.Visible;*/
            }
            if (TextBoxPrivilegio.Text.Length == 0)
            {
                _campoembranco = string.Concat(_campoembranco, "Privilegio \n");
                /*BlockObrigatorioPrivilegio.Visibility = Visibility.Visible;*/
            }

            if (ComboBox.Text == string.Empty)
            {
                _campoembranco = string.Concat(_campoembranco, "Modulo Pai \n");
                /*BlockObrigatorioModuloPai.Visibility = Visibility.Visible;*/
            }
            if (_campoembranco != string.Empty)
            {
                /*MessageBox.Show(_campoembranco);*/
                await this.ShowMessageAsync(@"Campo(s) Obrigatorio(s)", _campoembranco, MessageDialogStyle.Affirmative, null);

                _campoembranco = string.Empty;
                return;
            }

            if (_campoembranco == string.Empty)
            {
                // Insert
                if (UiMenu.Novo)
                {
                    if (RadMenu.IsChecked != null && RadMenu.IsChecked.Value)
                    {
                        Tipo = @"MENU";
                    }
                    else if (RadAplic.IsChecked != null && RadAplic.IsChecked.Value)
                    {
                        Tipo = @"APLICACAO";
                    }
                    var           modP = ComboBox.Text.Substring(0, 6);
                    List <string> sucesso;
                    OseFunctions.InsertNewModulo(Tipo,
                                                 TextBox.Text,
                                                 TextBoxDescricao.Text,
                                                 TextBoxPrivilegio.Text,
                                                 modP,
                                                 out sucesso);
                    foreach (var i in sucesso)
                    {
                        if (i == @"Sucesso")
                        {
                            await this.ShowMessageAsync(@"Sucesso", @"Criado com sucesso . . .");

                            this.Close();
                        }
                        else if (i == @"Falha" + @"Chave duplicada")
                        {
                            await this.ShowMessageAsync(@"Falha", @"Modulo já cadastrado !!!");

                            TextBox.Focus();
                        }
                        else if (i == @"Falha")
                        {
                            await this.ShowMessageAsync(@"Falha", @"Erro cadastrar novo modulo !!!");

                            TextBox.Focus();
                        }
                    }
                }
                // Update
                else
                {
                    // Compara os dados
                    if (RadMenu.IsChecked != null && RadMenu.IsChecked.Value)
                    {
                        Tipo = @"Menu";
                    }
                    else if (RadAplic.IsChecked != null && RadAplic.IsChecked.Value)
                    {
                        Tipo = @"Aplicacao";
                    }
                    if (UiMenu.Tipo.ToString() != Tipo ||
                        UiMenu.Modulo != TextBox.Text ||
                        UiMenu.Descricao != TextBoxDescricao.Text ||
                        UiMenu.Privilegio != TextBoxPrivilegio.Text ||
                        UiMenu.ModuloPai != ComboBox.Text.Substring(0, 6))
                    {
                        switch (Tipo)
                        {
                        case @"Menu":
                            UpdateTipo = @"MENU";
                            break;

                        case @"Aplicacao":
                            UpdateTipo = @"APLICACAO";
                            break;
                        }
                        int err;
                        OseFunctions.UpdateExisteModulo(UpdateTipo,
                                                        TextBox.Text,
                                                        TextBoxDescricao.Text,
                                                        TextBoxPrivilegio.Text,
                                                        ComboBox.Text.Substring(0, 6),
                                                        UiMenu.Modulo,
                                                        out err);
                        switch (err)
                        {
                        case 1062:     // -> [Err] 1062 - Duplicate entry 'NEW000' for key 'PRIMARY'
                            /*MessageBox.Show(@"Chave Duplicada -");*/
                            await this.ShowMessageAsync(@"Falha", @"Modulo já existente !!!");

                            break;

                        case 0:
                            /*MessageBox.Show(@"Update");*/
                            await this.ShowMessageAsync(@"Sucesso", @"Modulo Atualizado com sucesso ...");

                            this.Close();
                            break;
                        }
                    }
                }
            }
            _campoembranco = string.Empty;
        }