Exemplo n.º 1
0
        /// <summary>
        /// Get the passport details and estores them as parameters.
        /// If there is a passport with the MainPassport flag set, then use this passport.
        /// Otherwise use the most recent passport which has a passport number.
        /// </summary>
        /// <param name="APartnerKey">Partner key</param>
        /// <returns>true if one passport was found, otherwise false</returns>
        private bool GetPassport(Int64 APartnerKey)
        {
            PmPassportDetailsTable PassportTable = new PmPassportDetailsTable();

            PmPassportDetailsRow ResultPassportRow = GetLatestPassport(APartnerKey, situation);

            if (ResultPassportRow != null)
            {
                // add the results to the parameters
                foreach (DataColumn col in PassportTable.Columns)
                {
                    situation.GetParameters().Add(StringHelper.UpperCamelCase(col.ColumnName, true,
                                                                              true), new TVariant(ResultPassportRow[col.ColumnName]));
                }
            }
            else
            {
                // add empty results to the parameters.
                // Otherwise the old rsults from the previous calculations will be used.
                foreach (DataColumn col in PassportTable.Columns)
                {
                    situation.GetParameters().Add(StringHelper.UpperCamelCase(col.ColumnName, true,
                                                                              true), new TVariant(""));
                }
            }

            return(ResultPassportRow != null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines a PERSON's Nationalities (deduced from its passports).
        /// </summary>
        /// <remarks>
        /// <para>Algorithm:</para>
        /// <list type="number">
        ///   <item>Check pm_main_passport_l flag</item>
        ///     <list type="number">
        ///       <item>if null, don't do anything special (Note: Partner Import does not write to this field, it stays null if it isn't found in the import file [which will be the case for Petra 2.x])</item>
        ///       <item>if false, do likewise</item>
        ///       <item>if true, list as FIRST Country</item>
        ///     </list>
        ///   </list>
        /// <item>Order by pm_date_of_issue_d</item>
        ///   <list type="number">
        ///     <item>order Countries by pm_date_of_issue_d DESC, except for the FIRST Country</item>
        ///     <list type="number">
        ///       <item>in case there are several FIRST Countries (which in theory should not happen), they are ordered by pm_date_of_issue_d DESC in themselves at the beginning of the list of Countries.</item>
        ///     </list>
        ///   </list>
        /// <item>Check for passport expiration</item>
        ///   <list type="number">
        ///     <item>If a passport's expiry date is set and it is in the past</item>
        ///     <list type="number">
        ///       <item>show the Country + " (exp.)".</item>
        ///     </list>
        ///   </list>
        /// <item>Elimination of duplicate listings</item>
        ///   <list type="number">
        ///     <item>If a country of issue comes up twice</item>
        ///     <list type="number">
        ///       <item>eliminate the duplicate, except if the Country is listed once by its name and one with the exp. postfix.</item>
        ///     </list>
        ///   </list>
        /// <para>Additionally, a warning text " MAIN!)" to the postfix " (exp." is added if the expired passport is the
        /// 'Main Passport' (pm_main_passport_l=true) of the PERSON.</para>
        /// </remarks>
        /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside).
        /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param>
        /// <param name="APassportDetailsDT"></param>
        /// <returns></returns>
        public static string DeterminePersonsNationalities(TGetCacheableDataTableFromCache ACacheRetriever, PmPassportDetailsTable APassportDetailsDT)
        {
            HashSet <string>     Nationalities    = new HashSet <string>();
            string               NationalitiesStr = String.Empty;
            PmPassportDetailsRow PassportDR;

            DataView OrderedPassportsDV = new DataView(
                APassportDetailsDT, null, PmPassportDetailsTable.GetDateOfIssueDBName() + " DESC",
                DataViewRowState.CurrentRows);

            // If a Passport's MainPassport flag is set, record it as the first Nationality
            foreach (DataRowView OrderedPassport in OrderedPassportsDV)
            {
                PassportDR = (PmPassportDetailsRow)OrderedPassport.Row;

                if (!PassportDR.IsMainPassportNull() &&
                    PassportDR.MainPassport)
                {
                    // Add the Nationality (Note: Duplicates are taken care of automatically as this is a HashSet!)
                    Nationalities.Add(DeterminePassportNationality(ACacheRetriever, PassportDR));

                    // Note: We could leave the loop here if we assume that there is ever only going to be ONE
                    // 'first Nationality', but that assumption could be wrong and we want to make sure to list
                    // all 'first Nationalities', ordered by pm_date_of_issue_d DESC in themselves.
                }
            }

            // Add the rest of the Nationalities (Note: Duplicates are taken care of automatically as this is a HashSet!)
            foreach (DataRowView OrderedPassport in OrderedPassportsDV)
            {
                Nationalities.Add(DeterminePassportNationality(ACacheRetriever, (PmPassportDetailsRow)OrderedPassport.Row));
            }

            // Put all Nationalities in a string
            foreach (string Nationality in Nationalities)
            {
                NationalitiesStr += Nationality + ", ";
            }

            if (NationalitiesStr.Length > 0)
            {
                return(NationalitiesStr.Substring(0, NationalitiesStr.Length - 2));  // remove last comma
            }
            else
            {
                return(String.Empty);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets nationalities from all of a Partner's recorded passports
        /// </summary>
        /// <param name="APartnerKey">Partner key</param>
        /// <returns>returns nationalities in a comma seperated string</returns>
        private string GetNationalities(Int64 APartnerKey)
        {
            TCacheable CommonCacheable = new TCacheable();

            StringCollection PassportColumns = StringHelper.StrSplit(
                PmPassportDetailsTable.GetDateOfIssueDBName() + "," +
                PmPassportDetailsTable.GetDateOfExpirationDBName() + "," +
                PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," +
                PmPassportDetailsTable.GetMainPassportDBName(), ",");

            PmPassportDetailsTable PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey,
                                                                                              PassportColumns, situation.GetDatabaseConnection().Transaction, null, 0, 0);

            return(Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities(
                       @CommonCacheable.GetCacheableTable, PassportDetailsDT));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the passport details and restores them as parameters.
        /// If there is a passport with the MainPassport flag set, then use this passport.
        /// Otherwise use the most recent passport which has a passport number.
        /// </summary>
        /// <param name="APartnerKey">Partner key</param>
        /// <param name="ASituation">A current Report Situation</param>
        /// <returns>true if one passport was found, otherwise false</returns>
        public static PmPassportDetailsRow GetLatestPassport(Int64 APartnerKey, TRptSituation ASituation)
        {
            PmPassportDetailsTable PassportTable     = null;
            PmPassportDetailsRow   ResultPassportRow = null;

            StringCollection PassportCollumns = new StringCollection();
            StringCollection OrderList        = new StringCollection();

            PassportCollumns.Add(PmPassportDetailsTable.GetPassportNationalityCodeDBName());
            PassportCollumns.Add(PmPassportDetailsTable.GetPassportNumberDBName());
            PassportCollumns.Add(PmPassportDetailsTable.GetDateOfExpirationDBName());
            PassportCollumns.Add(PmPassportDetailsTable.GetFullPassportNameDBName());
            OrderList.Add("ORDER BY " + PmPassportDetailsTable.GetDateOfExpirationDBName() + " DESC");

            PassportTable = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey,
                                                                   PassportCollumns, ASituation.GetDatabaseConnection().Transaction,
                                                                   OrderList, 0, 0);

            // Look for MainPassport flag
            foreach (PmPassportDetailsRow Row in PassportTable.Rows)
            {
                if (!Row.IsMainPassportNull() &&
                    Row.MainPassport)
                {
                    ResultPassportRow = Row;
                    break;
                }
            }

            // Look for the most recent passport with a passport number
            if (ResultPassportRow == null)
            {
                foreach (PmPassportDetailsRow Row in PassportTable.Rows)
                {
                    if (Row.PassportNumber.Length > 0)
                    {
                        ResultPassportRow = Row;
                        break;
                    }
                }
            }

            return(ResultPassportRow);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds one partner to the report table
        /// </summary>
        /// <param name="APartnerKey">The partner key of the current partner</param>
        /// <param name="AGender">Gender of the current partner</param>
        /// <param name="ALanguageCode">The mother language of the current partner</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns></returns>
        public bool CalculateNationalities(long APartnerKey, String AGender, String ALanguageCode, ref TRptSituation ASituation)
        {
            TCacheable CommonCacheable = new TCacheable();

            StringCollection PassportColumns = StringHelper.StrSplit(
                PmPassportDetailsTable.GetDateOfIssueDBName() + "," +
                PmPassportDetailsTable.GetDateOfExpirationDBName() + "," +
                PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," +
                PmPassportDetailsTable.GetMainPassportDBName(), ",");

            PmPassportDetailsTable PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey,
                                                                                              PassportColumns, ASituation.GetDatabaseConnection().Transaction, null, 0, 0);

            string Nationalities = Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities(
                @CommonCacheable.GetCacheableTable, PassportDetailsDT);

            string[] NationalitiesArray = Nationalities.Split(',');

            bool          FoundNationality      = false;
            List <string> PreviousNationalities = new List <string>();

            foreach (string Nationality in NationalitiesArray)
            {
                string SingleNationality = Nationality;

                // remove all characters other than the country name
                SingleNationality = Nationality.TrimStart(' ');

                if (SingleNationality.EndsWith(Ict.Petra.Shared.MPersonnel.Calculations.PASSPORT_EXPIRED))
                {
                    SingleNationality = SingleNationality.Remove(SingleNationality.Length -
                                                                 Ict.Petra.Shared.MPersonnel.Calculations.PASSPORT_EXPIRED.Length);
                }
                else if (SingleNationality.EndsWith(Ict.Petra.Shared.MPersonnel.Calculations.PASSPORTMAIN_EXPIRED))
                {
                    SingleNationality = SingleNationality.Remove(SingleNationality.Length -
                                                                 Ict.Petra.Shared.MPersonnel.Calculations.PASSPORTMAIN_EXPIRED.Length);
                }

                if (SingleNationality == "")
                {
                    SingleNationality = Catalog.GetString("UNKNOWN");
                }

                // make sure that this nationality has not already been processed for this partner
                if (!PreviousNationalities.Contains(SingleNationality))
                {
                    for (int Counter = 0; Counter < FNationalityTable.Rows.Count; ++Counter)
                    {
                        if (((String)FNationalityTable.Rows[Counter][COLUMNNATIONALITYCODE] == SingleNationality))
                        {
                            FoundNationality = true;
                            AddAttendeeToTable(Counter, AGender, SingleNationality, ALanguageCode);
                        }
                    }

                    if (!FoundNationality)
                    {
                        AddAttendeeToTable(-1, AGender, SingleNationality, ALanguageCode);
                    }

                    PreviousNationalities.Add(SingleNationality);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines a PERSON's Nationalities (deduced from its passports).
        /// </summary>
        /// <remarks>
        /// <para>Algorithm:</para>
        /// <list type="number">
        ///   <item>Check pm_main_passport_l flag</item>
        ///     <list type="number">
        ///       <item>if null, don't do anything special (Note: Partner Import does not write to this field, it stays null if it isn't found in the import file [which will be the case for Petra 2.x])</item>
        ///       <item>if false, do likewise</item>
        ///       <item>if true, list as FIRST Country</item>
        ///     </list>
        ///   </list>
        /// <item>Order by pm_date_of_issue_d</item>
        ///   <list type="number">
        ///     <item>order Countries by pm_date_of_issue_d DESC, except for the FIRST Country</item>
        ///     <list type="number">
        ///       <item>in case there are several FIRST Countries (which in theory should not happen), they are ordered by pm_date_of_issue_d DESC in themselves at the beginning of the list of Countries.</item>
        ///     </list>
        ///   </list>
        /// <item>Check for passport expiration</item>
        ///   <list type="number">
        ///     <item>If a passport's expiry date is set and it is in the past</item>
        ///     <list type="number">
        ///       <item>show the Country + " (exp.)".</item>
        ///     </list>
        ///   </list>
        /// <item>Elimination of duplicate listings</item>
        ///   <list type="number">
        ///     <item>If a country of issue comes up twice</item>
        ///     <list type="number">
        ///       <item>eliminate the duplicate, except if the Country is listed once by its name and one with the exp. postfix.</item>
        ///     </list>
        ///   </list>
        /// <para>Additionally, a warning text " MAIN!)" to the postfix " (exp." is added if the expired passport is the
        /// 'Main Passport' (pm_main_passport_l=true) of the PERSON.</para>
        /// </remarks>
        /// <param name="ACacheRetriever">Delegate that returns the specified DataTable from the data cache (client- or serverside).
        /// Delegate Method needs to be for the MPartner Cache (that is, it needs to work with the <see cref="TCacheableCommonTablesEnum" /> Enum!</param>
        /// <param name="APassportDetailsDT"></param>
        /// <returns></returns>
        public static string DeterminePersonsNationalities(TGetCacheableDataTableFromCache ACacheRetriever, PmPassportDetailsTable APassportDetailsDT)
        {
            HashSet <string>Nationalities = new HashSet <string>();
            string NationalitiesStr = String.Empty;
            PmPassportDetailsRow PassportDR;

            DataView OrderedPassportsDV = new DataView(
                APassportDetailsDT, null, PmPassportDetailsTable.GetDateOfIssueDBName() + " DESC",
                DataViewRowState.CurrentRows);

            // If a Passport's MainPassport flag is set, record it as the first Nationality
            foreach (DataRowView OrderedPassport in OrderedPassportsDV)
            {
                PassportDR = (PmPassportDetailsRow)OrderedPassport.Row;

                if (!PassportDR.IsMainPassportNull()
                    && PassportDR.MainPassport)
                {
                    // Add the Nationality (Note: Duplicates are taken care of automatically as this is a HashSet!)
                    Nationalities.Add(DeterminePassportNationality(ACacheRetriever, PassportDR));

                    // Note: We could leave the loop here if we assume that there is ever only going to be ONE
                    // 'first Nationality', but that assumption could be wrong and we want to make sure to list
                    // all 'first Nationalities', ordered by pm_date_of_issue_d DESC in themselves.
                }
            }

            // Add the rest of the Nationalities (Note: Duplicates are taken care of automatically as this is a HashSet!)
            foreach (DataRowView OrderedPassport in OrderedPassportsDV)
            {
                Nationalities.Add(DeterminePassportNationality(ACacheRetriever, (PmPassportDetailsRow)OrderedPassport.Row));
            }

            // Put all Nationalities in a string
            foreach (string Nationality in Nationalities)
            {
                NationalitiesStr += Nationality + ", ";
            }

            if (NationalitiesStr.Length > 0)
            {
                return NationalitiesStr.Substring(0, NationalitiesStr.Length - 2);  // remove last comma
            }
            else
            {
                return String.Empty;
            }
        }
Exemplo n.º 7
0
        public static TSubmitChangesResult SubmitChangesServerSide(ref IndividualDataTDS AInspectDS,
                                                                   ref PartnerEditTDS APartnerEditInspectDS,
                                                                   TDBTransaction ASubmitChangesTransaction,
                                                                   out TVerificationResultCollection AVerificationResult)
        {
            TSubmitChangesResult SubmissionResult;

            PmJobAssignmentTable PmJobAssignmentTableSubmit;

            AVerificationResult = new TVerificationResultCollection();

            if (AInspectDS != null)
            {
                SubmissionResult = TSubmitChangesResult.scrOK;

                // Job Assignments: make sure that jobs exist for assignments
                if (AInspectDS.Tables.Contains(PmJobAssignmentTable.GetTableName()) &&
                    (AInspectDS.PmJobAssignment.Rows.Count > 0))
                {
                    UmJobTable JobTableTemp = new UmJobTable();

                    UmJobTable JobTableSubmit = new UmJobTable();
                    UmJobRow   JobRow;

                    PmJobAssignmentTableSubmit = AInspectDS.PmJobAssignment;

                    // every job_assignment_row needs to have a row that it references in um_job
                    foreach (PmJobAssignmentRow JobAssignmentRow in PmJobAssignmentTableSubmit.Rows)
                    {
                        if (JobAssignmentRow.RowState != DataRowState.Deleted)
                        {
                            JobTableTemp = UmJobAccess.LoadByPrimaryKey(JobAssignmentRow.UnitKey,
                                                                        JobAssignmentRow.PositionName,
                                                                        JobAssignmentRow.PositionScope,
                                                                        JobAssignmentRow.JobKey,
                                                                        ASubmitChangesTransaction);

                            // if no corresponding job record found then we need to create one
                            // (job key was already set on client side to new value so merging back to the
                            // client does not cause problems because of primary key change)
                            if (JobTableTemp.Count == 0)
                            {
                                JobRow = (UmJobRow)JobTableSubmit.NewRow();

                                JobRow.UnitKey          = JobAssignmentRow.UnitKey;
                                JobRow.PositionName     = JobAssignmentRow.PositionName;
                                JobRow.PositionScope    = JobAssignmentRow.PositionScope;
                                JobRow.JobKey           = JobAssignmentRow.JobKey;
                                JobRow.FromDate         = JobAssignmentRow.FromDate;
                                JobRow.ToDate           = JobAssignmentRow.ToDate;
                                JobRow.CommitmentPeriod = "None";
                                JobRow.TrainingPeriod   = "None";

                                // Need to update the JobKey field in job assignment table record from job record
                                JobAssignmentRow.JobKey = JobRow.JobKey;

                                JobTableSubmit.Rows.Add(JobRow);
                            }
                            else
                            {
                                // job record exists: in this case we need to update JobKey in
                                // the Job Assignment Record from Job Row
                                JobAssignmentRow.JobKey = ((UmJobRow)JobTableTemp.Rows[0]).JobKey;
                            }
                        }
                    }

                    // submit table with newly created jobs
                    if (JobTableSubmit.Rows.Count > 0)
                    {
                        UmJobAccess.SubmitChanges(JobTableSubmit, ASubmitChangesTransaction);
                    }
                }

                // now submit the whole dataset at once
                IndividualDataTDSAccess.SubmitChanges(AInspectDS);

                // Need to merge tables back into APartnerEditInspectDS so the updated s_modification_id_t is returned
                // correctly to the Partner Edit.
                // Unfortunately this can't be done simply by using merge method of the dataset since they are two different
                // types but has to be done per table.
                if (AInspectDS.Tables.Contains(PmSpecialNeedTable.GetTableName()) &&
                    (AInspectDS.PmSpecialNeed.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmSpecialNeedTable.GetTableName()].Merge(AInspectDS.PmSpecialNeed);
                }

                if (AInspectDS.Tables.Contains(PmPersonAbilityTable.GetTableName()) &&
                    (AInspectDS.PmPersonAbility.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPersonAbilityTable.GetTableName()].Merge(AInspectDS.PmPersonAbility);
                }

                if (AInspectDS.Tables.Contains(PmPassportDetailsTable.GetTableName()) &&
                    (AInspectDS.PmPassportDetails.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPassportDetailsTable.GetTableName()].Merge(AInspectDS.PmPassportDetails);
                }

                if (AInspectDS.Tables.Contains(PmPersonalDataTable.GetTableName()) &&
                    (AInspectDS.PmPersonalData.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPersonalDataTable.GetTableName()].Merge(AInspectDS.PmPersonalData);
                }

                if (AInspectDS.Tables.Contains(PmPersonLanguageTable.GetTableName()) &&
                    (AInspectDS.PmPersonLanguage.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPersonLanguageTable.GetTableName()].Merge(AInspectDS.PmPersonLanguage);
                }

                if (AInspectDS.Tables.Contains(PmPersonEvaluationTable.GetTableName()) &&
                    (AInspectDS.PmPersonEvaluation.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPersonEvaluationTable.GetTableName()].Merge(AInspectDS.PmPersonEvaluation);
                }

                if (AInspectDS.Tables.Contains(PmStaffDataTable.GetTableName()) &&
                    (AInspectDS.PmStaffData.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmStaffDataTable.GetTableName()].Merge(AInspectDS.PmStaffData);
                }

                if (AInspectDS.Tables.Contains(PmPersonSkillTable.GetTableName()) &&
                    (AInspectDS.PmPersonSkill.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPersonSkillTable.GetTableName()].Merge(AInspectDS.PmPersonSkill);
                }

                if (AInspectDS.Tables.Contains(PmPastExperienceTable.GetTableName()) &&
                    (AInspectDS.PmPastExperience.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmPastExperienceTable.GetTableName()].Merge(AInspectDS.PmPastExperience);
                }

                if (AInspectDS.Tables.Contains(PmDocumentTable.GetTableName()) &&
                    (AInspectDS.PmDocument.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmDocumentTable.GetTableName()].Merge(AInspectDS.PmDocument);
                }

                if (AInspectDS.Tables.Contains(PmJobAssignmentTable.GetTableName()) &&
                    (AInspectDS.PmJobAssignment.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmJobAssignmentTable.GetTableName()].Merge(AInspectDS.PmJobAssignment);
                }

                if (AInspectDS.Tables.Contains(PmGeneralApplicationTable.GetTableName()) &&
                    (AInspectDS.PmGeneralApplication.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmGeneralApplicationTable.GetTableName()].Merge(AInspectDS.PmGeneralApplication);
                }

                if (AInspectDS.Tables.Contains(PmShortTermApplicationTable.GetTableName()) &&
                    (AInspectDS.PmShortTermApplication.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmShortTermApplicationTable.GetTableName()].Merge(AInspectDS.PmShortTermApplication);
                }

                if (AInspectDS.Tables.Contains(PmYearProgramApplicationTable.GetTableName()) &&
                    (AInspectDS.PmYearProgramApplication.Rows.Count > 0))
                {
                    APartnerEditInspectDS.Tables[PmYearProgramApplicationTable.GetTableName()].Merge(AInspectDS.PmYearProgramApplication);
                }
            }
            else
            {
                TLogging.LogAtLevel(8, "TIndividualDataWebConnector.SubmitChangesServerSide: AInspectDS = nil!");
                SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved;
            }

            return(SubmissionResult);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Retrieves data that will be shown on the 'Overview' UserControl and adds it to <paramref name="AIndividualDataDS" />.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of the Person to load data for.</param>
        /// <param name="AIndividualDataDS">Typed DataSet of Type <see cref="IndividualDataTDS" />. Needs to be instantiated already!</param>
        /// <param name="AReadTransaction">Open Database transaction.</param>
        /// <returns>void</returns>
        private static void BuildSummaryData(Int64 APartnerKey, ref IndividualDataTDS AIndividualDataDS, TDBTransaction AReadTransaction)
        {
            string StrNotAvailable = Catalog.GetString("Not Available");
            IndividualDataTDSSummaryDataTable     SummaryDT;
            IndividualDataTDSSummaryDataRow       SummaryDR;
            IndividualDataTDSMiscellaneousDataRow MiscellaneousDataDR = AIndividualDataDS.MiscellaneousData[0];
            PPersonTable           PPersonDT;
            PPersonRow             PersonDR = null;
            PmPassportDetailsTable PassportDetailsDT;
            PmStaffDataTable       PmStaffDataDT;
            PmStaffDataRow         PmStaffDataDR     = null;
            PmJobAssignmentTable   PmJobAssignmentDT = null;
            PUnitTable             PUnitDT           = null;
            PmJobAssignmentRow     PmJobAssignmentDR;
            IndividualDataTDSJobAssignmentStaffDataCombinedRow JobAssiStaffDataCombDR;
            int                       JobAssiStaffDataCombKey = 0;
            TCacheable                CommonCacheable         = new TCacheable();
            TPartnerCacheable         PartnerCacheable        = new TPartnerCacheable();
            string                    MaritalStatusDescr;
            StringCollection          PassportColumns;
            string                    Nationalities;
            PPartnerRelationshipTable PartnerRelationshipDT;
            PPartnerTable             PartnerDT;
            PPartnerRow               PartnerDR = null;
            PLocationRow              LocationDR;
            PPartnerLocationRow       PartnerLocationDR;
            string                    PhoneNumber;
            string                    EmailAddress;
            Int64                     ChurchPartnerKey;

            SummaryDT = new IndividualDataTDSSummaryDataTable();
            SummaryDR = SummaryDT.NewRowTyped(false);

            SummaryDR.PartnerKey = APartnerKey;

            #region Person Info

            PPersonDT = PPersonAccess.LoadByPrimaryKey(APartnerKey, AReadTransaction);

            if (PPersonDT.Rows.Count == 1)
            {
                PersonDR = (PPersonRow)PPersonDT.Rows[0];
            }

            if (PersonDR != null)
            {
                SummaryDR.DateOfBirth = PersonDR.DateOfBirth;
                SummaryDR.Gender      = PersonDR.Gender;

                MaritalStatusDescr = PartnerCodeHelper.GetMaritalStatusDescription(
                    @PartnerCacheable.GetCacheableTable, PersonDR.MaritalStatus);

                if (MaritalStatusDescr != String.Empty)
                {
                    MaritalStatusDescr = " - " + MaritalStatusDescr;
                }

                SummaryDR.MaritalStatus = PersonDR.MaritalStatus + MaritalStatusDescr;
            }
            else
            {
                SummaryDR.SetDateOfBirthNull();
                SummaryDR.Gender        = StrNotAvailable;
                SummaryDR.MaritalStatus = StrNotAvailable;
            }

            #region Nationalities

            PassportColumns = StringHelper.StrSplit(
                PmPassportDetailsTable.GetDateOfIssueDBName() + "," +
                PmPassportDetailsTable.GetDateOfExpirationDBName() + "," +
                PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," +
                PmPassportDetailsTable.GetMainPassportDBName(), ",");

            PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey,
                                                                       PassportColumns, AReadTransaction, null, 0, 0);

            Nationalities = Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities(
                @CommonCacheable.GetCacheableTable, PassportDetailsDT);

            if (Nationalities != String.Empty)
            {
                SummaryDR.Nationalities = Nationalities;
            }
            else
            {
                SummaryDR.Nationalities = StrNotAvailable;
            }

            #endregion

            #region Phone and Email (from 'Best Address')

            if (TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(APartnerKey, out PhoneNumber, out EmailAddress))
            {
                SummaryDR.PrimaryPhoneNumber  = PhoneNumber ?? StrNotAvailable;
                SummaryDR.PrimaryEmailAddress = EmailAddress ?? StrNotAvailable;
            }
            else
            {
                SummaryDR.PrimaryPhoneNumber  = StrNotAvailable;
                SummaryDR.PrimaryEmailAddress = StrNotAvailable;
            }

            #endregion

            #endregion

            #region Commitments/Jobs

            PmStaffDataDT = PmStaffDataAccess.LoadViaPPerson(APartnerKey, AReadTransaction);
            MiscellaneousDataDR.ItemsCountCommitmentPeriods = PmStaffDataDT.Rows.Count;

            // First check if the PERSON has got any Commitments
            if (PmStaffDataDT.Rows.Count > 0)
            {
                foreach (DataRow DR in PmStaffDataDT.Rows)
                {
                    JobAssiStaffDataCombDR            = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false);
                    JobAssiStaffDataCombDR.Key        = JobAssiStaffDataCombKey++;
                    JobAssiStaffDataCombDR.PartnerKey = APartnerKey;

                    PmStaffDataDR = (PmStaffDataRow)DR;

                    if (!(PmStaffDataDR.IsReceivingFieldNull()) &&
                        (PmStaffDataDR.ReceivingField != 0))
                    {
                        PUnitDT = PUnitAccess.LoadByPrimaryKey(PmStaffDataDR.ReceivingField, AReadTransaction);

                        JobAssiStaffDataCombDR.FieldKey  = PmStaffDataDR.ReceivingField;
                        JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName;
                    }
                    else
                    {
                        JobAssiStaffDataCombDR.FieldKey  = 0;
                        JobAssiStaffDataCombDR.FieldName = "[None]";
                    }

                    JobAssiStaffDataCombDR.Position = PmStaffDataDR.JobTitle;
                    JobAssiStaffDataCombDR.FromDate = PmStaffDataDR.StartOfCommitment;
                    JobAssiStaffDataCombDR.ToDate   = PmStaffDataDR.EndOfCommitment;

                    AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR);
                }
            }
            else
            {
                // The PERSON hasn't got any Commitments, therefore check if the PERSON has any Job Assignments

                PmJobAssignmentDT = PmJobAssignmentAccess.LoadViaPPartner(APartnerKey, AReadTransaction);

                if (PmJobAssignmentDT.Rows.Count > 0)
                {
                    foreach (DataRow DR in PmJobAssignmentDT.Rows)
                    {
                        JobAssiStaffDataCombDR            = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false);
                        JobAssiStaffDataCombDR.Key        = JobAssiStaffDataCombKey++;
                        JobAssiStaffDataCombDR.PartnerKey = APartnerKey;

                        PmJobAssignmentDR = (PmJobAssignmentRow)DR;

                        if (PmJobAssignmentDR.UnitKey != 0)
                        {
                            PUnitDT = PUnitAccess.LoadByPrimaryKey(PmJobAssignmentDR.UnitKey, AReadTransaction);

                            JobAssiStaffDataCombDR.FieldKey  = PmJobAssignmentDR.UnitKey;
                            JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName;
                        }
                        else
                        {
                            JobAssiStaffDataCombDR.FieldKey  = 0;
                            JobAssiStaffDataCombDR.FieldName = "[None]";
                        }

                        JobAssiStaffDataCombDR.Position = PmJobAssignmentDR.PositionName;
                        JobAssiStaffDataCombDR.FromDate = PmJobAssignmentDR.FromDate;
                        JobAssiStaffDataCombDR.ToDate   = PmJobAssignmentDR.ToDate;

                        AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR);
                    }
                }
            }

            #endregion

            #region Church Info

            SummaryDR.ChurchName                           = StrNotAvailable;
            SummaryDR.ChurchAddress                        = StrNotAvailable;
            SummaryDR.ChurchPrimaryPhoneNumber             = StrNotAvailable;
            SummaryDR.ChurchPastor                         = StrNotAvailable;
            SummaryDR.ChurchPastorsPrimaryPhoneNumber      = StrNotAvailable;
            SummaryDR.NumberOfShownSupportingChurchPastors = 0;

            // Find SUPPCHURCH Relationship
            PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] {
                new TSearchCriteria(PPartnerRelationshipTable.GetRelationKeyDBName(), APartnerKey),
                new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "SUPPCHURCH")
            },
                                                                                 AReadTransaction);

            SummaryDR.NumberOfShownSupportingChurches = PartnerRelationshipDT.Rows.Count;

            if (PartnerRelationshipDT.Rows.Count > 0)
            {
                ChurchPartnerKey = PartnerRelationshipDT[0].PartnerKey;

                // Load Church Partner
                PartnerDT = PPartnerAccess.LoadByPrimaryKey(ChurchPartnerKey, AReadTransaction);

                if (PartnerDT.Rows.Count > 0)
                {
                    PartnerDR = PartnerDT[0];

                    // Church Name
                    if (PartnerDR.PartnerShortName != String.Empty)
                    {
                        SummaryDR.ChurchName = PartnerDR.PartnerShortName;
                    }

                    #region Church Address and Phone

                    ServerCalculations.DetermineBestAddress(PartnerRelationshipDT[0].PartnerKey, out PartnerLocationDR, out LocationDR);

                    if (LocationDR != null)
                    {
                        SummaryDR.ChurchAddress = Calculations.DetermineLocationString(LocationDR,
                                                                                       Calculations.TPartnerLocationFormatEnum.plfCommaSeparated);
                    }

                    if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].PartnerKey,
                                                                       out PhoneNumber))
                    {
                        SummaryDR.ChurchPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable;
                    }
                    else
                    {
                        SummaryDR.ChurchPrimaryPhoneNumber = StrNotAvailable;
                    }

                    #endregion

                    #region Pastor

                    // Find PASTOR Relationship
                    PartnerRelationshipDT.Rows.Clear();
                    PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] {
                        new TSearchCriteria(PPartnerRelationshipTable.GetPartnerKeyDBName(), ChurchPartnerKey),
                        new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "PASTOR")
                    },
                                                                                         AReadTransaction);

                    SummaryDR.NumberOfShownSupportingChurchPastors = PartnerRelationshipDT.Rows.Count;

                    if (PartnerRelationshipDT.Rows.Count > 0)
                    {
                        // Load PASTOR Partner
                        PartnerDT = PPartnerAccess.LoadByPrimaryKey(PartnerRelationshipDT[0].RelationKey, AReadTransaction);

                        if (PartnerDT.Rows.Count > 0)
                        {
                            PartnerDR = PartnerDT[0];

                            // Pastor's Name
                            if (PartnerDR.PartnerShortName != String.Empty)
                            {
                                SummaryDR.ChurchPastor = PartnerDR.PartnerShortName;
                            }

                            #region Pastor's Phone

                            if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].RelationKey,
                                                                               out PhoneNumber))
                            {
                                SummaryDR.ChurchPastorsPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable;
                            }
                            else
                            {
                                SummaryDR.ChurchPastorsPrimaryPhoneNumber = StrNotAvailable;
                            }

                            #endregion
                        }
                    }

                    #endregion
                }
            }

            #endregion

            // Add Summary DataRow to Summary DataTable
            SummaryDT.Rows.Add(SummaryDR);

            // Add Row to 'SummaryData' DataTable in Typed DataSet 'IndividualDataTDS'
            AIndividualDataDS.Merge(SummaryDT);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get the passport details and estores them as parameters.
        /// If there is a passport with the MainPassport flag set, then use this passport.
        /// Otherwise use the most recent passport which has a passport number.
        /// </summary>
        /// <param name="APartnerKey">Partner key</param>
        /// <returns>true if one passport was found, otherwise false</returns>
        private bool GetPassport(Int64 APartnerKey)
        {
            PmPassportDetailsTable PassportTable = new PmPassportDetailsTable();

            PmPassportDetailsRow ResultPassportRow = GetLatestPassport(APartnerKey, situation);

            if (ResultPassportRow != null)
            {
                // add the results to the parameters
                foreach (DataColumn col in PassportTable.Columns)
                {
                    situation.GetParameters().Add(StringHelper.UpperCamelCase(col.ColumnName, true,
                            true), new TVariant(ResultPassportRow[col.ColumnName]));
                }
            }
            else
            {
                // add empty results to the parameters.
                // Otherwise the old rsults from the previous calculations will be used.
                foreach (DataColumn col in PassportTable.Columns)
                {
                    situation.GetParameters().Add(StringHelper.UpperCamelCase(col.ColumnName, true,
                            true), new TVariant(""));
                }
            }

            return ResultPassportRow != null;
        }