Exemple #1
0
        public Pet GetPet(int pet_id)
        {
            Pet pet = new Pet();

            PetTipoBusiness pet_tipo_business = new PetTipoBusiness();
            ClienteBusiness cliente_business  = new ClienteBusiness();

            try
            {
                this.connection.Open();

                this.command.CommandText = string.Format(@"SELECT 
                                            id,
                                            id_pet_tipo,
                                            id_cliente,
                                            nome,
                                            raca,
                                            porte,
                                            alergias,
                                            observacao,
                                            autorizacao,
                                            ultima_alteracao,
                                            responsavel
                                           FROM pet
                                           WHERE
                                           id = '{0}'", pet_id);
                MySqlDataReader reader = command.ExecuteReader();

                while (reader.Read())//Enquanto existir dados no select
                {
                    pet.id               = (reader["id"].ToString() != null && reader["id"].ToString() != string.Empty) ? Int32.Parse(reader["id"].ToString()) : 0;
                    pet.id_pet_tipo      = (reader["id_pet_tipo"].ToString() != null && reader["id_pet_tipo"].ToString() != string.Empty) ? Int32.Parse(reader["id_pet_tipo"].ToString()) : 0;
                    pet.id_cliente       = (reader["id_cliente"].ToString() != null && reader["id_cliente"].ToString() != string.Empty) ? Int32.Parse(reader["id_cliente"].ToString()) : 0;
                    pet.nome             = (reader["nome"].ToString() != null && reader["nome"].ToString() != string.Empty) ? reader["nome"].ToString() : "";
                    pet.raca             = (reader["raca"].ToString() != null && reader["raca"].ToString() != string.Empty) ? reader["raca"].ToString() : "";
                    pet.porte            = (reader["porte"].ToString() != null && reader["porte"].ToString() != string.Empty) ? reader["porte"].ToString() : "";
                    pet.alergias         = (reader["alergias"].ToString() != null && reader["alergias"].ToString() != string.Empty) ? reader["alergias"].ToString() : "";
                    pet.observacao       = (reader["observacao"].ToString() != null && reader["observacao"].ToString() != string.Empty) ? reader["observacao"].ToString() : "";
                    pet.autorizacao      = (reader["autorizacao"].ToString() != null && reader["autorizacao"].ToString() != string.Empty) ? reader["autorizacao"].ToString() : "";
                    pet.ultima_alteracao = (reader["ultima_alteracao"].ToString() != null && reader["ultima_alteracao"].ToString() != string.Empty) ? DateTime.Parse(reader["ultima_alteracao"].ToString()) : new DateTime();
                    pet.responsavel      = (reader["responsavel"].ToString() != null && reader["responsavel"].ToString() != string.Empty) ? reader["responsavel"].ToString() : "";

                    pet.pet_tipo = pet_tipo_business.GetPetTipo(pet.id_pet_tipo);
                    pet.cliente  = cliente_business.GetCliente(pet.id_cliente);
                }


                this.connection.Close();
            }
            catch (Exception ex)
            {
                if (this.connection.State == System.Data.ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            return(pet);
        }
Exemple #2
0
        public List <Agendamento> GetAllAgendamentoss()
        {
            List <Agendamento> agendamentos_list = new List <Agendamento>();

            ClienteBusiness     cliente_business     = new ClienteBusiness();
            PetBusiness         pet_business         = new PetBusiness();
            ServicoBusiness     servico_business     = new ServicoBusiness();
            FuncionarioBusiness funcionario_business = new FuncionarioBusiness();

            try
            {
                this.connection.Open();

                this.command.CommandText = @"SELECT 
                                            id,
                                            id_cliente,
                                            id_pet,
                                            id_servico,
                                            id_funcionario,
                                            data_inicio,
                                            data_termino,
                                            notificacao_enviada,
                                            cancelamento,
                                            ultima_alteracao,
                                            responsavel
                                           FROM agendamento ORDER BY data_inicio DESC";
                MySqlDataReader reader = command.ExecuteReader();

                while (reader.Read())//Enquanto existir dados no select
                {
                    Agendamento agendamento = new Agendamento();

                    agendamento.id                  = (reader["id"].ToString() != null && reader["id"].ToString() != string.Empty) ? Int32.Parse(reader["id"].ToString()) : 0;
                    agendamento.id_cliente          = (reader["id_cliente"].ToString() != null && reader["id_cliente"].ToString() != string.Empty) ? Int32.Parse(reader["id_cliente"].ToString()) : 0;
                    agendamento.id_pet              = (reader["id_pet"].ToString() != null && reader["id_pet"].ToString() != string.Empty) ? Int32.Parse(reader["id_pet"].ToString()) : 0;
                    agendamento.id_servico          = (reader["id_servico"].ToString() != null && reader["id_servico"].ToString() != string.Empty) ? Int32.Parse(reader["id_servico"].ToString()) : 0;
                    agendamento.id_funcionario      = (reader["id_funcionario"].ToString() != null && reader["id_funcionario"].ToString() != string.Empty) ? Int32.Parse(reader["id_funcionario"].ToString()) : 0;
                    agendamento.data_inicio         = (reader["data_inicio"].ToString() != null && reader["data_inicio"].ToString() != string.Empty) ? DateTime.Parse(reader["data_inicio"].ToString()) : new DateTime();
                    agendamento.data_termino        = (reader["data_termino"].ToString() != null && reader["data_termino"].ToString() != string.Empty) ? DateTime.Parse(reader["data_termino"].ToString()) : new DateTime();
                    agendamento.notificacao_enviada = (reader["notificacao_enviada"].ToString() != null && reader["notificacao_enviada"].ToString() != string.Empty) ? Boolean.Parse(reader["notificacao_enviada"].ToString()) : false;
                    agendamento.cancelamento        = (reader["cancelamento"].ToString() != null && reader["cancelamento"].ToString() != string.Empty) ? Boolean.Parse(reader["cancelamento"].ToString()) : false;
                    agendamento.ultima_alteracao    = (reader["ultima_alteracao"].ToString() != null && reader["ultima_alteracao"].ToString() != string.Empty) ? DateTime.Parse(reader["ultima_alteracao"].ToString()) : new DateTime();
                    agendamento.responsavel         = (reader["responsavel"].ToString() != null && reader["responsavel"].ToString() != string.Empty) ? reader["responsavel"].ToString() : "";

                    agendamento.data_inicio_br  = agendamento.data_inicio.ToString();
                    agendamento.data_termino_br = agendamento.data_termino.ToString();

                    agendamento.cliente     = cliente_business.GetCliente(agendamento.id_cliente);
                    agendamento.pet         = pet_business.GetPet(agendamento.id_pet);
                    agendamento.servico     = servico_business.GetServico(agendamento.id_servico);
                    agendamento.funcionario = funcionario_business.GetFuncionario(agendamento.id_funcionario);

                    agendamentos_list.Add(agendamento);
                }


                this.connection.Close();
            }
            catch (Exception ex)
            {
                if (this.connection.State == System.Data.ConnectionState.Open)
                {
                    this.connection.Close();
                }
            }

            return(agendamentos_list);
        }