Example #1
0
        public static string CadFuncionario(Cad_Usuario_DTO obj)
        {
            try
            {
                string script = "INSERT INTO tb_funcionario (nome, rg, cpf, ctps, endereco, tel_fixo, tel_celular, tipo, foto, usuario, senha) " +
                                "VALUES (@nome, @rg, @cpf, @ctps, @end, @fixo, @cel, @tipo, @foto, @user, @ pass)";
                MySqlCommand cm = new MySqlCommand(script, Conexao_DAL.Conexao());

                cm.Parameters.AddWithValue("@nome", obj.Nome);
                cm.Parameters.AddWithValue("@nome", obj.RG);

                cm.ExecuteNonQuery();

                return("Funcionário cadastrado com sucesso!");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (Conexao_DAL.Conexao().State != ConnectionState.Closed)
                {
                    Conexao_DAL.Conexao().Close();
                }
            }
        }
Example #2
0
        public static BuscaEndereco BuscarEndereco(BuscaEndereco obj)
        {
            try
            {
                string script = "SELECT cep, rua, bairro, CID.nome as _CID, EST.sigla as _EST   " +
                                "FROM Enderecos ED " +
                                "INNER JOIN Cidades CID ON CID.cod = ED.fk_cidade " +
                                "INNER JOIN Estados EST ON EST.cod = ED.fk_estado " +
                                "WHERE cep = @CEP;";

                MySqlCommand cm = new MySqlCommand(script, Conexao_DAL.Conexao());

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

                MySqlDataReader dados = cm.ExecuteReader();

                while (dados.Read())
                {
                    if (dados.HasRows)
                    {
                        obj.Rua    = dados["rua"].ToString();
                        obj.Bairro = dados["bairro"].ToString();
                        obj.Cidade = dados["_CID"].ToString();
                        obj.UF     = dados["_EST"].ToString();
                        return(obj);
                    }
                }
                throw new Exception("CEP não encontrado!");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (Conexao_DAL.Conexao().State != ConnectionState.Closed)
                {
                    Conexao_DAL.Conexao().Close();
                }
            }
        }
Example #3
0
        public static Login_DTO Login(Login_DTO obj)
        {
            try
            {
                string       script = "select cod, usuario, senha, nome, tipo, foto FROM TB_Funcionario WHERE usuario = @usuario and senha = @senha";
                MySqlCommand cm     = new MySqlCommand(script, Conexao_DAL.Conexao());
                cm.Parameters.AddWithValue("@usuario", obj.Login);
                cm.Parameters.AddWithValue("@senha", obj.Senha);

                MySqlDataReader dados = cm.ExecuteReader();

                while (dados.Read())
                {
                    if (dados.HasRows)
                    {
                        obj.ID   = int.Parse(dados["cod"].ToString());
                        obj.Nome = dados["nome"].ToString();
                        obj.Tipo = dados["tipo"].ToString();
                        obj.Foto = dados["foto"].ToString();
                        return(obj);
                    }
                }
                throw new Exception("Usuário ou senha inválidos");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (Conexao_DAL.Conexao().State != ConnectionState.Closed)
                {
                    Conexao_DAL.Conexao().Close();
                }
            }
        }