protected void grvNiveis_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView grv = ((GridView)sender); // Se estiver cancelando o registro que acabou de ser incluído, exclui do DataTable. if (VS_Dt_Niveis[grv.EditIndex].nvl_id <= 0) { VS_Dt_Niveis.RemoveAt(grv.EditIndex); } grv.EditIndex = -1; if (lblObservacao.Visible) { lblObservacao.Visible = false; VS_Aux_Dois_Niveis = 0; VS_Dt_Niveis.Clear(); } if (VS_Dt_Niveis.Any()) { VS_ordem_ultimo = VS_Dt_Niveis.LastOrDefault().nvl_ordem; } CarregaNiveis(true); }
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); } }