コード例 #1
0
        private void RetrieveSelection(FormControloAutRel frm, DataRow relRow)
        {
            try
            {
                if (relRow != null)                 // edição
                {
                    frm.SetEditMode();
                }

                frm.ShowDialog();

                GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection());
                try
                {
                    LoadData(CurrentControloAut, ho.Connection);
                    ModelToView();
                }
                finally
                {
                    ho.Dispose();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                throw ex;
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 // O parametro relRow tanto poderá ser um controloAutRelRow como um RelacaoHierarquicaRow
 private void RetrieveSelection(FormControloAutRel frm)
 {
     RetrieveSelection(frm, null);
 }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            ((frmMain)TopLevelControl).EnterWaitMode();
            try
            {
                // se após uma gravação o contexto ficar inválido
                if (CurrentControloAut.RowState == DataRowState.Detached || CurrentControloAut.isDeleted == 1)
                {
                    MessageBox.Show("A notícia de autoridade que está a utilizar foi eliminada " + Environment.NewLine + "por outro utilizador não sendo por isso possível continuar a " + Environment.NewLine + "editá-la.", "Edição de Entidade Produtora", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                try
                {
                    GisaDataSetHelper.ManageDatasetConstraints(false);

                    IDbConnection conn = GisaDataSetHelper.GetConnection();
                    try
                    {
                        conn.Open();
                        LoadData(CurrentControloAut, conn);
                    }
                    finally
                    {
                        conn.Close();
                    }

                    GisaDataSetHelper.ManageDatasetConstraints(true);
                }
                catch (ConstraintException ex)
                {
                    Debug.Assert(false, ex.Message);
                }
            }
            finally
            {
                ((frmMain)TopLevelControl).LeaveWaitMode();
            }

            FormControloAutRel frm = null;

            ((frmMain)TopLevelControl).EnterWaitMode();
            try
            {
                frm = new FormControloAutRel(CurrentControloAut, ((frmMain)TopLevelControl).MasterPanel);
                frm.caList.AllowedNoticiaAut(TipoNoticiaAut.EntidadeProdutora);
                frm.caList.ReloadList();
                frm.caList.txtFiltroDesignacao.Clear();

                if (frm.caList.Items.Count > 0)
                {
                    frm.caList.SelectItem(frm.caList.Items[0]);
                }
            }
            finally
            {
                ((frmMain)TopLevelControl).LeaveWaitMode();
            }

            RetrieveSelection(frm);
        }
コード例 #6
0
		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);
				}
			}
		}
コード例 #7
0
ファイル: PanelCARelacoes.cs プロジェクト: aureliopires/gisa
		private void RetrieveSelection(FormControloAutRel frm, DataRow relRow)
		{
			try
			{
				if (relRow != null) // edição
					frm.SetEditMode();

                frm.ShowDialog();

				GisaDataSetHelper.HoldOpen ho = new GisaDataSetHelper.HoldOpen(GisaDataSetHelper.GetConnection());
				try
				{
					LoadData(CurrentControloAut, ho.Connection);
					ModelToView();
				}
				finally
				{
					ho.Dispose();
				}
			}
			catch (Exception ex)
			{
				Trace.WriteLine(ex);
				throw ex;
			}
		}
コード例 #8
0
ファイル: PanelCARelacoes.cs プロジェクト: aureliopires/gisa
		// O parametro relRow tanto poderá ser um controloAutRelRow como um RelacaoHierarquicaRow
		private void RetrieveSelection(FormControloAutRel frm)
		{
			RetrieveSelection(frm, null);
		}
コード例 #9
0
ファイル: PanelCARelacoes.cs プロジェクト: aureliopires/gisa
		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);
		}
コード例 #10
0
ファイル: PanelCARelacoes.cs プロジェクト: aureliopires/gisa
		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			((frmMain)TopLevelControl).EnterWaitMode();
			try
			{
				// se após uma gravação o contexto ficar inválido
				if (CurrentControloAut.RowState == DataRowState.Detached || CurrentControloAut.isDeleted == 1)
				{
					MessageBox.Show("A notícia de autoridade que está a utilizar foi eliminada " + Environment.NewLine + "por outro utilizador não sendo por isso possível continuar a " + Environment.NewLine + "editá-la.", "Edição de Entidade Produtora", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
				}

				try
				{
					GisaDataSetHelper.ManageDatasetConstraints(false);

					IDbConnection conn = GisaDataSetHelper.GetConnection();
					try
					{
						conn.Open();
						LoadData(CurrentControloAut, conn);
					}
					finally
					{
						conn.Close();
					}

					GisaDataSetHelper.ManageDatasetConstraints(true);
				}
				catch (ConstraintException ex)
				{
					Debug.Assert(false, ex.Message);
				}
			}
			finally
			{
				((frmMain)TopLevelControl).LeaveWaitMode();
			}

			FormControloAutRel frm = null;
			((frmMain)TopLevelControl).EnterWaitMode();
			try
			{
                frm = new FormControloAutRel(CurrentControloAut, ((frmMain)TopLevelControl).MasterPanel);
				frm.caList.AllowedNoticiaAut(TipoNoticiaAut.EntidadeProdutora);
				frm.caList.ReloadList();
				frm.caList.txtFiltroDesignacao.Clear();

				if (frm.caList.Items.Count > 0)
					frm.caList.SelectItem(frm.caList.Items[0]);
			}
			finally
			{
				((frmMain)TopLevelControl).LeaveWaitMode();
			}

			RetrieveSelection(frm);
		}