protected virtual void updateContextStatusBar(GISATreeNode node)
        {
            if (!(MasterPanel.isContextPanel(this)))
            {
                return;
            }
            if (node == null || node.NivelRow.RowState == DataRowState.Detached)
            {
                ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Empty;
            }
            else
            {
                GISADataset.RelacaoHierarquicaRow   rhRow  = ((GISATreeNode)node).RelacaoHierarquicaRow;
                GISADataset.TipoNivelRelacionadoRow tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);

                ArrayList pathEstrut = ControloNivelList.GetCodigoCompletoCaminhoUnico(node);
                if (pathEstrut.Count == 0)
                {
                    ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Format("  {0}: {1}", tnrRow.Designacao, node.NivelRow.Codigo);
                }
                else
                {
                    ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Format("  {0}: {1}", tnrRow.Designacao, Nivel.buildPath(pathEstrut));
                }
            }
        }
 public override void UpdateToolBarButtons(ListViewItem item)
 {
     if (this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Estrutural)
     {
         //vista estrutural
         GISADataset.NivelRow nRow = null;
         GISADataset.TipoNivelRelacionadoRow tnrRow = null;
         if (this.nivelNavigator1.EPFilterMode) // modo filtro
         {
             if (item != null && item.ListView != null && !(((GISADataset.NivelRow)item.Tag).RowState == DataRowState.Detached))
             {
                 //contexto da listview
                 nRow = (GISADataset.NivelRow)item.Tag;
             }
             if (nRow != null && !(nRow.RowState == DataRowState.Detached))
             {
                 tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica().FirstOrDefault());
             }
         }
         this.ToolBarButtonToggleEstruturaSeries.Enabled = this.nivelNavigator1.isTogglable(nRow, tnrRow) && PermissoesHelper.AllowExpand;
     }
     else
     {
         this.ToolBarButtonToggleEstruturaSeries.Enabled = true;
     }
     SetButtonFiltroState();
 }
Exemple #3
0
        private string GetCodigoCompleto(object element)
        {
            MasterPanelPermissoesPlanoClassificacao mpPPC = (MasterPanelPermissoesPlanoClassificacao)(((frmMain)this.TopLevelControl).MasterPanel);
            string nCod = null;

            if (element is GISATreeNode)
            {
                GISATreeNode node       = (GISATreeNode)element;
                ArrayList    pathEstrut = ControloNivelList.GetCodigoCompletoCaminhoUnico(node);
                if (pathEstrut.Count == 0)
                {
                    nCod = node.NivelRow.Codigo;
                }
                else
                {
                    nCod = Nivel.buildPath(pathEstrut);
                }
            }
            else if (element is ListViewItem)
            {
                ListViewItem item = (ListViewItem)element;
                GISADataset.RelacaoHierarquicaRow rhRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", ((GISADataset.NivelRow)item.Tag).ID, mpPPC.nivelNavigator1.ContextBreadCrumbsPathID))[0]);

                GISADataset.TipoNivelRelacionadoRow tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);

                ArrayList pathEstrut = ControloNivelList.GetCodigoCompletoCaminhoUnico(mpPPC.nivelNavigator1.SelectedNode);

                ArrayList pathDoc = mpPPC.nivelNavigator1.GetCodigoCompletoCaminhoUnico(item);
                if (pathDoc.Count == 0 && pathEstrut.Count == 0)
                {
                    nCod = tnrRow.Designacao;
                }
                else
                {
                    nCod = string.Format("{0}/{1}", Nivel.buildPath(pathEstrut), Nivel.buildPath(pathDoc));
                }
            }
            return(nCod);
        }
        protected virtual void updateContextStatusBar(ListViewItem listViewItem)
        {
            if (!(MasterPanel.isContextPanel(this)))
            {
                return;
            }

            if (listViewItem == null || (listViewItem != null && listViewItem.ListView == null) || ((GISADataset.NivelRow)listViewItem.Tag).RowState == DataRowState.Detached)
            {
                ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Empty;
            }
            else
            {
                // prever a situação onde, concorrentemente, outro utilizador fez cut/paste do nível em(questão)
                // mudando assim, o caminho actual do mesmo
                if (GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", ((GISADataset.NivelRow)listViewItem.Tag).ID, this.nivelNavigator1.ContextBreadCrumbsPathID)).Length > 0)
                {
                    GISADataset.RelacaoHierarquicaRow rhRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", ((GISADataset.NivelRow)listViewItem.Tag).ID, this.nivelNavigator1.ContextBreadCrumbsPathID))[0]);

                    GISADataset.TipoNivelRelacionadoRow tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);

                    ArrayList pathEstrut = ControloNivelList.GetCodigoCompletoCaminhoUnico(this.nivelNavigator1.SelectedNode);
                    ArrayList pathDoc    = this.nivelNavigator1.GetCodigoCompletoCaminhoUnico(listViewItem);
                    if (pathDoc.Count == 0 && pathEstrut.Count == 0)
                    {
                        ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Format("  {0}", tnrRow.Designacao);
                    }
                    else
                    {
                        ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Format("  {0}: {1}/{2}", tnrRow.Designacao, Nivel.buildPath(pathEstrut), Nivel.buildPath(pathDoc));
                    }
                }
                else
                {
                    ((frmMain)TopLevelControl).StatusBarPanelHint.Text = string.Empty;
                }
            }
        }
