private void ToolBarButtonCreateMenuItemClick(object sender, EventArgs e) { ((frmMain)TopLevelControl).EnterWaitMode(); GISADataset.TipoNivelRelacionadoRow tnrRow = ((TipoNivelMenuItem)sender).Row; var nivelRow = GisaDataSetHelper.GetInstance().Nivel.Cast <GISADataset.NivelRow>().Single(r => r.ID == this.nivelNavigator1.ContextBreadCrumbsPathID); var frm = new FormNivelDocumentalFedora(); frm.IDTipoNivelRelacionado = tnrRow.ID; // necessário para validação do código parcial bool successfulSave = handleNewNivel(frm, nivelRow, tnrRow); ((frmMain)TopLevelControl).LeaveWaitMode(); // O UpdateToolBarButtons não é executado quando é adicionado um novo nível documental pois // esta operação já é feita durante a inserção do nó (caso essa inserção não aconteça por // motivos de conflito de concorrência o método pode ser executado de forma a impedir o // acesso de opções ao utilizador que poderiam levar a um crash da aplicação). Executar o // UpdateToolBarButtons neste ponto para a situação acima mencionada vai alterar // erradamente o estado dos botões if ((this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Estrutural && successfulSave) || (this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Documental && !successfulSave)) { if (this.nivelNavigator1.SelectedItems.Count > 0) { UpdateToolBarButtons(this.nivelNavigator1.SelectedItems[0]); } else { UpdateToolBarButtons(); } } }
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); } }