private void EditNivel() { var nRow = this.nivelNavigator1.SelectedNivel; var frdRow = nRow.GetFRDBaseRows().Single(); var rhRow = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica().First(); var tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow); var frm = new FormNivelDocumentalFedora(); frm.IDTipoNivelRelacionado = tnrRow.ID; string WindowTitle = string.Format("Editar {0}", tnrRow.Designacao); frm.Text = WindowTitle; frm.txtCodigo.Text = nRow.Codigo; frm.txtDesignacao.Text = Nivel.GetDesignacao(nRow); frm.FRDBaseRow = nRow.GetFRDBaseRows().Single(); frm.LoadData(); var idxFRDCARow = frdRow.GetIndexFRDCARows().SingleOrDefault(r => r["Selector"] != DBNull.Value && r.Selector == -1); // show form and receive user feedback if (frm.ShowDialog() == DialogResult.OK) { Trace.WriteLine("A editar nível..."); GISADataset.NivelDesignadoRow ndRow = null; nRow.Codigo = frm.txtCodigo.Text; // Um Nivel documental deve ter obrigatoriamente um NivelDesignado. Debug.Assert(nRow.GetNivelDesignadoRows().Length > 0); ndRow = nRow.GetNivelDesignadoRows()[0]; ndRow.Designacao = frm.txtDesignacao.Text; var tipologiaSelected = ((FormNivelDocumentalFedora)frm).Tipologia; if (tipologiaSelected == null && idxFRDCARow != null) { idxFRDCARow.Delete(); } else if (tipologiaSelected != null && idxFRDCARow == null) { idxFRDCARow = GisaDataSetHelper.GetInstance().IndexFRDCA.AddIndexFRDCARow(frdRow, ((FormNivelDocumentalFedora)frm).Tipologia.ControloAutRow, -1, new byte[] { }, 0); } else if (tipologiaSelected != null && idxFRDCARow != null && idxFRDCARow.IDControloAut != tipologiaSelected.IDControloAut) { idxFRDCARow.Delete(); idxFRDCARow = GisaDataSetHelper.GetInstance().IndexFRDCA.AddIndexFRDCARow(frdRow, ((FormNivelDocumentalFedora)frm).Tipologia.ControloAutRow, -1, new byte[] { }, 0); } string termoToCompare = frm.Tipologia == null ? null : ((FormNivelDocumentalFedora)frm).Tipologia.DicionarioRow.Termo; if (objetoDigital != null && objetoDigital.tipologia != termoToCompare) { objetoDigital.tipologia = tipologiaSelected != null ? tipologiaSelected.DicionarioRow.Termo : ""; objetoDigital.state = State.modified; } // registar a edição do item selecionado CurrentContext.RaiseRegisterModificationEvent(nRow.GetFRDBaseRows()[0]); PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments pcArgs = new PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments(); pcArgs.nRowID = nRow.ID; pcArgs.ndRowID = ndRow.ID; // Se se tratar de uma entidade detentora não passar os Ids de uma relação // hierárquica para um nível superior pois não existe nenhum. if (nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica().Length > 0) { pcArgs.rhRowID = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].ID; pcArgs.rhRowIDUpper = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].IDUpper; } pcArgs.testOnlyWithinNivel = true; // actualizar objecto digital caso exista var preTransactionAction = new PreTransactionAction(); var args = new PersistencyHelper.FedoraIngestPreTransactionArguments(); preTransactionAction.args = args; preTransactionAction.preTransactionDelegate = delegate(PersistencyHelper.PreTransactionArguments preTransactionArgs) { string msg = null; if (objetoDigital != null) { preTransactionArgs.cancelAction = !SessionHelper.AppConfiguration.GetCurrentAppconfiguration().FedoraHelperSingleton.Ingest(objetoDigital, out msg); } preTransactionArgs.message = msg; }; PersistencyHelper.SaveResult successfulSave = PersistencyHelper.save(DelegatesHelper.ensureUniqueCodigo, pcArgs, preTransactionAction); if (!pcArgs.successful) { MessageBox.Show(pcArgs.message, "Edição da unidade de descrição", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (successfulSave == PersistencyHelper.SaveResult.successful) { GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection()); try { List <string> IDNiveis = new List <string>(); IDNiveis.Add(nRow.ID.ToString()); GISA.Search.Updater.updateNivelDocumental(IDNiveis); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw; } finally { ho.Dispose(); } } PersistencyHelper.cleanDeletedData(); // Actualizar a interface com os novos valores. Se editarmos a // raiz (estrutural) da vista documental é necessário actualizar // automaticamente também a vista estrutural. if (!(nRow.RowState == DataRowState.Detached)) { if (this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Estrutural) { this.nivelNavigator1.UpdateSelectedNodeName(Nivel.GetDesignacao(nRow)); } else { this.nivelNavigator1.UpdateSelectedListItemName(Nivel.GetDesignacao(nRow)); } } // Forçar a gravação do documento CurrentContext.SetNivelEstrututalDocumental(null); CurrentContext.SetNivelEstrututalDocumental(nRow); } }