Exemple #5
0
		public ArrayList AddNivel(TreeView trvw, GISADataset.NivelRow nRow, GISADataset.NivelRow nUpperRow, IDbConnection connection)
		{
			ArrayList result = new ArrayList();
			GISATreeNode node = null;
			// Para as EDs (em relação às quais não existem níveis superiores)
			if (nUpperRow == null)
			{
				node = FindTreeNodeByNivelRow(trvw.Nodes, nRow);
				if (node == null)
				{
					node = new GISATreeNode(Nivel.GetDesignacao(nRow));
					//Node.Tag = rhRow
					node.NivelRow = nRow;
					node.NivelUpperRow = null;

					GISADataset.TipoNivelRelacionadoRow tnrRow = null;
					int iconIndex = 0;
					tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(node.NivelRow, node.NivelUpperRow);
					iconIndex = -1;

					if (tnrRow != null)
					{
						iconIndex = System.Convert.ToInt32(tnrRow.GUIOrder);
					}
					if (nRow.CatCode.Trim().Equals("CA"))
					{
						if (iconIndex == -1)
						{
							node.ImageIndex = SharedResourcesOld.CurrentSharedResources.NivelImageIncognitoControloAut();
						}
						else
						{
							node.ImageIndex = SharedResourcesOld.CurrentSharedResources.NivelImageControloAut(iconIndex);
						}
					}
					else
					{
						if (iconIndex == -1)
						{
							node.ImageIndex = SharedResourcesOld.CurrentSharedResources.NivelImageIncognito();
						}
						else
						{
							node.ImageIndex = SharedResourcesOld.CurrentSharedResources.NivelImageBase(iconIndex);
						}
					}
					node.SelectedImageIndex = node.ImageIndex;
					trvw.Nodes.Add(node);
				}
				result.Add(node);
			}
			else
			{
				ArrayList ParentNodes = new ArrayList();
				GISADataset.RelacaoHierarquicaRow[] TempParentRelations = Nivel.GetParentRelations(nRow, nUpperRow, connection);

				//Obter os nós pai com base nas rows pai
				if (TempParentRelations.Length == 0)
				{
					ArrayList nodes = null;
					nodes = AddNivel(trvw, nUpperRow, null, connection);
					ParentNodes.AddRange(nodes);
				}
				foreach (GISADataset.RelacaoHierarquicaRow parentRhRow in TempParentRelations)
				{
					ArrayList nodes = null;
					nodes = AddNivel(trvw, parentRhRow.NivelRowByNivelRelacaoHierarquica, parentRhRow.NivelRowByNivelRelacaoHierarquicaUpper, connection);
					ParentNodes.AddRange(nodes);
				}

				// Neste ponto ParentNodes contém todos os nós a que um nó de nRow deverá ser adicionado
				foreach (TreeNode parentNode in ParentNodes)
				{
					node = FindTreeNodeByNivelRow(parentNode.Nodes, nRow);
					if (node == null)
					{
						node = new GISATreeNode(Nivel.GetDesignacao(nRow));
						//node.Tag = rhRow
						node.NivelRow = nRow;
						node.NivelUpperRow = nUpperRow;
						string data = FormatYearsInterval(node.RelacaoHierarquicaRow);
						if (data.Length > 0)
						{
							node.Text = string.Format("{0}   {1}", node.Text, data);
						}
						if (nRow.CatCode.Trim().Equals("CA"))
						{
							node.ImageIndex = SharedResourcesOld.CurrentSharedResources.NivelImageControloAut(System.Convert.ToInt32(TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(node.RelacaoHierarquicaRow).GUIOrder));
						}
						else
						{
							node.ImageIndex = SharedResourcesOld.CurrentSharedResources.NivelImageBase(System.Convert.ToInt32(TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(node.RelacaoHierarquicaRow).GUIOrder));
						}
						node.SelectedImageIndex = node.ImageIndex;
						parentNode.Nodes.Add(node);
					}
					result.Add(node);
				}
			}
			return result;
		}
