public static bool Validar_CADASTRO(CADASTRO_DTO obj)
        {
            try
            {
                string     sql = "select * from TB_FUNCIONARIOS where CPF = @CPF";
                SqlCommand cm  = new SqlCommand(sql, Conexao_DAL.Cad_Func());

                cm.Parameters.AddWithValue("@CPF", obj.CPF);


                SqlDataReader dados = cm.ExecuteReader(); //serve para executar
                while (dados.Read())                      //executa o loop para encontrar os dados
                {
                    if (dados.HasRows)                    //Se ele encontrar ele executa esse código, se achar ele coloca em um vetor
                    {
                        return(true);
                    }
                }
                return(false);
            }

            catch (Exception xy)
            {
                throw new Exception(xy.Message);
            }
        }
Пример #2
0
 public static string alterar(CADASTRO_DTO obj)
 {
     try
     {
         string     sql = "UPDATE tb_funcionarios SET nome=@nome, CPF=@CPF, RG=@RG, endereco=@endereco, agencia=@agencia, conta=@conta, banco=@banco, numero=@numero, cidade=@cidade, bairro = @bairro, estado=@estado, telefone=@telefone";
         SqlCommand cm  = new SqlCommand(sql, Conexao_DAL.Cad_Func());
         cm.Parameters.AddWithValue("@nome", obj.nome);
         cm.Parameters.AddWithValue("@CPF", obj.CPF);
         cm.Parameters.AddWithValue("@RG", obj.RG);
         cm.Parameters.AddWithValue("@endereco", obj.endereco);
         cm.Parameters.AddWithValue("@agencia", obj.agencia);
         cm.Parameters.AddWithValue("@conta", obj.conta);
         cm.Parameters.AddWithValue("@banco", obj.banco);
         cm.Parameters.AddWithValue("@numero", obj.numero);
         cm.Parameters.AddWithValue("@cidade", obj.cidade);
         cm.Parameters.AddWithValue("@bairro", obj.bairro);
         cm.Parameters.AddWithValue("@estado", obj.estado);
         cm.Parameters.AddWithValue("@telefone", obj.telefone);
         cm.ExecuteNonQuery();
         return("Alterado com sucesso!");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Пример #3
0
 public static string val_cad_func(CADASTRO_DTO obj)
 {
     try
     {
         string     sql = "insert into tb_funcionarios(nome, CPF, RG, endereco, agencia, conta, banco, numero, cidade, bairro, estado, telefone) values(@nome, @CPF, @RG, @endereco, @agencia, @conta, @banco, @numero, @cidade, @bairro, @estado, @telefone)";
         SqlCommand cm  = new SqlCommand(sql, Conexao_DAL.Cad_Func());
         cm.Parameters.AddWithValue("@nome", obj.nome);
         cm.Parameters.AddWithValue("@CPF", obj.CPF);
         cm.Parameters.AddWithValue("@RG", obj.RG);
         cm.Parameters.AddWithValue("@endereco", obj.endereco);
         cm.Parameters.AddWithValue("@agencia", obj.agencia);
         cm.Parameters.AddWithValue("@conta", obj.conta);
         cm.Parameters.AddWithValue("@banco", obj.banco);
         cm.Parameters.AddWithValue("@numero", obj.numero);
         cm.Parameters.AddWithValue("@cidade", obj.cidade);
         cm.Parameters.AddWithValue("@bairro", obj.bairro);
         cm.Parameters.AddWithValue("@estado", obj.estado);
         cm.Parameters.AddWithValue("@telefone", obj.telefone);
         SqlDataReader dados = cm.ExecuteReader();
         //DataTable dt = new DataTable();
         //dt = sql();
         return("Sucesso!");
     }
     catch (Exception exe)
     {
         return("ERRO Ao cadastrar" + exe.Message);
     }
     finally
     {
         if (Conexao_DAL.Login().State != ConnectionState.Closed)
         {
             Conexao_DAL.Login().Close();
         }
     }
 }
Пример #4
0
        public static string Alterar(CADASTRO_DTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.nome))
            {
                return("Campo nome Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.CPF))
            {
                return("Campo CPF Vazio");
            }

            if (string.IsNullOrWhiteSpace(obj.RG))
            {
                return("Campo RG Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.endereco))
            {
                return("Campo endereço Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.conta))
            {
                return("Campo conta Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.agencia))
            {
                return("Campo agencia Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.banco))
            {
                return("Campo banco Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.cidade))
            {
                return("Campo cidade Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.bairro))
            {
                return("Campo bairro Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.estado))
            {
                return("Campo estado Vazio");
            }
            try                        //o try está servindo para tentar capturar uma  excessão caso a conversão não seja relizada com sucesso
            {
                int.Parse(obj.numero); //convertendo o objeto número para inteiro, já que na declaração do objeto é string
            }
            catch
            {
                return("O campo numero deve conter UM NÚMERO!");
            }
            if (string.IsNullOrWhiteSpace(obj.telefone))
            {
                return("Campo telefone Vazio");
            }
            return(CADASTRO_DAL.alterar(obj));
        }
Пример #5
0
        private void btnCadastroFunc_Click(object sender, EventArgs e)
        {
            try
            {
                CADASTRO_DTO obj = new CADASTRO_DTO();
                obj.nome     = txtNomeFun.Text;
                obj.CPF      = mTxtCPF.Text;
                obj.RG       = txtRgFunc.Text;
                obj.banco    = cbbBancoFunc.Text;
                obj.agencia  = txtAgenciaFunc.Text;
                obj.conta    = txtContaFunc.Text;
                obj.endereco = txtEndereco.Text;
                obj.cidade   = txtCidade.Text;
                obj.bairro   = txtBairro.Text;
                obj.estado   = CbEstado.Text;
                obj.numero   = txtNumero.Text;
                obj.telefone = mTxtTelefone.Text;
                string retorno;//a string de retorno servirá para trazer o retorno que irá vir da classe bll ou dal
                retorno = CADASTRO_BLL.Val_Cad_Func(obj);

                if (retorno == "Sucesso!")
                {
                    MessageBox.Show(retorno, "Funcionário cadastrado", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    txtNomeFun.Clear();
                    txtRgFunc.Clear();
                    cbbBancoFunc.Text = "";
                    txtAgenciaFunc.Clear();
                    txtContaFunc.Clear();
                    txtEndereco.Clear();
                    txtCidade.Clear();
                    txtBairro.Clear();
                    CbEstado.Text = "";
                    txtNumero.Clear();
                    mTxtTelefone.Clear();
                    mTxtCPF.Clear();
                }
                else
                {
                    MessageBox.Show(retorno, "Funcionário não foi cadastrado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            /*catch (Exception ex)//MOSTRA A EXCEÇÃO NO BANCO, PORÉM COM SOFTWARE PRONTO NÃO É BOM MOSTRAR PARA O USUÁRIO!!
             * {
             *
             *  MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #6
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                string CPF;
                CPF = mTxtCPF.Text;
                Buscar_BLL   bll = new Buscar_BLL();
                CADASTRO_DTO obj = new CADASTRO_DTO();

                obj                    = bll.Val_Busca((CPF));
                txtNomeFun.Text        = obj.nome;
                txtRgFunc.Text         = obj.RG;
                cbbBancoFunc.Text      = obj.banco;
                txtAgenciaFunc.Text    = obj.agencia;
                txtContaFunc.Text      = obj.conta;
                txtEndereco.Text       = obj.endereco;
                txtCidade.Text         = obj.cidade;
                txtBairro.Text         = obj.bairro;
                CbEstado.Text          = obj.estado;
                txtNumero.Text         = obj.numero;
                mTxtTelefone.Text      = obj.telefone;
                btnAlterarFunc.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            /*try
             * {
             *  CADASTRO_DTO obj = new CADASTRO_DTO();
             *  obj.CPF = mTxtCPF.Text;
             *  string retorna;
             *  retorna = Buscar_BLL.Val_Busca(obj);
             *  if (retorna == "Funcionário encontrado!")
             *  {
             *      MessageBox.Show(retorna, "Funcionário encontrado!" + obj, MessageBoxButtons.OK, MessageBoxIcon.Information);
             *
             *
             *
             *  }
             *  else
             *  {
             *      MessageBox.Show(retorna, "Funcionário não foi encontrado", MessageBoxButtons.OK, MessageBoxIcon.Information);
             *  }
             * }
             * catch (Exception ex)
             * {
             *  throw new Exception(ex.Message);
             *
             * }*/
        }
Пример #7
0
 private void btnAlterarFunc_Click(object sender, EventArgs e)
 {
     try
     {
         CADASTRO_DTO obj = new CADASTRO_DTO();
         obj.nome     = txtNomeFun.Text;
         obj.CPF      = mTxtCPF.Text;
         obj.RG       = txtRgFunc.Text;
         obj.banco    = cbbBancoFunc.Text;
         obj.agencia  = txtAgenciaFunc.Text;
         obj.conta    = txtContaFunc.Text;
         obj.endereco = txtEndereco.Text;
         obj.cidade   = txtCidade.Text;
         obj.bairro   = txtBairro.Text;
         obj.estado   = CbEstado.Text;
         obj.numero   = txtNumero.Text;
         obj.telefone = mTxtTelefone.Text;
         string retorno;//a string de retorno servirá para trazer o retorno que irá vir da classe bll ou dal
         retorno = CADASTRO_BLL.Alterar(obj);
         if (retorno == "Sucesso!")
         {
             MessageBox.Show(retorno, "Cadastro Alterado", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             txtNomeFun.Clear();
             txtRgFunc.Clear();
             cbbBancoFunc.Text = "";
             txtAgenciaFunc.Clear();
             txtContaFunc.Clear();
             txtEndereco.Clear();
             txtCidade.Clear();
             txtBairro.Clear();
             CbEstado.Text = "";
             txtNumero.Clear();
             mTxtTelefone.Clear();
             mTxtCPF.Clear();
         }
         else
         {
             MessageBox.Show(retorno, "Cadastro não foi alterado", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #8
0
        public static CADASTRO_DTO Buscar(string CPF)
        {
            try
            {
                CADASTRO_DTO obj = new CADASTRO_DTO();
                string       sql = "select * from tb_funcionarios where CPF = @CPF";
                SqlCommand   com = new SqlCommand(sql, Conexao_DAL.Cad_Func());//é necessário colocar a string onde irá pesquisar no banco, e a classe de conexão da onde vem.
                com.Parameters.AddWithValue("@CPF", CPF);
                SqlDataReader execut = com.ExecuteReader();


                while (execut.Read())
                {
                    if (execut.HasRows)
                    {
                        obj.ID       = int.Parse(execut["cod_funcionario"].ToString());
                        obj.nome     = execut["nome"].ToString();
                        obj.CPF      = execut["CPF"].ToString();
                        obj.RG       = execut["RG"].ToString();
                        obj.cidade   = execut["cidade"].ToString();
                        obj.estado   = execut["estado"].ToString();
                        obj.bairro   = execut["bairro"].ToString();
                        obj.endereco = execut["endereco"].ToString();
                        obj.conta    = execut["conta"].ToString();
                        obj.banco    = execut["banco"].ToString();
                        obj.telefone = execut["telefone"].ToString();
                        obj.agencia  = execut["agencia"].ToString();
                        obj.numero   = execut["numero"].ToString();
                        return(obj);
                    }
                }
                throw new Exception("Não encontrado!");
            }

            catch (Exception xy)
            {
                throw new Exception(xy.Message);
            }

            /*public static List<CADASTRO_DTO> Buscar(CADASTRO_DTO obj)
             * {
             *  try
             *  {
             *      List<CADASTRO_DTO> valor = new List<CADASTRO_DTO>();
             *      //CADASTRO_DTO obj = new CADASTRO_DTO();
             *
             *      string script = "select * from tb_funcionarios where CPF = @CPF";
             *      SqlCommand com = new SqlCommand(script, Conexao_DAL.Cad_Func());
             *      com.Parameters.AddWithValue("@CPF", obj.CPF);//passando o valor do obj.CPF para variável @CPF
             *
             *      SqlDataReader dados = com.ExecuteReader();
             *      while (dados.Read())
             *      {
             *
             *          valor.Add(obj);
             *
             *      }
             *      return valor;
             *  }
             *  catch
             *  {
             *      throw new Exception("Erro no primeiro catch");
             *  }
             *
             * }*/

            /*public DataTable buscar(String valor)
             * {
             *  DataTable dt = new DataTable();
             *  SqlDataAdapter da = new SqlDataAdapter("Select * from table tb_funcionarios where CPF like '%" + valor + "%'", Conexao_DAL.Cad_Func());
             *  da.Fill(dt);//fill executa o comando do data adapter, e preenche o datatable com os valores da busca
             *  return dt;
             * }*/


            /*
             *
             * SqlConnection sqlConnection1 = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RESTAURANTE;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
             * SqlCommand cmd = new SqlCommand();
             * SqlDataReader reader;
             *
             * cmd.CommandText = "select * from tb_funcionarios where CPF = @CPF";
             * cmd.Parameters.AddWithValue("@CPF", obj.CPF);
             * cmd.CommandType = CommandType.Text;
             * cmd.Connection = sqlConnection1;
             *
             * sqlConnection1.Open();
             *
             * reader = cmd.ExecuteReader();
             * // Data is accessible through the DataReader object here.
             *
             * sqlConnection1.Close();*/
        }
Пример #9
0
        public static string Val_Cad_Func(CADASTRO_DTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.nome))
            {
                return("Campo nome Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.CPF))
            {
                return("Campo CPF Vazio");
            }

            if (string.IsNullOrWhiteSpace(obj.RG))
            {
                return("Campo RG Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.endereco))
            {
                return("Campo endereço Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.conta))
            {
                return("Campo conta Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.agencia))
            {
                return("Campo agencia Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.banco))
            {
                return("Campo banco Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.cidade))
            {
                return("Campo cidade Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.bairro))
            {
                return("Campo bairro Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.estado))
            {
                return("Campo estado Vazio");
            }
            try                        //o try está servindo para tentar capturar uma  excessão caso a conversão não seja relizada com sucesso
            {
                int.Parse(obj.numero); //convertendo o objeto número para inteiro, já que na declaração do objeto é string
            }
            catch
            {
                return("O campo numero deve conter UM NÚMERO!");
            }
            if (string.IsNullOrWhiteSpace(obj.telefone))
            {
                return("Campo telefone Vazio");
            }
            bool testaCPF = CONFIRMAR_CADASTRO.Validar_CADASTRO(obj);

            if (testaCPF == true)
            {
                return("Funcionário já cadastrado!");
            }
            return(CADASTRO_DAL.val_cad_func(obj));
        }