コード例 #1
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;
        }
コード例 #2
0
ファイル: ImportExport.cs プロジェクト: js1987/openpetragit
        /// <summary>
        /// Check that I seem to have the right partner tables for this PartnerClass.
        ///
        /// If the child records (PPerson, PFamily, etc) have no ModificationID,
        /// (because these are new records - not originally from the database)
        /// I need to get the current one from the server to prevent it sulking.
        /// </summary>
        /// <param name="PartnerRow"></param>
        /// <param name="MainDS"></param>
        /// <param name="ReferenceResults"></param>
        /// <param name="Transaction"></param>
        /// <returns></returns>
        private static bool CheckPartnerClass(PPartnerRow PartnerRow,
            PartnerImportExportTDS MainDS,
            ref TVerificationResultCollection ReferenceResults,
            TDBTransaction Transaction)
        {
            if (PartnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY)
            {
                if (MainDS.PFamily.Rows.Count < 1)
                {
                    AddVerificationResult(ref ReferenceResults, "Internal Error - No Family row for FAMILY", TResultSeverity.Resv_Critical);
                    return false;
                }

                PFamilyTable Table = PFamilyAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, Transaction);

                if (Table.Rows.Count > 0)
                {
                    MainDS.PFamily[0].DateCreated = Table[0].DateCreated;
                    MainDS.PFamily[0].CreatedBy = Table[0].CreatedBy;
                    MainDS.PFamily[0].ModificationId = Table[0].ModificationId;
                }
            }

            if (PartnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON)
            {
                if (MainDS.PPerson.Rows.Count < 1)
                {
                    AddVerificationResult(ref ReferenceResults, "Internal Error - No Person row for PERSON", TResultSeverity.Resv_Critical);
                    return false;
                }

                PPersonTable Table = PPersonAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, Transaction);

                if (Table.Rows.Count > 0)
                {
                    MainDS.PPerson[0].DateCreated = Table[0].DateCreated;
                    MainDS.PPerson[0].CreatedBy = Table[0].CreatedBy;
                    MainDS.PPerson[0].ModificationId = Table[0].ModificationId;
                }

                if ((MainDS.PPerson[0].IsFamilyIdNull()) || (MainDS.PPerson[0].FamilyId == 0)) // Every Person must have a FamilyId..
                {
                    bool FamilyIdOk = false;

                    if (MainDS.PPerson[0].PartnerKey > 0) // If I've got a real key, then my existing FamilyId might also be real
                    {
                        PPersonTable PersonTable = PPersonAccess.LoadByPrimaryKey(MainDS.PPerson[0].PartnerKey, Transaction);

                        if (PersonTable.Rows.Count != 0)
                        {
                            MainDS.PPerson[0].FamilyId = PersonTable[0].FamilyId;
                            FamilyIdOk = true;
                        }
                    }

                    if (!FamilyIdOk)  // Otherwise I'll just grab one that's available.
                    {
                        TPartnerFamilyIDHandling IdFactory = new TPartnerFamilyIDHandling();
                        TFamilyIDSuccessEnum FamIdRes = TFamilyIDSuccessEnum.fiSuccess;
                        int NewFamilyId;
                        String NewFamilyMsg;

                        FamIdRes = IdFactory.GetNewFamilyID(MainDS.PPerson[0].FamilyKey, out NewFamilyId, out NewFamilyMsg);

                        if (FamIdRes != TFamilyIDSuccessEnum.fiError)
                        {
                            MainDS.PPerson[0].FamilyId = NewFamilyId;
                        }
                        else
                        {
                            AddVerificationResult(ref ReferenceResults,
                                "Problem generating family id: " + NewFamilyMsg,
                                TResultSeverity.Resv_Critical);
                            return false;
                        }
                    }
                }
            }

            if (PartnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT)
            {
                if (MainDS.PUnit.Rows.Count < 1)
                {
                    AddVerificationResult(ref ReferenceResults, "Internal Error - No Unit row for UNIT", TResultSeverity.Resv_Critical);
                    return false;
                }

                PUnitTable Table = PUnitAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, Transaction);

                if (Table.Rows.Count > 0)
                {
                    MainDS.PUnit[0].DateCreated = Table[0].DateCreated;
                    MainDS.PUnit[0].CreatedBy = Table[0].CreatedBy;
                    MainDS.PUnit[0].ModificationId = Table[0].ModificationId;
                }
            }

            if (PartnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_CHURCH)
            {
                if (MainDS.PChurch.Rows.Count < 1)
                {
                    AddVerificationResult(ref ReferenceResults, "Internal Error - No Church row for CHURCH", TResultSeverity.Resv_Critical);
                    return false;
                }

                PChurchTable Table = PChurchAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, Transaction);

                if (Table.Rows.Count > 0)
                {
                    MainDS.PChurch[0].DateCreated = Table[0].DateCreated;
                    MainDS.PChurch[0].CreatedBy = Table[0].CreatedBy;
                    MainDS.PChurch[0].ModificationId = Table[0].ModificationId;
                }
            }

            if (PartnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION)
            {
                if (MainDS.POrganisation.Rows.Count < 1)
                {
                    AddVerificationResult(ref ReferenceResults,
                        "Internal Error - No Organisation row for ORGANISATION",
                        TResultSeverity.Resv_Critical);
                    return false;
                }

                POrganisationTable Table = POrganisationAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, Transaction);

                if (Table.Rows.Count > 0)
                {
                    MainDS.POrganisation[0].DateCreated = Table[0].DateCreated;
                    MainDS.POrganisation[0].CreatedBy = Table[0].CreatedBy;
                    MainDS.POrganisation[0].ModificationId = Table[0].ModificationId;
                }
            }

            if (PartnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_BANK)
            {
                if (MainDS.PBank.Rows.Count < 1)
                {
                    AddVerificationResult(ref ReferenceResults, "Internal Error - No Bank row for BANK", TResultSeverity.Resv_Critical);
                    return false;
                }

                PBankTable Table = PBankAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, Transaction);

                if (Table.Rows.Count > 0)
                {
                    MainDS.PBank[0].DateCreated = Table[0].DateCreated;
                    MainDS.PBank[0].CreatedBy = Table[0].CreatedBy;
                    MainDS.PBank[0].ModificationId = Table[0].ModificationId;
                }
            }

            return true;
        }
