Esempio n. 1
0
		protected override void AcceptContents(object Value)
		{
			GISADataset.ControloAutRow ControloAutRow = (GISADataset.ControloAutRow)Value;

			if (FRDBase != null)
			{
				// Carregar nivel do CA largado

				IDbConnection conn = GisaDataSetHelper.GetConnection();
				try
				{
					conn.Open();
					DBAbstractDataLayer.DataAccessRules.NivelRule.Current.LoadNivelByControloAut(ControloAutRow.ID, GisaDataSetHelper.GetInstance(), conn);
				}
				finally
				{
					conn.Close();
				}

				if (IsValidRelacaoHierarquica(ControloAutRow))
				{
					// Apresentar form que permita escolher a data da relação
					FormRelacaoHierarquica frmRh = new FormRelacaoHierarquica();
					// Pode-se obter a primeira relação encontrada para efeitos de determinação 
					// do tipo de nível uma vez que o tipo de nível dos níveis documentais nunca se alterará
					frmRh.relacaoNvl.TipoNivelRelacionadoRow = TipoNivelRelacionado.GetPrimeiraRelacaoEncontrada(this.FRDBase.NivelRow).TipoNivelRelacionadoRow;
					frmRh.relacaoNvl.ContextNivelRow = ControloAutRow.GetNivelControloAutRows()[0].NivelRow;
					if (frmRh.ShowDialog() == DialogResult.Cancel)
					{
						return;
					}

					if (GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", this.FRDBase.NivelRow.ID, ControloAutRow.GetNivelControloAutRows()[0].NivelRow.ID), "", DataViewRowState.Deleted).Length > 0)
					{

						GisaDataSetHelper.GetInstance().RelacaoHierarquica.Select(string.Format("ID={0} AND IDUpper={1}", this.FRDBase.NivelRow.ID, ControloAutRow.GetNivelControloAutRows()[0].NivelRow.ID), "", DataViewRowState.Deleted)[0].AcceptChanges();
					}

					GISADataset.RelacaoHierarquicaRow rhRow = null;
					rhRow = GisaDataSetHelper.GetInstance().RelacaoHierarquica.NewRelacaoHierarquicaRow();
					TempRelacaoHierarquica = rhRow;

					rhRow.ID = this.FRDBase.NivelRow.ID;
					rhRow.IDUpper = ControloAutRow.GetNivelControloAutRows()[0].NivelRow.ID;
					rhRow.IDTipoNivelRelacionado = TipoNivelRelacionado.GetTipoNivelRelacionadoDaPrimeiraRelacaoEncontrada(this.FRDBase.NivelRow).ID;
					rhRow.Descricao = frmRh.relacaoNvl.txtDescricao.Text;
					rhRow.InicioAno = frmRh.relacaoNvl.dtRelacaoInicio.ValueYear;
					rhRow.InicioMes = frmRh.relacaoNvl.dtRelacaoInicio.ValueMonth;
					rhRow.InicioDia = frmRh.relacaoNvl.dtRelacaoInicio.ValueDay;
					rhRow.FimAno = frmRh.relacaoNvl.dtRelacaoFim.ValueYear;
					rhRow.FimMes = frmRh.relacaoNvl.dtRelacaoFim.ValueMonth;
					rhRow.FimDia = frmRh.relacaoNvl.dtRelacaoFim.ValueDay;
					GisaDataSetHelper.GetInstance().RelacaoHierarquica.AddRelacaoHierarquicaRow(rhRow);

                    // no caso de se tratar de uma entidade produtora é necessário validar o código de referência do nivel documental do contexto
                    if (ControloAutRow.IDTipoNoticiaAut == (long)TipoNoticiaAut.EntidadeProdutora)
                    {
                        var argsPC = new PersistencyHelper.EnsureUniqueCodigoNivelPreConcArguments();
                        argsPC.rhRowID = rhRow.ID;
                        argsPC.rhRowIDUpper = rhRow.IDUpper;

                        var postSaveAction = new PostSaveAction();
                        PersistencyHelper.UpdatePermissionsPostSaveArguments args = new PersistencyHelper.UpdatePermissionsPostSaveArguments();
                        postSaveAction.args = args;

                        postSaveAction.postSaveDelegate = delegate(PersistencyHelper.PostSaveArguments postSaveArgs)
                        {
                            if (argsPC.successful)
                            {
                                if (this.parent == null)
                                    Debug.Assert(false, "CONTEXTO PARENT DEVE ESTAR DEFINIDO.");

                                if (this.parent.GetType() == typeof(MasterPanelSeries))
                                {
                                    ((MasterPanelSeries)this.parent).CurrentContext.RaiseRegisterModificationEvent(this.FRDBase);
                                    PersistencyHelperRule.Current.saveRows(GisaDataSetHelper.GetInstance().FRDBaseDataDeDescricao,
                                        GisaDataSetHelper.GetInstance().FRDBaseDataDeDescricao.Cast<GISADataset.FRDBaseDataDeDescricaoRow>().Where(r => r.RowState == DataRowState.Added).ToArray(), postSaveArgs.tran);
                                }
                            }
                        };

                        var result = PersistencyHelper.save(DelegatesHelper.verificaCodigosRepetidos, argsPC, postSaveAction, true);

                        if (result == PersistencyHelper.SaveResult.successful)
                        {
                            PersistencyHelper.cleanDeletedData();
                            GisaDataSetHelper.VisitControloAutDicionario(ControloAutRow, DisplayFormaAutorizada);
                            GISA.Search.Updater.updateNivelDocumental(this.FRDBase.NivelRow.ID);
                        }
                        else
                        {
                            if (argsPC.message.Length > 0)
                                MessageBox.Show(argsPC.message, "Adição", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }

					
				}
				else
				{
					MessageBox.Show("Não é possível a existência de items repetidos.", "Adição", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				}
			}
			else if (this.ControloAut != null)
			{
				Debug.Assert(false, "ORGANIC RELATIONS BETWEEN CAS NOT IMPLEMENTED. SHOULDN'T BE NEEDED");
			}
		}
Esempio n. 2
0
		private void btnEdit_Click(object sender, System.EventArgs e)
		{
			if (lstVwProdutores.SelectedItems.Count == 1 && lstVwProdutores.SelectedItems[0].Tag is GISADataset.RelacaoHierarquicaRow)
			{
				GISADataset.RelacaoHierarquicaRow rhRow = null;
				rhRow = (GISADataset.RelacaoHierarquicaRow)(lstVwProdutores.SelectedItems[0].Tag);

				// Apresentar form que permita editar a relação
				FormRelacaoHierarquica frmRh = new FormRelacaoHierarquica();
				frmRh.relacaoNvl.TipoNivelRelacionadoRow = rhRow.TipoNivelRelacionadoRow;
				frmRh.relacaoNvl.ContextNivelRow = rhRow.NivelRowByNivelRelacaoHierarquicaUpper;
				frmRh.relacaoNvl.txtDescricao.Text = GisaDataSetHelper.GetDBNullableText(rhRow, "Descricao");
				frmRh.relacaoNvl.dtRelacaoInicio.ValueYear = GisaDataSetHelper.GetDBNullableText(rhRow, "InicioAno");
				frmRh.relacaoNvl.dtRelacaoInicio.ValueMonth = GisaDataSetHelper.GetDBNullableText(rhRow, "InicioMes");
				frmRh.relacaoNvl.dtRelacaoInicio.ValueDay = GisaDataSetHelper.GetDBNullableText(rhRow, "InicioDia");
				frmRh.relacaoNvl.dtRelacaoFim.ValueYear = GisaDataSetHelper.GetDBNullableText(rhRow, "FimAno");
				frmRh.relacaoNvl.dtRelacaoFim.ValueMonth = GisaDataSetHelper.GetDBNullableText(rhRow, "FimMes");
				frmRh.relacaoNvl.dtRelacaoFim.ValueDay = GisaDataSetHelper.GetDBNullableText(rhRow, "FimDia");
				if (frmRh.ShowDialog() == DialogResult.Cancel)
					return;

				rhRow.Descricao = frmRh.relacaoNvl.txtDescricao.Text;
				rhRow.InicioAno = GISA.Utils.GUIHelper.ReadYear(frmRh.relacaoNvl.dtRelacaoInicio.ValueYear);
				rhRow.InicioMes = GISA.Utils.GUIHelper.ReadMonth(frmRh.relacaoNvl.dtRelacaoInicio.ValueMonth);
				rhRow.InicioDia = GISA.Utils.GUIHelper.ReadDay(frmRh.relacaoNvl.dtRelacaoInicio.ValueDay);
				rhRow.FimAno = GISA.Utils.GUIHelper.ReadYear(frmRh.relacaoNvl.dtRelacaoFim.ValueYear);
				rhRow.FimMes = GISA.Utils.GUIHelper.ReadMonth(frmRh.relacaoNvl.dtRelacaoFim.ValueMonth);
				rhRow.FimDia = GISA.Utils.GUIHelper.ReadDay(frmRh.relacaoNvl.dtRelacaoFim.ValueDay);
			}
			updateDatasRelacao(lstVwProdutores.SelectedItems[0]);
		}