Esempio n. 1
0
 private bool CreateDocumentoInterno(ref EntidadeInterna ei, long tnr)
 {
     bool cancel = false;
     FormAddNivel form = new FormAddNivel();
     form.IDTipoNivelRelacionado = tnr;
     if (ei != null)
     {
         form.txtDesignacao.Text = ei != null ? ((DocumentoGisa)ei).Titulo : "";
         if (tnr == TipoNivelRelacionado.SD)
             form.txtCodigo.Text = ei != null ? ((DocumentoGisa)ei).Codigo : "";
     }
     switch (form.ShowDialog())
     {
         case DialogResult.OK:
             var documento = new DocumentoGisa();
             documento.Tipo = tnr == (long)TipoNivelRelacionado.SD ? TipoEntidadeInterna.DocumentoSimples : TipoEntidadeInterna.DocumentoComposto;
             if (tnr == (long)TipoNivelRelacionado.SD)
                 documento.CopyProperties(this.correspDocumento);
             documento.Titulo = form.txtDesignacao.Text;
             documento.Codigo = form.txtCodigo.Text;
             ei = this.InternalEntitiesLst.AddInternalEntity(documento);
             break;
         case DialogResult.Cancel:
             cancel = true;
             break;
     }
     return cancel;
 }
Esempio n. 2
0
		private void EditNivel(FormAddNivel frm, GISADataset.NivelRow NivelRow)
		{
            GISADataset.TipoNivelRelacionadoRow tnrRow;
            if (NivelRow.IDTipoNivel == TipoNivel.LOGICO && GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select("ID="+NivelRow.ID.ToString()).Length == 0)
                tnrRow = GisaDataSetHelper.GetInstance().TipoNivelRelacionado.Cast<GISADataset.TipoNivelRelacionadoRow>().Single(r => r.ID == TipoNivelRelacionado.ED);
            else
                tnrRow = GisaDataSetHelper.GetInstance().RelacaoHierarquica.Cast<GISADataset.RelacaoHierarquicaRow>().First(r => r.ID == NivelRow.ID && r.RowState != DataRowState.Deleted).TipoNivelRelacionadoRow;

			string WindowTitle = string.Format("Editar {0}", tnrRow.Designacao);
			// Don't allow to edit a Nivel without a Controlo 
			// Autoridade using a form with Controlo Autoridade.
			// frm will only be of type FormNivelEstrutural if the
			// related administration option is set to "demand a ControloAutoridade"
			if (frm is FormNivelEstrutural && ! (NivelRow.CatCode.Trim().Equals("CA")))
			{
				MessageBox.Show("O nível selecionado não foi definido com " + "base numa entidade produtora." + System.Environment.NewLine + "Assim, para que este nível seja editável é necessário " + "que a aplicação esteja " + System.Environment.NewLine + "configurada para lidar com níveis não controlados.", WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
				return;
			}
			else if (! (frm is FormNivelEstrutural) && ! (NivelRow.CatCode.Trim().Equals("NVL")))
			{
				MessageBox.Show("O nível selecionado foi definido com " + "base numa entidade produtora." + System.Environment.NewLine + "Assim, para que este nível seja editável é necessário " + "que a aplicação esteja " + System.Environment.NewLine + "configurada para lidar com níveis controlados.", WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
				return;
			}

			frm.Text = WindowTitle;
			frm.txtCodigo.Text = NivelRow.Codigo;
			frm.txtDesignacao.Text = Nivel.GetDesignacao(NivelRow);
			// se se tratar de uma série ou subsérie o código será sempre automático
			if (tnrRow.ID == TipoNivelRelacionado.SR || tnrRow.ID == TipoNivelRelacionado.SSR)
				frm.txtCodigo.Enabled = false;

			frm.LoadData();

			if (NivelRow.TipoNivelRow.ID != TipoNivel.LOGICO)
			{
				// populate controls with data so that it can be edited

				if (frm is FormNivelEstrutural)
				{
                    FormNivelEstrutural tempWith1 = (FormNivelEstrutural)frm;
					if (NivelRow.CatCode.Trim().Equals("CA"))
					{
						tempWith1.caList.txtFiltroDesignacao.Text = tempWith1.txtDesignacao.Text;
                        tempWith1.caList.ReloadList();
						tempWith1.chkControloAut = true;
					}
					else if (NivelRow.CatCode.Trim().Equals("NVL"))
						tempWith1.chkControloAut = false;
				}
			}

			// show form and receive user feedback
			switch (frm.ShowDialog())
			{
				case DialogResult.OK:
				Trace.WriteLine("A editar nível...");
					GISADataset.NivelDesignadoRow ndRow = null;
					
					// Um Nivel documental deve ter obrigatoriamente um NivelDesignado.
                    Debug.Assert(NivelRow.GetNivelDesignadoRows().Length > 0);
					ndRow = NivelRow.GetNivelDesignadoRows()[0];
                    
                    NivelRow.Codigo = frm.txtCodigo.Text;
                    ndRow.Designacao = frm.txtDesignacao.Text;

                    // registar a edição do item selecionado
                    if (NivelRow.IDTipoNivel != TipoNivel.LOGICO)
                        CurrentContext.RaiseRegisterModificationEvent(NivelRow.GetFRDBaseRows()[0]);

					PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments pcArgs = new PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments();
					pcArgs.nRowID = NivelRow.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 (NivelRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica().Length > 0)
					{
						pcArgs.rhRowID = NivelRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].ID;
						pcArgs.rhRowIDUpper = NivelRow.GetRelacaoHierarquicaRowsByNivelRelacaoHierarquica()[0].IDUpper;
					}
					pcArgs.testOnlyWithinNivel = true;

                    PersistencyHelper.SaveResult successfulSave = PersistencyHelper.save(DelegatesHelper.ensureUniqueCodigo, pcArgs);
					if (! pcArgs.successful)
						MessageBox.Show(pcArgs.message, "Criação de 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(NivelRow.ID.ToString());
                            GISA.Search.Updater.updateNivelDocumental(IDNiveis);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.ToString());
                            throw;
                        }
                        finally
                        {
                            ho.Dispose();
                        }
                    }

                    PersistencyHelper.cleanDeletedData(PersistencyHelper.determinaNuvem("RelacaoHierarquica"));

					// 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 (! (NivelRow.RowState == DataRowState.Detached))
					{
                        if (this.nivelNavigator1.PanelToggleState == NivelNavigator.ToggleState.Estrutural)
							this.nivelNavigator1.UpdateSelectedNodeName(Nivel.GetDesignacao(NivelRow));
						else
                            this.nivelNavigator1.UpdateSelectedListItemName(Nivel.GetDesignacao(NivelRow));
					}

					// Forçar a gravação do documento
					CurrentContext.SetNivelEstrututalDocumental(null);
					CurrentContext.SetNivelEstrututalDocumental(NivelRow);
					break;
			}
		}