Example #1
0
        //==============================================

        public void CarregaDataGrid()
        {
            ClnUsuarioRepository ObjUsuario = new ClnUsuarioRepository();                     //Criar Obj

            dgv.DataSource = ObjUsuario.ListarUsuariosCadUsuario(txtPesquisa.Text).Tables[0]; //Método Listar que passa o parâmetro do texto digitado para o Grid
            //Cria os Cabeçalhos de cada coluna
            dgv.Columns[0].HeaderText = ("COD");
            dgv.Columns[1].HeaderText = ("USUARIO");
            dgv.AutoResizeColumns(); //Tamanho exato da maior coluna
            if (dgv.RowCount == 0)   //Se não houver dados no DGV, os botão serão desativados
            {
                //btnRelatorio.Enabled = false; //Desativar os botões
                //btnConsultar.Enabled = false;
                btnEditar.Enabled  = false;
                btnExcluir.Enabled = false;
                MessageBox.Show("NÃO FORAM ENCONTRADOS DADOS COM A INFORMAÇÃO: " + txtPesquisa.Text, "Verificar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dgv.DataSource   = null; //Limpa o cabeçalho
                txtPesquisa.Text = "";
                txtPesquisa.Focus();
            }
            else
            {
                //btnRelatorio.Enabled = true; //Ativar os botões
                //btnConsultar.Enabled = true;
                btnEditar.Enabled  = true;
                btnExcluir.Enabled = true;
            }
        }
Example #2
0
        private void btnSair_Click(object sender, EventArgs e)
        {
            ClnUsuarioRepository ObjUser = new ClnUsuarioRepository();
            //Aqui listo se usuario é Administrador
            string      TipoUser = "******";
            IDataReader drDadosListarUserAdmin;

            drDadosListarUserAdmin = ObjUser.ListarUserAdmin(txtUsuarioCookie.Text, txtSenhaCookie.Text, TipoUser);
            if (drDadosListarUserAdmin.Read())
            {
                FrmMenuPrincipal ObjMenu = new FrmMenuPrincipal();
                ObjMenu.txtUsuarioCookie.Text = txtUsuarioCookie.Text;
                ObjMenu.txtSenhaCookie.Text   = txtSenhaCookie.Text;
                ObjMenu.Show();
                this.Close();
            }
            else
            {
                FrmMenuPrincipal ObjMenu = new FrmMenuPrincipal();
                ObjMenu.txtUsuarioCookie.Text = txtUsuarioCookie.Text;
                ObjMenu.txtSenhaCookie.Text   = txtSenhaCookie.Text;
                ObjMenu.BtnGerencia.Visible   = false;
                ObjMenu.Show();
                this.Close();
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            string str  = txtUsuario.Text;
            string test = str.Replace("'", "'");

            if (txtUsuario.Text != test)
            {
                MessageBox.Show("Nome de Usuario ou senhas Incorretas.", "Problema ao Logar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSenha.Text = "";
                txtUsuario.Focus();
            }
            else
            {
                ClnUsuarioRepository ObjUser = new ClnUsuarioRepository();
                //Aqui Listo se o usuario é ativo = 0
                IDataReader drDadosListarUsuarioBloqueado;
                drDadosListarUsuarioBloqueado = ObjUser.ListarUsuarioBloqueado(txtUsuario.Text, txtSenha.Text);
                //Aqui listo usuario comum
                IDataReader drDadosListarUsuario;
                drDadosListarUsuario = ObjUser.ListarUsuario(txtUsuario.Text, txtSenha.Text);
                //Aqui listo se usuario é Administrador
                string      TipoUser = "******";
                IDataReader drDadosListarUserAdmin;
                drDadosListarUserAdmin = ObjUser.ListarUserAdmin(txtUsuario.Text, txtSenha.Text, TipoUser);

                if (drDadosListarUsuarioBloqueado.Read())
                {
                    MessageBox.Show("Usuario esta desabilitado, informe seu supervisor.", "Problema ao Logar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtSenha.Text = "";
                    txtUsuario.Focus();
                }
                else
                {
                    if (drDadosListarUserAdmin.Read())
                    {
                        this.Visible = false;
                        FrmMenuPrincipal ObjMenu = new FrmMenuPrincipal();
                        ObjMenu.txtUsuarioCookie.Text = txtUsuario.Text;
                        ObjMenu.txtSenhaCookie.Text   = txtSenha.Text;
                        ObjMenu.Show();
                    }
                    else if (drDadosListarUsuario.Read())
                    {
                        this.Visible = false;
                        FrmMenuPrincipal ObjMenu = new FrmMenuPrincipal();
                        ObjMenu.BtnGerencia.Visible   = false;
                        ObjMenu.txtUsuarioCookie.Text = txtUsuario.Text;
                        ObjMenu.txtSenhaCookie.Text   = txtSenha.Text;
                        ObjMenu.Show();
                    }
                    else
                    {
                        MessageBox.Show("Nome de Usuario ou senhas Incorretas.", "Problema ao Logar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtSenha.Text = "";
                        txtUsuario.Focus();
                    }
                }
            }
        }
        private void Btn2_Click(object sender, EventArgs e)
        {
            ClnUsuarioRepository ObjUser = new ClnUsuarioRepository();
            IDataReader          drDadosListarUserAdmin;
            string TipoLogin = "******";

            drDadosListarUserAdmin = ObjUser.ListarUserAdmin(txtDois.Text, txtUm.Text, TipoLogin);

            if (lblFuncao.Text == "Excluir Usuario")
            {
                if (drDadosListarUserAdmin.Read())
                {
                    int msg;                                                                                                                                                                         //Pergunta e aguarda resposta
                    msg = Convert.ToInt32(MessageBox.Show("Deseja excluir o registro? " + Convert.ToString(txtCinco.Text), "E X C L U S Ã O", MessageBoxButtons.YesNo, MessageBoxIcon.Information)); //msg aguardando resposta

                    //Exclusão física, será apagado do BD
                    if (msg == 6)                                        //6 representa Yes e 7 No
                    {
                        ObjUser.Excluir(Convert.ToInt32(lblCinco.Text)); //Por Código
                        MessageBox.Show("Registro excluído com sucesso", "E X C L U S Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        FrmCadUsuario ObjCadUsuario = new FrmCadUsuario();
                        ObjCadUsuario.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("OPERAÇÃO CANCELADA", "CANCELAMENTO E X C L U S Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        FrmCadUsuario ObjCadUsuario = new FrmCadUsuario();
                        ObjCadUsuario.Show();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Usuario administrador ou senhas incorretas", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (lblFuncao.Text == "Editar Usuario")
            {
                FrmCadUsuario ObjCadUsuario = new FrmCadUsuario();
                ObjCadUsuario.Text                = ">>> Alterar <<<";
                ObjCadUsuario.txtSenha.Visible    = false;
                ObjCadUsuario.lblSenha.Text       = "Necessario Logar para alterar a senha";
                ObjCadUsuario.LblPesquisar.Text   = "Atenção voce esta alterando o Usuario:";
                ObjCadUsuario.txtPesquisa.Enabled = false;
                ObjCadUsuario.txtPesquisa.Text    = Convert.ToString(txtCinco.Text); //Envia para o campo código o valor do código marcado
                ObjCadUsuario.btnEditar.Visible   = false;
                ObjCadUsuario.btnExcluir.Visible  = false;
                ObjCadUsuario.btnGravar.Text      = "&Alterar";
                ObjCadUsuario.TxtCod.Text         = Convert.ToString(lblCinco.Text); //Envia para o campo código o valor do código marcado
                ObjCadUsuario.txtUsuario.Focus();
                ObjCadUsuario.EnumProperty = ClnFuncoesGerais.Operacao.Alteracao;    //Informa que é Alteração
                ObjCadUsuario.ShowDialog();
                this.Close();
            }
        }
        private void btnAtribuirADM_Click(object sender, EventArgs e)
        {
            int msg;                                                                                                                                                                                                                           //Pergunta e aguarda resposta

            msg = Convert.ToInt32(MessageBox.Show("Deseja dar permisão de Administrador para o Usuario? " + Convert.ToString(dgv.CurrentRow.Cells[1].Value), "Ativar ADM para usuario", MessageBoxButtons.YesNo, MessageBoxIcon.Information)); //msg aguardando resposta

            //Exclusão física, será apagado do BD
            if (msg == 6)                                                                 //6 representa Yes e 7 No
            {
                ClnUsuarioRepository objFunc = new ClnUsuarioRepository();                //Apagar da Agenda
                objFunc.AtivarUsuarioADM(Convert.ToInt32(dgv.CurrentRow.Cells[0].Value)); //Por Código
                MessageBox.Show("Usuario atribuido com sucesso", "Ativar ADM para usuario", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("OPERAÇÃO CANCELADA", "Ativar ADM para usuario", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            CarregaDataGrid();
        }
Example #6
0
        private void BtnExcluir_Click(object sender, EventArgs e)
        {
            int msg;                                                                                                                                                                                         //Pergunta e aguarda resposta

            msg = Convert.ToInt32(MessageBox.Show("Deseja excluir o registro? " + Convert.ToString(dgv.CurrentRow.Cells[1].Value), "E X C L U S Ã O", MessageBoxButtons.YesNo, MessageBoxIcon.Information)); //msg aguardando resposta

            //Exclusão física, será apagado do BD
            if (msg == 6)                                                           //6 representa Yes e 7 No
            {
                ClnUsuarioRepository objUsuario = new ClnUsuarioRepository();       //Apagar da Agenda
                objUsuario.Excluir(Convert.ToInt32(dgv.CurrentRow.Cells[0].Value)); //Por Código
                MessageBox.Show("Registro excluído com sucesso", "E X C L U S Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("OPERAÇÃO CANCELADA", "CANCELAMENTO E X C L U S Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            CarregaDataGrid();
        }
Example #7
0
 private void btnGravar_Click(object sender, EventArgs e)
 {
     //Verifica se os campos nome e telefone estão preenchidos, porque são obrigatórios
     if ((txtUsuario.Text == ""))
     {
         MessageBox.Show("Opa!!! algum Campo ficou em branco. ", "Item Novo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         txtPesquisa.Focus();
     }
     else
     {
         ClnUsuarioRepository Usuario = new ClnUsuarioRepository();
         Usuario.LOGIN    = txtUsuario.Text;
         Usuario.SENHA    = txtSenha.Text;
         Usuario.TIPOUSER = "******";
         if (btnGravar.Text == "&Alterar")
         {
             Usuario.COD = Convert.ToInt32(TxtCod.Text);
         }
         if (ObjOperacao == ClnFuncoesGerais.Operacao.Inclusao)//Verifica se é inclusão faça
         {
             Usuario.Gravar();
             MessageBox.Show("Usuario: " + txtUsuario.Text + ", cadastrado com sucesso", "Item Novo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtUsuario.Text  = "";
             txtSenha.Text    = "";
             txtPesquisa.Text = "";
             CarregaDataGrid();                                       //Chama o Método Preencher a Grid
         }
         else if (ObjOperacao == ClnFuncoesGerais.Operacao.Alteracao) //Verifica se é alteração faça
         {
             Usuario.Alterar();
             MessageBox.Show("Usuario " + txtUsuario.Text + ", Alterado com sucesso", "Alteração", MessageBoxButtons.OK, MessageBoxIcon.Information);
             CarregaDataGrid(); //Chama o Método Preencher a Grid
             FrmCadUsuario objCadUsuario = new FrmCadUsuario();
             objCadUsuario.Show();
             this.Close();
         }
     }
 }