Example #1
0
        public static void FillFormDataFromPartner(Int64 APartnerKey,
            ref TFormDataPartner AFormDataPartner,
            TFormLetterInfo AFormLetterInfo,
            Int64 ASiteKey = 0,
            Int32 ALocationKey = 0)
        {
            TPartnerClass PartnerClass;
            String ShortName;
            TStdPartnerStatusCode PartnerStatusCode;
            Int64 FamilyKey = 0;

            TFormDataPartner formData = null;

            TDBTransaction ReadTransaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                ref ReadTransaction,
                delegate
                {
                    if (MCommonMain.RetrievePartnerShortName(APartnerKey, out ShortName, out PartnerClass, out PartnerStatusCode, ReadTransaction))
                    {
                        switch (PartnerClass)
                        {
                            case TPartnerClass.PERSON:
                                formData = new TFormDataPerson();
                                formData.IsPersonRecord = true;
                                break;

                            default:
                                formData = new TFormDataPartner();
                                formData.IsPersonRecord = false;
                                break;
                        }

                        // set current date
                        formData.CurrentDate = DateTime.Today;

                        // retrieve general Partner information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eGeneral))
                        {
                            String SiteName;
                            TPartnerClass SiteClass;

                            if (TPartnerServerLookups.GetPartnerShortName(DomainManager.GSiteKey, out SiteName, out SiteClass))
                            {
                                formData.RecordingField = SiteName;
                            }
                        }

                        // retrieve general Partner information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePartner))
                        {
                            PPartnerTable PartnerTable;
                            PPartnerRow PartnerRow;
                            PartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction);

                            if (PartnerTable.Count > 0)
                            {
                                PartnerRow = (PPartnerRow)PartnerTable.Rows[0];

                                formData.PartnerKey = PartnerRow.PartnerKey.ToString("0000000000");
                                formData.Name = Calculations.FormatShortName(PartnerRow.PartnerShortName, eShortNameFormat.eReverseWithoutTitle);
                                formData.ShortName = PartnerRow.PartnerShortName;
                                formData.LocalName = PartnerRow.PartnerShortNameLoc;
                                formData.AddresseeType = PartnerRow.AddresseeTypeCode;
                                formData.LanguageCode = PartnerRow.LanguageCode;
                                formData.Notes = PartnerRow.Comment;
                                formData.ReceiptLetterFrequency = PartnerRow.ReceiptLetterFrequency;

                                if (PartnerRow.PartnerShortName.Contains(","))
                                {
                                    formData.Title = Calculations.FormatShortName(PartnerRow.PartnerShortName, eShortNameFormat.eOnlyTitle);
                                }
                                else
                                {
                                    formData.Title = "";
                                }
                            }

                            if (PartnerClass == TPartnerClass.PERSON)
                            {
                                PPersonTable PersonTable;
                                PPersonRow PersonRow;
                                PersonTable = PPersonAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction);

                                if (PersonTable.Count > 0)
                                {
                                    PersonRow = (PPersonRow)PersonTable.Rows[0];

                                    formData.FirstName = PersonRow.FirstName;
                                    formData.LastName = PersonRow.FamilyName;
                                }
                            }
                            else if (PartnerClass == TPartnerClass.FAMILY)
                            {
                                PFamilyTable FamilyTable;
                                PFamilyRow FamilyRow;
                                FamilyTable = PFamilyAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction);

                                if (FamilyTable.Count > 0)
                                {
                                    FamilyRow = (PFamilyRow)FamilyTable.Rows[0];

                                    formData.FirstName = FamilyRow.FirstName;
                                    formData.LastName = FamilyRow.FamilyName;
                                }
                            }
                        }

                        // retrieve Person information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePerson)
                            && (PartnerClass == TPartnerClass.PERSON)
                            && (formData.GetType() == typeof(TFormDataPerson)))
                        {
                            PPersonTable PersonTable;
                            PPersonRow PersonRow;
                            TFormDataPerson PersonFormData = (TFormDataPerson)formData;
                            PersonTable = PPersonAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction);

                            if (PersonTable.Count > 0)
                            {
                                PersonRow = (PPersonRow)PersonTable.Rows[0];
                                PersonFormData.Title = PersonRow.Title;
                                PersonFormData.Decorations = PersonRow.Decorations;
                                PersonFormData.MiddleName = PersonRow.MiddleName1;
                                PersonFormData.PreferedName = PersonRow.PreferedName;
                                PersonFormData.DateOfBirth = PersonRow.DateOfBirth;
                                PersonFormData.Gender = PersonRow.Gender;
                                PersonFormData.MaritalStatus = PersonRow.MaritalStatus;
                                PersonFormData.OccupationCode = PersonRow.OccupationCode;

                                if (!PersonRow.IsOccupationCodeNull()
                                    && (PersonRow.OccupationCode != ""))
                                {
                                    // retrieve occupation description from occupation table
                                    TPartnerCacheable CachePopulator = new TPartnerCacheable();
                                    POccupationTable OccupationTable =
                                        (POccupationTable)CachePopulator.GetCacheableTable(TCacheablePartnerTablesEnum.OccupationList);
                                    POccupationRow OccupationRow = (POccupationRow)OccupationTable.Rows.Find(new object[] { PersonRow.OccupationCode });

                                    if (OccupationRow != null)
                                    {
                                        PersonFormData.Occupation = OccupationRow.OccupationDescription;
                                    }
                                }

                                // Get supporting church, if there is one.  (Actually there may be more than one!)
                                // The RelationKey should hold the PERSON key and PartnerKey should hold supporter key
                                PPartnerRelationshipTable tmpTable = new PPartnerRelationshipTable();
                                PPartnerRelationshipRow templateRow = tmpTable.NewRowTyped(false);
                                templateRow.RelationName = "SUPPCHURCH";
                                templateRow.RelationKey = APartnerKey;

                                PPartnerRelationshipTable supportingChurchTable =
                                    PPartnerRelationshipAccess.LoadUsingTemplate(templateRow, ReadTransaction);
                                int supportingChurchCount = supportingChurchTable.Rows.Count;

                                // If the user has got RelationKey and PartnerKey back to front we will get no results
                                PersonFormData.SendingChurchName = String.Empty;

                                for (int i = 0; i < supportingChurchCount; i++)
                                {
                                    // Go round each supporting church
                                    // Get the short name for the sending church
                                    // Foreign key constraint means that this row is bound to exist
                                    string churchName;
                                    TPartnerClass churchClass;
                                    TStdPartnerStatusCode churchStatus;
                                    long supportingChurchKey = ((PPartnerRelationshipRow)supportingChurchTable.Rows[i]).PartnerKey;

                                    if (MCommonMain.RetrievePartnerShortName(supportingChurchKey, out churchName, out churchClass, out churchStatus,
                                            ReadTransaction))
                                    {
                                        // The church name can be empty but that would be unusual
                                        // churchClass should be CHURCH or ORGANISATION if everything is the right way round
                                        // but we do not check this - nor churchStatus
                                        if (churchName.Length == 0)
                                        {
                                            churchName = Catalog.GetString("Not available");
                                        }

                                        if (supportingChurchCount > 1)
                                        {
                                            if (i > 0)
                                            {
                                                PersonFormData.SendingChurchName += Catalog.GetString(" AND ");
                                            }

                                            PersonFormData.SendingChurchName += String.Format("{0}: '{1}'", i + 1, churchName);
                                        }
                                        else
                                        {
                                            PersonFormData.SendingChurchName += String.Format("'{0}'", churchName);
                                        }
                                    }
                                }

                                // we need this for later in case we retrieve family members
                                FamilyKey = PersonRow.FamilyKey;

                                // retrieve Special Needs information
                                if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eSpecialNeeds))
                                {
                                    PmSpecialNeedTable SpecialNeedTable;
                                    PmSpecialNeedRow SpecialNeedRow;
                                    SpecialNeedTable = PmSpecialNeedAccess.LoadViaPPerson(APartnerKey, ReadTransaction);

                                    if (SpecialNeedTable.Count > 0)
                                    {
                                        SpecialNeedRow = (PmSpecialNeedRow)SpecialNeedTable.Rows[0];
                                        PersonFormData.DietaryNeeds = SpecialNeedRow.DietaryComment;
                                        PersonFormData.MedicalNeeds = SpecialNeedRow.MedicalComment;
                                        PersonFormData.OtherNeeds = SpecialNeedRow.OtherSpecialNeed;
                                        PersonFormData.Vegetarian = SpecialNeedRow.VegetarianFlag;
                                    }
                                }

                                // retrieve Personal Data information
                                if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePersonalData))
                                {
                                    PmPersonalDataTable PersonalDataTable;
                                    PmPersonalDataRow PersonalDataRow;
                                    PersonalDataTable = PmPersonalDataAccess.LoadViaPPerson(APartnerKey, ReadTransaction);

                                    if (PersonalDataTable.Count > 0)
                                    {
                                        PersonalDataRow = (PmPersonalDataRow)PersonalDataTable.Rows[0];

                                        if (!PersonalDataRow.IsBelieverSinceYearNull()
                                            && (PersonalDataRow.BelieverSinceYear != 0))
                                        {
                                            PersonFormData.YearsBeliever = (DateTime.Today.Year - PersonalDataRow.BelieverSinceYear).ToString();
                                        }

                                        PersonFormData.CommentBeliever = PersonalDataRow.BelieverSinceComment;
                                    }
                                }
                            }
                        }

                        // retrieve Family member information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eFamilyMember))
                        {
                            // Retrieve family key for FAMILY class. In case of PERSON this has already been done earlier.
                            if (PartnerClass == TPartnerClass.FAMILY)
                            {
                                FamilyKey = APartnerKey;
                            }

                            if (FamilyKey != 0)
                            {
                                PPersonTable FamilyMembersTable;
                                TFormDataFamilyMember FamilyMemberRecord;
                                String PersonShortName;
                                TPartnerClass PersonClass;
                                FamilyMembersTable = PPersonAccess.LoadViaPFamily(FamilyKey, ReadTransaction);

                                foreach (PPersonRow PersonRow in FamilyMembersTable.Rows)
                                {
                                    // only add this person if it is not the main record
                                    if (PersonRow.PartnerKey != APartnerKey)
                                    {
                                        FamilyMemberRecord = new TFormDataFamilyMember();

                                        TPartnerServerLookups.GetPartnerShortName(PersonRow.PartnerKey, out PersonShortName, out PersonClass);
                                        FamilyMemberRecord.Name = PersonShortName;
                                        FamilyMemberRecord.DateOfBirth = PersonRow.DateOfBirth;

                                        formData.AddFamilyMember(FamilyMemberRecord);
                                    }
                                }
                            }
                        }

                        // retrieve Contact information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eContact))
                        {
                            string Phone;
                            string Email;

                            // retrieve primary phone and primary email
                            TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(APartnerKey, out Phone, out Email);

                            formData.PrimaryPhone = Phone;
                            formData.PrimaryEmail = Email;

                            // check for skype as it may not often be used
                            // if there is more than one skype id then at the moment the first one found is used
                            if (AFormLetterInfo.ContainsTag("Skype"))
                            {
                                PPartnerAttributeTable AttributeTable = PPartnerAttributeAccess.LoadViaPPartner(APartnerKey, ReadTransaction);

                                foreach (PPartnerAttributeRow AttributeRow in AttributeTable.Rows)
                                {
                                    if (AttributeRow.AttributeType == "Skype") // check if we can maybe use constant value instead of string
                                    {
                                        formData.Skype = AttributeRow.Value;
                                        break;
                                    }
                                }
                            }
                        }

                        // retrieve Location and formality information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLocation)
                            || AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLocationBlock)
                            || AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eFormalGreetings))
                        {
                            PLocationTable LocationTable;
                            PLocationRow LocationRow;
                            String CountryName = "";

                            if (ALocationKey == 0)
                            {
                                // no address set -> retrieve best address
                                TAddressTools.GetBestAddress(APartnerKey, out LocationTable, out CountryName, ReadTransaction);
                            }
                            else
                            {
                                LocationTable = PLocationAccess.LoadByPrimaryKey(ASiteKey, ALocationKey, ReadTransaction);
                            }

                            if (LocationTable.Count > 0)
                            {
                                LocationRow = (PLocationRow)LocationTable.Rows[0];
                                formData.LocationKey = LocationRow.LocationKey;
                                formData.Address1 = LocationRow.Locality;
                                formData.AddressStreet2 = LocationRow.StreetName;
                                formData.Address3 = LocationRow.Address3;
                                formData.PostalCode = LocationRow.PostalCode;
                                formData.County = LocationRow.County;
                                formData.CountryName = CountryName;
                                formData.City = LocationRow.City;
                                formData.CountryCode = LocationRow.CountryCode;

                                // retrieve country name from country table
                                TCacheable CachePopulator = new TCacheable();
                                PCountryTable CountryTable = (PCountryTable)CachePopulator.GetCacheableTable(TCacheableCommonTablesEnum.CountryList);
                                PCountryRow CountryRow = (PCountryRow)CountryTable.Rows.Find(new object[] { LocationRow.CountryCode });

                                if (CountryRow != null)
                                {
                                    formData.CountryName = CountryRow.CountryName;
                                    formData.CountryInLocalLanguage = CountryRow.CountryNameLocal;
                                }
                            }

                            // build address block (need to have retrieved location data beforehand)
                            if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLocationBlock))
                            {
                                formData.AddressBlock = BuildAddressBlock(formData, AFormLetterInfo.AddressLayoutCode, PartnerClass, ReadTransaction);
                            }

                            // retrieve formality information (need to have retrieved country, language and addressee type beforehand)
                            if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eFormalGreetings))
                            {
                                String SalutationText;
                                String ClosingText;

                                InitializeFormality(AFormLetterInfo, ReadTransaction);
                                AFormLetterInfo.RetrieveFormalityGreeting(formData, out SalutationText, out ClosingText);
                                ResolveGreetingPlaceholders(formData, AFormLetterInfo, APartnerKey, ShortName, PartnerClass, ref SalutationText,
                                    ref ClosingText, ReadTransaction);

                                formData.FormalSalutation = SalutationText;
                                formData.FormalClosing = ClosingText;
                            }
                        }

                        // retrieve Contact Log information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eContactLog))
                        {
                            PContactLogTable ContactLogTable;
                            TFormDataContactLog ContactLogRecord;
                            ContactLogTable = PContactLogAccess.LoadViaPPartnerPPartnerContact(APartnerKey, ReadTransaction);

                            foreach (PContactLogRow ContactLogRow in ContactLogTable.Rows)
                            {
                                ContactLogRecord = new TFormDataContactLog();

                                ContactLogRecord.Contactor = ContactLogRow.Contactor;
                                ContactLogRecord.Notes = ContactLogRow.ContactComment;

                                formData.AddContactLog(ContactLogRecord);
                            }
                        }

                        // retrieve Subscription information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eSubscription))
                        {
                            PSubscriptionTable SubscriptionTable;
                            TFormDataSubscription SubscriptionRecord;

                            SubscriptionTable = PSubscriptionAccess.LoadViaPPartnerPartnerKey(APartnerKey, ReadTransaction);

                            foreach (PSubscriptionRow SubscriptionRow in SubscriptionTable.Rows)
                            {
                                SubscriptionRecord = new TFormDataSubscription();

                                SubscriptionRecord.PublicationCode = SubscriptionRow.PublicationCode;
                                SubscriptionRecord.Status = SubscriptionRow.SubscriptionStatus;

                                formData.AddSubscription(SubscriptionRecord);
                            }
                        }

                        // retrieve banking information
                        if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eBanking))
                        {
                            PBankingDetailsUsageTable BankingDetailsUsageTable = new PBankingDetailsUsageTable();
                            PBankingDetailsUsageRow BankingDetailsUsageTemplateRow = BankingDetailsUsageTable.NewRowTyped(false);
                            BankingDetailsUsageTemplateRow.PartnerKey = APartnerKey;
                            BankingDetailsUsageTemplateRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN;

                            BankingDetailsUsageTable = PBankingDetailsUsageAccess.LoadUsingTemplate(BankingDetailsUsageTemplateRow, ReadTransaction);

                            if (BankingDetailsUsageTable.Count > 0)
                            {
                                // in this case there is a main bank account for this partner
                                PBankingDetailsTable BankingDetailsTable;
                                PBankingDetailsRow BankingDetailsRow;

                                BankingDetailsTable =
                                    (PBankingDetailsTable)(PBankingDetailsAccess.LoadByPrimaryKey(((PBankingDetailsUsageRow)BankingDetailsUsageTable.
                                                                                                   Rows[0]).
                                                               BankingDetailsKey, ReadTransaction));

                                if (BankingDetailsTable.Count > 0)
                                {
                                    BankingDetailsRow = (PBankingDetailsRow)BankingDetailsTable.Rows[0];
                                    formData.BankAccountName = BankingDetailsRow.AccountName;
                                    formData.BankAccountNumber = BankingDetailsRow.BankAccountNumber;
                                    formData.IBANUnformatted = BankingDetailsRow.Iban;
                                    //formData.IBANFormatted = ...;

                                    // now retrieve bank information
                                    PBankTable BankTable;
                                    PBankRow BankRow;

                                    BankTable = (PBankTable)(PBankAccess.LoadByPrimaryKey(BankingDetailsRow.BankKey, ReadTransaction));

                                    if (BankTable.Count > 0)
                                    {
                                        BankRow = (PBankRow)BankTable.Rows[0];
                                        formData.BankName = BankRow.BranchName;
                                        formData.BankBranchCode = BankRow.BranchCode;
                                        formData.BICSwiftCode = BankRow.Bic;
                                    }
                                }
                            }
                        }

                        if ((PartnerClass == TPartnerClass.PERSON)
                            && (formData.GetType() == typeof(TFormDataPerson)))
                        {
                            // retrieve Passport information
                            if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.ePassport))
                            {
                                PmPassportDetailsTable PassportTable;
                                TFormDataPassport PassportRecord;
                                PassportTable = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, ReadTransaction);

                                foreach (PmPassportDetailsRow PassportRow in PassportTable.Rows)
                                {
                                    PassportRecord = new TFormDataPassport();

                                    PassportRecord.PassportName = PassportRow.FullPassportName;
                                    PassportRecord.NationalityCode = PassportRow.PassportNationalityCode;

                                    // retrieve country name from country table
                                    TCacheable CachePopulator = new TCacheable();
                                    PCountryTable CountryTable =
                                        (PCountryTable)CachePopulator.GetCacheableTable(TCacheableCommonTablesEnum.CountryList);
                                    PCountryRow CountryRow = (PCountryRow)CountryTable.Rows.Find(new object[] { PassportRow.PassportNationalityCode });

                                    if (CountryRow != null)
                                    {
                                        PassportRecord.NationalityName = CountryRow.CountryName;
                                    }

                                    PassportRecord.TypeCode = PassportRow.PassportDetailsType;
                                    // retrieve passport type name from type table
                                    TPersonnelCacheable PersonnelCachePopulator = new TPersonnelCacheable();
                                    PtPassportTypeTable TypeTable =
                                        (PtPassportTypeTable)PersonnelCachePopulator.GetCacheableTable(TCacheablePersonTablesEnum.PassportTypeList);
                                    PtPassportTypeRow TypeRow = (PtPassportTypeRow)TypeTable.Rows.Find(new object[] { PassportRow.PassportDetailsType });

                                    if (TypeRow != null)
                                    {
                                        PassportRecord.TypeDescription = TypeRow.Description;
                                    }

                                    // set number and nationality in main record (only for main passport or if there is just one)
                                    if (PassportRow.MainPassport || (PassportTable.Count == 1))
                                    {
                                        ((TFormDataPerson)formData).PassportNumber = PassportRow.PassportNumber;
                                        ((TFormDataPerson)formData).PassportNationality = PassportRow.PassportNationalityCode;
                                        ((TFormDataPerson)formData).PassportName = PassportRow.FullPassportName;
                                    }

                                    PassportRecord.DateOfIssue = PassportRow.DateOfIssue;
                                    PassportRecord.PlaceOfIssue = PassportRow.PlaceOfIssue;
                                    PassportRecord.DateOfExpiry = PassportRow.DateOfExpiration;
                                    PassportRecord.PlaceOfBirth = PassportRow.PlaceOfBirth;

                                    ((TFormDataPerson)formData).AddPassport(PassportRecord);
                                }
                            }

                            // retrieve Language information
                            if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eLanguage))
                            {
                                PmPersonLanguageTable PersonLanguageTable;
                                TFormDataLanguage PersonLanguageRecord;
                                PersonLanguageTable = PmPersonLanguageAccess.LoadViaPPerson(APartnerKey, ReadTransaction);

                                foreach (PmPersonLanguageRow PersonLanguageRow in PersonLanguageTable.Rows)
                                {
                                    PersonLanguageRecord = new TFormDataLanguage();

                                    PersonLanguageRecord.Code = PersonLanguageRow.LanguageCode;

                                    // retrieve language name from language table
                                    TCacheable CachePopulator = new TCacheable();
                                    PLanguageTable LanguageTable =
                                        (PLanguageTable)CachePopulator.GetCacheableTable(TCacheableCommonTablesEnum.LanguageCodeList);
                                    PLanguageRow LanguageRow = (PLanguageRow)LanguageTable.Rows.Find(new object[] { PersonLanguageRow.LanguageCode });

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

                                    PersonLanguageRecord.Level = PersonLanguageRow.LanguageLevel.ToString();

                                    // retrieve language level name from language level table
                                    TPersonnelCacheable CachePopulatorPersonnel = new TPersonnelCacheable();
                                    PtLanguageLevelTable LanguageLevelTable =
                                        (PtLanguageLevelTable)CachePopulatorPersonnel.GetCacheableTable(TCacheablePersonTablesEnum.LanguageLevelList);
                                    PtLanguageLevelRow LanguageLevelRow =
                                        (PtLanguageLevelRow)LanguageLevelTable.Rows.Find(new object[] { PersonLanguageRow.LanguageLevel });

                                    if (LanguageLevelRow != null)
                                    {
                                        PersonLanguageRecord.LevelDesc = LanguageLevelRow.LanguageLevelDescr;
                                    }

                                    PersonLanguageRecord.Comment = PersonLanguageRow.Comment;

                                    ((TFormDataPerson)formData).AddLanguage(PersonLanguageRecord);
                                }
                            }

                            // retrieve Skill information
                            if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eSkill))
                            {
                                PmPersonSkillTable PersonSkillTable;
                                TFormDataSkill PersonSkillRecord;
                                PersonSkillTable = PmPersonSkillAccess.LoadViaPPerson(APartnerKey, ReadTransaction);

                                foreach (PmPersonSkillRow PersonSkillRow in PersonSkillTable.Rows)
                                {
                                    PersonSkillRecord = new TFormDataSkill();

                                    PersonSkillRecord.Category = PersonSkillRow.SkillCategoryCode;
                                    PersonSkillRecord.Description = PersonSkillRow.DescriptionEnglish;

                                    // if no description in local language then use english
                                    PersonSkillRecord.DescriptionLocalOrDefault = PersonSkillRow.DescriptionLocal;

                                    if (PersonSkillRow.DescriptionLocal != "")
                                    {
                                        PersonSkillRecord.DescriptionLocalOrDefault = PersonSkillRow.DescriptionEnglish;
                                    }

                                    PersonSkillRecord.Level = PersonSkillRow.SkillLevel;

                                    // retrieve skill level name from skill level table
                                    TPersonnelCacheable CachePopulatorPersonnel = new TPersonnelCacheable();
                                    PtSkillLevelTable SkillLevelTable =
                                        (PtSkillLevelTable)CachePopulatorPersonnel.GetCacheableTable(TCacheablePersonTablesEnum.SkillLevelList);
                                    PtSkillLevelRow SkillLevelRow =
                                        (PtSkillLevelRow)SkillLevelTable.Rows.Find(new object[] { PersonSkillRow.SkillLevel });

                                    if (SkillLevelRow != null)
                                    {
                                        PersonSkillRecord.LevelDesc = SkillLevelRow.Description;
                                    }

                                    PersonSkillRecord.YearsExp = PersonSkillRow.YearsOfExperience;
                                    PersonSkillRecord.Professional = PersonSkillRow.ProfessionalSkill;
                                    PersonSkillRecord.Degree = PersonSkillRow.Degree;
                                    PersonSkillRecord.Comment = PersonSkillRow.Comment;

                                    ((TFormDataPerson)formData).AddSkill(PersonSkillRecord);
                                }
                            }

                            // retrieve past work experience information
                            if (AFormLetterInfo.IsRetrievalRequested(TFormDataRetrievalSection.eWorkExperience))
                            {
                                TFormDataWorkExperience PersonExpRecord;
                                String UnitShortName;
                                TPartnerClass UnitClass;

                                // retrieve applications for short term events
                                String SqlStmt = TDataBase.ReadSqlFile("Personnel.FormLetters.GetAppTravelDates.sql");

                                OdbcParameter[] parameters = new OdbcParameter[1];
                                parameters[0] = new OdbcParameter("PartnerKey", OdbcType.BigInt);
                                parameters[0].Value = APartnerKey;

                                DataTable travelData = DBAccess.GDBAccessObj.SelectDT(SqlStmt, "TravelDates", ReadTransaction, parameters);

                                for (int i = 0; i < travelData.Rows.Count; i++)
                                {
                                    PersonExpRecord = new TFormDataWorkExperience();

                                    if ((travelData.Rows[i][0]).GetType() == typeof(DateTime))
                                    {
                                        PersonExpRecord.StartDate = (DateTime?)travelData.Rows[i][0];
                                    }

                                    if ((travelData.Rows[i][1]).GetType() == typeof(DateTime))
                                    {
                                        PersonExpRecord.EndDate = (DateTime?)travelData.Rows[i][1];
                                    }

                                    PersonExpRecord.Organisation = "";
                                    PersonExpRecord.Role = "";
                                    PersonExpRecord.Category = "";
                                    PersonExpRecord.SameOrg = true;
                                    PersonExpRecord.SimilarOrg = true;
                                    PersonExpRecord.Comment = "";

                                    // check if unit exists and use unit name as location
                                    if (TPartnerServerLookups.GetPartnerShortName((Int64)travelData.Rows[i][2], out UnitShortName, out UnitClass))
                                    {
                                        PersonExpRecord.Location = UnitShortName;
                                    }
                                    else
                                    {
                                        PersonExpRecord.Location = travelData.Rows[i][3].ToString();
                                    }

                                    ((TFormDataPerson)formData).AddWorkExperience(PersonExpRecord);
                                }

                                // retrieve actual past experience records
                                PmPastExperienceTable PersonExpTable;
                                PersonExpTable = PmPastExperienceAccess.LoadViaPPerson(APartnerKey, ReadTransaction);

                                foreach (PmPastExperienceRow PersonExpRow in PersonExpTable.Rows)
                                {
                                    PersonExpRecord = new TFormDataWorkExperience();

                                    PersonExpRecord.StartDate = PersonExpRow.StartDate;
                                    PersonExpRecord.EndDate = PersonExpRow.EndDate;
                                    PersonExpRecord.Location = PersonExpRow.PrevLocation;
                                    PersonExpRecord.Organisation = PersonExpRow.OtherOrganisation;
                                    PersonExpRecord.Role = PersonExpRow.PrevRole;
                                    PersonExpRecord.Category = PersonExpRow.Category;
                                    PersonExpRecord.SameOrg = PersonExpRow.PrevWorkHere;
                                    PersonExpRecord.SimilarOrg = PersonExpRow.PrevWork;
                                    PersonExpRecord.Comment = PersonExpRow.PastExpComments;

                                    ((TFormDataPerson)formData).AddWorkExperience(PersonExpRecord);
                                }
                            }
                        }
                    }
                });

            AFormDataPartner = formData;
        }
Example #2
0
        /// <summary>
        ///  add work experience record to list
        /// </summary>
        public void AddWorkExperience(TFormDataWorkExperience ARecord)
        {
            WorkExp.Add(ARecord);

            if (ARecord.SimilarOrg
                || ARecord.SameOrg)
            {
                WorkExpNonProfit.Add(ARecord);
            }
            else
            {
                WorkExpOther.Add(ARecord);
            }
        }