public bool Inserir(agendamento a)
        {
            // função para cadastrar agendamento
            try
            {
                // busca o mediador para ver o local dele
                Mediador_Model mModel = new Mediador_Model();
                mediador       med    = new mediador();
                med = mModel.Obter(a.id_mediador);

                // então registra o local do mediador logado no agendamento
                a.id_local = med.id_local;

                a.ativo = true;

                Table <agendamento> tb = getTable();
                tb.InsertOnSubmit(a);
                tb.Context.SubmitChanges();

                return(true);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(false);
            }
        }
        public bool Inserir(agendamento a)
        {
            // função para cadastrar agendamento
            try
            {
                // busca o mediador para ver o local dele
                Mediador_Model mModel = new Mediador_Model();
                mediador med = new mediador();
                med = mModel.Obter(a.id_mediador);

                // então registra o local do mediador logado no agendamento
                a.id_local = med.id_local;

                a.ativo = true;

                Table<agendamento> tb = getTable();
                tb.InsertOnSubmit(a);
                tb.Context.SubmitChanges();

                return true;
            }
            catch (Exception e)
            {
                message = e.Message;
                return false;
            }
        }
 public bool Arquivar(agendamento a)
 {
     try
     {
         a.ativo = false;
         return(Alterar(a));
     }
     catch (Exception e)
     {
         message = e.Message;
         return(false);
     }
 }
 public bool Arquivar(agendamento a)
 {
     try
     {
         a.ativo = false;
         return Alterar(a);
     }
     catch (Exception e)
     {
         message = e.Message;
         return false;
     }
 }
        protected void btnAgendar_Click(object sender, EventArgs e)
        {
            if (ValidaAgendamento())
            {
                Agendamento_Model model = new Agendamento_Model();

                agendamento a = new agendamento();

                DateTime dDataInicial, dDataFinal;

                dDataInicial = DateTime.Parse(txtData.Value + " " + txtHoraInicial.Value + ":00");
                dDataFinal   = DateTime.Parse(txtData.Value + " " + txtHoraFinal.Value + ":00");

                a.descricao      = txtDescricaoAgendamento.Value;
                a.id_solicitacao = int.Parse(txtId.Value);
                a.data_inicial   = dDataInicial;
                a.data_final     = dDataFinal;
                a.id_mediador    = Master.GetLogado().id;

                Local_Model mLocal = new Local_Model();
                if (model.VerificarDisponibilidade(a, mLocal.Obter(Master.GetLogado().id_local)))
                {
                    if (model.Inserir(a))
                    {
                        Master.Sucesso("Horário agendado com sucesso.");
                        LimpaCamposAgendamento();
                        InsereDescSoli("Solicitação já agendada.");
                    }
                    else
                    {
                        Master.Alerta("Erro ao agendar horário. Erro: " + model.message);
                    }
                }
                else
                {
                    // se model.message estiver vazio, então ele retornou false pois o horário está vago,
                    // se nao, houve erro na consulta
                    if (model.message == "")
                    {
                        Master.Alerta("O horário escolhido já está agendado, selecione outro horário.");
                    }
                    else
                    {
                        Master.Alerta("Erro ao agendar horário. Erro: " + model.message);
                    }
                }
            }
        }
示例#6
0
        protected void btnAgendar_Click(object sender, EventArgs e)
        {
            if (ValidaAgendamento())
            {
                Agendamento_Model model = new Agendamento_Model();

                agendamento a = new agendamento();

                DateTime dDataInicial, dDataFinal;

                dDataInicial = DateTime.Parse(txtDataAgendar.Value + " " + txtHoraInicial.Value + ":00");
                dDataFinal = DateTime.Parse(txtDataAgendar.Value + " " + txtHoraFinal.Value + ":00");

                a.descricao = txtDescricaoAgendamento.Value;
                a.data_inicial = dDataInicial;
                a.data_final = dDataFinal;
                a.id_mediador = Master.GetLogado().id;

                Local_Model mLocal = new Local_Model();
                if (model.VerificarDisponibilidade(a, mLocal.Obter(Master.GetLogado().id_local)))
                {
                    if (model.Inserir(a))
                    {
                        Master.Sucesso("Horário agendado com sucesso.");
                        LimparAgendamento();
                        CarregarAgenda();
                    }
                    else
                    {
                        Master.Alerta("Erro ao agendar horário. Erro: " + model.message);
                    }
                }
                else
                {
                    // se model.message estiver vazio, então ele retornou false pois o horário está vago,
                    // se nao, houve erro na consulta
                    if (model.message == "")
                    {
                        Master.Alerta("O horário escolhido já está agendado, selecione outro horário.");
                    }
                    else
                    {
                        Master.Alerta("Erro ao agendar horário. Erro: " + model.message);
                    }
                }
            }
        }
