private void PopulateDescricaoText() { if (lstVwRelacoes.SelectedItems.Count == 1) { object row = lstVwRelacoes.SelectedItems[0].Tag; if (((DataRow)row).RowState == DataRowState.Detached) { return; } if (row is GISADataset.ControloAutRelRow) { GISADataset.ControloAutRelRow carRow = null; carRow = (GISADataset.ControloAutRelRow)row; txtDescricaoRelacao.Text = carRow.Descricao; } else if (row is GISADataset.RelacaoHierarquicaRow) { GISADataset.RelacaoHierarquicaRow rhRow = null; rhRow = (GISADataset.RelacaoHierarquicaRow)row; if (rhRow.IsDescricaoNull()) { txtDescricaoRelacao.Text = string.Empty; } else { txtDescricaoRelacao.Text = rhRow.Descricao; } } } else { txtDescricaoRelacao.Text = string.Empty; } }
private void AddIdentidadeInstituicao(GISADataset.ControloAutRelRow carRow) { if (carRow.IDTipoRel != Convert.ToInt64(TipoControloAutRel.Instituicao)) { return; } DataRow[] cadRows = GisaDataSetHelper.GetInstance().ControloAutDicionario.Select("IDControloAut=" + carRow.ControloAutRowByControloAutControloAutRelAlias.ID.ToString() + " AND IDTipoControloAutForma=" + System.Enum.Format(typeof(TipoControloAutForma), TipoControloAutForma.FormaAutorizada, "D")); if (cadRows.Length > 0) { Debug.Assert(cadRows.Length == 1); GISADataset.ControloAutDicionarioRow cadRow = (GISADataset.ControloAutDicionarioRow)(cadRows[0]); if (!(alreadyExistInList(carRow))) { ListViewItem tempWith1 = lstVwIdentidadeInstituicoes.Items.Add(cadRow.DicionarioRow.Termo); if (((GISADataset.ControloAutDicionarioRow)cadRow).ControloAutRow.IsChaveColectividadeNull()) { tempWith1.SubItems.Add(string.Empty); } else { tempWith1.SubItems.Add(((GISADataset.ControloAutDicionarioRow)cadRow).ControloAutRow.ChaveColectividade); } tempWith1.Tag = carRow; } } }
private void GetRelPanelCAControl(PersistencyHelper.PreConcArguments args) { GISADataset.ControloAutRelRow newCARRow = null; GISADataset.ControloAutRelRow delCARRow = null; PersistencyHelper.VerifyRelExistencePreConcArguments vrePsa = null; vrePsa = (PersistencyHelper.VerifyRelExistencePreConcArguments)args; //Added if (GisaDataSetHelper.GetInstance().ControloAutRel.Select(string.Format("(IDControloAut={0} AND IDControloAutAlias={1}) OR (IDControloAut={1} AND IDControloAutAlias={0})", vrePsa.ID, vrePsa.IDUpper)).Length > 0) { newCARRow = (GISADataset.ControloAutRelRow)(GisaDataSetHelper.GetInstance().ControloAutRel.Select(string.Format("(IDControloAut={0} AND IDControloAutAlias={1}) OR (IDControloAut={1} AND IDControloAutAlias={0})", vrePsa.ID, vrePsa.IDUpper))[0]); } //Del if (GisaDataSetHelper.GetInstance().ControloAutRel.Select(string.Format("(IDControloAut={0} AND IDControloAutAlias={1}) OR (IDControloAut={1} AND IDControloAutAlias={0})", vrePsa.ID, vrePsa.IDUpper), null, DataViewRowState.Deleted).Length > 0) { delCARRow = (GISADataset.ControloAutRelRow)(GisaDataSetHelper.GetInstance().ControloAutRel.Select(string.Format("(IDControloAut={0} AND IDControloAutAlias={1}) OR (IDControloAut={1} AND IDControloAutAlias={0})", vrePsa.ID, vrePsa.IDUpper), null, DataViewRowState.Deleted)[0]); } //bd int result = ControloAutRule.Current.ExistsRel(vrePsa.ID, vrePsa.IDUpper, vrePsa.IDTipoRel, vrePsa.isCARRow, vrePsa.tran); switch (result) { case 0: vrePsa.CreateEditResult = PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError; break; case 1: vrePsa.CreateEditResult = PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.RelationAlreadyExists; break; case 2: vrePsa.CreateEditResult = PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.CyclicRelation; break; case 3: vrePsa.CreateEditResult = PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.CADeleted; break; } if (newCARRow != null && delCARRow == null && result == Convert.ToInt64(PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError)) { //Comportamento normal: a relação é criada } else if (newCARRow != null && delCARRow != null && !(result == Convert.ToInt64(PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError))) { delCARRow.AcceptChanges(); } else if (newCARRow != null && delCARRow == null && result == Convert.ToInt64(PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError)) { newCARRow.AcceptChanges(); } else if (newCARRow != null && delCARRow != null && result == Convert.ToInt64(PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError)) { delCARRow.AcceptChanges(); newCARRow.AcceptChanges(); } }
private void PutControloAutRelInTreeView(GISADataset.ControloAutRelRow carRow, GISADataset.ControloAutDicionarioRow ControloAutDicionario, bool selectNewItem) { GISADataset.TipoControloAutRelRow tcarRow = null; DataRow[] cadRows = null; // procurar o ramo correcto onde adicionar a relação foreach (TreeNode Node in trVwTermoIndexacao.Nodes) { if (Node.Tag is GISADataset.TipoControloAutRelRow) { try { tcarRow = (GISADataset.TipoControloAutRelRow)Node.Tag; if (carRow.IDTipoRel == tcarRow.ID) { long ControloAutID = -1; if (carRow.IDControloAut == currentControloAut.ID && carRow.TipoControloAutRelRow.Designacao.Equals(Node.Text)) { ControloAutID = carRow.ControloAutRowByControloAutControloAutRelAlias.ID; } else if (carRow.IDControloAutAlias == currentControloAut.ID && carRow.TipoControloAutRelRow.DesignacaoInversa.Equals(Node.Text)) { ControloAutID = carRow.ControloAutRowByControloAutControloAutRel.ID; } if (ControloAutID != -1) { // procurar a forma autorizada cadRows = GisaDataSetHelper.GetInstance().ControloAutDicionario.Select(string.Format("IDControloAut={0} AND IDTipoControloAutForma=1", ControloAutID)); if (cadRows.Length > 0) { // adicionar o CA à árvore RegisterNode(Node, carRow, (GISADataset.ControloAutDicionarioRow)(cadRows[0]), selectNewItem); break; } } } } catch (NullReferenceException ex) { // Ignore the Null Pointer, it's "Termo de Topo" if (string.Compare(Node.Text, "termo de topo", true) != 0) { throw ex; } } catch (Exception ex) { Trace.WriteLine(ex); throw; } } } }
private void UpdateEditedItem(ListViewItem item) { // prever a situação de se ter tentado editar uma relação entretanto apagada por // outro utilizador (nesse caso, a interface não é actualizada) if (((DataRow)item.Tag).RowState == DataRowState.Detached) { return; } if (item.Tag is GISADataset.ControloAutRelRow) { GISADataset.ControloAutRelRow carRow = null; carRow = (GISADataset.ControloAutRelRow)item.Tag; if (carRow.ControloAutRowByControloAutControloAutRelAlias.IsChaveColectividadeNull()) { item.SubItems[colIdentificador.Index].Text = string.Empty; } else { item.SubItems[colIdentificador.Index].Text = carRow.ControloAutRowByControloAutControloAutRelAlias.ChaveColectividade; } item.SubItems[colCategoria.Index].Text = carRow.TipoControloAutRelRow.Designacao; item.SubItems[colDataInicio.Index].Text = GISA.Utils.GUIHelper.FormatDate(carRow.InicioAno, carRow.InicioMes, carRow.InicioDia); item.SubItems[colDataFim.Index].Text = GISA.Utils.GUIHelper.FormatDate(carRow.FimAno, carRow.FimMes, carRow.FimDia); item.SubItems[colDescricao.Index].Text = GUIHelper.GUIHelper.ClipText(carRow.Descricao); txtDescricaoRelacao.Text = carRow.Descricao; } else if (item.Tag is GISADataset.RelacaoHierarquicaRow) { GISADataset.RelacaoHierarquicaRow rhRow = null; rhRow = (GISADataset.RelacaoHierarquicaRow)item.Tag; GISADataset.ControloAutRow relatedCA = null; relatedCA = rhRow.NivelRowByNivelRelacaoHierarquica.GetNivelControloAutRows()[0].ControloAutRow; GISADataset.TipoControloAutRelRow tcarHierarquicaRow = null; tcarHierarquicaRow = (GISADataset.TipoControloAutRelRow)(GisaDataSetHelper.GetInstance().TipoControloAutRel.Select(string.Format("ID={0:d}", TipoControloAutRel.Hierarquica))[0]); if (relatedCA.IsChaveColectividadeNull()) { item.SubItems[colIdentificador.Index].Text = string.Empty; } else { item.SubItems[colIdentificador.Index].Text = relatedCA.ChaveColectividade; } // nao actualizar a categoria uma vez que este valor nunca poderá ser editado nas relações hierarquicas item.SubItems[colDataInicio.Index].Text = GISA.Utils.GUIHelper.FormatDate(rhRow.InicioAno, rhRow.InicioMes, rhRow.InicioDia); item.SubItems[colDataFim.Index].Text = GISA.Utils.GUIHelper.FormatDate(rhRow.FimAno, rhRow.FimMes, rhRow.FimDia); item.SubItems[colDescricao.Index].Text = GUIHelper.GUIHelper.ClipText(rhRow.Descricao); txtDescricaoRelacao.Text = rhRow.Descricao; } }
private void PopulateThesaurus(IDbConnection conn) { GISADataset.ControloAutRelRow carRow = null; ArrayList CurrentTermos = new ArrayList(); CurrentTermos = ControloAutRule.Current.GetTermos(currentControloAut.ID, conn); trVwTermoIndexacao.BeginUpdate(); foreach (ArrayList Termo in CurrentTermos) { carRow = (GISADataset.ControloAutRelRow)(GisaDataSetHelper.GetInstance().ControloAutRel.Select(string.Format("(IDControloAut={0} AND IDControloAutAlias={1}) AND IDTipoRel IN (1, 2) AND isDeleted = 0 ", Termo[0].ToString(), Termo[1].ToString()))[0]); PutControloAutRelInTreeView(carRow, null, false); } trVwTermoIndexacao.EndUpdate(); }
private void UpdateCA(object rel) { GISADataset.ControloAutRelRow carRow = null; GISADataset.RelacaoHierarquicaRow rhRow = null; if (rel.GetType() == typeof(GISADataset.ControloAutRelRow)) { carRow = (GISADataset.ControloAutRelRow)rel; GISA.Search.Updater.updateProdutor(new List<string>() { carRow.IDControloAut.ToString(), carRow.IDControloAutAlias.ToString() }); } else { rhRow = (GISADataset.RelacaoHierarquicaRow)rel; GISA.Search.Updater.updateProdutor(rhRow.NivelRowByNivelRelacaoHierarquica.GetNivelControloAutRows()[0].IDControloAut); GISA.Search.Updater.updateProdutor(rhRow.NivelRowByNivelRelacaoHierarquicaUpper.GetNivelControloAutRows()[0].IDControloAut); } }
public void RepopulateThesaurus(GISADataset.ControloAutRelRow newCarRows, bool justTermoDeTopo) { GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection()); try { if (!justTermoDeTopo) { ClearThesaurus(); PopulateThesaurus(ho.Connection); } if (newCarRows != null && newCarRows.RowState != DataRowState.Detached) { trVwTermoIndexacao.SelectedNode = nodeList[newCarRows]; } try { ReloadTermoDeTopo(ho.Connection); } catch (Exception ex) { Trace.WriteLine(ex); throw; } RepopulateTermoDeTopo(); } catch (Exception) { throw; } finally { ho.Dispose(); } }
private void btnEdit_Click(object sender, EventArgs e) { DataRow relRow = null; relRow = (DataRow)(lstVwRelacoes.SelectedItems[0].Tag); // verificar se tanto a entidade produtora seleccionada como contexto como a relação seleccionada // para edição não foram apagadas concorrentemente por outro utilizador if (CurrentControloAut.RowState == DataRowState.Detached) { MessageBox.Show("Não é possível editar qualquer relação da entidade produtora " + System.Environment.NewLine + "selecionada uma vez que foi apagada por outro utilizador.", "Edição de Relações", MessageBoxButtons.OK, MessageBoxIcon.Warning); lstVwRelacoes.SelectedItems.Clear(); lstVwRelacoes.Items.Clear(); return; } else if (relRow.RowState == DataRowState.Detached) { MessageBox.Show("Não é possível editar a relação selecionada uma " + System.Environment.NewLine + "vez que foi apagada por outro utilizador.", "Edição de Relações", MessageBoxButtons.OK, MessageBoxIcon.Warning); ListViewItem lvItem = lstVwRelacoes.SelectedItems[0]; lstVwRelacoes.SelectedItems.Clear(); lstVwRelacoes.Items.Remove(lvItem); return; } GISADataset.ControloAutRow caRow = null; GISADataset.ControloAutRelRow carRow = null; GISADataset.RelacaoHierarquicaRow rhRow = null; FormControloAutRel frm = null; if (relRow is GISADataset.ControloAutRelRow) { frm = new FormControloAutRel(CurrentControloAut, ((frmMain)TopLevelControl).MasterPanel); carRow = (GISADataset.ControloAutRelRow)relRow; if (carRow.ControloAutRowByControloAutControloAutRel == CurrentControloAut) { caRow = carRow.ControloAutRowByControloAutControloAutRelAlias; } else if (carRow.ControloAutRowByControloAutControloAutRelAlias == CurrentControloAut) { caRow = carRow.ControloAutRowByControloAutControloAutRel; // nas edições, ao visualizar uma relação pelo outro extremo é necessário alterar a designação da relação apresentada frm.relacaoCA.cbTipoControloAutRel.DisplayMember = "Designacao"; } } else if (relRow is GISADataset.RelacaoHierarquicaRow) { rhRow = (GISADataset.RelacaoHierarquicaRow)relRow; caRow = rhRow.NivelRowByNivelRelacaoHierarquica.GetNivelControloAutRows()[0].ControloAutRow; // Se estivermos a ver o extremo errado da relação hierarquica trocamos para o outro extremo if (CurrentControloAut == caRow) { caRow = rhRow.NivelRowByNivelRelacaoHierarquicaUpper.GetNivelControloAutRows()[0].ControloAutRow; frm = new FormControloAutRel(caRow, ((frmMain)TopLevelControl).MasterPanel); // nas edições, ao visualizar uma relação pelo outro extremo é necessário alterar a designação da relação apresentada frm.relacaoCA.cbTipoControloAutRel.DisplayMember = "Designacao"; } else { frm = new FormControloAutRel(CurrentControloAut, ((frmMain)TopLevelControl).MasterPanel); } } GISADataset.ControloAutDicionarioRow cadRow = null; string termo = null; cadRow = ControloAutHelper.getFormaAutorizada(caRow); termo = cadRow.DicionarioRow.Termo; frm.ContextRel = relRow; frm.caList.AllowedNoticiaAut(TipoNoticiaAut.EntidadeProdutora); frm.caList.SelectedItems.Clear(); frm.caList.txtFiltroDesignacao.Text = termo.Trim(); frm.caList.ReloadList(); frm.caList.SelectItem(cadRow); frm.caList.txtFiltroDesignacao.Clear(); // popular datas frm.relacaoCA.dtRelacaoInicio.ValueYear = GisaDataSetHelper.GetDBNullableText(relRow, "InicioAno"); frm.relacaoCA.dtRelacaoInicio.ValueMonth = GisaDataSetHelper.GetDBNullableText(relRow, "InicioMes"); frm.relacaoCA.dtRelacaoInicio.ValueDay = GisaDataSetHelper.GetDBNullableText(relRow, "InicioDia"); frm.relacaoCA.dtRelacaoFim.ValueYear = GisaDataSetHelper.GetDBNullableText(relRow, "FimAno"); frm.relacaoCA.dtRelacaoFim.ValueMonth = GisaDataSetHelper.GetDBNullableText(relRow, "FimMes"); frm.relacaoCA.dtRelacaoFim.ValueDay = GisaDataSetHelper.GetDBNullableText(relRow, "FimDia"); frm.relacaoCA.txtDescricao.Text = GisaDataSetHelper.GetDBNullableText(relRow, "Descricao"); // Encontrar e selecionar o TipoControloAutRel correcto if (relRow is GISADataset.ControloAutRelRow) { foreach (object drView in frm.relacaoCA.cbTipoControloAutRel.Items) { if (((GISADataset.TipoControloAutRelRow)drView).ID == carRow.TipoControloAutRelRow.ID) { frm.relacaoCA.cbTipoControloAutRel.SelectedItem = drView; } } } else if (relRow is GISADataset.RelacaoHierarquicaRow) { foreach (object drView in frm.relacaoCA.cbTipoControloAutRel.Items) { if (((GISADataset.TipoControloAutRelRow)drView).ID == Convert.ToInt64(TipoControloAutRel.Hierarquica)) { frm.relacaoCA.cbTipoControloAutRel.SelectedItem = drView; break; } } bool foundTipoNivel = false; foreach (TipoNivelRelacionado.PossibleSubNivel subNivel in frm.relacaoCA.cbTipoNivel.Items) { if (subNivel.SubIDTipoNivelRelacionado == rhRow.IDTipoNivelRelacionado) { frm.relacaoCA.cbTipoNivel.SelectedItem = subNivel; foundTipoNivel = true; break; } } // O tipo de nivel já definido pode nao ser encontrado entre os possiveis // se o tipo de nivel do pai tiver entretanto também ele mudado. Nesse caso // adicionamos mais esse tipo de nivel de forma a ser mantida a selecção // anteriormente existente. if (!foundTipoNivel) { ArrayList data = null; data = (ArrayList)frm.relacaoCA.cbTipoNivel.DataSource; TipoNivelRelacionado.PossibleSubNivel subTipoNivel = null; string inicioAno = string.Empty; string inicioMes = string.Empty; string inicioDia = string.Empty; string fimAno = string.Empty; string fimMes = string.Empty; string fimDia = string.Empty; if (!rhRow.IsInicioAnoNull()) { inicioAno = rhRow.InicioAno; } if (!rhRow.IsInicioMesNull()) { inicioMes = rhRow.InicioMes; } if (!rhRow.IsInicioDiaNull()) { inicioDia = rhRow.InicioDia; } if (!rhRow.IsFimAnoNull()) { fimAno = rhRow.FimAno; } if (!rhRow.IsFimMesNull()) { fimMes = rhRow.FimMes; } if (!rhRow.IsFimDiaNull()) { fimDia = rhRow.FimDia; } subTipoNivel = new TipoNivelRelacionado.PossibleSubNivel(rhRow.IDTipoNivelRelacionado, rhRow.TipoNivelRelacionadoRow.Designacao, inicioAno, inicioMes, inicioDia, fimAno, fimMes, fimDia, true); int idx = data.Add(subTipoNivel); frm.relacaoCA.cbTipoNivel.ImageIndexes.Add(SharedResourcesOld.CurrentSharedResources.NivelImageBase(System.Convert.ToInt32(subTipoNivel.SubIDTipoNivelRelacionado))); frm.relacaoCA.cbTipoNivel.DataSource = null; frm.relacaoCA.cbTipoNivel.DataSource = data; frm.relacaoCA.cbTipoNivel.DisplayMember = "DesignacaoComposta"; frm.relacaoCA.cbTipoNivel.SelectedItem = subTipoNivel; } } RetrieveSelection(frm, relRow); }
protected override void AcceptContents(object Value) { this.ControloAutRow = (GISADataset.ControloAutRow)Value; if (FRDBaseRow != null) { NotPresentInIndexResults indexPresence = NotPresentInIndex(ControloAutRow); switch (indexPresence) { case NotPresentInIndexResults.NotPresentInIndex: { TempIndexFRDCA = NewRow(ControloAutRow); GISADataset.ControloAutDicionarioRow[] cadRows = null; cadRows = (GISADataset.ControloAutDicionarioRow[])(GisaDataSetHelper.GetInstance().ControloAutDicionario.Select(string.Format("IDControloAut={0} AND IDTipoControloAutForma = {1:d}", ControloAutRow.ID, TipoControloAutForma.FormaAutorizada))); if (cadRows.Length == 0) { GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection()); try { DBAbstractDataLayer.DataAccessRules.ControloAutRule.Current.LoadFormaAutorizada(ControloAutRow.ID, GisaDataSetHelper.GetInstance(), ho.Connection); } finally { ho.Dispose(); } cadRows = (GISADataset.ControloAutDicionarioRow[])(GisaDataSetHelper.GetInstance().ControloAutDicionario.Select(string.Format("IDControloAut={0} AND IDTipoControloAutForma = {1:d}", ControloAutRow.ID, TipoControloAutForma.FormaAutorizada))); } if (cadRows.Length > 0) { DisplayFormaAutorizada(cadRows[0]); } break; } case NotPresentInIndexResults.PresentInIndex: { MessageBox.Show("Não é possível a existência de items repetidos.", "Adição", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } case NotPresentInIndexResults.PresentInIndexDeleted: { GISADataset.ControloAutDicionarioRow[] cadRows = null; TempIndexFRDCA = GetRow(); cadRows = (GISADataset.ControloAutDicionarioRow[])(GisaDataSetHelper.GetInstance().ControloAutDicionario.Select(string.Format("IDControloAut={0} AND IDTipoControloAutForma = {1:d}", ControloAutRow.ID, TipoControloAutForma.FormaAutorizada))); if (cadRows.Length == 0) { GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection()); try { DBAbstractDataLayer.DataAccessRules.ControloAutRule.Current.LoadFormaAutorizada(ControloAutRow.ID, GisaDataSetHelper.GetInstance(), ho.Connection); } finally { ho.Dispose(); } cadRows = (GISADataset.ControloAutDicionarioRow[])(GisaDataSetHelper.GetInstance().ControloAutDicionario.Select(string.Format("IDControloAut={0} AND IDTipoControloAutForma = {1:d}", ControloAutRow.ID, TipoControloAutForma.FormaAutorizada))); } if (cadRows.Length > 0) { DisplayFormaAutorizada(cadRows[0]); } break; } } } else if (this.ControloAutRow != null) { // TODO: FIXME legibilidade // Determinar se Value já se encontra em ControloAutRel try { // make sure we do not relate an item to itself if (ControloAutRow.ID == this.ControloAutRow.ID) { return; } // If the dropped item was not already added to the selected // item (or vice versa) if (GisaDataSetHelper.GetInstance().ControloAutRel.Select(GetRelConstraint(ControloAutRow, this.ControloAutRow) + " OR " + GetRelConstraint(this.ControloAutRow, ControloAutRow)).Length == 0) { // adicionar nova relação FormControloAutRel frm = new FormControloAutRel(ControloAutRow, parent); switch (frm.ShowDialog()) { case DialogResult.OK: TempIndexFRDCA = GisaDataSetHelper.GetInstance().ControloAutRel.NewControloAutRelRow(); GISADataset.ControloAutRelRow tempWith1 = (GISADataset.ControloAutRelRow)TempIndexFRDCA; tempWith1.IDControloAut = this.ControloAutRow.ID; tempWith1.IDControloAutAlias = ControloAutRow.ID; tempWith1["IDTipoRel"] = ((GISADataset.TipoControloAutRelRow)(((DataRowView)frm.relacaoCA.cbTipoControloAutRel.SelectedItem).Row)).ID; tempWith1.Descricao = frm.relacaoCA.txtDescricao.Text; GisaDataSetHelper.GetInstance().ControloAutRel.AddControloAutRelRow((GISADataset.ControloAutRelRow)TempIndexFRDCA); break; case DialogResult.Cancel: return; } GisaDataSetHelper.VisitControloAutDicionario(ControloAutRow, DisplayFormaAutorizada); } } catch (Exception ex) { Trace.WriteLine(ex); } } }
private bool validateData() { GISADataset.ControloAutDicionarioRow cadRow = ControloAutDicionarioAutorizado; GISADataset.TipoControloAutRelRow tcarRow = null; tcarRow = (GISADataset.TipoControloAutRelRow)relacaoCA.cbTipoControloAutRel.SelectedItem; PersistencyHelper.VerifyRelExistencePreConcArguments pcArgs = new PersistencyHelper.VerifyRelExistencePreConcArguments(); IDbConnection conn = GisaDataSetHelper.GetConnection(); try { conn.Open(); DBAbstractDataLayer.DataAccessRules.NivelRule.Current.LoadNivelByControloAut(cadRow.IDControloAut, GisaDataSetHelper.GetInstance(), conn); } catch (Exception ex) { Trace.WriteLine(ex); throw ex; } finally { conn.Close(); } string errorTitle = "Erro ao estabelecer relação"; if (! mInEditMode) { // Garantir que uma EP não é relacionada com ela própria. if (cadRow.ControloAutRow.ID == ContextControloAut.ID) { MessageBox.Show("Não é permitido relacionar uma notícia de autoridade consigo própria.", errorTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } // validar que a relação que pretendemos criar ainda não existe if (GisaDataSetHelper.GetInstance().ControloAutRel.Select(string.Format("((IDControloAut={0} AND IDControloAutAlias={1}) OR (IDControloAut={1} AND IDControloAutAlias={0})) AND IDTipoRel = {2:d}", cadRow.ControloAutRow.ID, ContextControloAut.ID, tcarRow.ID)).Length > 0 || (tcarRow.ID == Convert.ToInt64(TipoControloAutRel.Hierarquica) && GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1} OR ID={1} AND IDUpper={0}", cadRow.ControloAutRow.GetNivelControloAutRows()[0].NivelRow.ID, ContextControloAut.GetNivelControloAutRows()[0].NivelRow.ID)).Length > 0)) { MessageBox.Show("Não é permitida mais que uma relação do mesmo tipo " + Environment.NewLine + "entre as mesmas duas entidades produtoras.", errorTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } //Agir de forma diferente conforme seja uma relação hierarquica ou seja uma relação de outro qualquer tipo if (tcarRow.ID == Convert.ToInt64(TipoControloAutRel.Hierarquica)) { // Carregar informação do Nível do CA com que se pretende estabelecer esta relação GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection()); try { DBAbstractDataLayer.DataAccessRules.FRDRule.Current.LoadRetrieveSelectionData(GisaDataSetHelper.GetInstance(), cadRow.IDControloAut, ho.Connection); DBAbstractDataLayer.DataAccessRules.FRDRule.Current.LoadFRD(GisaDataSetHelper.GetInstance(), ContextControloAut.GetNivelControloAutRows()[0].NivelRow.ID, ho.Connection); } finally { ho.Dispose(); } long tnrID = 0; tnrID = ((TipoNivelRelacionado.PossibleSubNivel)relacaoCA.cbTipoNivel.SelectedItem).SubIDTipoNivelRelacionado; GISADataset.RelacaoHierarquicaRow rhRow = null; rhRow = GisaDataSetHelper.GetInstance().RelacaoHierarquica.NewRelacaoHierarquicaRow(); rhRow.IDUpper = cadRow.ControloAutRow.GetNivelControloAutRows()[0].NivelRow.ID; rhRow.ID = ContextControloAut.GetNivelControloAutRows()[0].NivelRow.ID; rhRow.IDTipoNivelRelacionado = tnrID; // Guardar datas rhRow.InicioAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoInicio.ValueYear); rhRow.InicioMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoInicio.ValueMonth); rhRow.InicioDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoInicio.ValueDay); rhRow.FimAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoFim.ValueYear); rhRow.FimMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoFim.ValueMonth); rhRow.FimDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoFim.ValueDay); rhRow.Descricao = relacaoCA.txtDescricao.Text; //rhRow.isDeleted = 0; GisaDataSetHelper.GetInstance().RelacaoHierarquica.AddRelacaoHierarquicaRow(rhRow); pcArgs.ID = rhRow.ID; pcArgs.IDUpper = rhRow.IDUpper; pcArgs.IDTipoRel = rhRow.IDTipoNivelRelacionado; pcArgs.isCARRow = false; // actualizar permissões implícitas var postSaveAction = new PostSaveAction(); PersistencyHelper.UpdatePermissionsPostSaveArguments args = new PersistencyHelper.UpdatePermissionsPostSaveArguments(); postSaveAction.args = args; postSaveAction.postSaveDelegate = delegate(PersistencyHelper.PostSaveArguments postSaveArgs) { if (!postSaveArgs.cancelAction && ContextControloAut.RowState != DataRowState.Detached && pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError) { if (this.parent.GetType() == typeof(MasterPanelControloAut)) { ((MasterPanelControloAut)this.parent).CurrentContext.RaiseRegisterModificationEvent(this.ContextControloAut); var caRegRow = GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao.Cast<GISADataset.ControloAutDataDeDescricaoRow>().Single(r => r.RowState == DataRowState.Added); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao, new GISADataset.ControloAutDataDeDescricaoRow[] { caRegRow }, postSaveArgs.tran); var frdRow = rhRow.NivelRowByNivelRelacaoHierarquica.GetFRDBaseRows().SingleOrDefault(); if (frdRow == null) { var tipoFRD = (GISADataset.TipoFRDBaseRow)(GisaDataSetHelper.GetInstance().TipoFRDBase.Select("ID=" + DomainValuesHelper.stringifyEnumValue(TipoFRDBase.FRDOIRecolha))[0]); frdRow = GisaDataSetHelper.GetInstance().FRDBase.AddFRDBaseRow(rhRow.NivelRowByNivelRelacaoHierarquica, tipoFRD, "", "", new byte[] { }, 0); var dp = GisaDataSetHelper.GetInstance().SFRDDatasProducao.AddSFRDDatasProducaoRow(frdRow, "", "", "", "", false, "", "", "", "", false, new byte[] { }, 0); var ce = GisaDataSetHelper.GetInstance().SFRDConteudoEEstrutura.AddSFRDConteudoEEstruturaRow(frdRow, "", "", new byte[] { }, 0); var c = GisaDataSetHelper.GetInstance().SFRDContexto.AddSFRDContextoRow(frdRow, "", "", "", false, new byte[] { }, 0); var da = GisaDataSetHelper.GetInstance().SFRDDocumentacaoAssociada.AddSFRDDocumentacaoAssociadaRow(frdRow, "", "", "", "", new byte[] { }, 0); var ds = GisaDataSetHelper.GetInstance().SFRDDimensaoSuporte.AddSFRDDimensaoSuporteRow(frdRow, "", new byte[] { }, 0); var ng = GisaDataSetHelper.GetInstance().SFRDNotaGeral.AddSFRDNotaGeralRow(frdRow, "", new byte[] { }, 0); var CurrentSFRDAvaliacao = GisaDataSetHelper.GetInstance().SFRDAvaliacao.NewSFRDAvaliacaoRow(); CurrentSFRDAvaliacao.FRDBaseRow = frdRow; CurrentSFRDAvaliacao.IDPertinencia = 1; CurrentSFRDAvaliacao.IDDensidade = 1; CurrentSFRDAvaliacao.IDSubdensidade = 1; CurrentSFRDAvaliacao.Publicar = false; CurrentSFRDAvaliacao.Observacoes = ""; CurrentSFRDAvaliacao.AvaliacaoTabela = false; GisaDataSetHelper.GetInstance().SFRDAvaliacao.AddSFRDAvaliacaoRow(CurrentSFRDAvaliacao); var condA = GisaDataSetHelper.GetInstance().SFRDCondicaoDeAcesso.AddSFRDCondicaoDeAcessoRow(frdRow, "", "", "", "", new byte[] { }, 0); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().FRDBase, new DataRow[] { frdRow }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDDatasProducao, new DataRow[] { dp }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDConteudoEEstrutura, new DataRow[] { ce }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDContexto, new DataRow[] { c }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDDocumentacaoAssociada, new DataRow[] { da }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDDimensaoSuporte, new DataRow[] { ds }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDNotaGeral, new DataRow[] { ng }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDAvaliacao, new DataRow[] { CurrentSFRDAvaliacao }, postSaveArgs.tran); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().SFRDCondicaoDeAcesso, new DataRow[] { condA }, postSaveArgs.tran); } var nvlRegRow = RecordRegisterHelper .CreateFRDBaseDataDeDescricaoRow(frdRow, caRegRow.TrusteeUserRowByTrusteeUserControloAutDataDeDescricao, caRegRow.TrusteeUserRowByTrusteeUserControloAutDataDeDescricaoAuthority, caRegRow.DataAutoria); nvlRegRow.DataEdicao = caRegRow.DataEdicao; nvlRegRow.IDTipoNivelRelacionado = rhRow.IDTipoNivelRelacionado; GisaDataSetHelper.GetInstance().FRDBaseDataDeDescricao.AddFRDBaseDataDeDescricaoRow(nvlRegRow); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().FRDBaseDataDeDescricao, GisaDataSetHelper.GetInstance().FRDBaseDataDeDescricao.Cast<GISADataset.FRDBaseDataDeDescricaoRow>().Where(r => r.RowState == DataRowState.Added).ToArray(), postSaveArgs.tran); } } }; PersistencyHelper.save(ValidateCreateRel, pcArgs, postSaveAction); PersistencyHelper.cleanDeletedData(); if (ContextControloAut.RowState == DataRowState.Detached) { MessageBox.Show("Não é possível estabelecer a relação uma vez que a notícia de autoridade " + System.Environment.NewLine + "selecionada no painel superior foi apagada por outro utilizador.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { if (pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.RelationAlreadyExists) { MessageBox.Show("Não é permitida mais que uma relação do mesmo tipo entre as mesmas duas entidades produtoras.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else if (pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.CyclicRelation) { MessageBox.Show("Prestes a criar um conjunto de relações cíclicas.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else if (pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.CADeleted) { MessageBox.Show("Não é possível estabelecer a relação uma vez que uma das notícias de autoridade " + System.Environment.NewLine + "foi apagada por outro utilizador.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { GISA.Search.Updater.updateProdutor(new List<string>() { cadRow.ControloAutRow.ID.ToString(), ContextControloAut.ID.ToString()}); GISA.Search.Updater.updateNivelDocumentalComProdutores(cadRow.ControloAutRow.GetNivelControloAutRows()[0].ID); } } } else { GISADataset.ControloAutRelRow carRow = null; carRow = GisaDataSetHelper.GetInstance().ControloAutRel.NewControloAutRelRow(); carRow.IDControloAut = cadRow.ControloAutRow.ID; carRow.IDControloAutAlias = ContextControloAut.ID; carRow.IDTipoRel = tcarRow.ID; // Guardar datas carRow.InicioAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoInicio.ValueYear); carRow.InicioMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoInicio.ValueMonth); carRow.InicioDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoInicio.ValueDay); carRow.FimAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoFim.ValueYear); carRow.FimMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoFim.ValueMonth); carRow.FimDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoFim.ValueDay); carRow.Descricao = relacaoCA.txtDescricao.Text; GisaDataSetHelper.GetInstance().ControloAutRel.AddControloAutRelRow(carRow); pcArgs.ID = carRow.IDControloAut; pcArgs.IDUpper = carRow.IDControloAutAlias; pcArgs.IDTipoRel = carRow.IDTipoRel; pcArgs.isCARRow = true; var postSaveAction = new PostSaveAction(); PersistencyHelper.UpdatePermissionsPostSaveArguments args = new PersistencyHelper.UpdatePermissionsPostSaveArguments(); postSaveAction.args = args; postSaveAction.postSaveDelegate = delegate(PersistencyHelper.PostSaveArguments postSaveArgs) { if (!postSaveArgs.cancelAction && ContextControloAut.RowState != DataRowState.Detached && pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError) { if (this.parent.GetType() == typeof(MasterPanelControloAut)) { ((MasterPanelControloAut)this.parent).CurrentContext.RaiseRegisterModificationEvent(this.ContextControloAut); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao, GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao.Cast<GISADataset.ControloAutDataDeDescricaoRow>().Where(r => r.RowState == DataRowState.Added).ToArray(), postSaveArgs.tran); } } }; PersistencyHelper.save(ValidateCreateRel, pcArgs, postSaveAction); PersistencyHelper.cleanDeletedData(); if (ContextControloAut.RowState == DataRowState.Detached) { MessageBox.Show("Não é possível estabelecer a relação uma vez que a notícia de autoridade " + System.Environment.NewLine + "selecionada no painel superior foi apagada por outro utilizador.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { if (pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.RelationAlreadyExists) { MessageBox.Show("Não é permitida mais que uma relação do mesmo tipo entre as mesmas duas entidades produtoras.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { GISA.Search.Updater.updateProdutor(new List<string>() { carRow.IDControloAut.ToString(), carRow.IDControloAutAlias.ToString() }); } } } } else // edição { //Agir de forma diferente conforme seja uma relação hierarquica ou seja uma relação de outro qualquer tipo if (tcarRow.ID == Convert.ToInt64(TipoControloAutRel.Hierarquica)) { long tnrID = 0; tnrID = ((TipoNivelRelacionado.PossibleSubNivel)relacaoCA.cbTipoNivel.SelectedItem).SubIDTipoNivelRelacionado; GISADataset.RelacaoHierarquicaRow rhRow = null; rhRow = (GISADataset.RelacaoHierarquicaRow)ContextRel; // Guardar tipo de nivel rhRow.IDTipoNivelRelacionado = tnrID; // Guardar datas rhRow.InicioAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoInicio.ValueYear); rhRow.InicioMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoInicio.ValueMonth); rhRow.InicioDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoInicio.ValueDay); rhRow.FimAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoFim.ValueYear); rhRow.FimMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoFim.ValueMonth); rhRow.FimDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoFim.ValueDay); // Guardar descrição rhRow.Descricao = relacaoCA.txtDescricao.Text; var postSaveAction = new PostSaveAction(); PersistencyHelper.UpdatePermissionsPostSaveArguments args = new PersistencyHelper.UpdatePermissionsPostSaveArguments(); postSaveAction.args = args; postSaveAction.postSaveDelegate = delegate(PersistencyHelper.PostSaveArguments postSaveArgs) { if (!postSaveArgs.cancelAction && ContextControloAut.RowState != DataRowState.Detached && pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError) { if (this.parent.GetType() == typeof(MasterPanelControloAut)) { ((MasterPanelControloAut)this.parent).CurrentContext.RaiseRegisterModificationEvent(this.ContextControloAut); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao, GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao.Cast<GISADataset.ControloAutDataDeDescricaoRow>().Where(r => r.RowState == DataRowState.Added).ToArray(), postSaveArgs.tran); } } }; PersistencyHelper.SaveResult successfulSave = PersistencyHelper.save(postSaveAction); PersistencyHelper.cleanDeletedData(); if (successfulSave == PersistencyHelper.SaveResult.successful) UpdateCA(rhRow); } else { GISADataset.ControloAutRelRow carRow = null; carRow = (GISADataset.ControloAutRelRow)ContextRel; // Actualização de uma relação previamente existente carRow["IDTipoRel"] = ((GISADataset.TipoControloAutRelRow)relacaoCA.cbTipoControloAutRel.SelectedItem).ID; // guardar datas carRow.InicioAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoInicio.ValueYear); carRow.InicioMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoInicio.ValueMonth); carRow.InicioDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoInicio.ValueDay); carRow.FimAno = GISA.Utils.GUIHelper.ReadYear(relacaoCA.dtRelacaoFim.ValueYear); carRow.FimMes = GISA.Utils.GUIHelper.ReadMonth(relacaoCA.dtRelacaoFim.ValueMonth); carRow.FimDia = GISA.Utils.GUIHelper.ReadDay(relacaoCA.dtRelacaoFim.ValueDay); carRow.Descricao = relacaoCA.txtDescricao.Text; var postSaveAction = new PostSaveAction(); PersistencyHelper.UpdatePermissionsPostSaveArguments args = new PersistencyHelper.UpdatePermissionsPostSaveArguments(); postSaveAction.args = args; postSaveAction.postSaveDelegate = delegate(PersistencyHelper.PostSaveArguments postSaveArgs) { if (!postSaveArgs.cancelAction && ContextControloAut.RowState != DataRowState.Detached && pcArgs.CreateEditResult == PersistencyHelper.VerifyRelExistencePreConcArguments.CreateEditRelationErrors.NoError) { if (this.parent.GetType() == typeof(MasterPanelControloAut)) { ((MasterPanelControloAut)this.parent).CurrentContext.RaiseRegisterModificationEvent(this.ContextControloAut); PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao, GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao.Cast<GISADataset.ControloAutDataDeDescricaoRow>().Where(r => r.RowState == DataRowState.Added).ToArray(), postSaveArgs.tran); } } }; PersistencyHelper.SaveResult successfulSave = PersistencyHelper.save(postSaveAction); PersistencyHelper.cleanDeletedData(); if (successfulSave == PersistencyHelper.SaveResult.successful) UpdateCA(carRow); } } //TODO: PARA ALGUMAS DAS SEGUINTES VALIDACOES SERÁ NECESSÁRIO TRAZER PARA DENTRO DESTE FORM UMA GRANDE PARTE DA LOGICA EXISTENTE FORA DELE, NOMEADAMENTE A NOÇÃO DE SE ESTE FORM ESTÁ A SER UTILIZADO NA CRIAÇÃO OU NA EDIÇÃO DE UMA DADA RELAÇÃO //ToDo: validar que as datas da relação não vão para alem das datas de existencia de ambos os níveis (superior e inferior) //ToDo: validar que o tipo de nivel escolhido está de acordo com os tipos de nivel subordinados return true; }
private void PutControloAutRelInTreeView(GISADataset.ControloAutRelRow carRow, GISADataset.ControloAutDicionarioRow ControloAutDicionario) { PutControloAutRelInTreeView(carRow, ControloAutDicionario, true); }
public void RepopulateThesaurus(GISADataset.ControloAutRelRow newCarRows) { RepopulateThesaurus(newCarRows, false); }
public void RegisterNode(TreeNode Node, GISADataset.ControloAutRelRow ControloAutRel, GISADataset.ControloAutDicionarioRow ControloAutDicionario, bool selectIt) { RegisterNode(Node, ControloAutDicionario.DicionarioRow.Termo, ControloAutRel, selectIt); }
public void RegisterNode(TreeNode Node, GISADataset.ControloAutRelRow ControloAutRel, GISADataset.ControloAutDicionarioRow ControloAutDicionario) { RegisterNode(Node, ControloAutRel, ControloAutDicionario, true); }
private void btnAdd_Click(object sender, EventArgs e) { if (CurrentControloAut.RowState == DataRowState.Detached) { MessageBox.Show("A notícia de autoridade selecionada como contexto foi " + System.Environment.NewLine + "apagada por outro utilizador e por esse motivo não pode ser editada.", "Edição de Notícia de Autoridade", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } FormPickControloAut frmPick = new FormPickControloAut(CurrentControloAut); frmPick.Text = "Notícia de autoridade - Pesquisar entidades produtoras"; frmPick.caList.AllowedNoticiaAut(TipoNoticiaAut.EntidadeProdutora); frmPick.caList.ReloadList(); if (frmPick.caList.Items.Count > 0) { frmPick.caList.SelectItem(frmPick.caList.Items[0]); } GISADataset.ControloAutRow caRow = null; GISADataset.ControloAutRelRow carRow = null; GISADataset.TipoControloAutRelRow tcarRow = null; switch (frmPick.ShowDialog()) { case DialogResult.OK: foreach (ListViewItem li in frmPick.caList.SelectedItems) { caRow = ((GISADataset.ControloAutDicionarioRow)li.Tag).ControloAutRow; // Proteger contra relações repetidas string query = string.Format("({0} OR {1}) AND IDTipoRel = {2}", GetRelConstraint(caRow, CurrentControloAut), GetRelConstraint(CurrentControloAut, caRow), System.Enum.Format(typeof(TipoControloAutRel), TipoControloAutRel.Instituicao, "D")); if ((GisaDataSetHelper.GetInstance().ControloAutRel.Select(query)).Length == 0) { tcarRow = (GISADataset.TipoControloAutRelRow)(GisaDataSetHelper.GetInstance().TipoControloAutRel.Select("ID=" + System.Enum.Format(typeof(TipoControloAutRel), TipoControloAutRel.Instituicao, "D"))[0]); carRow = GisaDataSetHelper.GetInstance().ControloAutRel.NewControloAutRelRow(); carRow.ControloAutRowByControloAutControloAutRel = CurrentControloAut; carRow.ControloAutRowByControloAutControloAutRelAlias = caRow; carRow.TipoControloAutRelRow = tcarRow; carRow["Descricao"] = DBNull.Value; carRow["InicioAno"] = DBNull.Value; carRow["InicioMes"] = DBNull.Value; carRow["InicioDia"] = DBNull.Value; carRow["FimAno"] = DBNull.Value; carRow["FimMes"] = DBNull.Value; carRow["FimDia"] = DBNull.Value; GisaDataSetHelper.GetInstance().ControloAutRel.AddControloAutRelRow(carRow); PersistencyHelper.VerifyRelExistencePreConcArguments pcArgs = new PersistencyHelper.VerifyRelExistencePreConcArguments(); pcArgs.ID = caRow.ID; pcArgs.IDUpper = CurrentControloAut.ID; pcArgs.IDTipoRel = Convert.ToInt64(TipoControloAutRel.Instituicao); PersistencyHelper.SaveResult successfulSave = PersistencyHelper.save(GetRelPanelCAControl, pcArgs); PersistencyHelper.cleanDeletedData(); if (carRow.RowState == DataRowState.Detached) { MessageBox.Show("Não foi possível estabelecer a relação uma vez que a notícia de autoridade " + System.Environment.NewLine + "que pretende associar foi apagada por outro utilizador.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } else { AddIdentidadeInstituicao(carRow); // registar inserção ((frmMain)TopLevelControl).CurrentContext.RaiseRegisterModificationEvent(CurrentControloAut); if (successfulSave == PersistencyHelper.SaveResult.successful) { UpdateCA(CurrentControloAut); UpdateCA(caRow); } } } else { MessageBox.Show("A relação que pretende adicionar já existe.", "Erro ao estabelecer relação", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } break; case DialogResult.Cancel: break; } }