private void LoadAvailableModulesIntoCheckedListBox()
        {
            string CheckedMember = "CHECKED";
            string DisplayMember = SModuleTable.GetModuleNameDBName();
            string ValueMember   = SModuleTable.GetModuleIdDBName();

            DataTable NewTable = FMainDS.SModule.DefaultView.ToTable(true, new string[] { ValueMember, DisplayMember });

            NewTable.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));

            clbUserGroup.Columns.Clear();
            clbUserGroup.AddCheckBoxColumn("", NewTable.Columns[CheckedMember], 17, false);
            clbUserGroup.AddTextColumn(Catalog.GetString("Module"), NewTable.Columns[ValueMember], 120);
            clbUserGroup.AddTextColumn(Catalog.GetString("Description"), NewTable.Columns[DisplayMember], 342);
            clbUserGroup.DataBindGrid(NewTable, ValueMember, CheckedMember, ValueMember, false, true, false);
        }
Пример #2
0
        /// <summary>
        /// use the permissions of the user to get all offices that this user has permissions for
        /// </summary>
        /// <returns></returns>
        private static List <Int64> GetRegistrationOfficeKeysOfUser(TDBTransaction ATransaction)
        {
            List <Int64> AllowedRegistrationOffices = new List <long>();

            // get all offices that have registrations for this event
            DataTable offices = DBAccess.GDBAccessObj.SelectDT(
                String.Format("SELECT DISTINCT {0} FROM PUB_{1}",
                              PmShortTermApplicationTable.GetRegistrationOfficeDBName(),
                              PmShortTermApplicationTable.GetTableDBName()),
                "registrationoffice", ATransaction);

            // if there are no REG-... module permissions for anyone, allow all offices? this would help with a base database for testing?
            Int32 CountRegModules =
                Convert.ToInt32(DBAccess.GDBAccessObj.ExecuteScalar("SELECT COUNT(*) FROM " + SModuleTable.GetTableDBName() + " WHERE " +
                                                                    SModuleTable.GetModuleIdDBName() + " LIKE 'REG-%'", ATransaction));

            foreach (DataRow officeRow in offices.Rows)
            {
                Int64 RegistrationOffice = Convert.ToInt64(officeRow[0]);
                try
                {
                    if ((CountRegModules == 0) || TModuleAccessManager.CheckUserModulePermissions(String.Format("REG-{0:10}",
                                                                                                                StringHelper.PartnerKeyToStr(RegistrationOffice))))
                    {
                        AllowedRegistrationOffices.Add(RegistrationOffice);
                    }
                }
                catch (ESecurityModuleAccessDeniedException)
                {
                    // no permissions for this registration office
                }
            }

            // the organizer has access to all attendees
            if (AllowedRegistrationOffices.Count > MINIMUM_OFFICES_TO_BECOME_ORGANIZER)
            {
                AllowedRegistrationOffices = new List <long>();

                foreach (DataRow officeRow in offices.Rows)
                {
                    Int64 RegistrationOffice = Convert.ToInt64(officeRow[0]);
                    AllowedRegistrationOffices.Add(RegistrationOffice);
                }
            }

            return(AllowedRegistrationOffices);
        }
        private static void GenerateRegistrationOffices(string ACountryName, Int64 APartnerKey, string ACountryCode)
        {
            if (PUnitAccess.Exists(APartnerKey, null))
            {
                TLogging.Log("Office with key " + APartnerKey.ToString() + " already exists.");
                return;
            }

            PartnerEditTDS MainDS = new PartnerEditTDS();

            PPartnerRow partnerRow = MainDS.PPartner.NewRowTyped(true);

            partnerRow.PartnerKey        = APartnerKey;
            partnerRow.PartnerShortName  = ACountryName;
            partnerRow.PartnerClass      = MPartnerConstants.PARTNERCLASS_UNIT;
            partnerRow.StatusCode        = MPartnerConstants.PARTNERSTATUS_ACTIVE;
            partnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION;
            MainDS.PPartner.Rows.Add(partnerRow);

            PUnitRow unitRow = MainDS.PUnit.NewRowTyped(true);

            unitRow.PartnerKey   = partnerRow.PartnerKey;
            unitRow.UnitName     = partnerRow.PartnerShortName;
            unitRow.CountryCode  = ACountryCode;
            unitRow.UnitTypeCode = MPartnerConstants.UNIT_TYPE_FIELD;
            MainDS.PUnit.Rows.Add(unitRow);

            PLocationRow locationRow = MainDS.PLocation.NewRowTyped();

            locationRow.SiteKey     = partnerRow.PartnerKey;
            locationRow.LocationKey = 0;
            locationRow.StreetName  = "No valid address on file";
            locationRow.CountryCode = ACountryCode;
            MainDS.PLocation.Rows.Add(locationRow);

            PPartnerLocationRow partnerlocationRow = MainDS.PPartnerLocation.NewRowTyped();

            partnerlocationRow.PartnerKey  = partnerRow.PartnerKey;
            partnerlocationRow.SiteKey     = locationRow.SiteKey;
            partnerlocationRow.LocationKey = locationRow.LocationKey;
            MainDS.PPartnerLocation.Rows.Add(partnerlocationRow);

            PPartnerTypeRow partnertypeRow = MainDS.PPartnerType.NewRowTyped();

            partnertypeRow.PartnerKey = partnerRow.PartnerKey;
            partnertypeRow.TypeCode   = MPartnerConstants.PARTNERTYPE_LEDGER;
            MainDS.PPartnerType.Rows.Add(partnertypeRow);

            UmUnitStructureRow unitStructureRow = MainDS.UmUnitStructure.NewRowTyped();

            unitStructureRow.ParentUnitKey = 1000000;
            unitStructureRow.ChildUnitKey  = partnerRow.PartnerKey;
            MainDS.UmUnitStructure.Rows.Add(unitStructureRow);

            PartnerEditTDSAccess.SubmitChanges(MainDS);

            string sqlInsertModule =
                String.Format("INSERT INTO PUB_{0}({1}, {2}) VALUES ('REG-{3:0000000000}','Registration {4}')",
                              SModuleTable.GetTableDBName(),
                              SModuleTable.GetModuleIdDBName(),
                              SModuleTable.GetModuleNameDBName(),
                              APartnerKey,
                              ACountryName);
            string sqlInsertModulePermissions =
                String.Format("INSERT INTO PUB_{0}({1}, {2}, {3}) VALUES ('DEMO', 'REG-{4:0000000000}',true)",
                              SUserModuleAccessPermissionTable.GetTableDBName(),
                              SUserModuleAccessPermissionTable.GetUserIdDBName(),
                              SUserModuleAccessPermissionTable.GetModuleIdDBName(),
                              SUserModuleAccessPermissionTable.GetCanAccessDBName(),
                              APartnerKey);

            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlInsertModule, Transaction);
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlInsertModulePermissions, Transaction);
                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                DBAccess.GDBAccessObj.RollbackTransaction();
            }
        }