Ejemplo n.º 1
0
		protected override void AddTrustee()
		{
            GISADataset.TrusteeRow truRow = null;
			GISADataset.TrusteeUserRow usrRow = null;

			FormCreateTrustee form = new FormCreateTrustee();
			form.Text = "Novo utilizador";
			switch (form.ShowDialog())
			{
				case DialogResult.OK:
                    ((frmMain)TopLevelControl).EnterWaitMode();
					truRow = GisaDataSetHelper.GetInstance().Trustee.NewTrusteeRow();
					truRow.Name = form.txtTrusteeName.Text;
					truRow.Description = string.Empty;
					truRow.CatCode = "USR";
					truRow.BuiltInTrustee = false;
					truRow.IsActive = true;
					truRow.Versao = new byte[]{};
					truRow.isDeleted = 0;
					usrRow = GisaDataSetHelper.GetInstance().TrusteeUser.NewTrusteeUserRow();
					usrRow.Password = "";
					usrRow.FullName = "";
					usrRow.IsAuthority = false;
					usrRow["IDTrusteeUserDefaultAuthority"] = DBNull.Value;
					usrRow.Versao = new byte[]{};
					usrRow.isDeleted = 0;
					usrRow.TrusteeRow = truRow;

                    // selecionar o grupo "TODOS"
                    GISADataset.TrusteeGroupRow tgRow = (GISADataset.TrusteeGroupRow)(((GISADataset.TrusteeRow)(GisaDataSetHelper.GetInstance().Trustee.Select("Name='ACESSO_COMPLETO'")[0])).GetTrusteeGroupRows()[0]);

                    // incluir o novo utilizador no grupo "TODOS" por omissão
					GisaDataSetHelper.GetInstance().Trustee.AddTrusteeRow(truRow);
					GisaDataSetHelper.GetInstance().TrusteeUser.AddTrusteeUserRow(usrRow);
					GisaDataSetHelper.GetInstance().UserGroups.AddUserGroupsRow(usrRow, tgRow, new byte[]{}, 0);

					PersistencyHelper.CreateTrusteePreConcArguments ctpca = new PersistencyHelper.CreateTrusteePreConcArguments();
					ctpca.truRowID = truRow.ID;
					ctpca.usrRowID = usrRow.ID;

					Trace.WriteLine("A criar utilizador...");

                    PersistencyHelper.save(AddTrusteeIfUsernameDoesntExist, ctpca);
					PersistencyHelper.cleanDeletedData();

					if (! ctpca.successful)
					{
						MessageBox.Show("Este nome já existe atribuído a um utilizador ou grupo, " + Environment.NewLine + "por favor escolha outro nome.", form.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
						UpdateTrustees(null);
					}
					else
					{
                        // actualizar interface
						UpdateTrustees(truRow);
					}

                    ((frmMain)TopLevelControl).LeaveWaitMode();
                    break;
				case DialogResult.Cancel:
				break;
			}
		}
Ejemplo n.º 2
0
		protected override void AddTrustee()
		{
			GISADataset.TrusteeRow truRow = null;
			GISADataset.TrusteeGroupRow grpRow = null;

			FormCreateTrustee form = new FormCreateTrustee();
			form.Text = "Novo grupo de utilizadores";
			switch (form.ShowDialog())
			{
				case DialogResult.OK:
					truRow = GisaDataSetHelper.GetInstance().Trustee.NewTrusteeRow();
					truRow.Name = form.txtTrusteeName.Text;
					truRow.Description = string.Empty;
					truRow.CatCode = "GRP";
					truRow.BuiltInTrustee = false;
					truRow.IsActive = true;
					truRow.Versao = new byte[]{};
					truRow.isDeleted = 0;
					grpRow = GisaDataSetHelper.GetInstance().TrusteeGroup.NewTrusteeGroupRow();
					grpRow.Versao = new byte[]{};
					grpRow.isDeleted = 0;
					grpRow.TrusteeRow = truRow;

					GisaDataSetHelper.GetInstance().Trustee.AddTrusteeRow(truRow);
					GisaDataSetHelper.GetInstance().TrusteeGroup.AddTrusteeGroupRow(grpRow);

					PersistencyHelper.CreateTrusteePreConcArguments ctpca = new PersistencyHelper.CreateTrusteePreConcArguments();
					ctpca.truRowID = truRow.ID;
					ctpca.grpRowID = grpRow.ID;

					Trace.WriteLine("A criar o grupo de utilizador...");

                    PersistencyHelper.SaveResult successfulSave = PersistencyHelper.save(addTrusteeIfUsernameDoesntExist, ctpca);
					PersistencyHelper.cleanDeletedData();

					if (! ctpca.successful)
					{
						MessageBox.Show("Este nome já existe atribuído a um utilizador ou grupo, " + Environment.NewLine + "por favor escolha outro nome.", form.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
						UpdateTrustees(null);
					}
					else
						UpdateTrustees(truRow);

					break;
				case DialogResult.Cancel:
				break;
			}
		}