コード例 #1
0
        public static int calculaCodigo(String str)
        {
            int r;

            r = RestauranteDAO.calculacodigo(str);
            return(r);
        }
コード例 #2
0
ファイル: RestauranteBO.cs プロジェクト: rbuenonet/usc
        public Retorno consultar(long id)
        {
            IRestauranteDAO restauranteDao = new RestauranteDAO();
            Retorno         retorno        = new Retorno();

            try
            {
                retorno.status = true;
                if (id == 0)
                {
                    retorno.status   = false;
                    retorno.mensagem = "Informe um id para realizar a consulta.";
                }

                retorno.objeto   = restauranteDao.consultar(id);
                retorno.mensagem = "Consulta realizada com sucesso.";
                return(retorno);
            }
            catch (Exception ex)
            {
                retorno.status   = false;
                retorno.mensagem = ex.Message;
                return(retorno);
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            String NomeRestaurante = textBox1.Text;
            float  longitude       = Convert.ToSingle((textBox2.Text));
            float  latitude        = Convert.ToSingle((textBox3.Text));

            String Descricao  = textBox4.Text;
            String Localidade = textBox5.Text;
            String Rua        = textBox6.Text;
            String CodPostal  = textBox7.Text;
            int    Telefone;

            int.TryParse(textBox8.Text, out Telefone);
            String email = textBox9.Text;
            String datai = dateTimePicker1.Text;
            String dataf = dateTimePicker2.Text;
            int    idRestaurante;

            if ((idRestaurante = Restaurante.calculaCodigo(NomeRestaurante)) != -1)
            {
                Tarefa tar = new Tarefa(idRestaurante, longitude, latitude, Descricao, Localidade, Rua, CodPostal, Telefone, email, datai, dataf);
                if (TarefaDAO.putTarefa(tar) != -1)
                {
                    MessageBox.Show("Tarefa adicionada");
                    mp.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Ocorreu algum erro");
                    mp.Show();
                    this.Hide();
                }
            }
            else
            {
                Restaurante rest = new Restaurante(NomeRestaurante, longitude, latitude, Descricao, Localidade, Rua, CodPostal, Telefone, email);
                RestauranteDAO.putRestaurante(rest);
                idRestaurante = Restaurante.calculaCodigo(NomeRestaurante);
                Tarefa tar = new Tarefa(idRestaurante, longitude, latitude, Descricao, Localidade, Rua, CodPostal, Telefone, email, datai, dataf);
                if (TarefaDAO.putTarefa(tar) != -1)
                {
                    MessageBox.Show("Tarefa adicionada");
                    mp.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Ocorreu algum erro");
                    mp.Show();
                    this.Hide();
                }
            }
        }
コード例 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            String t1  = textBox1.Text;
            String t3  = textBox3.Text;
            String t4  = textBox4.Text;
            int    res = RestauranteDAO.updates(idRestaurante, t1, t3, t4);

            if (res == 0)
            {
                MessageBox.Show("Actualizações efectuadas");
            }
            else
            {
                MessageBox.Show("Ocorreu algum erro");
            }
            mp = new Inicial();
            mp.Show();
            this.Dispose();
        }
コード例 #5
0
ファイル: RestauranteBO.cs プロジェクト: rbuenonet/usc
        public Retorno listar()
        {
            IRestauranteDAO restauranteDao = new RestauranteDAO();
            Retorno         retorno        = new Retorno();

            try
            {
                retorno.status   = true;
                retorno.objeto   = restauranteDao.listar();
                retorno.mensagem = "Listagem realizada com sucesso.";
                return(retorno);
            }
            catch (Exception ex)
            {
                retorno.status   = false;
                retorno.mensagem = ex.Message;
                return(retorno);
            }
        }