Exemple #6
0
        private void SeleccaoActual(out GISADataset.NivelRow NivelRow, out GISADataset.TipoNivelRelacionadoRow TnrRow)
        {
            //Obter selecção actual
            GISATreeNode selectedNode = null;

            GISADataset.NivelRow nRow                  = null;
            GISADataset.NivelRow nUpperRow             = null;
            GISADataset.RelacaoHierarquicaRow   rhRow  = null;
            GISADataset.TipoNivelRelacionadoRow tnrRow = null;

            // Estas variaveis identificam o contexto definido pelo breadcrumbspath da vista documental
            // (só são usadas quando a vista actual é a documental)
            GISADataset.NivelRow nRowBC                  = null;
            GISADataset.NivelRow nUpperRowBC             = null;
            GISADataset.RelacaoHierarquicaRow   rhRowBC  = null;
            GISADataset.TipoNivelRelacionadoRow tnrRowBC = null;

            if (this.mPanelToggleState == ToggleState.Estrutural)
            {
                //vista estrutural
                if (mEPFilterMode)
                {
                    var selItem = this.nivelEstruturalList1.SelectedItems.FirstOrDefault();
                    if (selItem != null)
                    {
                        nRow = selItem.Tag as GISADataset.NivelRow;
                    }
                }
                else
                {
                    selectedNode = (GISATreeNode)this.controloNivelListEstrutural1.SelectedNode;
                    if (selectedNode != null && !(selectedNode.NivelRow.RowState == DataRowState.Detached))
                    {
                        nRow      = selectedNode.NivelRow;
                        nUpperRow = selectedNode.NivelUpperRow;
                    }
                }
            }
            else
            {
                //vista documental
                if (!(this.nivelDocumentalListNavigator1.SelectedItems.Count == 0))
                {
                    nRow = (GISADataset.NivelRow)(this.nivelDocumentalListNavigator1.SelectedItems[0].Tag);
                }

                if (nRow != null && !(nRow.RowState == DataRowState.Detached))
                {
                    nUpperRow = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].NivelRowByNivelRelacaoHierarquicaUpper;
                }
            }

            if (nRow != null && !(nRow.RowState == DataRowState.Detached) && nUpperRow == null)
            {
                if (this.mPanelToggleState == ToggleState.Estrutural && this.mEPFilterMode)
                {
                    rhRow  = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica().FirstOrDefault();
                    tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);
                }
                else
                {
                    tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(null);
                }
            }
            else if (nUpperRow != null && !(nUpperRow.RowState == DataRowState.Detached) && nRow != null && !(nRow.RowState == DataRowState.Detached))
            {
                if (this.mPanelToggleState == ToggleState.Estrutural)
                {
                    rhRow = selectedNode.RelacaoHierarquicaRow;
                    // excluimos desta forma as relacoes hirarquicas entretanto eliminadas (as que seriam NULL mas cujo nó respectivo teria um NivelUpper)
                    if (selectedNode.NivelUpperRow != null && rhRow != null)
                    {
                        tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);
                    }
                }
                else
                {
                    //Documental
                    if (nRow != null)
                    {
                        DataRow[] rhRows = GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", nRow.ID.ToString(), nUpperRow.ID.ToString()));
                        // A relação pode ter desaparecido por algum motivo (ie, concorrencia).
                        if (rhRows.Length > 0)
                        {
                            rhRow  = (GISADataset.RelacaoHierarquicaRow)(rhRows[0]);
                            tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);
                        }
                    }
                    if (nRowBC != null && nUpperRowBC != null)
                    {
                        DataRow[] rhRowBCs = GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", nRowBC.ID.ToString(), nUpperRowBC.ID.ToString()));
                        // A relação pode ter desaparecido por algum motivo (ie, concorrencia).
                        if (rhRowBCs.Length > 0)
                        {
                            rhRowBC  = (GISADataset.RelacaoHierarquicaRow)(rhRowBCs[0]);
                            tnrRowBC = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRowBC);
                        }
                    }
                }
            }

            NivelRow = nRow;
            TnrRow   = tnrRow;
        }
        public override void UpdateToolBarButtons(ListViewItem item)
        {
            base.UpdateToolBarButtons(item);

            //Obter selecção actual
            GISATreeNode selectedNode = null;

            GISADataset.NivelRow nRow                  = null;
            GISADataset.NivelRow nUpperRow             = null;
            GISADataset.RelacaoHierarquicaRow   rhRow  = null;
            GISADataset.TipoNivelRelacionadoRow tnrRow = null;
            // Estas variaveis identificam o contexto definido pelo breadcrumbspath da vista documental
            // (só são usadas quando a vista actual é a documental)
            GISADataset.NivelRow nRowBC                  = null;
            GISADataset.NivelRow nUpperRowBC             = null;
            GISADataset.RelacaoHierarquicaRow   rhRowBC  = null;
            GISADataset.TipoNivelRelacionadoRow tnrRowBC = null;

            if (this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Estrutural)
            {
                //vista estrutural
                if (this.nivelNavigator1.EPFilterMode) // modo filtro
                {
                    if (item != null && item.ListView != null && !(((GISADataset.NivelRow)item.Tag).RowState == DataRowState.Detached))
                    {
                        //contexto da listview
                        nRow = (GISADataset.NivelRow)item.Tag;
                    }
                }
                else //modo árvore
                {
                    //vista estrutural
                    selectedNode = (GISATreeNode)this.nivelNavigator1.SelectedNode;
                    if (selectedNode != null && !(selectedNode.NivelRow.RowState == DataRowState.Detached))
                    {
                        nRow      = selectedNode.NivelRow;
                        nUpperRow = selectedNode.NivelUpperRow;
                    }
                }
            }
            else
            {
                //vista documental
                if (item != null && item.ListView != null && !(((GISADataset.NivelRow)item.Tag).RowState == DataRowState.Detached))
                {
                    //contexto da listview
                    nRow      = (GISADataset.NivelRow)item.Tag;
                    nUpperRow = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].NivelRowByNivelRelacaoHierarquicaUpper;
                }

                //contexto do breadcrumbspath
                nRowBC      = GisaDataSetHelper.GetInstance().Nivel.Cast <GISADataset.NivelRow>().SingleOrDefault(r => r.RowState != DataRowState.Deleted && r.ID == this.nivelNavigator1.ContextBreadCrumbsPathID);
                nUpperRowBC = GisaDataSetHelper.GetInstance().Nivel.Cast <GISADataset.NivelRow>().SingleOrDefault(r => r.RowState != DataRowState.Deleted && r.ID == this.nivelNavigator1.ContextBreadCrumbsPathIDUpper);
            }

            if (nRow != null && !(nRow.RowState == DataRowState.Detached) && nUpperRow == null)
            {
                tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(null);
            }
            else if (nUpperRow != null && !(nUpperRow.RowState == DataRowState.Detached) && nRow != null && !(nRow.RowState == DataRowState.Detached))
            {
                if (this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Estrutural)
                {
                    rhRow = selectedNode.RelacaoHierarquicaRow;
                    // excluimos desta forma as relacoes hirarquicas entretanto eliminadas (as que seriam NULL mas cujo nó respectivo teria um NivelUpper)
                    if (selectedNode.NivelUpperRow != null && rhRow != null)
                    {
                        tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);
                    }
                }
                else
                {
                    if (item != null && item.ListView != null)
                    {
                        DataRow[] rhRows = GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", nRow.ID.ToString(), nUpperRow.ID.ToString()));
                        // A relação pode ter desaparecido por algum motivo (ie, concorrencia).
                        if (rhRows.Length > 0)
                        {
                            rhRow  = (GISADataset.RelacaoHierarquicaRow)(rhRows[0]);
                            tnrRow = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRow);
                        }
                    }
                    if (nRowBC != null && nUpperRowBC != null)
                    {
                        DataRow[] rhRowBCs = GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", nRowBC.ID.ToString(), nUpperRowBC.ID.ToString()));
                        // A relação pode ter desaparecido por algum motivo (ie, concorrencia).
                        if (rhRowBCs.Length > 0)
                        {
                            rhRowBC  = (GISADataset.RelacaoHierarquicaRow)(rhRowBCs[0]);
                            tnrRowBC = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRowBC);
                        }
                    }
                }
            }

            if (nRow == null && this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Documental && nRowBC != null && nUpperRowBC != null)
            {
                GISADataset.RelacaoHierarquicaRow[] bcRHRow = (GISADataset.RelacaoHierarquicaRow[])(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", nRowBC.ID.ToString(), nUpperRowBC.ID.ToString())));
                if (bcRHRow.Length > 0)
                {
                    if (bcRHRow[0].IDTipoNivelRelacionado < TipoNivelRelacionado.SD)
                    {
                        ToolBarButtonCreateAny.Enabled = AllowCreate && PermissoesHelper.AllowCreate;
                    }
                    else
                    {
                        ToolBarButtonCreateAny.Enabled = false;
                    }
                    rhRowBC  = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", nRowBC.ID.ToString(), nUpperRowBC.ID.ToString()))[0]);
                    tnrRowBC = TipoNivelRelacionado.GetTipoNivelRelacionadoFromRelacaoHierarquica(rhRowBC);
                    ConfigureContextMenu(nRowBC, nUpperRowBC, tnrRowBC, tnrRowBC);
                    ToolBarButtonEdit.Enabled   = false;
                    ToolBarButtonRemove.Enabled = false;
                }
                else
                {
                    ToolBarButtonCreateAny.Enabled = false;
                    ToolBarButtonPaste.Enabled     = false;
                }
            }
            else if (TipoNivel.isNivelDocumental(nRow))
            {
                ToolBarButtonCreateAny.Enabled = AllowCreate && PermissoesHelper.AllowCreate;
                ConfigureContextMenu(nRowBC, nUpperRowBC, tnrRow, tnrRowBC);
                if (rhRow.IDTipoNivelRelacionado == TipoNivelRelacionado.D)
                {
                    ToolBarButtonEdit.Enabled   = AllowEdit && PermissoesHelper.AllowEdit;
                    ToolBarButtonRemove.Enabled = NiveisHelper.isRemovable(nRow, nUpperRow, false) && AllowDelete && PermissoesHelper.AllowDelete;
                }
                else if (rhRow.IDTipoNivelRelacionado == TipoNivelRelacionado.SD)
                {
                    ToolBarButtonEdit.Enabled   = AllowEdit && PermissoesHelper.AllowEdit;
                    ToolBarButtonRemove.Enabled = NiveisHelper.isRemovable(nRow, nUpperRow, false) && AllowDelete && PermissoesHelper.AllowDelete && PermissoesHelper.ObjDigAllowWrite;
                }
                else
                {
                    ToolBarButtonEdit.Enabled   = false;
                    ToolBarButtonRemove.Enabled = false;
                }
            }
            else
            {
                ToolBarButtonCreateAny.Enabled = false;
                ToolBarButtonEdit.Enabled      = false;
                ToolBarButtonRemove.Enabled    = false;
            }
        }
        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);
            }
        }