public void SetUp() { ds = new GISADataset(); ds.Merge(GisaDataSetHelper.GetInstance()); r1 = ds.Nivel.NewNivelRow(); r1.IDTipoNivel = 1; r1.Codigo = "Teste"; r2 = ds.Nivel.NewNivelRow(); r2.IDTipoNivel = 2; r2.Codigo = "Teste"; r3 = ds.RelacaoHierarquica.NewRelacaoHierarquicaRow(); r3.ID = r2.ID; r3.IDUpper = r1.ID; ds.Nivel.Rows.Add(r1); ds.Nivel.Rows.Add(r2); ds.RelacaoHierarquica.Rows.Add(r3); GISADataset.NivelDesignadoRow r4 = ds.NivelDesignado.NewNivelDesignadoRow(); r4.ID = r1.ID; r4.Designacao = "Designacao"; ds.NivelDesignado.AddNivelDesignadoRow(r4); }
public static void EnsureNivelUpperExists(PersistencyHelper.PreConcArguments args) { PersistencyHelper.VerifyIfRHNivelUpperExistsPreConcArguments pcArgs = null; pcArgs = (PersistencyHelper.VerifyIfRHNivelUpperExistsPreConcArguments)args; GISADataset.NivelRow nRow = (GISADataset.NivelRow)(GisaDataSetHelper.GetInstance().Nivel.Select("ID=" + pcArgs.nRowID.ToString())[0]); long rhRowIDUpper = nRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].IDUpper; if (rhRowIDUpper < 0) { pcArgs.RHNivelUpperExists = true; } else { // antes de obter o código verificar se adição de um novo nível ainda é possível (por razões de concorrência) pcArgs.RHNivelUpperExists = NivelRule.Current.isNivelDeleted(rhRowIDUpper, args.tran); } if (!pcArgs.RHNivelUpperExists) { GISADataset.RelacaoHierarquicaRow rhRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", pcArgs.rhRowID, pcArgs.rhRowIDUpper))[0]); GISADataset.NivelDesignadoRow ndRow = (GISADataset.NivelDesignadoRow)(GisaDataSetHelper.GetInstance().NivelDesignado.Select("ID=" + pcArgs.ndRowID.ToString())[0]); GISADataset.FRDBaseRow frdBaseRow = (GISADataset.FRDBaseRow)(GisaDataSetHelper.GetInstance().FRDBase.Select("ID=" + pcArgs.frdBaseID.ToString())[0]); System.Data.DataSet tempgisaBackup1 = pcArgs.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup1, rhRow); pcArgs.gisaBackup = tempgisaBackup1; rhRow.RejectChanges(); System.Data.DataSet tempgisaBackup2 = pcArgs.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup2, ndRow); pcArgs.gisaBackup = tempgisaBackup2; ndRow.RejectChanges(); System.Data.DataSet tempgisaBackup3 = pcArgs.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup3, nRow); pcArgs.gisaBackup = tempgisaBackup3; nRow.RejectChanges(); System.Data.DataSet tempgisaBackup4 = pcArgs.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup4, frdBaseRow); pcArgs.gisaBackup = tempgisaBackup4; frdBaseRow.RejectChanges(); pcArgs.message = "Não foi possível criar a unidade informacional uma" + Environment.NewLine + "vez que a unidade superior foi apagada por outro utilizador."; } }
public static GISADataset.NivelRow CreateUF(GISADataset.NivelRow nivelED, string designacaoUF, string guiaUF) { GISADataset.TipoNivelRelacionadoRow tnrRow = (GISADataset.TipoNivelRelacionadoRow)(GisaDataSetHelper.GetInstance().TipoNivelRelacionado.Select(string.Format("ID={0}", TipoNivelRelacionado.UF))[0]); GISADataset.NivelRow nufRow = null; GISADataset.NivelDesignadoRow ndufRow = null; GISADataset.RelacaoHierarquicaRow rhufRow = null; GISADataset.NivelUnidadeFisicaRow nufufRow = null; GISADataset.FRDBaseRow frdufRow = null; // nivel nufRow = GisaDataSetHelper.GetInstance().Nivel.NewNivelRow(); // nivelDesignado ndufRow = GisaDataSetHelper.GetInstance().NivelDesignado.NewNivelDesignadoRow(); // RelacaoHierarquica rhufRow = GisaDataSetHelper.GetInstance().RelacaoHierarquica.NewRelacaoHierarquicaRow(); // NivelUnidadeFisicaRow nufufRow = GisaDataSetHelper.GetInstance().NivelUnidadeFisica.NewNivelUnidadeFisicaRow(); // FRDBaseRow frdufRow = GisaDataSetHelper.GetInstance().FRDBase.NewFRDBaseRow(); GISADataset tempWith1 = GisaDataSetHelper.GetInstance(); Trace.WriteLine("A criar unidade física..."); nufRow.TipoNivelRow = tnrRow.TipoNivelRow; nufRow.Codigo = UnidadesFisicasHelper.GenerateNewCodigoString(nivelED, System.DateTime.Now.Year); nufRow.CatCode = "NVL"; ndufRow.NivelRow = nufRow; ndufRow.Designacao = designacaoUF; //CreateUF_edID = nivelED.ID; //CreateUF_designacao = designacaoUF; //CreateUF_guia = guiaUF; rhufRow.NivelRowByNivelRelacaoHierarquica = nufRow; rhufRow.TipoNivelRelacionadoRow = (GISADataset.TipoNivelRelacionadoRow)(GisaDataSetHelper.GetInstance().TipoNivelRelacionado.Select(string.Format("ID={0}", TipoNivelRelacionado.UF))[0]); rhufRow["InicioAno"] = DBNull.Value; rhufRow["InicioMes"] = DBNull.Value; rhufRow["InicioDia"] = DBNull.Value; rhufRow["FimAno"] = DBNull.Value; rhufRow["FimMes"] = DBNull.Value; rhufRow["FimDia"] = DBNull.Value; rhufRow.NivelRowByNivelRelacaoHierarquicaUpper = nivelED; nufufRow.GuiaIncorporacao = guiaUF; nufufRow.NivelDesignadoRow = ndufRow; frdufRow.NivelRow = nufRow; frdufRow.NotaDoArquivista = string.Empty; frdufRow.TipoFRDBaseRow = (GISADataset.TipoFRDBaseRow)(GisaDataSetHelper.GetInstance().TipoFRDBase.Select(string.Format("ID={0}", System.Enum.Format(typeof(TipoFRDBase), TipoFRDBase.FRDUnidadeFisica, "D")))[0]); frdufRow.RegrasOuConvencoes = string.Empty; tempWith1.Nivel.AddNivelRow(nufRow); tempWith1.NivelDesignado.AddNivelDesignadoRow(ndufRow); tempWith1.RelacaoHierarquica.AddRelacaoHierarquicaRow(rhufRow); tempWith1.NivelUnidadeFisica.AddNivelUnidadeFisicaRow(nufufRow); tempWith1.FRDBase.AddFRDBaseRow(frdufRow); var sfrdDatasProducaoRow = GisaDataSetHelper.GetInstance().SFRDDatasProducao.Cast <GISADataset.SFRDDatasProducaoRow>().Where(r => r.IDFRDBase == frdufRow.ID).SingleOrDefault(); if (sfrdDatasProducaoRow == null) { GisaDataSetHelper.GetInstance().SFRDDatasProducao.AddSFRDDatasProducaoRow(frdufRow, "", "", "", "", false, "", "", "", "", false, new byte[] { }, 0); } return(nufRow); }
public static void HandleUF(PersistencyHelper.PreConcArguments args) { PersistencyHelper.AddEditUFPreConcArguments aeufpca = null; PersistencyHelper.IsCodigoUFBeingUsedPreSaveArguments psa = null; aeufpca = (PersistencyHelper.AddEditUFPreConcArguments)args; psa = (PersistencyHelper.IsCodigoUFBeingUsedPreSaveArguments)aeufpca.psa; psa.cancelSetNewCodigo = false; aeufpca.message = string.Empty; GISADataset.RelacaoHierarquicaRow rhufRow = null; if (GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", aeufpca.rhufRowID, aeufpca.rhufRowIDUpper)).Length > 0) { rhufRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", aeufpca.rhufRowID, aeufpca.rhufRowIDUpper))[0]); } else if (GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", aeufpca.rhufRowID, aeufpca.rhufRowIDUpper), "", DataViewRowState.Deleted).Length > 0) { rhufRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", aeufpca.rhufRowID, aeufpca.rhufRowIDUpper), "", DataViewRowState.Deleted)[0]); } GISADataset.NivelDesignadoRow ndufRow = (GISADataset.NivelDesignadoRow)(GisaDataSetHelper.GetInstance().NivelDesignado.Select("ID=" + aeufpca.ndufRowID.ToString())[0]); GISADataset.NivelRow nivelUFRow = (GISADataset.NivelRow)(GisaDataSetHelper.GetInstance().Nivel.Select("ID=" + aeufpca.nivelUFRowID.ToString())[0]); if (aeufpca.Operation == PersistencyHelper.AddEditUFPreConcArguments.Operations.Create || aeufpca.Operation == PersistencyHelper.AddEditUFPreConcArguments.Operations.CreateLike) { GISADataset.NivelUnidadeFisicaRow nufufRow = (GISADataset.NivelUnidadeFisicaRow)(GisaDataSetHelper.GetInstance().NivelUnidadeFisica.Select("ID=" + aeufpca.nufufRowID.ToString())[0]); // validar criação de UF if (DBAbstractDataLayer.DataAccessRules.UFRule.Current.isNivelRowDeleted(rhufRow.NivelRowByNivelRelacaoHierarquicaUpper.ID, aeufpca.tran)) { var tempgisaBackup = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup, nufufRow); aeufpca.gisaBackup = tempgisaBackup; nufufRow.RejectChanges(); PersistencyHelper.BackupRow(ref tempgisaBackup, rhufRow); aeufpca.gisaBackup = tempgisaBackup; rhufRow.RejectChanges(); PersistencyHelper.BackupRow(ref tempgisaBackup, ndufRow); aeufpca.gisaBackup = tempgisaBackup; ndufRow.RejectChanges(); PersistencyHelper.BackupRow(ref tempgisaBackup, nivelUFRow); aeufpca.gisaBackup = tempgisaBackup; nivelUFRow.RejectChanges(); List <DataRow> lstRows = new List <DataRow>(); // recolher rows para fazer backup caso a operação seja "CREATE LIKE" if (aeufpca.Operation == PersistencyHelper.AddEditUFPreConcArguments.Operations.CreateLike) { lstRows.AddRange(GisaDataSetHelper.GetInstance().SFRDDatasProducao.Select("IDFRDBase=" + aeufpca.frdufRowID.ToString())); lstRows.AddRange(GisaDataSetHelper.GetInstance().SFRDUFCota.Select("IDFRDBase=" + aeufpca.frdufRowID.ToString())); lstRows.AddRange(GisaDataSetHelper.GetInstance().SFRDConteudoEEstrutura.Select("IDFRDBase=" + aeufpca.frdufRowID.ToString())); lstRows.AddRange(GisaDataSetHelper.GetInstance().SFRDUFDescricaoFisica.Select("IDFRDBase=" + aeufpca.frdufRowID.ToString())); foreach (long uaAssociadaID in aeufpca.uaAssociadas) { lstRows.AddRange(GisaDataSetHelper.GetInstance().SFRDUnidadeFisica.Select(string.Format("IDFRDBase={0} AND IDNivel={1}", uaAssociadaID, aeufpca.nivelUFRowID))); } } lstRows.AddRange(GisaDataSetHelper.GetInstance().FRDBase.Select("ID=" + aeufpca.frdufRowID.ToString())); PersistencyHelper.BackupRows(ref tempgisaBackup, lstRows); aeufpca.gisaBackup = tempgisaBackup; aeufpca.OperationError = PersistencyHelper.AddEditUFPreConcArguments.OperationErrors.NewUF; aeufpca.message = "A entidade produtora que pretende associar à unidade física foi eliminada por outro utilizador. Esta operação não poderá, por isso, ser concluída."; psa.cancelSetNewCodigo = true; aeufpca.continueSave = false; } } else { // validar edição de UF bool isUFDeleted = DBAbstractDataLayer.DataAccessRules.UFRule.Current.isNivelRowDeleted(nivelUFRow.ID, aeufpca.tran); // verificar se a UF a editar não foi apagada por outro utilizador if (isUFDeleted) { System.Data.DataSet tempgisaBackup6 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup6, ndufRow); aeufpca.gisaBackup = tempgisaBackup6; ndufRow.RejectChanges(); System.Data.DataSet tempgisaBackup7 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup7, nivelUFRow); aeufpca.gisaBackup = tempgisaBackup7; nivelUFRow.RejectChanges(); aeufpca.OperationError = PersistencyHelper.AddEditUFPreConcArguments.OperationErrors.EditEDAndDesignacao; aeufpca.message = "A unidade física em edição foi eliminada por outro utilizador. " + Environment.NewLine + "Esta operação não poderá, por isso, ser concluída."; psa.cancelSetNewCodigo = true; aeufpca.continueSave = false; return; } // Verificar se se pretende alterar a entidade detentora associada bool isRelacaoHierarquicaDeleted = false; if (rhufRow.RowState == DataRowState.Deleted) { isRelacaoHierarquicaDeleted = DBAbstractDataLayer.DataAccessRules.UFRule.Current.isRelacaoHierarquicaDeleted(aeufpca.rhufRowID, aeufpca.rhufRowIDUpper, aeufpca.tran); } else { // a operação pretendida é editar a designação da UF e por esse motivo não é necessário // atribuir um novo código (a operação não é create e a entidade detentora não foi alterada) psa.cancelSetNewCodigo = true; aeufpca.continueSave = false; } GISADataset.RelacaoHierarquicaRow[] newRhufRow = (GISADataset.RelacaoHierarquicaRow[])(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", aeufpca.newRhufRowID, aeufpca.newRhufRowIDUpper))); // Verificar se outro utilizador também alterou (concorrentemente) a entidade detentora associada if (isRelacaoHierarquicaDeleted) { System.Data.DataSet tempgisaBackup8 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup8, newRhufRow[0]); aeufpca.gisaBackup = tempgisaBackup8; newRhufRow[0].RejectChanges(); System.Data.DataSet tempgisaBackup9 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup9, rhufRow); aeufpca.gisaBackup = tempgisaBackup9; rhufRow.RejectChanges(); System.Data.DataSet tempgisaBackup10 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup10, nivelUFRow); aeufpca.gisaBackup = tempgisaBackup10; nivelUFRow.RejectChanges(); aeufpca.OperationError = PersistencyHelper.AddEditUFPreConcArguments.OperationErrors.EditOriginalEd; aeufpca.message = "A entidade detentora da unidade física em edição foi alterada por outro utilizador." + Environment.NewLine + "Esta operação não poderá, por isso, ser concluída."; psa.cancelSetNewCodigo = true; aeufpca.continueSave = false; } else if (newRhufRow.Length > 0) // se tivermos alterado a entidade detentora da uf { // verificar se a ED a associar à UF não foi apagada por outro utilizador if (DBAbstractDataLayer.DataAccessRules.UFRule.Current.isNivelRowDeleted(newRhufRow[0].NivelRowByNivelRelacaoHierarquicaUpper.ID, aeufpca.tran)) { System.Data.DataSet tempgisaBackup11 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup11, newRhufRow[0]); aeufpca.gisaBackup = tempgisaBackup11; newRhufRow[0].RejectChanges(); System.Data.DataSet tempgisaBackup12 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup12, rhufRow); aeufpca.gisaBackup = tempgisaBackup12; rhufRow.RejectChanges(); System.Data.DataSet tempgisaBackup13 = aeufpca.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup13, nivelUFRow); aeufpca.gisaBackup = tempgisaBackup13; nivelUFRow.RejectChanges(); if (!isUFDeleted) { // UF existe mas a ED que se pretende adicionar não aeufpca.OperationError = PersistencyHelper.AddEditUFPreConcArguments.OperationErrors.EditNewEd; aeufpca.message = "A entidade produtora que pretende associar à unidade física foi eliminada por outro utilizador. Esta operação não poderá, por isso, ser concluída."; } psa.cancelSetNewCodigo = true; aeufpca.continueSave = false; } //else if (!isUFDeleted) //{ // // Tanto a UF como a ED existem; // NivelRule.Current.DeleteSFRDUnidadeFisica(nivelUFRow.ID, aeufpca.tran); // foreach (GISADataset.SFRDUnidadeFisicaRow relacaoRow in nivelUFRow.GetSFRDUnidadeFisicaRows()) // { // System.Data.DataSet tempgisaBackup14 = aeufpca.gisaBackup; // PersistencyHelper.BackupRow(ref tempgisaBackup14, relacaoRow); // aeufpca.gisaBackup = tempgisaBackup14; // relacaoRow.Delete(); // } //} } } }
public static void ensureUniqueCodigo(PersistencyHelper.PreConcArguments args) { PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments pcArgs = null; pcArgs = (PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments)args; GISADataset.NivelRow nRow = (GISADataset.NivelRow)(GisaDataSetHelper.GetInstance().Nivel.Select("ID=" + pcArgs.nRowID.ToString())[0]); GISADataset.NivelDesignadoRow ndRow = (GISADataset.NivelDesignadoRow)(GisaDataSetHelper.GetInstance().NivelDesignado.Select("ID=" + pcArgs.ndRowID.ToString())[0]); GISADataset.RelacaoHierarquicaRow rhRow = null; if (GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", pcArgs.rhRowID, pcArgs.rhRowIDUpper)).Length > 0) { rhRow = (GISADataset.RelacaoHierarquicaRow)(GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", pcArgs.rhRowID, pcArgs.rhRowIDUpper))[0]); } // Se o nível em questão for uma entidade detentora if (rhRow == null && nRow.TipoNivelRow.ID == TipoNivel.LOGICO) { if (DBAbstractDataLayer.DataAccessRules.NivelRule.Current.isUniqueCodigo(nRow.Codigo, nRow.ID, pcArgs.tran, pcArgs.testOnlyWithinNivel)) { pcArgs.successful = true; } else { var cod = nRow.Codigo; System.Data.DataSet tempgisaBackup1 = pcArgs.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup1, ndRow); pcArgs.gisaBackup = tempgisaBackup1; System.Data.DataSet tempgisaBackup2 = pcArgs.gisaBackup; PersistencyHelper.BackupRow(ref tempgisaBackup2, nRow); pcArgs.gisaBackup = tempgisaBackup2; ndRow.RejectChanges(); PermissoesHelper.UndoAddNivelGrantPermissions(nRow); nRow.RejectChanges(); pcArgs.message = string.Format( "Não é possível completar a operação porque não é permitido " + Environment.NewLine + "que duas unidades de informação tenham o mesmo código " + Environment.NewLine + "parcial ({0}) no mesmo nivel de descrição.", cod); } } else { // antes de obter o código verificar se adição de um novo nível ainda é possível (por razões // de concorrência é necessário garantir que tanto o nível acima mantém-se na base de dados // até o save estar terminado) bool upperRelationExists; if (rhRow.IDUpper < 0) { upperRelationExists = true; } else { upperRelationExists = NivelRule.Current.isNivelDeleted(rhRow.IDUpper, args.tran); } if (!upperRelationExists) { var frdRow = GisaDataSetHelper.GetInstance().FRDBase.Cast <GISADataset.FRDBaseRow>().Single(r => r.ID == pcArgs.frdBaseID); Nivel.DeleteInDataSet(frdRow, false, pcArgs.gisaBackup); Nivel.DeleteInDataSet(nRow, false, pcArgs.gisaBackup); pcArgs.message = "Não foi possível criar/editar a unidade informacional uma" + Environment.NewLine + "vez que a unidade superior foi apagada por outro utilizador."; } else { if (DBAbstractDataLayer.DataAccessRules.NivelRule.Current.isUniqueCodigo(nRow.Codigo, nRow.ID, pcArgs.tran, pcArgs.testOnlyWithinNivel, rhRow.NivelRowByNivelRelacaoHierarquicaUpper.ID)) { pcArgs.successful = true; } else { var cod = nRow.Codigo; if (nRow.RowState == DataRowState.Modified) { nRow.RejectChanges(); GisaDataSetHelper.GetInstance().IndexFRDCA.Cast <GISADataset.IndexFRDCARow>() .Where(r => r.RowState != DataRowState.Unchanged).ToList().ForEach(r => r.RejectChanges()); } else if (nRow.RowState == DataRowState.Added) { var frdRow = GisaDataSetHelper.GetInstance().FRDBase.Cast <GISADataset.FRDBaseRow>().Single(r => r.ID == pcArgs.frdBaseID); Nivel.DeleteInDataSet(frdRow, false, pcArgs.gisaBackup); Nivel.DeleteInDataSet(nRow, false, pcArgs.gisaBackup); } pcArgs.message = string.Format( "Não é possível completar a operação porque não é permitido " + Environment.NewLine + "que duas unidades de informação tenham o mesmo código " + Environment.NewLine + "parcial ({0}) no mesmo nivel de descrição.", cod); } } } }
public static PersistencyHelper.SetNewNivelOrderPreSaveArguments AddNivelDocumentoSimplesWithDelegateArgs(GISADataset.NivelDesignadoRow ndRow, long IDUpper, long IDTipoNivelRelacionado) { if (IDTipoNivelRelacionado != TipoNivelRelacionado.SD) { return(null); } var psArgsNivelDocSimples = new PersistencyHelper.SetNewNivelOrderPreSaveArguments(); GisaDataSetHelper.GetInstance().NivelDocumentoSimples.AddNivelDocumentoSimplesRow(ndRow, -1, new byte[] { }, 0); psArgsNivelDocSimples.nRowID = ndRow.ID; psArgsNivelDocSimples.nRowIDUpper = IDUpper; return(psArgsNivelDocSimples); }
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); } }