コード例 #3
0
ファイル: Partner.cs プロジェクト: js1987/openpetragit
        /// <summary>
        /// performs database changes to move person from current (old) family to new family record
        /// </summary>
        /// <param name="APersonKey"></param>
        /// <param name="AOldFamilyKey"></param>
        /// <param name="ANewFamilyKey"></param>
        /// <param name="AProblemMessage"></param>
        /// <returns>true if change of family completed successfully</returns>
        public static bool ChangeFamily(Int64 APersonKey, Int64 AOldFamilyKey, Int64 ANewFamilyKey,
            out String AProblemMessage)
        {
            bool Result = true;
            PFamilyTable OldFamilyDT;
            PFamilyTable NewFamilyDT;
            PPersonTable PersonDT;
            PPartnerRelationshipTable RelationshipDT;
            PPartnerRelationshipRow RelationshipRow;
            TPartnerFamilyIDHandling FamilyIDHandling;
            Int32 NewFamilyID;

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

            try
            {
                PersonDT = PPersonAccess.LoadByPrimaryKey(APersonKey, Transaction);

                FamilyIDHandling = new TPartnerFamilyIDHandling();

                if (FamilyIDHandling.GetNewFamilyID_FamilyChange(ANewFamilyKey, PersonDT[0].FamilyId, out NewFamilyID,
                        out AProblemMessage) == TFamilyIDSuccessEnum.fiError)
                {
                    // this should not really happen  but we cannot continue if it does
                    Result = false;
                }

                if (Result)
                {
                    // reset family id and family key for person
                    PersonDT[0].FamilyId = NewFamilyID;
                    PersonDT[0].FamilyKey = ANewFamilyKey;

                    PPersonAccess.SubmitChanges(PersonDT, Transaction);

                    // reset family members flag in old family if this person was the last family member
                    if (PPersonAccess.CountViaPFamily(AOldFamilyKey, Transaction) == 0)
                    {
                        OldFamilyDT = PFamilyAccess.LoadByPrimaryKey(AOldFamilyKey, Transaction);

                        OldFamilyDT[0].FamilyMembers = false;

                        PFamilyAccess.SubmitChanges(OldFamilyDT, Transaction);
                    }

                    // remove relationships between person and old family
                    PPartnerRelationshipAccess.DeleteByPrimaryKey(AOldFamilyKey, "FAMILY", APersonKey, Transaction);

                    // set family members flag for new family as there is now at least one member
                    NewFamilyDT = PFamilyAccess.LoadByPrimaryKey(ANewFamilyKey, Transaction);
                    NewFamilyDT[0].FamilyMembers = true;
                    PFamilyAccess.SubmitChanges(NewFamilyDT, Transaction);

                    // create relationship between person and new family
                    if ((!PPartnerRelationshipAccess.Exists(ANewFamilyKey, "FAMILY", APersonKey, Transaction)))
                    {
                        RelationshipDT = new PPartnerRelationshipTable();
                        RelationshipRow = RelationshipDT.NewRowTyped(true);
                        RelationshipRow.PartnerKey = ANewFamilyKey;
                        RelationshipRow.RelationKey = APersonKey;
                        RelationshipRow.RelationName = "FAMILY";
                        RelationshipRow.Comment = "System Generated";

                        RelationshipDT.Rows.Add(RelationshipRow);

                        PPartnerRelationshipAccess.SubmitChanges(RelationshipDT, Transaction);
                    }
                }

                if (Result)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                }
                else
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during a change of a Family:" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }

            return Result;
        }