Ejemplo n.º 1
0
        private void AdicionaLinhaDataTable()
        {
            sNivelOrientacaoCurricular row = new sNivelOrientacaoCurricular();

            row.nvl_id          = -1;
            row.cur_id          = VS_cur_id;
            row.crr_id          = VS_crr_id;
            row.crp_id          = VS_crp_id;
            row.cal_id          = VS_cal_id;
            row.tds_id          = VS_tds_id;
            row.nvl_ordem       = VS_ordem_ultimo;
            row.nvl_nome        = "";
            row.nvl_nomePlural  = String.Empty;
            row.nvl_situacao    = 0;
            row.nvl_dataCriacao = DateTime.Now;
            row.ocr_id          = -1;
            VS_Dt_Niveis.Add(row);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        protected void btnIncluir_Click(object sender, EventArgs e)
        {
            try
            {
                if (VS_ordem_ultimo < 0)
                {
                    VS_ordem_ultimo = 1;
                }
                else
                {
                    VS_ordem_ultimo++;
                }

                int    indexUltimo           = 0;
                int    indexEdit             = 0;
                string orientacao_curricular = "";

                if (VS_Dt_Niveis.Any())
                {
                    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.
                    orientacao_curricular = VS_Dt_Niveis.LastOrDefault().ocr_id.ToString();
                }

                if (VS_Dt_Niveis.Any() && !string.IsNullOrEmpty(orientacao_curricular))
                {
                    // penúltimo
                    sNivelOrientacaoCurricular rowNew = new sNivelOrientacaoCurricular();
                    rowNew.nvl_id          = -1;
                    rowNew.cur_id          = VS_cur_id;
                    rowNew.crr_id          = VS_crr_id;
                    rowNew.crp_id          = VS_crp_id;
                    rowNew.cal_id          = VS_cal_id;
                    rowNew.tds_id          = VS_tds_id;
                    rowNew.nvl_ordem       = VS_ordem_ultimo - 1;
                    rowNew.nvl_nome        = "";
                    rowNew.nvl_nomePlural  = String.Empty;
                    rowNew.nvl_situacao    = 0;
                    rowNew.nvl_dataCriacao = DateTime.Now;
                    rowNew.ocr_id          = -1;

                    // último
                    sNivelOrientacaoCurricular rowHab = new sNivelOrientacaoCurricular();
                    rowHab.nvl_id          = VS_Dt_Niveis.LastOrDefault().nvl_id;
                    rowHab.cur_id          = VS_cur_id;
                    rowHab.crr_id          = VS_crr_id;
                    rowHab.crp_id          = VS_crp_id;
                    rowHab.cal_id          = VS_cal_id;
                    rowHab.tds_id          = VS_tds_id;
                    rowHab.nvl_ordem       = VS_ordem_ultimo;
                    rowHab.nvl_nome        = VS_Dt_Niveis.LastOrDefault().nvl_nome;
                    rowHab.nvl_nomePlural  = VS_Dt_Niveis.LastOrDefault().nvl_nomePlural;
                    rowHab.nvl_situacao    = VS_Dt_Niveis.LastOrDefault().nvl_situacao;
                    rowHab.nvl_dataCriacao = VS_Dt_Niveis.LastOrDefault().nvl_dataCriacao;
                    rowHab.ocr_id          = VS_Dt_Niveis.LastOrDefault().ocr_id;

                    VS_Dt_Niveis.Remove(VS_Dt_Niveis.Last());
                    VS_Dt_Niveis.Add(rowNew);
                    VS_Dt_Niveis.Add(rowHab);

                    // Edita penúltima linha.
                    indexEdit = VS_Dt_Niveis.Count() - 2;
                }
                else if (VS_Dt_Niveis.Count() == 0)
                {
                    AdicionaLinhaDataTable();
                    //AdicionaLinhaDataTable();

                    lblObservacao.Text    = UtilBO.GetErroMessage("É necessário incluir no mínimo dois níveis curriculares.", UtilBO.TipoMensagem.Informacao);
                    lblObservacao.Visible = true;
                    VS_Aux_Dois_Niveis++;
                }
                else
                {
                    AdicionaLinhaDataTable();

                    // Edita última linha.
                    indexEdit = VS_Dt_Niveis.Count() - 1;
                }

                lblMsgGrid.Visible = false;

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

                // Desabilita botões até salvar esse novo registro.
                btnIncluir.Visible  = false;
                btnIncluir2.Visible = false;

                EscondeBotoes();
            }
            catch (Exception ex)
            {
                ApplicationWEB._GravaErro(ex);
                lblMensagem.Text = UtilBO.GetErroMessage("Erro ao tentar incluir o nível de orientação curricular.", UtilBO.TipoMensagem.Erro);
            }
        }