コード例 #6
0
ファイル: RestauranteBO.cs プロジェクト: rbuenonet/usc
        public Retorno salvar(RESTAURANTE restaurante)
        {
            IRestauranteDAO restauranteDao = new RestauranteDAO();
            Retorno         retorno        = new Retorno();
            long            id             = 0;

            try
            {
                id             = restaurante.ID;
                retorno.status = true;
                if (string.IsNullOrEmpty(restaurante.NOME))
                {
                    retorno.status   = false;
                    retorno.mensagem = "Preencha o nome do restaurante.";
                    return(retorno);
                }

                if (restaurante.ID == 0)
                {
                    id             = restauranteDao.salvar(restaurante);
                    restaurante    = new RESTAURANTE();
                    retorno.objeto = restaurante.ID = id;
                }
                else
                {
                    restauranteDao.atualizar(restaurante);
                }

                retorno.mensagem = "Registro salvo com sucesso.";
                return(retorno);
            }
            catch (Exception ex) {
                retorno.status   = false;
                retorno.mensagem = ex.Message;
                return(retorno);
            }
        }
コード例 #7
0
        /// <summary>
        /// Lista os restaurantes se o horario for menor 11:30
        /// Se o horario for maior ou igual a 11:30, devolve apenas o ganhador do dia
        /// </summary>
        /// <returns></returns>
        public Retorno listarRestaurante(long usuario_id)
        {
            IVotacaoDAO     votacaoDAO     = new VotacaoDAO();
            IGanhadorDAO    ganhadorDAO    = new GanhadorDAO();
            IRestauranteDAO restauranteDAO = new RestauranteDAO();
            DataVotacao     dataVotacao    = new DataVotacao();
            Retorno         retorno        = new Retorno();

            DateTime thisDay = DateTime.Now;

            try
            {
                if (thisDay.Hour > 12 || (thisDay.Hour == 11 && thisDay.Minute > 29))
                {
                    List <GANHADOR> ganhadores = ganhadorDAO.getGanhador(thisDay);
                    if (ganhadores.Count() == 1)
                    {
                        retorno.status   = true;
                        retorno.objeto   = restauranteDAO.consultar(ganhadores[0].RESTAURANTE_ID);
                        retorno.mensagem = "Listagem realizada com sucesso.";
                    }
                    else if (ganhadores.Count() == 0)
                    {
                        long restaurante_ganhador = votacaoDAO.getRestauranteGanhador(thisDay);

                        if (restaurante_ganhador > 0)
                        {
                            GANHADOR ganhador = new GANHADOR();
                            ganhador.DATA           = thisDay;
                            ganhador.RESTAURANTE_ID = restaurante_ganhador;
                            long id = ganhadorDAO.salvar(ganhador);

                            retorno.status   = true;
                            retorno.objeto   = restauranteDAO.consultar(restaurante_ganhador);
                            retorno.mensagem = "Listagem realizada com sucesso.";
                        }
                        else
                        {
                            retorno.status   = true;
                            retorno.objeto   = "";
                            retorno.mensagem = "Nenhum restaurante foi votado hoje.";
                        }
                    }
                    else
                    {
                        retorno.status   = false;
                        retorno.objeto   = "";
                        retorno.mensagem = "Ocorreu um erro. Comunique o administrador. Mais de um ganhador nesse dia: " + thisDay.Date;
                    }
                }
                else
                {
                    // testa se o usuario ja votou hoje
                    List <VOTACAO> votacao_dia = votacaoDAO.getVotacaoPorUsuarioDia(usuario_id, thisDay);
                    if (votacao_dia.Count() > 0)
                    {
                        retorno.status   = false;
                        retorno.mensagem = "Usuário já votou hoje. Aguarde o fim da votação.";
                        return(retorno);
                    }

                    List <DateTime> dias = dataVotacao.retornarData();
                    // recupera o id de todos os restaurantes que ganharam na semana
                    List <long>        ganhadores   = ganhadorDAO.listaRestauranteId(dias);
                    List <RESTAURANTE> restaurantes = restauranteDAO.listarPorGanhores(ganhadores);

                    retorno.status   = true;
                    retorno.objeto   = restaurantes;
                    retorno.mensagem = "Listagem realizada com sucesso.";
                }
                return(retorno);
            }
            catch (Exception ex)
            {
                retorno.status   = false;
                retorno.mensagem = ex.Message;
                return(retorno);
            }
        }