示例#7
0
        protected void gvAgenda_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // recupera a linha clicada no gridview
            int linha = Convert.ToInt32(e.CommandArgument);
            // recupera o id do agendamento na linha clicada
            Int32 id = (Int32)gvAgenda.DataKeys[linha].Value;

            if (e.CommandName == "Arquivar")
            {
                agendamento       a     = new agendamento();
                Agendamento_Model model = new Agendamento_Model();
                // busca o agendamento selecionado
                a = model.Obter(id);

                if (model.Arquivar(a))
                {
                    Master.Sucesso("Agendamento arquivado com sucesso");
                    CarregarAgenda();
                }
                else
                {
                    Master.Alerta("Erro ao excluír o agendamento. Erro:" + model.message);
                }
            }
            else if (e.CommandName == "Mediacao")
            {
                // deve abrir o cadastro de pessoa com o parametro AGEND
                // para quando abrir o cadastro ele salvar na sessão
                Response.Redirect("cad_pessoa.aspx?AGEND=" + id.ToString());
            }
            else if (e.CommandName == "Visualizar")
            {
                Mediacao_Model medm = new Mediacao_Model();
                try
                {
                    // visualiza a mediação correspondente a esse agendamento
                    Response.Redirect("detail_mediacao.aspx?ID=" + medm.ObterPorAgendamento(id).id.ToString());
                }
                catch (Exception error)
                {
                    Master.Alerta(error.Message);
                }
            }
        }
        public bool Alterar(agendamento a)
        {
            try
            {
                //Table<cidade> tb = getTable();
                dbDataContext       db = getDataContext();
                Table <agendamento> tb = getTable();

                db.alteraAgendamento(a.id, a.id_solicitacao, a.descricao, a.data_inicial, a.data_final, a.id_mediador, a.id_local, a.ativo);
                tb.Context.SubmitChanges();

                return(true);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(false);
            }
        }
        public bool Alterar(agendamento a)
        {
            try
            {
                //Table<cidade> tb = getTable();
                dbDataContext db = getDataContext();
                Table<agendamento> tb = getTable();

                db.alteraAgendamento(a.id, a.id_solicitacao, a.descricao, a.data_inicial, a.data_final,a.id_mediador,a.id_local, a.ativo);
                tb.Context.SubmitChanges();

                return true;
            }
            catch (Exception e)
            {
                message = e.Message;
                return false;
            }
        }
        public bool VerificarDisponibilidade(agendamento a, local nucleo)
        {// verifica se a próxima hora a partir do horário do agendamento está livre. Retorna TRUE se o horário estiver livre
            // retorna FALSE se o horário estiver já ocupado
            // e retorna FALSE + MESSAGE se houver erro na busca
            try
            {
                String sql = "select * from agendamentos where ( id_local = {0} ) and ( ativo = 1 ) and " +
                             "( ( data_inicial between {1} and {2} ) or ( data_final between {1} and {2} ) " +
                             "or ( data_inicial = {3} ) or ( data_final = {4} ) )";
                dbDataContext db  = getDataContext();
                var           qry = db.ExecuteQuery <agendamento>(sql, nucleo.id, a.data_inicial.AddMinutes(1), a.data_final.AddMinutes(-1)
                                                                  , a.data_inicial, a.data_final);
                message = "";

                return(qry.Count() < 1);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(false);
            }
        }
        public bool VerificarDisponibilidade(agendamento a, local nucleo)
        {
            // verifica se a próxima hora a partir do horário do agendamento está livre. Retorna TRUE se o horário estiver livre
            // retorna FALSE se o horário estiver já ocupado
            // e retorna FALSE + MESSAGE se houver erro na busca
            try
            {
                String sql = "select * from agendamentos where ( id_local = {0} ) and ( ativo = 1 ) and " +
                             "( ( data_inicial between {1} and {2} ) or ( data_final between {1} and {2} ) " +
                             "or ( data_inicial = {3} ) or ( data_final = {4} ) )";
                dbDataContext db = getDataContext();
                var qry = db.ExecuteQuery<agendamento>(sql, nucleo.id, a.data_inicial.AddMinutes(1),a.data_final.AddMinutes(-1)
                                            ,a.data_inicial,a.data_final);
                message = "";

                return (qry.Count() < 1);
            }
            catch (Exception e)
            {
                message = e.Message;
                return false;
            }
        }
示例#12
0
        protected void gvAgenda_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // recupera a linha clicada no gridview
            int linha = Convert.ToInt32(e.CommandArgument);
            // recupera o id do agendamento na linha clicada
            Int32 id = (Int32)gvAgenda.DataKeys[linha].Value;

            if (e.CommandName == "Arquivar")
            {
                agendamento a = new agendamento();
                Agendamento_Model model = new Agendamento_Model();
                // busca o agendamento selecionado
                a = model.Obter(id);

                if (model.Arquivar(a))
                {
                    Master.Sucesso("Agendamento arquivado com sucesso");
                    CarregarAgenda();
                }
                else
                {
                    Master.Alerta("Erro ao excluír o agendamento. Erro:" + model.message);
                }
            }
            else if (e.CommandName == "Mediacao")
            {
                // deve abrir o cadastro de pessoa com o parametro AGEND
                // para quando abrir o cadastro ele salvar na sessão
                Response.Redirect("cad_pessoa.aspx?AGEND=" + id.ToString());
            }
            else if (e.CommandName == "Visualizar")
            {
                Mediacao_Model medm = new Mediacao_Model();
                try
                {
                    // visualiza a mediação correspondente a esse agendamento
                    Response.Redirect("detail_mediacao.aspx?ID=" + medm.ObterPorAgendamento(id).id.ToString());
                }
                catch (Exception error)
                {
                    Master.Alerta(error.Message);
                }
            }
        }