Exemple #1
0
        /// <summary>
        /// Altera ordem dos níveis.
        /// </summary>
        private bool AlteraOrdem(int nvl_idDescer, int nvl_ordemDescer, int nvl_idSubir, int nvl_ordemSubir)
        {
            ORC_Nivel entityDescer = new ORC_Nivel {
                nvl_id = nvl_idDescer
            };

            ORC_NivelBO.GetEntity(entityDescer);
            entityDescer.nvl_ordem         = nvl_ordemDescer;
            entityDescer.nvl_dataAlteracao = DateTime.Now;

            ORC_Nivel entitySubir = new ORC_Nivel {
                nvl_id = nvl_idSubir
            };

            ORC_NivelBO.GetEntity(entitySubir);
            entitySubir.nvl_ordem         = nvl_ordemSubir;
            entitySubir.nvl_dataAlteracao = DateTime.Now;

            return(ORC_NivelBO.SaveOrdem(entityDescer, entitySubir));
        }
Exemple #2
0
        protected void grvNiveis_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string    nvl_nome       = "";
            string    nvl_nomePlural = String.Empty;
            bool      novo           = false;
            ORC_Nivel entityNivel;

            GridView grv = ((GridView)sender);

            try
            {
                GridViewRow row = grv.Rows[e.RowIndex];

                // Adiciona a segunda linha obrigatória pra poder salvar no mínimo 2 níveis de orientação curricular.
                if (lblObservacao.Visible && VS_Aux_Dois_Niveis == 1)
                {
                    string  nome    = string.Empty;
                    TextBox txtNome = (TextBox)row.FindControl("txtNomeNivel");
                    if (txtNome != null)
                    {
                        nome = txtNome.Text;
                    }

                    string  nomePlural    = string.Empty;
                    TextBox txtNomePlural = (TextBox)row.FindControl("txtNomePlural");
                    if (txtNomePlural != null)
                    {
                        nomePlural = txtNomePlural.Text;
                    }

                    List <sNivelOrientacaoCurricular> Dt_Niveis_Aux = VS_Dt_Niveis;
                    sNivelOrientacaoCurricular        primeiroNivel = VS_Dt_Niveis[0];
                    Dt_Niveis_Aux.RemoveAt(0);

                    //altera o nome da primeira linha que foi adicionada
                    primeiroNivel.nvl_nome       = nome;
                    primeiroNivel.nvl_nomePlural = nomePlural;

                    VS_Dt_Niveis.Clear();

                    VS_Dt_Niveis.Add(primeiroNivel);
                    VS_Dt_Niveis.AddRange(Dt_Niveis_Aux);

                    VS_ordem_ultimo++;
                    AdicionaLinhaDataTable();

                    // Habilita textbox para alterar o nível.
                    grvNiveis.EditIndex  = 1;
                    grvNiveis.DataSource = VS_Dt_Niveis;
                    grvNiveis.DataBind();
                    grvNiveis.Rows[1].Focus();

                    //esconde todos os botões
                    EscondeBotoes2Niveis();

                    VS_Aux_Dois_Niveis++;
                }
                else if (lblObservacao.Visible && VS_Aux_Dois_Niveis == 2)
                {
                    // salva linha 1
                    entityNivel = new ORC_Nivel
                    {
                        nvl_id            = -1,
                        cur_id            = VS_cur_id,
                        crr_id            = VS_crr_id,
                        crp_id            = VS_crp_id,
                        cal_id            = VS_cal_id,
                        tds_id            = VS_tds_id,
                        mat_id            = VS_mat_id,
                        nvl_ordem         = 1,
                        nvl_nome          = VS_Dt_Niveis[0].nvl_nome,
                        nvl_nomePlural    = VS_Dt_Niveis[0].nvl_nomePlural,
                        nvl_dataCriacao   = DateTime.Now,
                        nvl_dataAlteracao = DateTime.Now,
                        nvl_situacao      = 1,
                        IsNew             = true
                    };

                    ORC_NivelBO.Save(entityNivel);
                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Insert, "nvl_id: " + entityNivel.nvl_id);

                    // salva linha 2
                    TextBox txtNome = (TextBox)row.FindControl("txtNomeNivel");
                    if (txtNome != null)
                    {
                        nvl_nome = txtNome.Text;
                    }

                    TextBox txtNomePlural = (TextBox)row.FindControl("txtNomePlural");
                    if (txtNomePlural != null)
                    {
                        nvl_nomePlural = txtNomePlural.Text;
                    }

                    entityNivel = new ORC_Nivel
                    {
                        nvl_id            = VS_Dt_Niveis[e.RowIndex].nvl_id,
                        cur_id            = VS_Dt_Niveis[e.RowIndex].cur_id,
                        crr_id            = VS_Dt_Niveis[e.RowIndex].crr_id,
                        crp_id            = VS_Dt_Niveis[e.RowIndex].crp_id,
                        cal_id            = VS_Dt_Niveis[e.RowIndex].cal_id,
                        tds_id            = VS_Dt_Niveis[e.RowIndex].tds_id,
                        mat_id            = VS_mat_id,
                        nvl_ordem         = VS_Dt_Niveis[e.RowIndex].nvl_ordem,
                        nvl_nome          = nvl_nome,
                        nvl_nomePlural    = nvl_nomePlural,
                        nvl_dataCriacao   = VS_Dt_Niveis[e.RowIndex].nvl_dataCriacao,
                        nvl_dataAlteracao = DateTime.Now,
                        nvl_situacao      = 1,
                        IsNew             = true
                    };

                    ORC_NivelBO.Save(entityNivel);
                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Insert, "nvl_id: " + entityNivel.nvl_id);

                    lblObservacao.Visible = false;
                    lblMensagem.Text      = UtilBO.GetErroMessage("Os dois níveis de orientação curricular foram incluídos com sucesso.", UtilBO.TipoMensagem.Sucesso);
                    grv.EditIndex         = -1;

                    CarregaNiveis(true);
                }
                else
                {
                    TextBox txtNome = (TextBox)row.FindControl("txtNomeNivel");
                    if (txtNome != null)
                    {
                        nvl_nome = txtNome.Text;
                    }

                    TextBox txtNomePlural = (TextBox)row.FindControl("txtNomePlural");
                    if (txtNomePlural != null)
                    {
                        nvl_nomePlural = txtNomePlural.Text;
                    }

                    entityNivel = new ORC_Nivel
                    {
                        nvl_id            = VS_Dt_Niveis[e.RowIndex].nvl_id,
                        cur_id            = VS_Dt_Niveis[e.RowIndex].cur_id,
                        crr_id            = VS_Dt_Niveis[e.RowIndex].crr_id,
                        crp_id            = VS_Dt_Niveis[e.RowIndex].crp_id,
                        cal_id            = VS_Dt_Niveis[e.RowIndex].cal_id,
                        tds_id            = VS_Dt_Niveis[e.RowIndex].tds_id,
                        mat_id            = VS_mat_id,
                        nvl_ordem         = VS_Dt_Niveis[e.RowIndex].nvl_ordem,
                        nvl_nome          = nvl_nome,
                        nvl_nomePlural    = nvl_nomePlural,
                        nvl_dataCriacao   = VS_Dt_Niveis[e.RowIndex].nvl_dataCriacao,
                        nvl_dataAlteracao = DateTime.Now,
                        nvl_situacao      = 1
                    };

                    if (VS_Dt_Niveis[e.RowIndex].nvl_situacao == 0)
                    {
                        entityNivel.IsNew = true;
                        novo = true;
                    }
                    else
                    {
                        entityNivel.IsNew = false;
                    }

                    ORC_NivelBO.Save(entityNivel);
                    if (novo)
                    {
                        ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Insert, "nvl_id: " + entityNivel.nvl_id);
                        lblMensagem.Text = UtilBO.GetErroMessage("Nível de orientação curricular incluído com sucesso.", UtilBO.TipoMensagem.Sucesso);
                    }
                    else
                    {
                        ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Update, "nvl_id: " + entityNivel.nvl_id);
                        lblMensagem.Text = UtilBO.GetErroMessage("Nível de orientação curricular alterado com sucesso.", UtilBO.TipoMensagem.Sucesso);
                    }

                    grv.EditIndex = -1;

                    // Se é um registro novo, e o último possuir orientação curricular, altera a ordem dos dois registros.
                    int indexUltimo = VS_Dt_Niveis.Count() - 1;

                    // Se o último nível possuir orientação curricular, o novo registro deve ficar em penúltimo, para que o último se matenha em último.
                    string orientacao_curricular = VS_Dt_Niveis.LastOrDefault().ocr_id.ToString();

                    if (novo && !string.IsNullOrEmpty(orientacao_curricular))
                    {
                        int nvl_idDescer    = Convert.ToInt32(grvNiveis.DataKeys[indexUltimo]["nvl_id"]);
                        int nvl_ordemDescer = VS_Dt_Niveis.Count();
                        int nvl_idSubir     = entityNivel.nvl_id;
                        int nvl_ordemSubir  = VS_Dt_Niveis.Count() - 1;

                        bool returnAlteracao = AlteraOrdem(nvl_idDescer, nvl_ordemDescer, nvl_idSubir, nvl_ordemSubir);
                    }

                    CarregaNiveis(true);
                }
            }
            catch (MSTech.Validation.Exceptions.ValidationException ex)
            {
                lblMensagem.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
            }
            catch (DuplicateNameException ex)
            {
                lblMensagem.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Alerta);
            }
            catch (Exception ex)
            {
                ApplicationWEB._GravaErro(ex);
                lblMensagem.Text = UtilBO.GetErroMessage("Erro ao tentar salvar nível da orientação curricular.", UtilBO.TipoMensagem.Erro);
            }
        }
