Beispiel #1
0
 public int insereUsuario(Usuario_DTO USU)
 {
     try
     {
         /*Conexão com BD
          * Inserindo dados na tb_usuarios*/
         SqlConnection CON = new SqlConnection();
         CON.ConnectionString = Properties.Settings.Default.CST;
         SqlCommand CM = new SqlCommand();
         CM.CommandType = System.Data.CommandType.Text;
         CM.CommandText = "INSERT INTO tb_usuarios (nome, login, email, senha, cadastro, situacao, perfil)"
                          + "VALUES (@nome, @login, @email, @senha, @cadastro, @situacao, @perfil)";
         /*Parameters irá substituir os valores dentro do campo */
         CM.Parameters.Add("nome", System.Data.SqlDbType.VarChar).Value      = USU.nome;
         CM.Parameters.Add("login", System.Data.SqlDbType.VarChar).Value     = USU.login;
         CM.Parameters.Add("email", System.Data.SqlDbType.VarChar).Value     = USU.email;
         CM.Parameters.Add("senha", System.Data.SqlDbType.VarChar).Value     = USU.senha;
         CM.Parameters.Add("cadastro", System.Data.SqlDbType.DateTime).Value = USU.cadastro;
         CM.Parameters.Add("situacao", System.Data.SqlDbType.NVarChar).Value = USU.situacao;
         CM.Parameters.Add("perfil", System.Data.SqlDbType.Int).Value        = USU.perfil;
         CM.Connection = CON;
         CON.Open();
         int qtd = CM.ExecuteNonQuery();
         return(qtd);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
 public int editaUsuario(Usuario_DTO USU)
 {
     try
     {
         SqlConnection CON = new SqlConnection();
         CON.ConnectionString = Properties.Settings.Default.CST;
         SqlCommand CM = new SqlCommand();
         CM.CommandType = System.Data.CommandType.Text;
         /*Atenção ao nome dos campos que deve ser igual ao Banco de Dados*/
         CM.CommandText = "UPDATE tb_usuarios SET perfil=@perfil," +
                          "nome=@nome," + "login=@login," + "email=@email," + "senha=@senha," +
                          "cadastro=@cadastro," + "situacao=@situacao " + "WHERE cod_usuario=@cod_usuario";
         /*Parameters irá substituir os valores dentro do campo*/
         CM.Parameters.Add("perfil", System.Data.SqlDbType.Int).Value          = USU.perfil;
         CM.Parameters.Add("nome", System.Data.SqlDbType.VarChar).Value        = USU.nome;
         CM.Parameters.Add("login", System.Data.SqlDbType.VarChar).Value       = USU.login;
         CM.Parameters.Add("email", System.Data.SqlDbType.VarChar).Value       = USU.email;
         CM.Parameters.Add("senha", System.Data.SqlDbType.VarChar).Value       = USU.senha;
         CM.Parameters.Add("cadastro", System.Data.SqlDbType.DateTime).Value   = USU.cadastro;
         CM.Parameters.Add("situacao", System.Data.SqlDbType.VarChar).Value    = USU.situacao;
         CM.Parameters.Add("cod_usuario", System.Data.SqlDbType.VarChar).Value = USU.cod_usuario;
         CM.Connection = CON;
         /*Abre conexão*/
         CON.Open();
         int qtd = CM.ExecuteNonQuery();
         return(qtd);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
        public int deletaUsuario(Usuario_DTO usu)
        {
            try
            {
                MySqlConnection con = new MySqlConnection();
                con.ConnectionString = Properties.Settings.Default.CST;

                MySqlCommand cm = new MySqlCommand();
                cm.CommandType = System.Data.CommandType.Text;

                cm.CommandText = "DELETE FROM TBOD_USUARIO WHERE CD_USUARIO = @CD_USUARIO";

                cm.Parameters.Add("@CD_USUARIO", MySqlDbType.Int32).Value = usu.cd_usuario;
                cm.Connection = con;

                con.Open();
                int qtd = cm.ExecuteNonQuery();
                con.Close();

                return(qtd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
 public int deletaUsuario(Usuario_DTO USU)
 {
     try
     {
         return(new Usuario_DAL().deletaUsuario(USU));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int deletarUsuario(Usuario_DTO usu)
 {
     try
     {
         return(new UsuarioDAL().deletaUsuario(usu));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int insereUsuario(Usuario_DTO usu)
 {
     try
     {
         return(new UsuarioDAL().insereUsuario(usu));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #7
0
    private static Usuario_DTO filaDTOUsuario(Usuarios_DS.UsuariosRow fila)
    {
        Usuario_DTO objDTOUser = new Usuario_DTO();

        objDTOUser.id_usuario = fila.id_usuario;
        objDTOUser.usuario    = fila.usuario;
        objDTOUser.pass_user  = fila.pass_user;
        objDTOUser.id_rol     = fila.id_rol;
        objDTOUser.estado     = fila.estado;

        return(objDTOUser);
    }
Beispiel #8
0
 public int insereUsuario(Usuario_DTO USU)
 {
     /*Insere usuario será criado na DAL*/
     try
     {
         return(new Usuario_DAL().insereUsuario(USU));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #9
0
        private void buttonConfirmar_Click(object sender, EventArgs e)
        {
            if (modo == "novo")
            {
                try
                {
                    Usuario_DTO usuario_DTO = new Usuario_DTO();
                    usuario_DTO.Nome          = txtNome.Text;
                    usuario_DTO.Login         = txtLogin.Text;
                    usuario_DTO.Email         = txtEmail.Text;
                    usuario_DTO.Data_cadastro = System.DateTime.Now;
                    usuario_DTO.Senha         = txtSenha.Text;

                    if (comBoxSituacao.Text == "Ativo")
                    {
                        usuario_DTO.Situacao = "A";
                    }
                    else
                    {
                        usuario_DTO.Situacao = "I";
                    }
                    switch (comBoxPerfil.Text)
                    {
                    case "Administração":
                        usuario_DTO.Perfil = 1;
                        break;

                    case "Operação":
                        usuario_DTO.Perfil = 2;
                        break;

                    case "Gerencial":
                        usuario_DTO.Perfil = 3;
                        break;
                    }

                    int x = new UsuarioBLL().insereUsuario(usuario_DTO);
                    if (x > 0)
                    {
                        MessageBox.Show("Gravado Com Sucesso!");
                    }

                    //Recarregar Grid View
                    carregarGridView();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro Inesperado: " + ex.Message);
                }
                modo = "";
            }
        }
Beispiel #10
0
        public IList <Usuario_DTO> cargaUsuario()
        {
            try
            {
                MySqlConnection con = new MySqlConnection();
                con.ConnectionString = Properties.Settings.Default.CST;

                MySqlCommand CM = new MySqlCommand();

                CM.CommandType = System.Data.CommandType.Text;
                CM.CommandText = "SELECT * FROM TBOD_USUARIO";
                CM.Connection  = con;

                MySqlDataReader     MyER;
                IList <Usuario_DTO> listaUsuarioDTO = new List <Usuario_DTO>();

                con.Open();
                MyER = CM.ExecuteReader();

                if (MyER.HasRows)
                {
                    while (MyER.Read())
                    {
                        Usuario_DTO usu = new Usuario_DTO();

                        //Convertendo os valores
                        usu.cd_usuario  = Convert.ToInt32(MyER["CD_USUARIO"]);
                        usu.nm_nome     = Convert.ToString(MyER["NM_NOME"]);
                        usu.ds_login    = Convert.ToString(MyER["DS_LOGIN"]);
                        usu.ds_email    = Convert.ToString(MyER["DS_EMAIL"]);
                        usu.ds_senha    = Convert.ToString(MyER["DS_SENHA"]);
                        usu.dt_cadastro = Convert.ToDateTime(MyER["DT_CADASTRO"]);
                        usu.id_situacao = Convert.ToString(MyER["ID_SITUACAO"]);
                        usu.id_perfil   = Convert.ToInt32(MyER["ID_PERFIL"]);

                        //Adicionar a lista
                        listaUsuarioDTO.Add(usu);
                    }
                }
                con.Close();
                return(listaUsuarioDTO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        public IList <Usuario_DTO> cargaUsuario()
        {
            try
            {
                /*Conexão com BD
                 * Seleciona todos os dados da tb_usuarios*/
                SqlConnection CON = new SqlConnection();
                CON.ConnectionString = Properties.Settings.Default.CST;
                SqlCommand CM = new SqlCommand();
                CM.CommandType = System.Data.CommandType.Text;
                CM.CommandText = "SELECT*FROM tb_usuarios";
                CM.Connection  = CON;
                SqlDataReader       ER;
                IList <Usuario_DTO> listUsuarioDTO = new List <Usuario_DTO>();
                CON.Open();
                ER = CM.ExecuteReader();
                if (ER.HasRows)
                {
                    while (ER.Read())
                    {
                        Usuario_DTO usu = new Usuario_DTO();

                        /*nome dos objetos criados na DTO
                         * Cada objeto criado é enviado para a lista, possibilitando
                         * que no final vc tenha uma lista com vários usuários */
                        usu.cod_usuario = Convert.ToInt32(ER["cod_usuario"]);
                        usu.perfil      = Convert.ToInt32(ER["perfil"]);
                        usu.cadastro    = Convert.ToDateTime(ER["cadastro"]);
                        usu.nome        = Convert.ToString(ER["nome"]);
                        usu.email       = Convert.ToString(ER["email"]);
                        usu.login       = Convert.ToString(ER["cadastro"]);
                        usu.senha       = Convert.ToString(ER["senha"]);
                        usu.situacao    = Convert.ToString(ER["situacao"]);
                        listUsuarioDTO.Add(usu);
                    }
                }
                return(listUsuarioDTO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #12
0
        public int editarUsuario(Usuario_DTO usu)
        {
            try
            {
                MySqlConnection con = new MySqlConnection();
                con.ConnectionString = Properties.Settings.Default.CST;

                MySqlCommand CM = new MySqlCommand();
                CM.CommandType = System.Data.CommandType.Text;

                CM.CommandText =
                    "UPDATE TBOD_USUARIO " +
                    "SET ID_PERFIL = @ID_PERFIL," +
                    "NM_NOME = @NM_NOME," +
                    "DS_LOGIN = @DS_LOGIN," +
                    "DS_EMAIL = @DS_EMAIL," +
                    "DS_SENHA = @DS_SENHA," +
                    "ID_SITUACAO = @ID_SITUACAO " +

                    "WHERE CD_USUARIO=@CD_USUARIO";

                CM.Parameters.Add("ID_PERFIL", MySqlDbType.Int32).Value     = usu.id_perfil;
                CM.Parameters.Add("NM_NOME", MySqlDbType.VarChar).Value     = usu.nm_nome;
                CM.Parameters.Add("DS_LOGIN", MySqlDbType.VarChar).Value    = usu.ds_login;
                CM.Parameters.Add("DS_EMAIL", MySqlDbType.VarChar).Value    = usu.ds_email;
                CM.Parameters.Add("DS_SENHA", MySqlDbType.VarChar).Value    = usu.ds_senha;
                CM.Parameters.Add("ID_SITUACAO", MySqlDbType.VarChar).Value = usu.id_situacao;

                CM.Parameters.Add("CD_USUARIO", MySqlDbType.Int32).Value = usu.cd_usuario;

                CM.Connection = con;

                con.Open();
                int qtd = CM.ExecuteNonQuery();
                con.Close();

                return(qtd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #13
0
        public int insereUsuario(Usuario_DTO usu)
        {
            try
            {
                MySqlConnection con = new MySqlConnection();
                con.ConnectionString = Properties.Settings.Default.CST;

                MySqlCommand CM = new MySqlCommand();
                CM.CommandType = System.Data.CommandType.Text;

                CM.CommandText = "INSERT INTO TBOD_USUARIO VALUES(" +
                                 "(SELECT MAX(tus.CD_USUARIO)+1 FROM TBOD_USUARIO tus)," +
                                 "@NM_NOME," +
                                 "@DS_LOGIN," +
                                 "@DS_EMAIL," +
                                 "@DS_SENHA," +
                                 "SYSDATE()," +
                                 "@ID_SITUACAO," +
                                 "@ID_PERFIL" +
                                 ")";

                CM.Parameters.Add("NM_NOME", MySqlDbType.VarChar).Value  = usu.nm_nome;
                CM.Parameters.Add("DS_LOGIN", MySqlDbType.VarChar).Value = usu.ds_login;
                CM.Parameters.Add("DS_EMAIL", MySqlDbType.VarChar).Value = usu.ds_email;
                CM.Parameters.Add("DS_SENHA", MySqlDbType.VarChar).Value = usu.ds_senha;

                CM.Parameters.Add("ID_SITUACAO", MySqlDbType.VarChar).Value = usu.id_situacao;
                CM.Parameters.Add("ID_PERFIL", MySqlDbType.Int32).Value     = usu.id_perfil;

                CM.Connection = con;
                con.Open();
                int qtd = CM.ExecuteNonQuery();
                con.Close();
                return(qtd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #14
0
 public int deletaUsuario(Usuario_DTO USU)
 {
     try
     {
         /*Excluindo dados na tb_usuarios*/
         SqlConnection CON = new SqlConnection();
         CON.ConnectionString = Properties.Settings.Default.CST;
         SqlCommand CM = new SqlCommand();
         CM.CommandType = System.Data.CommandType.Text;
         CM.CommandText = "DELETE tb_usuarios WHERE cod_usuario = @cod_usuario";
         /*Têm um único parâmetro que será o código do usuário, só existe um*/
         CM.Parameters.Add("cod_usuario", System.Data.SqlDbType.Int).Value = USU.cod_usuario;
         CM.Connection = CON;
         CON.Open();
         int qtd = CM.ExecuteNonQuery();
         /*Retorna registros afetados*/
         return(qtd);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #15
0
        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            if (modo == "novo")
            {
                try
                {
                    /*Método insere usuário na classe UsuarioBLL*/
                    Usuario_DTO USU = new Usuario_DTO();
                    USU.nome     = txtNome.Text;
                    USU.login    = txtLogin.Text;
                    USU.email    = txtEmail.Text;
                    USU.cadastro = System.DateTime.Now;
                    USU.senha    = txtSenha.Text;
                    if (cboSituacao.Text == "Ativo")
                    {
                        USU.situacao = "A";
                    }
                    else
                    {
                        USU.situacao = "I";
                    }
                    switch (cboPerfil.Text)
                    {
                    case "Administrador":
                        USU.perfil = 1;
                        break;

                    case "Operador":
                        USU.perfil = 2;
                        break;

                    case "Gerencial":
                        USU.perfil = 3;
                        break;
                    }
                    int x = new Usuario_BLL().insereUsuario(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Gravado com Sucesso!");
                    }
                    carregaGrid();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro inesperado" + ex.Message);
                }
            }

            if (modo == "editar")
            {
                try
                {
                    if (codUsuSelecionado < 0)
                    {
                        //lblMensagem.Text = "Selecione um usuario antes de prosseguir";
                        MessageBox.Show("Selecione um usuario antes de prosseguir");
                        return;
                    }

                    Usuario_DTO USU = new Usuario_DTO();
                    USU.cod_usuario = codUsuSelecionado;
                    USU.nome        = txtNome.Text;
                    USU.login       = txtLogin.Text;
                    USU.email       = txtEmail.Text;
                    USU.cadastro    = System.DateTime.Now;
                    USU.senha       = txtSenha.Text;
                    if (cboSituacao.Text == "Ativo")
                    {
                        USU.situacao = "A";
                    }
                    else
                    {
                        USU.situacao = "I";
                    }
                    switch (cboPerfil.Text)
                    {
                    case "Administrador":
                        USU.perfil = 1;
                        break;

                    case "Operador":
                        USU.perfil = 2;
                        break;

                    case "Gerencial":
                        USU.perfil = 3;
                        break;
                    }
                    int x = new Usuario_BLL().editaUsuario(USU);
                    /*Verifica se houve alguma gravação*/
                    if (x > 0)
                    {
                        MessageBox.Show("Alterado com Sucesso!");
                    }
                    /*Recarrega o Grid após os dados serem gravados*/
                    carregaGrid();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro inesperado" + ex.Message);
                }
            }

            if (modo == "deletar")
            {
                try
                {
                    if (codUsuSelecionado < 0)
                    {
                        //lblMensagem.Text = "Selecione um usuario antes de prosseguir";
                        return;
                    }
                    Usuario_DTO USU = new Usuario_DTO();
                    USU.cod_usuario = codUsuSelecionado;
                    int x = new Usuario_BLL().deletaUsuario(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Excluido com Sucesso!");
                    }
                    /*Recarrega o Grid após os dados serem gravados*/
                    carregaGrid();
                    limpar_campos();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro inesperado" + ex.Message);
                }
            }

            modo = "";
        }
Beispiel #16
0
        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            Usuario_DTO USU = new Usuario_DTO();

            USU.cd_usuario = id_usuario;

            USU.nm_nome = txtNome.Text;

            USU.ds_login = txtLogin.Text;
            USU.ds_email = txtEmail.Text;

            USU.ds_senha = txtSenha.Text;

            USU.id_situacao = "I";
            if (cboSituacao.Text == "Ativo")
            {
                USU.id_situacao = "A";
            }

            switch (cboPerfil.Text)
            {
            case "Administrador":
                USU.id_perfil = 1;
                break;

            case "Operador":
                USU.id_perfil = 2;
                break;

            case "Gerencial":
                USU.id_perfil = 3;
                break;

            default:
                break;
            }

            if (comando == 1)
            {
                try
                {
                    int x = new UsuarioBLL().insereUsuario(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Gravado com sucesso!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro bro:" + ex);
                }
            }
            else if (comando == 2)
            {
                try
                {
                    int x = new UsuarioBLL().editarUsuario(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Editado com sucesso!");
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else if (comando == 3)
            {
                try
                {
                    int x = new UsuarioBLL().deletarUsuario(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Deletado com sucesso!");
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            comando = 0;
            carregarUsuarios();
        }