Exemplo n.º 1
0
        public Motorista GetObj(Motorista obj)
        {
            try
            {
                if (obj.Codigo != 0)
                {
                    DataTable table = dao.CarregarMotoristaDAO(obj.Codigo);


                    if (table != null)
                    {
                        int.TryParse(table.Rows[0]["Numero"].ToString(), out numero);
                        int.TryParse(table.Rows[0]["Cod_Cidade"].ToString(), out codCidade);
                        int.TryParse(table.Rows[0]["Cod_Estado"].ToString(), out codEstado);

                        Endereco end = new Endereco(table.Rows[0]["Cep"].ToString(),
                                                    table.Rows[0]["Logradouro"].ToString(),
                                                    numero,
                                                    table.Rows[0]["Bairro"].ToString(),
                                                    codCidade, codEstado);

                        DateTime.TryParse(table.Rows[0]["Data_Nascimento"].ToString(), out dataNasc);
                        DateTime.TryParse(table.Rows[0]["CNH_Vencimento"].ToString(), out cnhVencimento);

                        Motorista moto = new Motorista(Convert.ToInt32(table.Rows[0]["Cod_Motorista"]),
                                                       table.Rows[0]["Nome_Motorista"].ToString(),
                                                       dataNasc,
                                                       table.Rows[0]["Telefone_Motorista"].ToString(),
                                                       table.Rows[0]["Email_Motorista"].ToString(),
                                                       (EnumStatusMotorista)(table.Rows[0]["Status_Motorista"]), end,
                                                       (EnumCnhCategoriaMotorista)table.Rows[0]["CNH_Categoria"],
                                                       table.Rows[0]["CNH_Numero"].ToString(),
                                                       cnhVencimento);

                        return(moto);
                    }
                    else
                    {
                        throw new Exception("Dados não localizado.");
                    }
                }
                else
                {
                    throw new Exception("É necessário o código do motorista para obter dados.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }