Exemplo n.º 1
0
        /// <summary>
        /// Passes data as a Typed DataSet to the caller, containing a DataTable that corresponds with <paramref name="AIndivDataItem"></paramref>.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of the Person to load data for.</param>
        /// <param name="AIndivDataItem">The Individual Data Item for which data should be returned.</param>
        /// <param name="AReadTransaction">Open Database transaction.</param>
        /// <returns>A Typed DataSet containing a DataTable that corresponds with <paramref name="AIndivDataItem"></paramref>.</returns>
        private static IndividualDataTDS GetData(Int64 APartnerKey, TIndividualDataItemEnum AIndivDataItem, TDBTransaction AReadTransaction)
        {
            IndividualDataTDS IndividualDataDS = new IndividualDataTDS("IndividualData");   // create the IndividualDataTDS DataSet that will later be passed to the Client
            IndividualDataTDSMiscellaneousDataTable MiscellaneousDataDT;
            IndividualDataTDSMiscellaneousDataRow MiscellaneousDataDR;

            #region Create 'Miscellaneous' DataRow

            MiscellaneousDataDT = IndividualDataDS.MiscellaneousData;
            MiscellaneousDataDR = MiscellaneousDataDT.NewRowTyped(false);
            MiscellaneousDataDR.PartnerKey = APartnerKey;

            MiscellaneousDataDT.Rows.Add(MiscellaneousDataDR);

            #endregion

            switch (AIndivDataItem)
            {
                case TIndividualDataItemEnum.idiSummary:
                    BuildSummaryData(APartnerKey, ref IndividualDataDS, AReadTransaction);

                    DetermineItemCounts(MiscellaneousDataDR, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiPersonalLanguages:
                    PmPersonLanguageAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);

                    PLanguageTable LanguageTable = (PLanguageTable)TSharedDataCache.TMCommon.GetCacheableCommonTable(
                    TCacheableCommonTablesEnum.LanguageCodeList);
                    PLanguageRow LanguageRow;

                    foreach (IndividualDataTDSPmPersonLanguageRow PersonLanguageRow in IndividualDataDS.PmPersonLanguage.Rows)
                    {
                        LanguageRow = (PLanguageRow)LanguageTable.Rows.Find(new object[] { PersonLanguageRow.LanguageCode });

                        if (LanguageRow != null)
                        {
                            PersonLanguageRow.LanguageDescription = LanguageRow.LanguageDescription;
                        }
                    }

                    break;

                case TIndividualDataItemEnum.idiSpecialNeeds:
                    PmSpecialNeedAccess.LoadByPrimaryKey(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiPreviousExperiences:
                    PmPastExperienceAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiPersonalDocuments:
                    PmDocumentAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiJobAssignments:
                    PmJobAssignmentAccess.LoadViaPPartner(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiLocalPersonnelData:
                    // TODO: Fix this so LocalPersonnelData can actually load some data
                    bool labelsAvailable;
                    TOfficeSpecificDataLabelsUIConnector OfficeSpecificDataLabelsUIConnector;
                    OfficeSpecificDataLabelsUIConnector = new TOfficeSpecificDataLabelsUIConnector(APartnerKey,
                    TOfficeSpecificDataLabelUseEnum.Personnel);
                    IndividualDataDS.Merge(OfficeSpecificDataLabelsUIConnector.GetDataLocalPartnerDataValues(APartnerKey, out labelsAvailable, false,
                        AReadTransaction));
                    break;

                case TIndividualDataItemEnum.idiProgressReports:
                    PmPersonEvaluationAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiCommitmentPeriods:
                    PmStaffDataAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiPersonSkills:
                    PmPersonSkillAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiPersonalAbilities:
                    PmPersonAbilityAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiPassportDetails:
                    PmPassportDetailsAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);

                    PCountryTable CountryTable = (PCountryTable)TSharedDataCache.TMCommon.GetCacheableCommonTable(
                    TCacheableCommonTablesEnum.CountryList);
                    PCountryRow CountryRow;

                    foreach (IndividualDataTDSPmPassportDetailsRow PassportRow in IndividualDataDS.PmPassportDetails.Rows)
                    {
                        CountryRow = (PCountryRow)CountryTable.Rows.Find(new object[] { PassportRow.PassportNationalityCode });

                        if (CountryRow != null)
                        {
                            PassportRow.PassportNationalityName = CountryRow.CountryName;
                        }
                    }

                    break;

                case TIndividualDataItemEnum.idiPersonalData:
                    PmPersonalDataAccess.LoadByPrimaryKey(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiEmergencyData:
                    PmPersonalDataAccess.LoadByPrimaryKey(IndividualDataDS, APartnerKey, AReadTransaction);
                    break;

                case TIndividualDataItemEnum.idiApplications:
                    PmGeneralApplicationAccess.LoadViaPPersonPartnerKey(IndividualDataDS, APartnerKey, AReadTransaction);
                    PmShortTermApplicationAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);
                    PmYearProgramApplicationAccess.LoadViaPPerson(IndividualDataDS, APartnerKey, AReadTransaction);

                    IndividualDataTDSPmGeneralApplicationRow GenAppRow;
                    TPartnerClass PartnerClass;
                    TStdPartnerStatusCode PartnerStatus;
                    String EventOrFieldName;

                    //TODO: now go through all short and long term apps and set the
                    // two fields in general app for EventOrFieldName and ApplicationForEventOrField
                    foreach (PmShortTermApplicationRow ShortTermRow in IndividualDataDS.PmShortTermApplication.Rows)
                    {
                        GenAppRow = (IndividualDataTDSPmGeneralApplicationRow)IndividualDataDS.PmGeneralApplication.Rows.Find
                                        (new object[] { ShortTermRow.PartnerKey,
                                                        ShortTermRow.ApplicationKey, ShortTermRow.RegistrationOffice });
                        GenAppRow.ApplicationForEventOrField = Catalog.GetString("Event");

                        if (!ShortTermRow.IsStConfirmedOptionNull())
                        {
                            Ict.Petra.Server.MCommon.MCommonMain.RetrievePartnerShortName
                                (ShortTermRow.StConfirmedOption, out EventOrFieldName, out PartnerClass, out PartnerStatus);
                            GenAppRow.EventOrFieldName = EventOrFieldName;
                        }
                    }

                    foreach (PmYearProgramApplicationRow LongTermRow in IndividualDataDS.PmYearProgramApplication.Rows)
                    {
                        GenAppRow = (IndividualDataTDSPmGeneralApplicationRow)IndividualDataDS.PmGeneralApplication.Rows.Find
                                        (new object[] { LongTermRow.PartnerKey,
                                                        LongTermRow.ApplicationKey, LongTermRow.RegistrationOffice });
                        GenAppRow.ApplicationForEventOrField = Catalog.GetString("Field");

                        if (!GenAppRow.IsGenAppPossSrvUnitKeyNull())
                        {
                            Ict.Petra.Server.MCommon.MCommonMain.RetrievePartnerShortName
                                (GenAppRow.GenAppPossSrvUnitKey, out EventOrFieldName, out PartnerClass, out PartnerStatus);
                            GenAppRow.EventOrFieldName = EventOrFieldName;
                        }
                    }

                    break;

                    // TODO: work on all cases/load data for all Individual Data items
            }

            return IndividualDataDS;
        }
Exemplo n.º 2
0
        private PDataLabelValuePartnerTable GetDataLocalPartnerDataValuesInternal(out Boolean ALabelsAvailable, Boolean ACountOnly)
        {
            TDBTransaction ReadTransaction;
            Boolean NewTransaction = false;
            TOfficeSpecificDataLabelsUIConnector OfficeSpecificDataLabelsUIConnector;
            PDataLabelValuePartnerTable DataLabelValuePartnerDT;
            OfficeSpecificDataLabelsTDS OfficeSpecificDataLabels;

            ALabelsAvailable = false;

            DataLabelValuePartnerDT = new PDataLabelValuePartnerTable();

            try
            {
                ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                    TEnforceIsolationLevel.eilMinimum,
                    out NewTransaction);


                OfficeSpecificDataLabelsUIConnector = new TOfficeSpecificDataLabelsUIConnector(FPartnerKey,
                    MCommonTypes.PartnerClassEnumToOfficeSpecificDataLabelUseEnum(FPartnerClass));
                OfficeSpecificDataLabels = OfficeSpecificDataLabelsUIConnector.GetData();
                ALabelsAvailable =
                    (OfficeSpecificDataLabelsUIConnector.CountLabelUse(SharedTypes.PartnerClassEnumToString(FPartnerClass), ReadTransaction) != 0);

                if (!ACountOnly)
                {
                    DataLabelValuePartnerDT.Merge(OfficeSpecificDataLabels.PDataLabelValuePartner);
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetDataLocalPartnerDataValuesInternal: committed own transaction.");
                }
            }

            return DataLabelValuePartnerDT;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Passes data as a Typed DataSet to the Partner Edit Screen, containing multiple
        /// DataTables. The DataSets tables are with default data for a new Partner.
        ///
        /// </summary>
        /// <param name="ASiteKey">SiteKey for which the Partner should be created (optional)</param>
        /// <param name="APartnerKey">PartnerKey that the Partner should have (optional)</param>
        /// <param name="APartnerClass">PartnerClass that the Partner should have (optional)</param>
        /// <param name="ADesiredCountryCode">Country Code that the Partner's first address should have
        /// (if &lt;&gt; '', this overrides the Country Code that would be found out from the
        /// Site Key)</param>
        /// <param name="AAcquisitionCode">AcquisitionCode that the Partner should have (optional)</param>
        /// <param name="APrivatePartner">Set to true if this should become a Private Partner
        /// of the current user</param>
        /// <param name="AFamilyPartnerKey">PartnerKey of the Family (only needed if new Partner is of
        /// Partner Class PERSON)</param>
        /// <param name="AFamilySiteKey"></param>
        /// <param name="AFamilyLocationKey">LocationKey of the selected Location of the Family
        /// (only needed if new Partner is of Partner Class PERSON)
        /// </param>
        /// <param name="ASiteCountryCode"></param>
        /// <returns>void</returns>
        public PartnerEditTDS GetDataNewPartner(System.Int64 ASiteKey,
            System.Int64 APartnerKey,
            TPartnerClass APartnerClass,
            String ADesiredCountryCode,
            String AAcquisitionCode,
            Boolean APrivatePartner,
            Int64 AFamilyPartnerKey,
            Int64 AFamilySiteKey,
            Int32 AFamilyLocationKey,
            out String ASiteCountryCode)
        {
            TDBTransaction ReadTransaction;
            PPartnerRow PartnerRow;
            PartnerEditTDSPPersonRow PersonRow;
            PartnerEditTDSPFamilyRow FamilyRow;
            PChurchRow ChurchRow;
            POrganisationRow OrganisationRow;
            PBankRow BankRow;
            PUnitRow UnitRow;
            PVenueRow VenueRow;
            PPartnerRelationshipRow PartnerRelationshipRow;
            PartnerEditTDSMiscellaneousDataTable MiscellaneousDataDT;
            PartnerEditTDSMiscellaneousDataRow MiscellaneousDataDR;
            PPartnerTable PersonFamilyPartnerDT;
            PLocationTable SiteLocationDT;
            StringCollection SiteLocationRequiredColumns;
            DateTime CreationDate;

            String CreationUserID;
            String GiftReceiptingDefaults;
            String ReceiptLetterFrequency;
            String LanguageCode;

            String[] GiftReceiptingDefaultsSplit;
            Boolean ReceiptEachGift;
            TPartnerFamilyIDHandling FamilyIDHandling;
            int FamilyID;
            String ProblemMessage;
            Int32 ItemsCountAddresses = 0;
            Int32 ItemsCountAddressesActive = 0;
            Int32 ItemsCountSubscriptions = 0;
            Int32 ItemsCountSubscriptionsActive = 0;
            Int32 ItemsCountPartnerTypes = 0;
            Int32 ItemsCountPartnerRelationships = 0;
            Int32 ItemsCountFamilyMembers = 0;
            Int32 ItemsCountInterests = 0;
            Int32 ItemsCountContacts = 0;
            DateTime LastContactDate = DateTime.Now;
            Int64 FoundationOwner1Key = 0;
            Int64 FoundationOwner2Key = 0;
            bool HasEXWORKERPartnerType = false;
            PFamilyTable PersonFamilyDT;
            TOfficeSpecificDataLabelsUIConnector OfficeSpecificDataLabelsUIConnector;
            Boolean OfficeSpecificDataLabelsAvailable;

            ASiteCountryCode = "";
            FNewPartnerPartnerKey = APartnerKey;
            FNewPartnerPartnerClass = APartnerClass;
            CreationDate = DateTime.Today;
            CreationUserID = UserInfo.GUserInfo.UserID;

            // create the FPartnerEditScreenDS DataSet that will later be passed to the Client
            FPartnerEditScreenDS = new PartnerEditTDS(DATASETNAME);
            FPartnerKey = FNewPartnerPartnerKey;
            FPartnerClass = FNewPartnerPartnerClass;

            ReadTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.RepeatableRead);

            try
            {
                /*
                 * Create DataRow for PPartner
                 */
                #region Calculations

                // Determine Gift Processing settings
                GiftReceiptingDefaults = TSystemDefaultsCache.GSystemDefaultsCache.GetStringDefault(
                    TSystemDefaultsCache.PARTNER_GIFTRECEIPTINGDEFAULTS);

                if (GiftReceiptingDefaults != "")
                {
                    GiftReceiptingDefaultsSplit = GiftReceiptingDefaults.Split(',');
                    ReceiptLetterFrequency = GiftReceiptingDefaultsSplit[0];

                    if (GiftReceiptingDefaultsSplit[1] == "no")
                    {
                        ReceiptEachGift = false;
                    }
                    else
                    {
                        ReceiptEachGift = true;
                    }
                }
                else
                {
                    ReceiptLetterFrequency = "Annual";
                    ReceiptEachGift = false;
                }

                // Determine LanguageCode
                if (FPartnerClass != TPartnerClass.PERSON)
                {
                    LanguageCode = TUserDefaults.GetStringDefault(MSysManConstants.PARTNER_LANGUAGE, "99");
                }
                else
                {
                    PersonFamilyPartnerDT = PPartnerAccess.LoadByPrimaryKey(AFamilyPartnerKey, ReadTransaction);

                    if (PersonFamilyPartnerDT[0].LanguageCode == "99")
                    {
                        LanguageCode = TUserDefaults.GetStringDefault(MSysManConstants.PARTNER_LANGUAGE, "99");
                    }
                    else
                    {
                        LanguageCode = PersonFamilyPartnerDT[0].LanguageCode;
                    }
                }

                #endregion

                // We get the default values for all DataColumns
                // and then modify some.
                PartnerRow = FPartnerEditScreenDS.PPartner.NewRowTyped(true);
                PartnerRow.PartnerKey = FPartnerKey;
                PartnerRow.DateCreated = CreationDate;
                PartnerRow.CreatedBy = CreationUserID;
                PartnerRow.PartnerClass = SharedTypes.PartnerClassEnumToString(APartnerClass);
                PartnerRow.AcquisitionCode = AAcquisitionCode;

                // logical DataColumns must be initialised for DataBinding to work
                PartnerRow.NoSolicitations = false;
                PartnerRow.DeletedPartner = false;
                PartnerRow.ChildIndicator = false;
                PartnerRow.ReceiptLetterFrequency = ReceiptLetterFrequency;
                PartnerRow.ReceiptEachGift = ReceiptEachGift;
                PartnerRow.LanguageCode = LanguageCode;

                if (!APrivatePartner)
                {
                    PartnerRow.StatusCode = SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE);
                }
                else
                {
                    PartnerRow.StatusCode = SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscPRIVATE);
                    PartnerRow.Restricted = SharedConstants.PARTNER_PRIVATE_USER;
                    PartnerRow.UserId = CreationUserID;
                }

                PartnerRow.StatusChange = CreationDate;
                #region Partner Types
                TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetDataNewPartner: before PartnerClass switch");

                switch (APartnerClass)
                {
                    case TPartnerClass.PERSON:
                        // Load p_family record of the FAMILY that the PERSON will belong to
                        PersonFamilyDT = PFamilyAccess.LoadByPrimaryKey(AFamilyPartnerKey, ReadTransaction);

                        // Create DataRow for PPerson using the default values for all DataColumns
                        TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetDataNewPartner: before adding Person DataRow");

                        PersonRow = FPartnerEditScreenDS.PPerson.NewRowTyped(true);
                        PersonRow.PartnerKey = FPartnerKey;
                        PersonRow.DateCreated = CreationDate;
                        PersonRow.CreatedBy = CreationUserID;
                        PersonRow.FamilyKey = AFamilyPartnerKey;
                        PersonRow.FamilyName = PersonFamilyDT[0].FamilyName;
                        FamilyIDHandling = new TPartnerFamilyIDHandling();

                        if (FamilyIDHandling.GetNewFamilyID(AFamilyPartnerKey, out FamilyID, out ProblemMessage) == TFamilyIDSuccessEnum.fiError)
                        {
                            // this should not really happen  but we cannot continue if it does
                            throw new EPartnerFamilyIDException(ProblemMessage);
                        }

                        PersonRow.FamilyId = FamilyID;
                        PersonRow.OccupationCode = MPartnerConstants.DEFAULT_CODE_UNKNOWN;
                        FPartnerEditScreenDS.PPerson.Rows.Add(PersonRow);
                        GetFamilyMembersInternal(AFamilyPartnerKey, "", out ItemsCountFamilyMembers, true);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PFamilyTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(POrganisationTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PChurchTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PBankTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PUnitTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PVenueTable.GetTableName());

                        break;

                    case TPartnerClass.FAMILY:
                        TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetDataNewPartner: before adding Family DataRow");

                        // Create DataRow for PFamily using the default values for all DataColumns
                        FamilyRow = FPartnerEditScreenDS.PFamily.NewRowTyped(true);
                        FamilyRow.PartnerKey = FPartnerKey;
                        FamilyRow.DateCreated = CreationDate;
                        FamilyRow.CreatedBy = CreationUserID;
                        FPartnerEditScreenDS.PFamily.Rows.Add(FamilyRow);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PPersonTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(POrganisationTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PChurchTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PBankTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PUnitTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PVenueTable.GetTableName());

                        break;

                    case TPartnerClass.CHURCH:
                        // Create DataRow for PChurch using the default values for all DataColumns
                        ChurchRow = FPartnerEditScreenDS.PChurch.NewRowTyped(true);
                        ChurchRow.PartnerKey = FPartnerKey;
                        ChurchRow.DateCreated = CreationDate;
                        ChurchRow.CreatedBy = CreationUserID;

                        // logical DataColumns must be initialised for DataBinding to work
                        ChurchRow.Accomodation = false;
                        ChurchRow.PrayerGroup = false;
                        ChurchRow.MapOnFile = false;
                        FPartnerEditScreenDS.PChurch.Rows.Add(ChurchRow);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PPersonTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PFamilyTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(POrganisationTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PBankTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PUnitTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PVenueTable.GetTableName());

                        break;

                    case TPartnerClass.ORGANISATION:
                        // Create DataRow for POrganisation using the default values for all DataColumns
                        OrganisationRow = FPartnerEditScreenDS.POrganisation.NewRowTyped(true);
                        OrganisationRow.PartnerKey = FPartnerKey;
                        OrganisationRow.DateCreated = CreationDate;
                        OrganisationRow.CreatedBy = CreationUserID;

                        // logical DataColumns must be initialised for DataBinding to work
                        OrganisationRow.Religious = false;
                        OrganisationRow.Foundation = false;
                        FPartnerEditScreenDS.POrganisation.Rows.Add(OrganisationRow);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PPersonTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PFamilyTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PChurchTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PBankTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PUnitTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PVenueTable.GetTableName());

                        break;

                    case TPartnerClass.BANK:
                        // Create DataRow for PBank using the default values for all DataColumns
                        BankRow = FPartnerEditScreenDS.PBank.NewRowTyped(true);
                        BankRow.PartnerKey = FPartnerKey;
                        BankRow.DateCreated = CreationDate;
                        BankRow.CreatedBy = CreationUserID;
                        FPartnerEditScreenDS.PBank.Rows.Add(BankRow);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PPersonTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PFamilyTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(POrganisationTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PChurchTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PUnitTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PVenueTable.GetTableName());

                        break;

                    case TPartnerClass.UNIT:
                        // Create DataRow for PUnit using the default values for all DataColumns
                        UnitRow = FPartnerEditScreenDS.PUnit.NewRowTyped(true);
                        UnitRow.PartnerKey = FPartnerKey;
                        UnitRow.DateCreated = CreationDate;
                        UnitRow.CreatedBy = CreationUserID;
                        FPartnerEditScreenDS.PUnit.Rows.Add(UnitRow);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PPersonTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PFamilyTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PChurchTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PBankTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(POrganisationTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PVenueTable.GetTableName());

                        break;

                    case TPartnerClass.VENUE:
                        // Create DataRow for PVenue using the default values for all DataColumns
                        VenueRow = FPartnerEditScreenDS.PVenue.NewRowTyped(true);
                        VenueRow.PartnerKey = FPartnerKey;
                        VenueRow.DateCreated = CreationDate;
                        VenueRow.CreatedBy = CreationUserID;

                        // Makeup a VenueCode for now, as there is now way to let the user spec one quickly...
                        VenueRow.VenueCode = 'V' + FPartnerKey.ToString().Substring(1);
                        FPartnerEditScreenDS.PVenue.Rows.Add(VenueRow);

                        /*
                         * Remove other Partner Class Tables.
                         * This is needed for correct working of the creation of new Partners on the Client side (the ShowData Method of the 'Top Part'
                         * relies on null DataTables when determining which data of which DataTables to put into which Controls).
                         */
                        FPartnerEditScreenDS.Tables.Remove(PPersonTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PFamilyTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PChurchTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PBankTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(POrganisationTable.GetTableName());
                        FPartnerEditScreenDS.Tables.Remove(PUnitTable.GetTableName());

                        break;
                }

                PartnerRow.AddresseeTypeCode = TSharedAddressHandling.GetDefaultAddresseeType(APartnerClass);
                TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetDataNewPartner: before adding new Partner DataRow");

                // Add DataRow for PPartner
                FPartnerEditScreenDS.PPartner.Rows.Add(PartnerRow);

                if (APartnerClass == TPartnerClass.PERSON)
                {
                    /*
                     * Copy specified Family Address into the PLocation and PPartnerLocation
                     * table (is needed on the Client side to copy this address as the default
                     * address of the new Person and gets deleted there as soon as copying is
                     * done)
                     */
//                  TLogging.LogAtLevel(7, "Getting Family Address - AFamilyPartnerKey: " + AFamilyPartnerKey.ToString() + "; AFamilyLocationKey: " + AFamilyLocationKey.ToString());
                    TPPartnerAddressAggregate.LoadByPrimaryKey(FPartnerEditScreenDS,
                        AFamilyPartnerKey,
                        AFamilySiteKey,
                        AFamilyLocationKey,
                        ReadTransaction);

                    // Copy Special Types from the PERSON'S FAMILY to the PERSON
                    TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetDataNewPartner: before loading Special Types from FAMILY");

                    GetPartnerTypesForNewPartnerFromFamily(AFamilyPartnerKey, ReadTransaction);

                    /*
                     * Create Relationship between Family and Person
                     */
                    PartnerRelationshipRow = FPartnerEditScreenDS.PPartnerRelationship.NewRowTyped(true);
                    PartnerRelationshipRow.PartnerKey = AFamilyPartnerKey;
                    PartnerRelationshipRow.RelationKey = FPartnerKey;
                    PartnerRelationshipRow.RelationName = "FAMILY";
                    PartnerRelationshipRow.Comment = SharedConstants.ROW_IS_SYSTEM_GENERATED;
                    PartnerRelationshipRow.DateCreated = CreationDate;
                    PartnerRelationshipRow.CreatedBy = CreationUserID;
                    FPartnerEditScreenDS.PPartnerRelationship.Rows.Add(PartnerRelationshipRow);
                }

                #endregion

                // Note: Location and PartnerLocation for a new Partner are set up on the Client side!
                // Determine CountryCode for first Address of the Partner, if it is not overwritten
                if (ADesiredCountryCode == "")
                {
                    // TODO 1 oChristianK cPartner Edit / New Partner : Use a proper function to determine the 'Best' Address of the Unit...
                    SiteLocationRequiredColumns = new StringCollection();
                    SiteLocationRequiredColumns.Add(PLocationTable.GetLocationKeyDBName());
                    SiteLocationRequiredColumns.Add(PLocationTable.GetCountryCodeDBName());
                    SiteLocationDT = PLocationAccess.LoadViaPPartner(ASiteKey, SiteLocationRequiredColumns, ReadTransaction, null, 0, 0);

                    // For the moment just take the CountryCode that we find in the (random) first record...
                    ASiteCountryCode = SiteLocationDT[0].CountryCode;
                }

                /*
                 * Office Specific Data
                 */
                OfficeSpecificDataLabelsUIConnector = new TOfficeSpecificDataLabelsUIConnector(FPartnerKey,
                    MCommonTypes.PartnerClassEnumToOfficeSpecificDataLabelUseEnum(FPartnerClass));
                OfficeSpecificDataLabelsAvailable =
                    (OfficeSpecificDataLabelsUIConnector.CountLabelUse(SharedTypes.PartnerClassEnumToString(FPartnerClass), ReadTransaction) != 0);


                MiscellaneousDataDT = FPartnerEditScreenDS.MiscellaneousData;
                MiscellaneousDataDR = MiscellaneousDataDT.NewRowTyped(false);
                MiscellaneousDataDR.PartnerKey = FPartnerKey;

                if (AFamilyLocationKey != 0)
                {
                    MiscellaneousDataDR.SelectedSiteKey = AFamilySiteKey;
                    MiscellaneousDataDR.SelectedLocationKey = AFamilyLocationKey;
                }
                else
                {
                    MiscellaneousDataDR.SelectedSiteKey = -1;
                    MiscellaneousDataDR.SelectedLocationKey = -1;
                }

                MiscellaneousDataDR.SetLastGiftDateNull();
                MiscellaneousDataDR.LastGiftInfo = "";
                MiscellaneousDataDR.ItemsCountAddresses = ItemsCountAddresses;
                MiscellaneousDataDR.ItemsCountAddressesActive = ItemsCountAddressesActive;
                MiscellaneousDataDR.ItemsCountSubscriptions = ItemsCountSubscriptions;
                MiscellaneousDataDR.ItemsCountSubscriptionsActive = ItemsCountSubscriptionsActive;
                MiscellaneousDataDR.ItemsCountPartnerTypes = ItemsCountPartnerTypes;
                MiscellaneousDataDR.ItemsCountPartnerRelationships = ItemsCountPartnerRelationships;
                MiscellaneousDataDR.ItemsCountFamilyMembers = ItemsCountFamilyMembers;
                MiscellaneousDataDR.ItemsCountInterests = ItemsCountInterests;
                MiscellaneousDataDR.OfficeSpecificDataLabelsAvailable = OfficeSpecificDataLabelsAvailable;
                MiscellaneousDataDR.FoundationOwner1Key = FoundationOwner1Key;
                MiscellaneousDataDR.FoundationOwner2Key = FoundationOwner2Key;
                MiscellaneousDataDR.HasEXWORKERPartnerType = HasEXWORKERPartnerType;
                MiscellaneousDataDR.ItemsCountContacts = ItemsCountContacts;
                MiscellaneousDataDR.LastContactDate = LastContactDate;
                MiscellaneousDataDT.Rows.Add(MiscellaneousDataDR);
                MiscellaneousDataDT.AcceptChanges();
            }
            catch (Exception Exp)
            {
                TLogging.Log("Exception occured in GetDataNewPartner: " + Exp.ToString());
            }
            DBAccess.GDBAccessObj.CommitTransaction();

            // Remove all Tables that were not filled with data before remoting them
            // This will be the DataTables that exist for a certain Partner Class,
            // eg. Person  only one of those Tables will be filled, the other ones are
            // not needed at the Client side.
            // FPartnerEditScreenDS.RemoveEmptyTables;
            // For the moment we only remove the following table so that the Partner
            // Edit screen can discover the value of MiscellaneousDataDR.ItemsCountFamilyMembers
            FPartnerEditScreenDS.Tables.Remove(PartnerEditTDSFamilyMembersTable.GetTableName());

            return FPartnerEditScreenDS;
        }
Exemplo n.º 4
0
        private bool SubmitChangesOther(ref PartnerEditTDS AInspectDS,
            TDBTransaction ASubmitChangesTransaction,
            out TVerificationResultCollection AVerificationResult)
        {
            TOfficeSpecificDataLabelsUIConnector OfficeSpecificDataLabelsUIConnector;
            PartnerEditTDSFamilyMembersTable FamilyMembersTableSubmit;

            AVerificationResult = null;

//          TLogging.LogAtLevel(7, "TPartnerEditUIConnector.SubmitChanges: Instance hash is " + this.GetHashCode().ToString());
            bool AllSubmissionsOK = true;

            if (AInspectDS != null)
            {
                AVerificationResult = new TVerificationResultCollection();

                #region Partner

                if (AInspectDS.Tables.Contains(PPartnerTable.GetTableName()))
                {
                    SpecialPreSubmitProcessingPartner(AInspectDS.PPartner);

                    if (AInspectDS.PPartner.Rows.Count > 0)
                    {
                        ValidatePPartner(ref AVerificationResult, AInspectDS.PPartner);
                        ValidatePPartnerManual(ref AVerificationResult, AInspectDS.PPartner);

                        if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult))
                        {
                            AllSubmissionsOK = false;
                        }

                        // Business Rule: if the Partner's StatusCode changes, give the user the
                        // option to promote the change to all Family Members (if the Partner is
                        // a FAMILY and has Family Members).
                        if (AInspectDS.PPartner.Rows[0].HasVersion(DataRowVersion.Original)
                            && (AInspectDS.PPartner.Rows != AInspectDS.PPartner.Rows[0][PPartnerTable.GetStatusCodeDBName(), DataRowVersion.Current]))
                        {
//                          TLogging.LogAtLevel(7, this.GetType().FullName + ".SubmitChanges: StatusCode has changed");

                            // StatusCode has changed, now perform FamilyMembers promotion
                            // (the FamilyMembersInfoForStatusChange DataTable won't be nil if
                            // the user indicated so)
                            if (AInspectDS.FamilyMembersInfoForStatusChange != null)
                            {
                                if (!SpecialSubmitProcessingPartnerStatusChange(
                                        AInspectDS,
                                        AInspectDS.PPartner[0].StatusCode,
                                        AInspectDS.FamilyMembersInfoForStatusChange,
                                        ASubmitChangesTransaction))
                                {
                                    AllSubmissionsOK = false;
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Partner Types

                if (AInspectDS.Tables.Contains(PPartnerTypeTable.GetTableName()))
                {
                    if (!SpecialSubmitProcessingPartnerTypes(AInspectDS, ASubmitChangesTransaction))
                    {
                        AllSubmissionsOK = false;
                    }
                }

                #endregion

                #region Partner Details according to PartnerClass

                if (FPartnerClass == TPartnerClass.FAMILY)
                {
                    if (AInspectDS.Tables.Contains(PartnerEditTDSFamilyMembersTable.GetTableName()))
                    {
                        FamilyMembersTableSubmit = AInspectDS.FamilyMembers;
//                      TLogging.LogAtLevel(7, "FamilyMembersTableSubmit.Rows.Count: " + FamilyMembersTableSubmit.Rows.Count.ToString());

                        SpecialSubmitProcessingFamilyMembers(FamilyMembersTableSubmit, ASubmitChangesTransaction);
                    }
                }

                if (FPartnerClass == TPartnerClass.BANK)
                {
                    if (AInspectDS.Tables.Contains(PBankTable.GetTableName()))
                    {
                        if (AInspectDS.PBank.Rows.Count > 0)
                        {
                            ValidatePBank(ref AVerificationResult, AInspectDS.PBank);
                            ValidatePBankManual(ref AVerificationResult, AInspectDS.PBank);

                            if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult))
                            {
                                AllSubmissionsOK = false;
                            }
                        }
                    }
                }

                #endregion

                #region Contact Logs

                if (AInspectDS.Tables.Contains(PContactLogTable.GetTableName()) && AInspectDS.Tables.Contains(PPartnerContactTable.GetTableName()))
                {
                }

                #endregion

                #region Foundations

                if (AInspectDS.Tables.Contains(PFoundationTable.GetTableName()))
                {
                    DataView DeletedFoundationsDV = new DataView(AInspectDS.PFoundation, "", "", DataViewRowState.Deleted);

                    if (DeletedFoundationsDV.Count > 0)
                    {
                        /*
                         * Special handling in case a foundation got deleted: do a cascading
                         * delete (deletes p_foundation record and also existing records
                         * in p_foundation_deadline, p_foundation_proposal,
                         * p_foundation_proposal_detail)
                         */
                        TLogging.LogAtLevel(7, "TPartnerEditUIConnector.SubmitChanges: performing cascading delete for Foundation!");
                        PFoundationCascading.DeleteByPrimaryKey(FPartnerKey, ASubmitChangesTransaction, true);

                        // Now delete this DataRow to prevent SubmitChanges from trying to
                        // delete it and failing at it (for simplicity we suppose there is only
                        // one DataRow that got deleted)
                        DeletedFoundationsDV[0].Row.Delete();
                        DeletedFoundationsDV[0].Row.AcceptChanges();
                    }
                }

                #endregion

                #region Office Specific Data Labels

                if (AInspectDS.Tables.Contains(PDataLabelValuePartnerTable.GetTableName()))
                {
                    OfficeSpecificDataLabelsUIConnector = new TOfficeSpecificDataLabelsUIConnector(FPartnerKey,
                        MCommonTypes.PartnerClassEnumToOfficeSpecificDataLabelUseEnum(FPartnerClass));

                    OfficeSpecificDataLabelsUIConnector.PrepareChangesServerSide(
                        AInspectDS.PDataLabelValuePartner,
                        ASubmitChangesTransaction);
                }

                #endregion

                #region Partner Interests

                if (AInspectDS.Tables.Contains(PPartnerInterestTable.GetTableName()))
                {
                    foreach (PPartnerInterestRow row in AInspectDS.PPartnerInterest.Rows)
                    {
                        if (row.RowState != DataRowState.Deleted)
                        {
                            if (!row.IsFieldKeyNull())
                            {
                                if (row.FieldKey == 0)
                                {
                                    row.SetFieldKeyNull();
                                }
                            }
                        }
                    }
                }

                #endregion

                // Note: Locations and PartnerLocations are done sepearately in SubmitChangesAddresses!
                if (AllSubmissionsOK == false)
                {
                    TLogging.LogAtLevel(9,
                        Messages.BuildMessageFromVerificationResult("TPartnerEditUIConnector.SubmitChanges AVerificationResult: ",
                            AVerificationResult));
                }
            }
            else
            {
                TLogging.LogAtLevel(8, "TPartnerEditUIConnector.SubmitChanges AInspectDS = nil!");
                AllSubmissionsOK = false;
            }

            if (AVerificationResult.Count > 0)
            {
                // Downgrade TScreenVerificationResults to TVerificationResults in order to allow
                // Serialisation (needed for .NET Remoting).
                TVerificationResultCollection.DowngradeScreenVerificationResults(AVerificationResult);
            }

            return AllSubmissionsOK;
        }
        private DataTable GetDataLabelsForPartnerClassesListTable(TDBTransaction AReadTransaction, string ATableName)
        {
            const string PARTNERCLASSCOL = "PartnerClass";
            const string DLAVAILCOL = "DataLabelsAvailable";

            DataTable TmpTable;
            DataRow NewDR;
            TOfficeSpecificDataLabelsUIConnector OfficeSpecificDataLabelsUIConnector;

            // Create our custom Cacheable DataTable on-the-fly
            TmpTable = new DataTable(ATableName);
            DataColumn PKColumn = new DataColumn(PARTNERCLASSCOL, System.Type.GetType("System.String"));
            TmpTable.Columns.Add(PKColumn);
            TmpTable.Columns.Add(new DataColumn(DLAVAILCOL, System.Type.GetType("System.Boolean")));
            TmpTable.PrimaryKey = new DataColumn[] {
                PKColumn
            };

            /*
             * Create an Instance of TOfficeSpecificDataLabelsUIConnector - PartnerKey and DataLabelUse are not important here
             * because we only call Method 'CountLabelUse', which doesn't rely on any of them.
             */
            OfficeSpecificDataLabelsUIConnector = new TOfficeSpecificDataLabelsUIConnector(0,
                TOfficeSpecificDataLabelUseEnum.Family);

            // DataLabels available for PERSONs?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.PERSON);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            // DataLabels available for FAMILYs?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.FAMILY);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            // DataLabels available for CHURCHes?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.CHURCH);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            // DataLabels available for ORGANISATIONs?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.ORGANISATION);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            // DataLabels available for UNITs?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.UNIT);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            // DataLabels available for BANKs?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.BANK);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            // DataLabels available for VENUEs?
            NewDR = TmpTable.NewRow();
            NewDR[PARTNERCLASSCOL] = SharedTypes.PartnerClassEnumToString(TPartnerClass.VENUE);
            NewDR[DLAVAILCOL] =
                (OfficeSpecificDataLabelsUIConnector.CountLabelUse(NewDR[PARTNERCLASSCOL].ToString(), AReadTransaction) != 0);
            TmpTable.Rows.Add(NewDR);

            return TmpTable;
        }