Exemple #3
0
        /// <summary>
        /// Carrega os níveis de orientação curricular desse Curso, Currículo, CurrículoPeríodo e Calendário
        /// </summary>
        private void CarregaNiveis(bool habilitaBotoesIncluir)
        {
            try
            {
                ORC_NivelBO.CorrigirOrdem(VS_cur_id, VS_crr_id, VS_crp_id, VS_cal_id, VS_tds_id);

                VS_Dt_Niveis = ORC_NivelBO.SelecionaPorCursoGrupamentoCalendarioTipoDisciplina(VS_cur_id, VS_crr_id, VS_crp_id, VS_cal_id, VS_tds_id, VS_mat_id, 0); //Não colocar cache nessa consulta.

                VS_ordem_ultimo = VS_Dt_Niveis.LastOrDefault().nvl_ordem;

                grvNiveis.DataSource = VS_Dt_Niveis;
                grvNiveis.DataBind();

                if (grvNiveis.Rows.Count == 0)
                {
                    lblMsgGrid.Text    = "Não foram encontrados níveis da orientação curricular.";
                    lblMsgGrid.Visible = true;
                }
                else
                {
                    // Esconde botão subir na primeira linha da grid, e botão descer da última linha.
                    ((ImageButton)grvNiveis.Rows[0].FindControl("btnSubir")).Visible = false;
                    ((ImageButton)grvNiveis.Rows[grvNiveis.Rows.Count - 1].FindControl("btnDescer")).Visible = false;

                    // Se o último nível possuir orientação curricular, o novo registro deve ficar em penúltimo, para que o último se matenha em último.
                    string orientacao_curricular = VS_Dt_Niveis[grvNiveis.Rows.Count - 1].ocr_id.ToString();

                    if (!string.IsNullOrEmpty(orientacao_curricular) &&
                        Convert.ToInt32(orientacao_curricular) > 0)
                    {
                        ((ImageButton)grvNiveis.Rows[grvNiveis.Rows.Count - 1].FindControl("btnSubir")).Visible = false;
                        // Esconde botão de editar da última linha.
                        ((ImageButton)grvNiveis.Rows[grvNiveis.Rows.Count - 1].FindControl("btnAlterar")).Visible = false;
                        // Esconde botão de excluir da última linha.
                        ((ImageButton)grvNiveis.Rows[grvNiveis.Rows.Count - 1].FindControl("btnExcluir")).Visible = false;

                        if (grvNiveis.Rows.Count > 1)
                        {
                            // Esconde botão descer da penúltima linha.
                            ((ImageButton)grvNiveis.Rows[grvNiveis.Rows.Count - 2].FindControl("btnDescer")).Visible = false;
                        }
                    }

                    //Se tiver apenas 2 registros não permite excluir nenhum.
                    if (grvNiveis.Rows.Count == 2)
                    {
                        // Esconde botão de excluir das linhas.
                        ((ImageButton)grvNiveis.Rows[0].FindControl("btnExcluir")).Visible = false;
                        ((ImageButton)grvNiveis.Rows[1].FindControl("btnExcluir")).Visible = false;
                    }
                }

                if (habilitaBotoesIncluir)
                {
                    // Habilita botões.
                    btnIncluir.Visible  = habilitaBotoesIncluir;
                    btnIncluir2.Visible = habilitaBotoesIncluir;
                }

                updNiveis.Update();
            }
            catch (Exception ex)
            {
                ApplicationWEB._GravaErro(ex);
                lblMensagem.Text = UtilBO.GetErroMessage("Erro ao tentar carregar os níveis da orientação curricular.", UtilBO.TipoMensagem.Erro);
            }
        }
Exemple #4
0
        protected void grvNiveis_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Deletar")
            {
                try
                {
                    int index  = int.Parse(e.CommandArgument.ToString());
                    int nvl_id = Convert.ToInt32(grvNiveis.DataKeys[index].Value);

                    ORC_Nivel entity = new ORC_Nivel {
                        nvl_id = nvl_id
                    };
                    ORC_NivelBO.GetEntity(entity);
                    entity.nvl_situacao = 3;
                    ORC_NivelBO.Save(entity);

                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Update, "nvl_id: " + entity.nvl_id);
                    lblMensagem.Text = UtilBO.GetErroMessage("Nível da orientação curricular excluído com sucesso.", UtilBO.TipoMensagem.Sucesso);

                    CarregaNiveis(true);
                }
                catch (Exception ex)
                {
                    ApplicationWEB._GravaErro(ex);
                    lblMensagem.Text = UtilBO.GetErroMessage("Erro ao excluir o nível da orientação curricular.", UtilBO.TipoMensagem.Erro);
                }
            }
            else if (e.CommandName == "Subir")
            {
                try
                {
                    int index = int.Parse(e.CommandArgument.ToString());

                    int nvl_idDescer    = Convert.ToInt32(grvNiveis.DataKeys[index - 1]["nvl_id"]);
                    int nvl_ordemDescer = Convert.ToInt32(grvNiveis.DataKeys[index]["nvl_ordem"]);
                    int nvl_idSubir     = Convert.ToInt32(grvNiveis.DataKeys[index]["nvl_id"]);
                    int nvl_ordemSubir  = Convert.ToInt32(grvNiveis.DataKeys[index - 1]["nvl_ordem"]);

                    if (AlteraOrdem(nvl_idDescer, nvl_ordemDescer, nvl_idSubir, nvl_ordemSubir))
                    {
                        CarregaNiveis(true);
                    }

                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Update, "nvl_id: " + nvl_idDescer);
                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Update, "nvl_id: " + nvl_idSubir);
                }
                catch (Exception ex)
                {
                    ApplicationWEB._GravaErro(ex);
                    lblMensagem.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Erro);
                }
            }
            else if (e.CommandName == "Descer")
            {
                try
                {
                    int index = int.Parse(e.CommandArgument.ToString());

                    int nvl_idDescer    = Convert.ToInt32(grvNiveis.DataKeys[index]["nvl_id"]);
                    int nvl_ordemDescer = Convert.ToInt32(grvNiveis.DataKeys[index + 1]["nvl_ordem"]);
                    int nvl_idSubir     = Convert.ToInt32(grvNiveis.DataKeys[index + 1]["nvl_id"]);
                    int nvl_ordemSubir  = Convert.ToInt32(grvNiveis.DataKeys[index]["nvl_ordem"]);

                    if (AlteraOrdem(nvl_idDescer, nvl_ordemDescer, nvl_idSubir, nvl_ordemSubir))
                    {
                        CarregaNiveis(true);
                    }

                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Update, "nvl_id: " + nvl_idDescer);
                    ApplicationWEB._GravaLogSistema(LOG_SistemaTipo.Update, "nvl_id: " + nvl_idSubir);
                }
                catch (Exception ex)
                {
                    ApplicationWEB._GravaErro(ex);
                    lblMensagem.Text = UtilBO.GetErroMessage(ex.Message, UtilBO.TipoMensagem.Erro);
                }
            }
        }