/// <summary>
        /// Gives the user the option to update Gift Destination records if commitments have been added
        /// </summary>
        /// <param name="AInspectDS"></param>
        public bool UpdateGiftDestination(ref PartnerEditTDS AInspectDS)
        {
            PmStaffDataTable EligibleCommitments = new PmStaffDataTable();

            FIndividualDataDS = new IndividualDataTDS();
            FInspectDS = AInspectDS;

            FIndividualDataDS.Merge(AInspectDS);

            // return if no changes have been made to commitments
            if ((FIndividualDataDS.PmStaffData == null) || (FIndividualDataDS.PmStaffData.Rows.Count == 0))
            {
                return false;
            }

            // load original (currently saved) PmStaffData
            FOriginalCommitments = TRemote.MPersonnel.WebConnectors.LoadPersonellStaffData(AInspectDS.PPartner[0].PartnerKey).PmStaffData;

            if (!GetEligibleRowsForUpdatingGiftDestination(ref EligibleCommitments))
            {
                // no eligible records
                return false;
            }

            // iterate through each eligible row
            foreach (PmStaffDataRow EligibleCommitmentRow in EligibleCommitments.Rows)
            {
                UpdateGiftDestinationForSingleCommitment(EligibleCommitmentRow);
            }

            return true;
        }
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="e"></param>
        /// <param name="AMainDS"></param>
        /// <param name="AVerificationResult"></param>
        /// <returns></returns>
        public static Boolean VerifyUnitData(DataColumnChangeEventArgs e, PartnerEditTDS AMainDS, out TVerificationResult AVerificationResult)
        {
            Boolean ReturnValue;

            AVerificationResult = null;

            if (e.Column.ColumnName == PUnitTable.GetUnitNameDBName())
            {
                VerifyUnitNameChange(e, AMainDS, out AVerificationResult);
            }

            // any verification errors?
            if (AVerificationResult == null)
            {
                ReturnValue = true;
            }
            else
            {
                ReturnValue = false;

                // MessageBox.Show('VerifyUnitData: There was an error!');
            }

            return ReturnValue;
        }
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey, bool AWithAddressDetails, bool AWithSubscriptions, bool AWithRelationships)
        {
            PartnerEditTDS MainDS = new PartnerEditTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                delegate
                {
                    PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    if (MainDS.PPartner.Rows.Count > 0)
                    {
                        switch (MainDS.PPartner[0].PartnerClass)
                        {
                            case MPartnerConstants.PARTNERCLASS_FAMILY:
                                PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;

                            case MPartnerConstants.PARTNERCLASS_PERSON:
                                PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;

                            case MPartnerConstants.PARTNERCLASS_CHURCH:
                                PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;

                            case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                                POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                                break;
                        }

                        if (AWithAddressDetails)
                        {
                            PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                            PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        }

                        if (AWithRelationships)
                        {
                            PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                        }

                        if (AWithSubscriptions)
                        {
                            PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                        }
                    }
                });

            return MainDS;
        }
        /// <summary>todoComment</summary>
        public void PostInitUserControl(PartnerEditTDS AMainDS)
        {
            // exchanges instead of Icon=1 we get Icon=2
            FMainDS.PPartnerLocation.ColumnIconForSort.Expression = "IIF(Icon = 1, 2, IIF(Icon = 2, 1, 3))";

            // introduce sorting -> override DefaultView that was set in earlier methods
            DataView myDataView = new DataView(FMainDS.PPartnerLocation, "",
                PartnerEditTDSPPartnerLocationTable.GetIconForSortDBName() + " ASC, " +
                PartnerEditTDSPPartnerLocationTable.GetDateEffectiveDBName() +
                " DESC", DataViewRowState.CurrentRows);
            myDataView.AllowNew = false;
            grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView);
        }
        /// create a new family
        public static PPartnerRow CreateNewFamilyPartner(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY;
            PartnerRow.PartnerShortName = PartnerRow.PartnerKey.ToString() + ", TestPartner, Mr";

            PFamilyRow FamilyRow = AMainDS.PFamily.NewRowTyped();
            FamilyRow.PartnerKey = PartnerRow.PartnerKey;
            FamilyRow.FamilyName = PartnerRow.PartnerKey.ToString();
            FamilyRow.FirstName = "TestPartner";
            FamilyRow.Title = "Mr";
            AMainDS.PFamily.Rows.Add(FamilyRow);

            return PartnerRow;
        }
        private void InitializeManualCode()
        {
            // show this dialog in center of screen
            this.StartPosition = FormStartPosition.CenterScreen;

            FMainDS = new PartnerEditTDS();

            // now add the one subscription row to the DS that we are working with
            PContactLogTable ContactLogTable = new PContactLogTable();
            FMainDS.Merge(ContactLogTable);
            PContactLogRow ContactLogRow = FMainDS.PContactLog.NewRowTyped(true);
            ContactLogRow.ContactCode = "";
            FMainDS.PContactLog.Rows.Add(ContactLogRow);

            ucoContactLog.MainDS = FMainDS;
            ucoContactLog.SpecialInitUserControl();
            FPetraUtilsObject.HasChanges = false;
        }
        private void InitializeManualCode()
        {
            // show this dialog in center of screen
            this.StartPosition = FormStartPosition.CenterScreen;

            FMainDS = new PartnerEditTDS();

            // now add the one subscription row to the DS that we are working with
            PSubscriptionTable SubscriptionTable = new PSubscriptionTable();
            FMainDS.Merge(SubscriptionTable);
            PSubscriptionRow SubscriptionRow = FMainDS.PSubscription.NewRowTyped(true);
            SubscriptionRow.PublicationCode = ""; // avoid NOT NULL error message
            FMainDS.PSubscription.Rows.Add(SubscriptionRow);

            ucoSubscription.MainDS = FMainDS;
            ucoSubscription.SpecialInitUserControl();
            FPetraUtilsObject.HasChanges = false;
        }
        /// <summary>
        /// Populates the grid for the dialog for selecting Addresses to be merged.
        /// </summary>
        public void InitializeAddressGrid(long APartnerKey)
        {
            // set text for label
            lblInfo.Text = Catalog.GetString("The following addresses exist for the Partner being merged. Select the addresses to be transferred.") +
                           "\n\n" + Catalog.GetString("Any addresses which are not selected will be deleted!");

            string CheckedMember = "CHECKED";
            string Address1 = PLocationTable.GetLocalityDBName();
            string Street2 = PLocationTable.GetStreetNameDBName();
            string Address3 = PLocationTable.GetAddress3DBName();
            string City = PLocationTable.GetCityDBName();
            string LocationKey = PLocationTable.GetLocationKeyDBName();
            string SiteKey = PLocationTable.GetSiteKeyDBName();
            string LocationType = PPartnerLocationTable.GetLocationTypeDBName();


            FMainDS = TRemote.MPartner.Partner.WebConnectors.GetPartnerDetails(APartnerKey, true, false, false);
            DataView MyDataView = FMainDS.PLocation.DefaultView;

            FDataTable = MyDataView.ToTable(true, new string[] { Address1, Street2, Address3, City, LocationKey, SiteKey });
            FDataTable.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
            FDataTable.Columns.Add(LocationType, typeof(string));

            for (int Counter = 0; Counter < FMainDS.PLocation.Rows.Count; ++Counter)
            {
                FDataTable.Rows[Counter][LocationType] = FMainDS.PPartnerLocation.Rows[Counter][LocationType];
            }

            clbRecords.Columns.Clear();
            clbRecords.AddCheckBoxColumn("", FDataTable.Columns[CheckedMember], 17, false);
            clbRecords.AddTextColumn("Address-1", FDataTable.Columns[Address1]);
            clbRecords.AddTextColumn("Street-2", FDataTable.Columns[Street2]);
            clbRecords.AddTextColumn("Address-3", FDataTable.Columns[Address3]);
            clbRecords.AddTextColumn("City", FDataTable.Columns[City]);
            clbRecords.AddTextColumn("Location Type", FDataTable.Columns[LocationType]);
            clbRecords.ValueChanged += new EventHandler(OnCheckboxChange);

            clbRecords.DataBindGrid(FDataTable, Address1, CheckedMember, Address1, false, true, false);
            clbRecords.SetCheckedStringList("");

            clbRecords.AutoResizeGrid();
        }
        /// create a new partner
        public static PPartnerRow CreateNewPartner(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = AMainDS.PPartner.NewRowTyped();

            // get a new partner key
            Int64 newPartnerKey = -1;

            do
            {
                newPartnerKey = TNewPartnerKey.GetNewPartnerKey(DomainManager.GSiteKey);
                TNewPartnerKey.SubmitNewPartnerKey(DomainManager.GSiteKey, newPartnerKey, ref newPartnerKey);
                PartnerRow.PartnerKey = newPartnerKey;
            } while (newPartnerKey == -1);

            PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE;

            AMainDS.PPartner.Rows.Add(PartnerRow);

            TLogging.Log("Creating new partner: " + PartnerRow.PartnerKey.ToString());

            return PartnerRow;
        }
Beispiel #10
0
        /// <summary>
        /// create PPartnerLocation records for the FAMILY partner, and all the PERSON records of this family
        /// </summary>
        public static void GenerateAddressForFamily(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS)
        {
            PLocationRow locationRow = AMainDS.PLocation.NewRowTyped();

            locationRow.SiteKey     = 0; // DomainManager.GSiteKey;
            locationRow.LocationKey = (AMainDS.PLocation.Count + 1) * -1;
            locationRow.StreetName  = TXMLParser.GetAttribute(ACurrentNode, "Addr2");
            locationRow.PostalCode  = TXMLParser.GetAttribute(ACurrentNode, "PostCode");
            locationRow.City        = TXMLParser.GetAttribute(ACurrentNode, "City");
            locationRow.County      = TXMLParser.GetAttribute(ACurrentNode, "Province");
            locationRow.CountryCode = TXMLParser.GetAttribute(ACurrentNode, "CountryCode");

            AMainDS.PLocation.Rows.Add(locationRow);

            PPartnerLocationRow familyLocationRow = AMainDS.PPartnerLocation.NewRowTyped();

            familyLocationRow.PartnerKey   = AFamilyRow.PartnerKey;
            familyLocationRow.LocationKey  = locationRow.LocationKey;
            familyLocationRow.SiteKey      = locationRow.SiteKey;
            familyLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME;
            familyLocationRow.SendMail     = true;

            string gender = TXMLParser.GetAttribute(ACurrentNode, "familySituation");
            Random r      = new Random();

            string email = TXMLParser.GetAttribute(ACurrentNode, "FemaleEmail");

            if ((gender == "singleMan") || ((gender == "family") && (r.Next(2) == 0)))
            {
                email = TXMLParser.GetAttribute(ACurrentNode, "MaleEmail");
            }

            if (email.Length > 0)
            {
                PPartnerAttributeRow partnerAttributeRow = AMainDS.PPartnerAttribute.NewRowTyped();
                partnerAttributeRow.PartnerKey    = AFamilyRow.PartnerKey;
                partnerAttributeRow.AttributeType = MPartnerConstants.ATTR_TYPE_EMAIL;
                partnerAttributeRow.Index         = 0;
                partnerAttributeRow.Primary       = true;
                partnerAttributeRow.Value         = email;
                AMainDS.PPartnerAttribute.Rows.Add(partnerAttributeRow);

                partnerAttributeRow               = AMainDS.PPartnerAttribute.NewRowTyped();
                partnerAttributeRow.PartnerKey    = AFamilyRow.PartnerKey;
                partnerAttributeRow.AttributeType = MPartnerConstants.ATTR_TYPE_PARTNERS_PRIMARY_CONTACT_METHOD;
                partnerAttributeRow.Index         = 9999;
                partnerAttributeRow.Primary       = false;
                partnerAttributeRow.Value         = MPartnerConstants.ATTR_TYPE_EMAIL;
                AMainDS.PPartnerAttribute.Rows.Add(partnerAttributeRow);
            }

            AMainDS.PPartnerLocation.Rows.Add(familyLocationRow);

            DataView FamilyView = new DataView(AMainDS.PPerson);

            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort      = PPersonTable.GetFamilyIdDBName();

            // for each person, also create a location record
            for (int countPerson = 0; countPerson < FamilyView.Count; countPerson++)
            {
                PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row;

                PPartnerLocationRow personLocationRow = AMainDS.PPartnerLocation.NewRowTyped();
                personLocationRow.PartnerKey   = personRow.PartnerKey;
                personLocationRow.LocationKey  = familyLocationRow.LocationKey;
                personLocationRow.SiteKey      = familyLocationRow.SiteKey;
                personLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME;
                personLocationRow.SendMail     = false;
                AMainDS.PPartnerLocation.Rows.Add(personLocationRow);
            }
        }
        /// create a new BankingDetails record and a new PartnerBankingDetails record
        public static PartnerEditTDSPBankingDetailsRow CreateNewBankingRecords(long APartnerKey, PartnerEditTDS AMainDS, TDataBase ADataBase)
        {
            PartnerEditTDSPBankingDetailsRow BankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped();

            BankingDetailsRow.BankingDetailsKey = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_bank_details, ADataBase));
            BankingDetailsRow.BankingType       = MPartnerConstants.BANKINGTYPE_BANKACCOUNT;
            BankingDetailsRow.MainAccount       = true;
            AMainDS.PBankingDetails.Rows.Add(BankingDetailsRow);

            PPartnerBankingDetailsRow PartnerBankingDetailsRow = AMainDS.PPartnerBankingDetails.NewRowTyped();

            PartnerBankingDetailsRow.PartnerKey        = APartnerKey;
            PartnerBankingDetailsRow.BankingDetailsKey = BankingDetailsRow.BankingDetailsKey;
            AMainDS.PPartnerBankingDetails.Rows.Add(PartnerBankingDetailsRow);

            PBankingDetailsUsageRow BankingDetailsUsageRow = AMainDS.PBankingDetailsUsage.NewRowTyped();

            BankingDetailsUsageRow.PartnerKey        = APartnerKey;
            BankingDetailsUsageRow.BankingDetailsKey = BankingDetailsRow.BankingDetailsKey;
            BankingDetailsUsageRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN;
            AMainDS.PBankingDetailsUsage.Rows.Add(BankingDetailsUsageRow);

            return(BankingDetailsRow);
        }
        /// create a new venue
        public static PPartnerRow CreateNewVenuePartner(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_VENUE;
            PartnerRow.PartnerShortName = PartnerRow.PartnerKey.ToString() + ", TestVenue";

            PVenueRow VenueRow = AMainDS.PVenue.NewRowTyped();
            VenueRow.PartnerKey = PartnerRow.PartnerKey;
            VenueRow.VenueCode = "TEST" + PartnerRow.PartnerKey.ToString();
            VenueRow.VenueName = "TestVenue" + PartnerRow.PartnerKey.ToString();
            AMainDS.PVenue.Rows.Add(VenueRow);

            return PartnerRow;
        }
        /// create a new location
        public static void CreateNewLocation(Int64 APartnerKey, PartnerEditTDS AMainDS)
        {
            // avoid duplicate addresses: StreetName contains the partner key
            PLocationRow LocationRow = AMainDS.PLocation.NewRowTyped();

            LocationRow.SiteKey = DomainManager.GSiteKey;
            LocationRow.LocationKey = -1;
            LocationRow.StreetName = APartnerKey.ToString() + " Nowhere Lane";
            LocationRow.PostalCode = "LO2 2CX";
            LocationRow.City = "London";
            LocationRow.CountryCode = "99";
            AMainDS.PLocation.Rows.Add(LocationRow);

            PPartnerLocationRow PartnerLocationRow = AMainDS.PPartnerLocation.NewRowTyped();
            PartnerLocationRow.SiteKey = LocationRow.SiteKey;
            PartnerLocationRow.PartnerKey = APartnerKey;
            PartnerLocationRow.LocationKey = LocationRow.LocationKey;
            AMainDS.PPartnerLocation.Rows.Add(PartnerLocationRow);
        }
        /// create a new organisation
        public static PPartnerRow CreateNewOrganisationPartner(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_ORGANISATION;
            PartnerRow.PartnerShortName = PartnerRow.PartnerKey.ToString() + ", TestOrganisation";

            POrganisationRow OrganisationRow = AMainDS.POrganisation.NewRowTyped();
            OrganisationRow.PartnerKey = PartnerRow.PartnerKey;
            OrganisationRow.OrganisationName = "TestOrganisation";
            AMainDS.POrganisation.Rows.Add(OrganisationRow);

            return PartnerRow;
        }
        /// create a new bank
        public static PPartnerRow CreateNewBankPartner(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_BANK;
            PartnerRow.PartnerShortName = PartnerRow.PartnerKey.ToString() + ", TestBank";

            PBankRow BankRow = AMainDS.PBank.NewRowTyped();
            BankRow.PartnerKey = PartnerRow.PartnerKey;
            BankRow.BranchName = "TestBank";
            AMainDS.PBank.Rows.Add(BankRow);

            return PartnerRow;
        }
        public void TestDeleteFamily()
        {
            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;
            String               TextMessage;
            Boolean              CanDeletePartner;
            PPartnerRow          FamilyPartnerRow;
            PFamilyRow           FamilyRow;
            PPersonRow           PersonRow;
            TSubmitChangesResult result;
            Int64 PartnerKey;

            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS);
            result           = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Create family record");

            // check if Family partner can be deleted (still needs to be possible at this point)
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(FamilyPartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(CanDeletePartner);

            // add a person to the family which means the family is not allowed to be deleted any longer
            FamilyRow = (PFamilyRow)MainDS.PFamily.Rows[0];
            FamilyRow.FamilyMembers = true;
            TCreateTestPartnerData.CreateNewLocation(FamilyPartnerRow.PartnerKey, MainDS);
            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create new location");

            PartnerEditTDS PersonDS = new PartnerEditTDS();

            PersonRow = TCreateTestPartnerData.CreateNewPerson(PersonDS, FamilyPartnerRow.PartnerKey,
                                                               MainDS.PLocation[0].LocationKey, "Adam", "Mr", 0);
            PersonRow.FamilyKey = FamilyPartnerRow.PartnerKey;
            result = connector.SubmitChanges(ref PersonDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create person record");

            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(FamilyPartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(!CanDeletePartner);


            // create new family and create subscription given as gift from this family: not allowed to be deleted
            FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS);
            PPublicationTable PublicationTable = PPublicationAccess.LoadByPrimaryKey("TESTPUBLICATION", DBAccess.GDBAccessObj.Transaction);

            if (PublicationTable.Count == 0)
            {
                // first check if frequency "Annual" exists and if not then create it
                if (!AFrequencyAccess.Exists("Annual", DBAccess.GDBAccessObj.Transaction))
                {
                    // set up details (e.g. bank account) for this Bank so deletion is not allowed
                    AFrequencyTable FrequencyTable = new AFrequencyTable();
                    AFrequencyRow   FrequencyRow   = FrequencyTable.NewRowTyped();
                    FrequencyRow.FrequencyCode        = "Annual";
                    FrequencyRow.FrequencyDescription = "Annual Frequency";
                    FrequencyTable.Rows.Add(FrequencyRow);

                    AFrequencyAccess.SubmitChanges(FrequencyTable, DBAccess.GDBAccessObj.Transaction);
                }

                // now add the publication "TESTPUBLICATION"
                PPublicationRow PublicationRow = PublicationTable.NewRowTyped();
                PublicationRow.PublicationCode = "TESTPUBLICATION";
                PublicationRow.FrequencyCode   = "Annual";
                PublicationTable.Rows.Add(PublicationRow);

                PPublicationAccess.SubmitChanges(PublicationTable, DBAccess.GDBAccessObj.Transaction);
            }

            // make sure that "reason subscription given" exists
            if (!PReasonSubscriptionGivenAccess.Exists("FREE", DBAccess.GDBAccessObj.Transaction))
            {
                // set up details (e.g. bank account) for this Bank so deletion is not allowed
                PReasonSubscriptionGivenTable ReasonTable = new PReasonSubscriptionGivenTable();
                PReasonSubscriptionGivenRow   ReasonRow   = ReasonTable.NewRowTyped();
                ReasonRow.Code        = "FREE";
                ReasonRow.Description = "Free Subscription";
                ReasonTable.Rows.Add(ReasonRow);

                PReasonSubscriptionGivenAccess.SubmitChanges(ReasonTable, DBAccess.GDBAccessObj.Transaction);
            }

            // now add the publication "TESTPUBLICATION" to the first family record and indicate it was a gift from newly created family record
            PSubscriptionRow SubscriptionRow = MainDS.PSubscription.NewRowTyped();

            SubscriptionRow.PublicationCode     = "TESTPUBLICATION";
            SubscriptionRow.PartnerKey          = FamilyRow.PartnerKey;        // link subscription with original family
            SubscriptionRow.GiftFromKey         = FamilyPartnerRow.PartnerKey; // indicate that subscription is a gift from newly created family
            SubscriptionRow.ReasonSubsGivenCode = "FREE";
            MainDS.PSubscription.Rows.Add(SubscriptionRow);

            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "add publication to family record");

            // this should now not be allowed since partner record has a subscription linked to it
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(FamilyPartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(!CanDeletePartner);

            // now test actual deletion of Family partner
            FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS);
            PartnerKey       = FamilyPartnerRow.PartnerKey;
            result           = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create family record");

            // check if Family record is being deleted
            Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult));

            // check that Family record is really deleted
            Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey));
        }
Beispiel #17
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);
        }
        private void InitializeManualCode()
        {
            // show this dialog in center of screen
            this.StartPosition = FormStartPosition.CenterScreen;

            // remove validation handler for controls as we only want validation when clicking the ok button
            cmbPSubscriptionPublicationCode.Validated    -= new System.EventHandler(this.ControlValidatedHandler);
            cmbPSubscriptionSubscriptionStatus.Validated -= new System.EventHandler(this.ControlValidatedHandler);
            chkPSubscriptionGratisSubscription.Validated -= new System.EventHandler(this.ControlValidatedHandler);

            txtPSubscriptionNumberComplimentary.Validated     -= new System.EventHandler(this.ControlValidatedHandler);
            txtPSubscriptionPublicationCopies.Validated       -= new System.EventHandler(this.ControlValidatedHandler);
            cmbPSubscriptionReasonSubsGivenCode.Validated     -= new System.EventHandler(this.ControlValidatedHandler);
            cmbPSubscriptionReasonSubsCancelledCode.Validated -= new System.EventHandler(this.ControlValidatedHandler);
            txtPSubscriptionGiftFromKey.Validated             -= new System.EventHandler(this.ControlValidatedHandler);

            dtpPSubscriptionStartDate.Validated               -= new System.EventHandler(this.ControlValidatedHandler);
            dtpPSubscriptionExpiryDate.Validated              -= new System.EventHandler(this.ControlValidatedHandler);
            dtpPSubscriptionDateCancelled.Validated           -= new System.EventHandler(this.ControlValidatedHandler);
            dtpPSubscriptionDateNoticeSent.Validated          -= new System.EventHandler(this.ControlValidatedHandler);
            dtpPSubscriptionSubscriptionRenewalDate.Validated -= new System.EventHandler(this.ControlValidatedHandler);
            dtpPSubscriptionFirstIssue.Validated              -= new System.EventHandler(this.ControlValidatedHandler);
            dtpPSubscriptionLastIssue.Validated               -= new System.EventHandler(this.ControlValidatedHandler);

            txtPSubscriptionNumberIssuesReceived.Validated -= new System.EventHandler(this.ControlValidatedHandler);


            FMainDS = new PartnerEditTDS();

            // now add the one subscription row to the DS that we are working with
            PSubscriptionTable SubscriptionTable = new PSubscriptionTable();

            FMainDS.Merge(SubscriptionTable);
            PSubscriptionRow SubscriptionRow = FMainDS.PSubscription.NewRowTyped(true);

            SubscriptionRow.PublicationCode = ""; // avoid NOT NULL error message
            FMainDS.PSubscription.Rows.Add(SubscriptionRow);

            FPetraUtilsObject.HasChanges = false;

            // initialize all check box sections so fields are disabled
            OnTickChangeItem(chkChangeSubscriptionStatus, null);
            OnTickChangeItem(chkChangeGratisSubscription, null);

            OnTickChangeItem(chkChangeNumberComplimentary, null);
            OnTickChangeItem(chkChangePublicationCopies, null);
            OnTickChangeItem(chkChangeReasonSubsGivenCode, null);
            OnTickChangeItem(chkChangeReasonSubsCancelledCode, null);
            OnTickChangeItem(chkChangeGiftFromKey, null);

            OnTickChangeItem(chkChangeStartDate, null);
            OnTickChangeItem(chkChangeExpiryDate, null);
            OnTickChangeItem(chkChangeRenewalDate, null);
            OnTickChangeItem(chkChangeDateNoticeSent, null);
            OnTickChangeItem(chkChangeDateCancelled, null);

            OnTickChangeItem(chkChangeNumberIssuesReceived, null);
            OnTickChangeItem(chkChangeFirstIssue, null);
            OnTickChangeItem(chkChangeLastIssue, null);

            // Hook up this event manually here after all initalisation has happened as otherwise
            // Bug #2481 would occur if the first Publication in the 'Publication Code' ComboBox is not Valid
            cmbPSubscriptionPublicationCode.SelectedValueChanged += new System.EventHandler(this.PublicationCodeChanged);
        }
        public void TestNewPartnerWithLocation0()
        {
            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            PPartnerRow PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS);

            PPartnerLocationRow PartnerLocationRow = MainDS.PPartnerLocation.NewRowTyped();

            PartnerLocationRow.SiteKey         = DomainManager.GSiteKey;
            PartnerLocationRow.PartnerKey      = PartnerRow.PartnerKey;
            PartnerLocationRow.LocationKey     = 0;
            PartnerLocationRow.TelephoneNumber = PartnerRow.PartnerKey.ToString();
            MainDS.PPartnerLocation.Rows.Add(PartnerLocationRow);

            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;

            TSubmitChangesResult result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "There was a critical error when saving:");

            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Create a partner with location 0");

            TCreateTestPartnerData.CreateNewLocation(PartnerRow.PartnerKey, MainDS);

            // remove location 0, same is done in csharp\ICT\Petra\Client\MCommon\logic\UC_PartnerAddresses.cs TUCPartnerAddressesLogic::AddRecord
            // Check if record with PartnerLocation.LocationKey = 0 is around > delete it
            DataRow PartnerLocationRecordZero =
                MainDS.PPartnerLocation.Rows.Find(new object[] { PartnerRow.PartnerKey, DomainManager.GSiteKey, 0 });

            if (PartnerLocationRecordZero != null)
            {
                DataRow LocationRecordZero = MainDS.PLocation.Rows.Find(new object[] { DomainManager.GSiteKey, 0 });

                if (LocationRecordZero != null)
                {
                    LocationRecordZero.Delete();
                }

                PartnerLocationRecordZero.Delete();
            }

            ResponseDS = new PartnerEditTDS();
            result     = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "There was a critical error when saving:");

            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Replace location 0 of partner");

            Assert.AreEqual(1, MainDS.PPartnerLocation.Rows.Count, "the partner should only have one location in the dataset");

            // get all addresses of the partner
            TDBTransaction ReadTransaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                                                                      ref ReadTransaction,
                                                                      delegate
            {
                PPartnerLocationTable testPartnerLocations = PPartnerLocationAccess.LoadViaPPartner(PartnerRow.PartnerKey, ReadTransaction);
                Assert.AreEqual(1, testPartnerLocations.Rows.Count, "the partner should only have one location");
                Assert.Greater(testPartnerLocations[0].LocationKey, 0, "TPartnerEditUIConnector SubmitChanges returns valid location key");
            });
        }
Beispiel #20
0
        /// <summary>
        /// generate the partners from a text file that was generated with Benerator
        /// </summary>
        /// <param name="AInputBeneratorFile"></param>
        public static void GenerateWorkers(string AInputBeneratorFile)
        {
            PartnerEditTDS MainDS      = new PartnerEditTDS();
            PersonnelTDS   PersonnelDS = new PersonnelTDS();

            TDataBase      db          = DBAccess.Connect("GenerateWorkers");
            TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.ReadCommitted);

            // get a list of fields (all class UNIT, with unit type F)
            string    sqlGetFieldPartnerKeys = "SELECT p_partner_key_n, p_unit_name_c FROM PUB_p_unit WHERE u_unit_type_code_c = 'F'";
            DataTable FieldKeys = db.SelectDT(sqlGetFieldPartnerKeys, "keys", Transaction);

            // get a list of banks (all class BANK)
            string    sqlGetBankPartnerKeys = "SELECT p_partner_key_n FROM PUB_p_bank";
            DataTable BankKeys = db.SelectDT(sqlGetBankPartnerKeys, "keys", Transaction);

            Transaction.Rollback();

            // AlanP: May 2016 - We may no longer need the UTF8 because the method now automatically discovers the encoding even with no BOM
            XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml(AInputBeneratorFile, ",", Encoding.UTF8);

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            while (RecordNode != null)
            {
                string familySituation = TXMLParser.GetAttribute(RecordNode, "familySituation");

                PFamilyRow familyRecord = null;

                if (familySituation == "singleMan")
                {
                    familyRecord = GenerateFamilyRecord(RecordNode, "Male", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Male", MainDS);
                }
                else if (familySituation == "singleWoman")
                {
                    familyRecord = GenerateFamilyRecord(RecordNode, "Female", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Female", MainDS);
                }
                else if (familySituation == "family")
                {
                    familyRecord = GenerateFamilyRecord(RecordNode, "Male", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Male", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Female", MainDS);

                    int      AgeDifferenceSpouse = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "AgeDifferenceSpouse"));
                    DataView FamilyView          = new DataView(MainDS.PPerson);
                    FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + familyRecord.PartnerKey.ToString();
                    FamilyView.Sort      = PPersonTable.GetFamilyIdDBName();

                    PPersonRow HusbandPersonRow = (PPersonRow)FamilyView[0].Row;
                    PPersonRow WifePersonRow    = (PPersonRow)FamilyView[1].Row;
                    WifePersonRow.DateOfBirth =
                        WifePersonRow.DateOfBirth.Value.AddYears(
                            AgeDifferenceSpouse - (WifePersonRow.DateOfBirth.Value.Year - HusbandPersonRow.DateOfBirth.Value.Year));

                    if (DateTime.Today.Year - WifePersonRow.DateOfBirth.Value.Year < 19)
                    {
                        WifePersonRow.DateOfBirth.Value.AddYears(
                            19 - (DateTime.Today.Year - WifePersonRow.DateOfBirth.Value.Year));
                    }

                    int NumberOfChildren = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "numberOfChildren"));

                    for (int countChild = 0; countChild < NumberOfChildren; countChild++)
                    {
                        DateTime DateOfBirthChild = Convert.ToDateTime(
                            TXMLParser.GetAttribute(RecordNode,
                                                    "Child" + (countChild + 1).ToString() + "DateOfBirth"));

                        // mother must have been 19 when the child was born
                        if (DateOfBirthChild.Year < WifePersonRow.DateOfBirth.Value.Year + 19)
                        {
                            continue;
                        }

                        GeneratePersonRecord(RecordNode, familyRecord, "Child" + (countChild + 1).ToString(), MainDS);
                    }
                }

                GenerateAddressForFamily(RecordNode, familyRecord, MainDS);

                GenerateCommitmentRecord(RecordNode, familyRecord, MainDS, PersonnelDS, FieldKeys);

                GenerateBankDetails(RecordNode, familyRecord, MainDS, BankKeys);

                if (MainDS.PFamily.Rows.Count % 100 == 0)
                {
                    TLogging.Log("created worker " + MainDS.PFamily.Rows.Count.ToString() + " " + familyRecord.FamilyName);
                }

                RecordNode = RecordNode.NextSibling;
            }

            MainDS.ThrowAwayAfterSubmitChanges = true;

            PartnerEditTDSAccess.SubmitChanges(MainDS);

            PersonnelDS.ThrowAwayAfterSubmitChanges = true;
            PersonnelTDSAccess.SubmitChanges(PersonnelDS);

            TLogging.Log("after saving workers");
        }
Beispiel #21
0
        /// <summary>
        /// create PPartnerBankingDetail records for the FAMILY partner
        /// </summary>
        public static void GenerateBankDetails(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS,
                                               DataTable ABankKeys)
        {
            if (TXMLParser.HasAttribute(ACurrentNode, "bankaccount_bank"))
            {
                Int32 BankID =
                    Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "bankaccount_bank")) % ABankKeys.Rows.Count;
                long BankPartnerKey = Convert.ToInt64(ABankKeys.Rows[BankID].ItemArray[0]);

                PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped();

                bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1;
                bankingDetailsRow.BankKey           = BankPartnerKey;
                bankingDetailsRow.BankAccountNumber = TXMLParser.GetAttribute(ACurrentNode, "bankaccount_account");
                bankingDetailsRow.BankingType       = MPartnerConstants.BANKINGTYPE_BANKACCOUNT;
                bankingDetailsRow.AccountName       = AFamilyRow.FirstName + " " + AFamilyRow.FamilyName;

                AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow);

                PPartnerBankingDetailsRow partnerBankingRow = AMainDS.PPartnerBankingDetails.NewRowTyped();
                partnerBankingRow.PartnerKey        = AFamilyRow.PartnerKey;
                partnerBankingRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey;
                AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingRow);

                PBankingDetailsUsageRow bankingUsageRow = AMainDS.PBankingDetailsUsage.NewRowTyped();
                bankingUsageRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey;
                bankingUsageRow.PartnerKey        = AFamilyRow.PartnerKey;
                bankingUsageRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN;
                AMainDS.PBankingDetailsUsage.Rows.Add(bankingUsageRow);
            }
        }
Beispiel #22
0
        private static void GenerateCommitmentRecord(
            XmlNode ACurrentNode,
            PFamilyRow AFamilyRow,
            PartnerEditTDS AMainDS,
            PersonnelTDS APersonnelDS,
            DataTable AFieldKeys)
        {
            DataView FamilyView = new DataView(AMainDS.PPerson);

            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort      = PPersonTable.GetFamilyIdDBName();
            PPersonRow firstPerson = (PPersonRow)FamilyView[0].Row;

            int FieldID =
                Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "fieldCommitment")) % AFieldKeys.Rows.Count;
            long FieldPartnerKey = Convert.ToInt64(AFieldKeys.Rows[FieldID].ItemArray[0]);

            PPartnerGiftDestinationRow giftDestination = AMainDS.PPartnerGiftDestination.NewRowTyped();

            if (NextKeyForGiftDestination == -1)
            {
                NextKeyForGiftDestination = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination();
            }
            else
            {
                NextKeyForGiftDestination++;
            }

            giftDestination.Key           = NextKeyForGiftDestination;
            giftDestination.FieldKey      = FieldPartnerKey;
            giftDestination.PartnerKey    = AFamilyRow.PartnerKey;
            giftDestination.PartnerClass  = MPartnerConstants.PARTNERCLASS_FAMILY;
            giftDestination.DateEffective = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment"));

            PmStaffDataRow staffData = APersonnelDS.PmStaffData.NewRowTyped();

            staffData.SiteKey        = DomainManager.GSiteKey;
            staffData.Key            = (APersonnelDS.PmStaffData.Count + 1) * -1;
            staffData.PartnerKey     = firstPerson.PartnerKey;
            staffData.ReceivingField = FieldPartnerKey;

            // TODO: could add foreign nationals
            staffData.HomeOffice        = DomainManager.GSiteKey;
            staffData.OfficeRecruitedBy = DomainManager.GSiteKey;

            staffData.StartOfCommitment = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment"));
            int LengthCommitment = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "lengthCommitment"));

            staffData.StatusCode = "LONG-TERMER";

            if (LengthCommitment > 0)
            {
                string LengthCommitmentUnit = TXMLParser.GetAttribute(ACurrentNode, "lengthCommitmentUnit");

                if (LengthCommitmentUnit == "week")
                {
                    staffData.StatusCode      = "SHORT-TERMER";
                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddDays(7 * LengthCommitment);
                }
                else if (LengthCommitmentUnit == "month")
                {
                    staffData.StatusCode      = "SHORT-TERMER";
                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddMonths(LengthCommitment);
                }
                else if (LengthCommitmentUnit == "year")
                {
                    if (LengthCommitment < 3)
                    {
                        staffData.StatusCode = "WORKER";
                    }

                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddYears(LengthCommitment);
                }
            }

            APersonnelDS.PmStaffData.Rows.Add(staffData);

            giftDestination.DateExpires = staffData.EndOfCommitment;

            if (AMainDS.PPartnerGiftDestination == null)
            {
                AMainDS.PPartnerGiftDestination.Merge(new PPartnerGiftDestinationTable());
            }

            AMainDS.PPartnerGiftDestination.Rows.Add(giftDestination);

            // TODO depending on start and end date of commitment, set EX-WORKER or no special type yet at all
            string SpecialType = MPartnerConstants.PARTNERTYPE_WORKER;

            if (!staffData.IsEndOfCommitmentNull() && (staffData.EndOfCommitment < DateTime.Today))
            {
                SpecialType = MPartnerConstants.PARTNERTYPE_EX_WORKER;
            }

            if (SpecialType != string.Empty)
            {
                // create special type for family partner
                PPartnerTypeRow PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped();
                PartnerTypeRow.PartnerKey = AFamilyRow.PartnerKey;
                PartnerTypeRow.TypeCode   = SpecialType;
                AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);

                // set special type WORKER for the parents
                for (int countPerson = 0; countPerson < FamilyView.Count && countPerson < 2; countPerson++)
                {
                    PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row;

                    // create special type for the person partners
                    PartnerTypeRow            = AMainDS.PPartnerType.NewRowTyped();
                    PartnerTypeRow.PartnerKey = personRow.PartnerKey;
                    PartnerTypeRow.TypeCode   = SpecialType;
                    AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);
                }
            }
        }
Beispiel #23
0
        public void TestSaveNewPartnerWithLocation()
        {
            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            PPartnerRow PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS);

            TCreateTestPartnerData.CreateNewLocation(PartnerRow.PartnerKey, MainDS);

            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;

            TSubmitChangesResult result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                "There was a critical error when saving:");

            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "TPartnerEditUIConnector SubmitChanges return value");

            // check the location key for this partner. should not be negative
            Assert.AreEqual(1, MainDS.PPartnerLocation.Rows.Count, "TPartnerEditUIConnector SubmitChanges returns one location");
            Assert.Greater(MainDS.PPartnerLocation[0].LocationKey, 0, "TPartnerEditUIConnector SubmitChanges returns valid location key");
        }
Beispiel #24
0
        /// <summary>
        /// generate a family record
        /// </summary>
        public static PFamilyRow GenerateFamilyRecord(XmlNode ACurrentNode, string APrefix, PartnerEditTDS AMainDS)
        {
            PFamilyRow  FamilyRow  = AMainDS.PFamily.NewRowTyped();
            PPartnerRow PartnerRow = AMainDS.PPartner.NewRowTyped();

            if (NumberOfPartnerKeysReserved == 0)
            {
                NumberOfPartnerKeysReserved = 100;
                NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved);
            }

            long PartnerKey = NextPartnerKey;

            NextPartnerKey++;
            NumberOfPartnerKeysReserved--;

            PartnerRow.PartnerKey = PartnerKey;
            FamilyRow.PartnerKey  = PartnerRow.PartnerKey;

            FamilyRow.FirstName  = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FirstName");
            FamilyRow.FamilyName = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FamilyName");
            FamilyRow.Title      = TXMLParser.GetAttribute(ACurrentNode, APrefix + "Title");

            PartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(
                FamilyRow.FamilyName,
                FamilyRow.Title,
                FamilyRow.FirstName);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY;
            PartnerRow.StatusCode   = MPartnerConstants.PARTNERSTATUS_ACTIVE;

            AMainDS.PFamily.Rows.Add(FamilyRow);
            AMainDS.PPartner.Rows.Add(PartnerRow);

            return(FamilyRow);
        }
        /// <summary>
        /// Prepare the address changes. Check for the rules regarding locations
        /// </summary>
        public static TSubmitChangesResult PrepareChanges(PartnerEditTDS AInspectDS,
            Int64 APartnerKey,
            String APartnerClass,
            TDBTransaction ASubmitChangesTransaction,
            ref PartnerAddressAggregateTDS AResponseDS,
            out TVerificationResultCollection AVerificationResult)
        {
            PartnerAddressAggregateTDSSimilarLocationParametersTable ExistingLocationParametersDT;
            PartnerAddressAggregateTDSChangePromotionParametersTable ChangeLocationParametersDT;
            PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable AddressAddedOrChangedPromotionParametersDT;

            AVerificationResult = null;

            if (AInspectDS == null)
            {
//              TLogging.LogAtLevel(9, "SubmitChanges: AInspectDS = nil!");
                return TSubmitChangesResult.scrNothingToBeSaved;
            }

            AVerificationResult = new TVerificationResultCollection();
            TLocationPK[, ] SimilarLocationReUseKeyMapping = new TLocationPK[1, 2];

            if (AInspectDS.PLocation != null)
            {
//              TLogging.LogAtLevel(9, "SubmitChanges: PLocation Rows: " + AInspectDS.PLocation.Rows.Count.ToString());
            }

            if (AInspectDS.PPartnerLocation != null)
            {
//              TLogging.LogAtLevel(9, "SubmitChanges: PPartnerLocation Rows: " + AInspectDS.PPartnerLocation.Rows.Count.ToString());
            }

            if (TLogging.DL >= 8)
            {
                DebugLocationsBeforeSaving(AInspectDS);
            }

            // Check if Parameter Tables are passed in
            CheckParameterTables(AResponseDS,
                out ExistingLocationParametersDT,
                out ChangeLocationParametersDT,
                out AddressAddedOrChangedPromotionParametersDT);

            if (AInspectDS.PLocation != null)
            {
                TSubmitChangesResult result = ProcessLocationChanges(
                    AInspectDS.PLocation,
                    AInspectDS.PPartnerLocation,
                    ref AResponseDS,
                    ASubmitChangesTransaction,
                    APartnerKey,
                    ref ExistingLocationParametersDT,
                    ref SimilarLocationReUseKeyMapping,
                    ref AddressAddedOrChangedPromotionParametersDT,
                    ref ChangeLocationParametersDT,
                    ref AVerificationResult);

                if (result != TSubmitChangesResult.scrOK)
                {
                    // Stop processing here, we need more information!

                    return result;
                }
            }

            if (AInspectDS.PPartnerLocation != null)
            {
                TSubmitChangesResult result = ProcessPartnerLocationChanges(
                    AInspectDS.PPartnerLocation,
                    ref AResponseDS,
                    ASubmitChangesTransaction,
                    APartnerKey,
                    APartnerClass,
                    ref SimilarLocationReUseKeyMapping,
                    ref ExistingLocationParametersDT,
                    ref AddressAddedOrChangedPromotionParametersDT,
                    ref ChangeLocationParametersDT,
                    ref AVerificationResult);

                if (result != TSubmitChangesResult.scrOK)
                {
                    // Stop processing here, we need more information!

                    return result;
                }
            }

            /*
             * Actual saving of data
             */
            if (AInspectDS.PLocation != null)
            {
//              TLogging.LogAtLevel(9, "SubmitChanges: Length(SimilarLocationReUseKeyMapping): " + Convert.ToInt16(SimilarLocationReUseKeyMapping.GetLength(0)).ToString());

                if ((SimilarLocationReUseKeyMapping.GetLength(0) - 1) > 0)
                {
                    for (Int16 LocationReUseCounter = 1;
                         LocationReUseCounter <= SimilarLocationReUseKeyMapping.GetLength(0) - 1;
                         LocationReUseCounter += 1)
                    {
/* if DEBUGMODE
 *                      if (TLogging.DL >= 9)
 *                      {
 *                          TLogging.Log("LocationReUseCounter: " + LocationReUseCounter.ToString());
 *                          TLogging.Log(
 *                              "SubmitChanges: LocationReUseKeyMapping[" + LocationReUseCounter.ToString() +
 *                              ", 0].LocationKey: " +
 *                              SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].LocationKey.ToString());
 *                          TLogging.Log(
 *                              "SubmitChanges: LocationReUseKeyMapping[" + LocationReUseCounter.ToString() +
 *                              ", 1].LocationKey: " +
 *                              SimilarLocationReUseKeyMapping[LocationReUseCounter, 1].LocationKey.ToString());
 *                      }
 */
                        PLocationRow ReUsedLocationDR =
                            (PLocationRow)AInspectDS.PLocation.Rows.Find(
                                new System.Object[] { SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].SiteKey,
                                                      SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].LocationKey });

                        if (ReUsedLocationDR != null)
                        {
                            // Overwrite the originally submitted Key with the one that
                            // replaces it. This is needed to have the correct Key on
                            // the Client side!
                            ReUsedLocationDR.SiteKey = SimilarLocationReUseKeyMapping[LocationReUseCounter, 1].SiteKey;
                            ReUsedLocationDR.LocationKey = SimilarLocationReUseKeyMapping[LocationReUseCounter, 1].LocationKey;

                            // Make the DataRow 'unchanged' so that it doesn't get saved in the
                            // SubmitChanges call for PLocation!
                            ReUsedLocationDR.AcceptChanges();

                            // Remember that the row should not be submitted lateron
                            // NotToBeSubmittedLocationRows.Add(ReUsedLocationDR);
                        }
                        else
                        {
                            throw new EOPAppException("ReUsedLocationDR for SiteKey " +
                                SimilarLocationReUseKeyMapping[LocationReUseCounter,
                                                               0].SiteKey.ToString() + " and LocationKey " +
                                SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].LocationKey.ToString() + " could not be found!");
                        }
                    }
                }
            }

            if (AInspectDS.PPartnerLocation != null)
            {
//              TLogging.LogAtLevel(9, "SubmitChanges: Length(SimilarLocationReUseKeyMapping): " + Convert.ToInt16(SimilarLocationReUseKeyMapping.GetLength(0)).ToString());

                if ((SimilarLocationReUseKeyMapping.GetLength(0) - 1) > 0)
                {
                    for (Int16 LocationReUseCounter = 1;
                         LocationReUseCounter <= SimilarLocationReUseKeyMapping.GetLength(0) - 1;
                         LocationReUseCounter += 1)
                    {
//                      TLogging.LogAtLevel(9, "LocationReUseCounter: " + LocationReUseCounter.ToString());
//                      TLogging.LogAtLevel(9, "SubmitChanges: LocationReUseKeyMapping[" + LocationReUseCounter.ToString() + ", 0].LocationKey: " +
//                                SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].LocationKey.ToString());
                        PPartnerLocationRow ReUsedPartnerLocationDR = (PPartnerLocationRow)AInspectDS.PPartnerLocation.Rows.Find(
                            new System.Object[] { APartnerKey, SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].SiteKey,
                                                  SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].LocationKey });

                        if (ReUsedPartnerLocationDR != null)
                        {
                            // Overwrite the originally submitted Key with the one that
                            // replaces it. This is needed to have the correct Key on
                            // the Client side!
                            ReUsedPartnerLocationDR.SiteKey = SimilarLocationReUseKeyMapping[LocationReUseCounter, 1].SiteKey;
                            ReUsedPartnerLocationDR.LocationKey = SimilarLocationReUseKeyMapping[LocationReUseCounter, 1].LocationKey;
                        }
                        else
                        {
                            throw new EOPAppException("ReUsedPartnerLocationDR for SiteKey " +
                                SimilarLocationReUseKeyMapping[LocationReUseCounter,
                                                               0].SiteKey.ToString() + " and LocationKey " +
                                SimilarLocationReUseKeyMapping[LocationReUseCounter, 0].LocationKey.ToString() + " could not be found!");
                        }
                    }
                }
            }

            return TSubmitChangesResult.scrOK;
        }
Beispiel #26
0
        public static DataConsentTDS LastKnownEntry(
            Int64 APartnerKey,
            string ADataType
            )
        {
            TDBTransaction       T            = new TDBTransaction();
            TDataBase            DB           = DBAccess.Connect("Get Last known entry");
            DataConsentTDS       Set          = new DataConsentTDS();
            List <OdbcParameter> SQLParameter = new List <OdbcParameter>();

            DB.ReadTransaction(ref T, delegate {
                string sql = "SELECT " +
                             "`p_consent_history`.*, " +
                             "GROUP_CONCAT(`p_consent_history_permission`.`p_purpose_code_c` SEPARATOR ',') AS `AllowedPurposes` " +
                             "FROM `p_consent_history` " +
                             "LEFT JOIN `p_consent_history_permission` " +
                             "ON `p_consent_history`.`p_entry_id_i` = `p_consent_history_permission`.`p_consent_history_entry_i` " +
                             "WHERE `p_consent_history`.`p_partner_key_n` = ? " +
                             "AND `p_consent_history`.`p_type_c` = ? " +
                             "GROUP BY `p_consent_history`.`p_entry_id_i` " +
                             "ORDER BY `p_consent_history`.`p_entry_id_i` DESC " +
                             "LIMIT 1";

                SQLParameter.Add(new OdbcParameter("PartnerKey", OdbcType.BigInt)
                {
                    Value = APartnerKey
                });
                SQLParameter.Add(new OdbcParameter("DataType", OdbcType.VarChar)
                {
                    Value = ADataType
                });

                DB.SelectDT(Set.PConsentHistory, sql, T, SQLParameter.ToArray());

                if (Set.PConsentHistory.Count == 0)
                {
                    // there is no consent yet
                    // do we have a value at all?
                    List <string> Subscriptions;
                    List <string> PartnerTypes;
                    string DefaultEmailAddress;
                    string DefaultPhoneMobile;
                    string DefaultPhoneLandline;
                    PartnerEditTDS PartnerDS = TSimplePartnerEditWebConnector.GetPartnerDetails(APartnerKey,
                                                                                                out Subscriptions,
                                                                                                out PartnerTypes,
                                                                                                out DefaultEmailAddress,
                                                                                                out DefaultPhoneMobile,
                                                                                                out DefaultPhoneLandline);

                    if (ADataType == MPartnerConstants.CONSENT_TYPE_ADDRESS)
                    {
                        // what about new contact?
                        PLocationRow locationRow = null;

                        if (PartnerDS.PLocation.Rows.Count > 0)
                        {
                            locationRow = PartnerDS.PLocation[0];
                        }
                        else
                        {
                            locationRow = PartnerDS.PLocation.NewRowTyped();
                        }

                        PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped();
                        row.EntryId            = -1;
                        row.PartnerKey         = APartnerKey;
                        row.Type        = ADataType;
                        row.Value       = locationRow.StreetName + ", " + locationRow.PostalCode + " " + locationRow.City + ", " + locationRow.CountryCode;
                        row.ConsentDate = DateTime.Today;
                        Set.PConsentHistory.Rows.Add(row);
                    }

                    if (ADataType == MPartnerConstants.CONSENT_TYPE_EMAIL)
                    {
                        PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped();
                        row.EntryId            = -1;
                        row.PartnerKey         = APartnerKey;
                        row.Type        = ADataType;
                        row.Value       = DefaultEmailAddress;
                        row.ConsentDate = DateTime.Today;
                        Set.PConsentHistory.Rows.Add(row);
                    }

                    if (ADataType == MPartnerConstants.CONSENT_TYPE_LANDLINE)
                    {
                        PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped();
                        row.EntryId            = -1;
                        row.PartnerKey         = APartnerKey;
                        row.Type        = ADataType;
                        row.Value       = DefaultPhoneLandline;
                        row.ConsentDate = DateTime.Today;
                        Set.PConsentHistory.Rows.Add(row);
                    }

                    if (ADataType == MPartnerConstants.CONSENT_TYPE_MOBILE)
                    {
                        PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped();
                        row.EntryId            = -1;
                        row.PartnerKey         = APartnerKey;
                        row.Type        = ADataType;
                        row.Value       = DefaultPhoneMobile;
                        row.ConsentDate = DateTime.Today;
                        Set.PConsentHistory.Rows.Add(row);
                    }
                }

                PConsentChannelAccess.LoadAll(Set, T);
                PConsentPurposeAccess.LoadAll(Set, T);
            });

            return(Set);
        }
        /// create a new unit
        public static PPartnerRow CreateNewUnitPartnerWithTypeCode(PartnerEditTDS AMainDS, string AUnitType)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_UNIT;
            PartnerRow.PartnerShortName = PartnerRow.PartnerKey.ToString() + ", TestUnit";

            PUnitRow UnitRow = AMainDS.PUnit.NewRowTyped();
            UnitRow.PartnerKey = PartnerRow.PartnerKey;
            UnitRow.UnitName = "TestUnit";
            UnitRow.UnitTypeCode = AUnitType;
            AMainDS.PUnit.Rows.Add(UnitRow);

            return PartnerRow;
        }
        /// <summary>
        /// Creates data needed to test posting recalculations
        /// </summary>
        /// <param name="ARecipientKey">Partner Key of the recipient.</param>
        /// <param name="ARealRecipientLedgerNumber">What the RecipientLedgerNumber should be.</param>
        /// <param name="AFalseRecipientLedgerNumber">What the RecipientLedgerNumber is.</param>
        /// <param name="ARecurringGiftBatchNumber">Batch Number.</param>
        private void TestRecurringBatchSubmitRecalculations_Arrange(out long ARecipientKey,
                                                                    out long ARealRecipientLedgerNumber,
                                                                    out long AFalseRecipientLedgerNumber,
                                                                    out Int32 ARecurringGiftBatchNumber)
        {
            TVerificationResultCollection VerificationResult;
            TSubmitChangesResult          Result;
            DataSet ResponseDS;
            TPartnerEditUIConnector PartnerEditUIUIConnector = new TPartnerEditUIConnector();

            GiftBatchTDS   MainDS        = new GiftBatchTDS();
            PartnerEditTDS PartnerEditDS = new PartnerEditTDS();

            // this is a family partner in the test database
            const Int64 DONORKEY = 43005001;


            // create a new recipient
            TCreateTestPartnerData.CreateNewFamilyPartner(PartnerEditDS);
            ARecipientKey = PartnerEditDS.PFamily[0].PartnerKey;

            // create two new Unit partners
            TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS);
            TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS);
            AFalseRecipientLedgerNumber = PartnerEditDS.PPartner[0].PartnerKey;
            ARealRecipientLedgerNumber  = PartnerEditDS.PPartner[1].PartnerKey;

            PPartnerTypeRow PartnerTypeRow = PartnerEditDS.PPartnerType.NewRowTyped();

            PartnerTypeRow.PartnerKey = ARealRecipientLedgerNumber;
            PartnerTypeRow.TypeCode   = MPartnerConstants.PARTNERTYPE_COSTCENTRE;
            PartnerEditDS.PPartnerType.Rows.Add(PartnerTypeRow);

            // create a Gift Destination for family
            PPartnerGiftDestinationRow GiftDestination = PartnerEditDS.PPartnerGiftDestination.NewRowTyped(true);

            GiftDestination.Key           = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination();
            GiftDestination.PartnerKey    = ARecipientKey;
            GiftDestination.DateEffective = new DateTime(2011, 01, 01);
            GiftDestination.FieldKey      = ARealRecipientLedgerNumber;

            PartnerEditDS.PPartnerGiftDestination.Rows.Add(GiftDestination);

            // Guard Assertions
            Assert.That(PartnerEditDS.PFamily[0], Is.Not.Null);
            Assert.That(PartnerEditDS.PPartner[0], Is.Not.Null);
            Assert.That(PartnerEditDS.PPartner[1], Is.Not.Null);

            // Submit the new PartnerEditTDS records to the database
            ResponseDS = new PartnerEditTDS();
            Result     = PartnerEditUIUIConnector.SubmitChanges(ref PartnerEditDS, ref ResponseDS, out VerificationResult);

            // Guard Assertion
            Assert.That(Result, Is.EqualTo(
                            TSubmitChangesResult.scrOK), "SubmitChanges for PartnerEditDS failed: " + VerificationResult.BuildVerificationResultString());

            // link unit to Cost Centre
            DataTable PartnerCostCentreTbl = TGLSetupWebConnector.LoadCostCentrePartnerLinks(FLedgerNumber, 0);
            DataRow   PartnerCostCentreRow = PartnerCostCentreTbl.NewRow();

            PartnerCostCentreRow["PartnerKey"] = ARealRecipientLedgerNumber;
            PartnerCostCentreRow["IsLinked"]   = 4300;
            PartnerCostCentreTbl.Rows.Add(PartnerCostCentreRow);
            TGLSetupWebConnector.SaveCostCentrePartnerLinks(FLedgerNumber, PartnerCostCentreTbl);

            // create a new Recurring Gift Batch
            MainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber);
            ARecurringGiftBatchNumber = MainDS.ARecurringGiftBatch[0].BatchNumber;

            // create a new recurring gifts
            ARecurringGiftRow RecurringGiftRow = MainDS.ARecurringGift.NewRowTyped(true);

            RecurringGiftRow.LedgerNumber          = FLedgerNumber;
            RecurringGiftRow.BatchNumber           = ARecurringGiftBatchNumber;
            RecurringGiftRow.DonorKey              = DONORKEY;
            RecurringGiftRow.GiftTransactionNumber = 1;
            RecurringGiftRow.LastDetailNumber      = 1;

            MainDS.ARecurringGift.Rows.Add(RecurringGiftRow);

            // create a new RecurringGiftDetail
            ARecurringGiftDetailRow RecurringGiftDetail = MainDS.ARecurringGiftDetail.NewRowTyped(true);

            RecurringGiftDetail.LedgerNumber          = FLedgerNumber;
            RecurringGiftDetail.BatchNumber           = ARecurringGiftBatchNumber;
            RecurringGiftDetail.GiftTransactionNumber = 1;
            RecurringGiftDetail.DetailNumber          = 1;
            RecurringGiftDetail.RecipientLedgerNumber = AFalseRecipientLedgerNumber;
            RecurringGiftDetail.GiftAmount            = 100;
            RecurringGiftDetail.MotivationGroupCode   = "GIFT";
            RecurringGiftDetail.MotivationDetailCode  = "SUPPORT";
            RecurringGiftDetail.RecipientKey          = ARecipientKey;

            MainDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail);

            // Submit the new GiftBatchTDS records to the database
            Result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref MainDS, out VerificationResult);

            // Guard Assertion
            Assert.That(Result, Is.EqualTo(
                            TSubmitChangesResult.scrOK), "SaveGiftBatchTDS failed: " + VerificationResult.BuildVerificationResultString());
        }
        /// create a new church
        public static PPartnerRow CreateNewChurchPartner(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            // make sure denomation "UNKNOWN" exists as this is the default value
            if (!PDenominationAccess.Exists("UNKNOWN", DBAccess.GDBAccessObj.Transaction))
            {
                PDenominationTable DenominationTable = new PDenominationTable();
                PDenominationRow DenominationRow = DenominationTable.NewRowTyped();
                DenominationRow.DenominationCode = "UNKNOWN";
                DenominationRow.DenominationName = "Unknown";
                DenominationTable.Rows.Add(DenominationRow);
                PDenominationAccess.SubmitChanges(DenominationTable, DBAccess.GDBAccessObj.Transaction);
            }

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_CHURCH;
            PartnerRow.PartnerShortName = PartnerRow.PartnerKey.ToString() + ", TestChurch";

            PChurchRow ChurchRow = AMainDS.PChurch.NewRowTyped();
            ChurchRow.PartnerKey = PartnerRow.PartnerKey;
            ChurchRow.ChurchName = "TestChurch";
            ChurchRow.DenominationCode = "UNKNOWN";
            AMainDS.PChurch.Rows.Add(ChurchRow);

            return PartnerRow;
        }
Beispiel #30
0
        /// <summary>
        /// method for importing data entered on the web form
        /// </summary>
        /// <returns></returns>
        public static string DataImportFromForm(string AFormID, string AJSONFormData, bool ASendApplicationReceivedEmail)
        {
            if (AFormID == "TestPrintingEmail")
            {
                // This is a test for printing to PDF and sending an email, no partner is created in the database.
                // make sure you have a photo with name data\photos\815.jpg for the photo to appear in the pdf
                TApplicationFormData data = (TApplicationFormData)TJsonTools.ImportIntoTypedStructure(typeof(TApplicationFormData),
                                                                                                      AJSONFormData);
                data.RawData = AJSONFormData;

                string pdfIdentifier;
                string pdfFilename = GeneratePDF(0815, data.registrationcountrycode, data, out pdfIdentifier);
                try
                {
                    if (SendEmail(0815, data.registrationcountrycode, data, pdfFilename))
                    {
                        // return id of the PDF pdfIdentifier
                        string result = "{\"success\":true,\"data\":{\"pdfPath\":\"downloadPDF.aspx?pdf-id=" + pdfIdentifier + "\"}}";
                        return(result);
                    }
                    else
                    {
                        string message = String.Format(Catalog.GetString("We were not able to send the email to {0}"), data.email);
                        TLogging.Log("returning: " + "{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}");
                        return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}");
                    }
                }
                catch (Exception e)
                {
                    TLogging.Log(e.Message);
                    TLogging.Log(e.StackTrace);
                }
            }

            if (AFormID == "RegisterPerson")
            {
                TApplicationFormData data = (TApplicationFormData)TJsonTools.ImportIntoTypedStructure(typeof(TApplicationFormData),
                                                                                                      AJSONFormData);
                data.RawData = AJSONFormData;

                Int64  NewPersonPartnerKey = -1;
                string imageTmpPath        = String.Empty;

                try
                {
                    PartnerEditTDS MainDS = new PartnerEditTDS();

                    // TODO: check that email is unique. do not allow email to be associated with 2 records. this would cause trouble with authentication
                    // TODO: create a user for this partner

                    Int64 NewFamilyPartnerKey = CreateFamily(ref MainDS, data);
                    NewPersonPartnerKey = CreatePerson(ref MainDS, NewFamilyPartnerKey, data);
                    CreateAddress(ref MainDS, data, NewFamilyPartnerKey);

                    try
                    {
                        PartnerEditTDSAccess.SubmitChanges(MainDS);
                    }
                    catch (Exception Exc)
                    {
                        string message = "There is some critical error when saving to the database: " + Exc.ToString();
                        return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}");
                    }

                    // add a record for the application
                    ConferenceApplicationTDS ConfDS = new ConferenceApplicationTDS();
                    PmGeneralApplicationRow  GeneralApplicationRow = ConfDS.PmGeneralApplication.NewRowTyped();
                    GeneralApplicationRow.RawApplicationData = AJSONFormData;
                    GeneralApplicationRow.PartnerKey         = NewPersonPartnerKey;
                    GeneralApplicationRow.ApplicationKey     = -1;
                    GeneralApplicationRow.RegistrationOffice = data.registrationoffice;
                    GeneralApplicationRow.GenAppDate         = DateTime.Today;
                    GeneralApplicationRow.AppTypeName        = MConferenceConstants.APPTYPE_CONFERENCE;

                    // TODO pm_st_basic_camp_identifier_c is quite strange. will there be an overflow soon?
                    // see ticket https://sourceforge.net/apps/mantisbt/openpetraorg/view.php?id=161
                    GeneralApplicationRow.OldLink              = "";
                    GeneralApplicationRow.GenApplicantType     = "";
                    GeneralApplicationRow.GenApplicationStatus = MConferenceConstants.APPSTATUS_ONHOLD;
                    ConfDS.PmGeneralApplication.Rows.Add(GeneralApplicationRow);

                    PmShortTermApplicationRow ShortTermApplicationRow = ConfDS.PmShortTermApplication.NewRowTyped();
                    ShortTermApplicationRow.PartnerKey          = NewPersonPartnerKey;
                    ShortTermApplicationRow.ApplicationKey      = -1;
                    ShortTermApplicationRow.RegistrationOffice  = data.registrationoffice;
                    ShortTermApplicationRow.StAppDate           = DateTime.Today;
                    ShortTermApplicationRow.StApplicationType   = MConferenceConstants.APPTYPE_CONFERENCE;
                    ShortTermApplicationRow.StBasicOutreachId   = GeneralApplicationRow.OldLink;
                    ShortTermApplicationRow.StCongressCode      = data.role;
                    ShortTermApplicationRow.ConfirmedOptionCode = data.eventidentifier;
                    ShortTermApplicationRow.StConfirmedOption   = Convert.ToInt64(data.eventpartnerkey);
                    ShortTermApplicationRow.StFieldCharged      = data.registrationoffice;
                    ShortTermApplicationRow.Arrival             = data.dateofarrival;
                    ShortTermApplicationRow.Departure           = data.dateofdeparture;

                    ConfDS.PmShortTermApplication.Rows.Add(ShortTermApplicationRow);

                    // TODO ApplicationForms

                    try
                    {
                        ConferenceApplicationTDSAccess.SubmitChanges(ConfDS);
                    }
                    catch (Exception Exc)
                    {
                        string message = "There is some critical error when saving to the database: " + Exc.ToString();
                        return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}");
                    }

                    // process Photo
                    imageTmpPath = TAppSettingsManager.GetValue("Server.PathTemp") +
                                   Path.DirectorySeparatorChar +
                                   Path.GetFileName(data.imageid);

                    if (File.Exists(imageTmpPath))
                    {
                        string photosPath = TAppSettingsManager.GetValue("Server.PathData") + Path.DirectorySeparatorChar +
                                            "photos";

                        if (!Directory.Exists(photosPath))
                        {
                            Directory.CreateDirectory(photosPath);
                        }

                        File.Copy(imageTmpPath,
                                  photosPath +
                                  Path.DirectorySeparatorChar +
                                  NewPersonPartnerKey +
                                  Path.GetExtension(imageTmpPath).ToLower(), true);
                    }
                }
                catch (Exception e)
                {
                    TLogging.Log(e.Message);
                    TLogging.Log(e.StackTrace);
                    string message = "There is some critical error when saving to the database";
                    return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}");
                }

                if (ASendApplicationReceivedEmail)
                {
                    string pdfIdentifier;
                    string pdfFilename = GeneratePDF(NewPersonPartnerKey, data.registrationcountrycode, data, out pdfIdentifier);
                    try
                    {
                        if (SendEmail(NewPersonPartnerKey, data.registrationcountrycode, data, pdfFilename))
                        {
                            if (File.Exists(imageTmpPath))
                            {
                                // only delete the temp image after successful application. otherwise we have a problem with resending the application, because the tmp image is gone
                                File.Delete(imageTmpPath);
                            }

                            // return id of the PDF pdfIdentifier
                            string result = "{\"success\":true,\"data\":{\"pdfPath\":\"downloadPDF.aspx?pdf-id=" + pdfIdentifier + "\"}}";
                            return(result);
                        }
                    }
                    catch (Exception e)
                    {
                        TLogging.Log(e.Message);
                        TLogging.Log(e.StackTrace);
                    }
                }

                string message2 = String.Format(Catalog.GetString("We were not able to send the email to {0}"), data.email);
                string result2  = "{\"failure\":true, \"data\":{\"result\":\"" + message2 + "\"}}";

                if (ASendApplicationReceivedEmail)
                {
                    TLogging.Log(result2);
                }

                return(result2);
            }
            else
            {
                string message = "The server does not know about a form called " + AFormID;
                TLogging.Log(message);
                return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}");
            }
        }
        /// create a new BankingDetails record and a new PartnerBankingDetails record
        public static PartnerEditTDSPBankingDetailsRow CreateNewBankingRecords(long APartnerKey, PartnerEditTDS AMainDS)
        {
            PartnerEditTDSPBankingDetailsRow BankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped();

            BankingDetailsRow.BankingDetailsKey = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_bank_details));
            BankingDetailsRow.BankingType = MPartnerConstants.BANKINGTYPE_BANKACCOUNT;
            BankingDetailsRow.MainAccount = true;
            AMainDS.PBankingDetails.Rows.Add(BankingDetailsRow);

            PPartnerBankingDetailsRow PartnerBankingDetailsRow = AMainDS.PPartnerBankingDetails.NewRowTyped();
            PartnerBankingDetailsRow.PartnerKey = APartnerKey;
            PartnerBankingDetailsRow.BankingDetailsKey = BankingDetailsRow.BankingDetailsKey;
            AMainDS.PPartnerBankingDetails.Rows.Add(PartnerBankingDetailsRow);

            PBankingDetailsUsageRow BankingDetailsUsageRow = AMainDS.PBankingDetailsUsage.NewRowTyped();
            BankingDetailsUsageRow.PartnerKey = APartnerKey;
            BankingDetailsUsageRow.BankingDetailsKey = BankingDetailsRow.BankingDetailsKey;
            BankingDetailsUsageRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN;
            AMainDS.PBankingDetailsUsage.Rows.Add(BankingDetailsUsageRow);

            return BankingDetailsRow;
        }
Beispiel #32
0
        /// <summary>
        /// create PPartnerLocation records for the FAMILY partner, and all the PERSON records of this family
        /// </summary>
        public static void GenerateAddressForFamily(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS)
        {
            PLocationRow locationRow = AMainDS.PLocation.NewRowTyped();

            locationRow.SiteKey = 0; // DomainManager.GSiteKey;
            locationRow.LocationKey = (AMainDS.PLocation.Count + 1) * -1;
            locationRow.StreetName = TXMLParser.GetAttribute(ACurrentNode, "Addr2");
            locationRow.PostalCode = TXMLParser.GetAttribute(ACurrentNode, "PostCode");
            locationRow.City = TXMLParser.GetAttribute(ACurrentNode, "City");
            locationRow.County = TXMLParser.GetAttribute(ACurrentNode, "Province");
            locationRow.CountryCode = TXMLParser.GetAttribute(ACurrentNode, "CountryCode");

            AMainDS.PLocation.Rows.Add(locationRow);

            PPartnerLocationRow familyLocationRow = AMainDS.PPartnerLocation.NewRowTyped();

            familyLocationRow.PartnerKey = AFamilyRow.PartnerKey;
            familyLocationRow.LocationKey = locationRow.LocationKey;
            familyLocationRow.SiteKey = locationRow.SiteKey;
            familyLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME;
            familyLocationRow.SendMail = true;

            AMainDS.PPartnerLocation.Rows.Add(familyLocationRow);

            DataView FamilyView = new DataView(AMainDS.PPerson);
            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort = PPersonTable.GetFamilyIdDBName();

            // for each person, also create a location record
            for (int countPerson = 0; countPerson < FamilyView.Count; countPerson++)
            {
                PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row;

                PPartnerLocationRow personLocationRow = AMainDS.PPartnerLocation.NewRowTyped();
                personLocationRow.PartnerKey = personRow.PartnerKey;
                personLocationRow.LocationKey = familyLocationRow.LocationKey;
                personLocationRow.SiteKey = familyLocationRow.SiteKey;
                personLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME;
                personLocationRow.SendMail = true;
                AMainDS.PPartnerLocation.Rows.Add(personLocationRow);

                string prefix = "Male";

                if (countPerson == 1)
                {
                    prefix = "Female";
                }
                else if (countPerson > 1)
                {
                    prefix = "Child" + (countPerson - 1).ToString();
                }

                personLocationRow.EmailAddress = TXMLParser.GetAttribute(ACurrentNode, prefix + "Email");

                // set email of first person for whole family
                if (countPerson == 0)
                {
                    familyLocationRow.EmailAddress = personLocationRow.EmailAddress;
                }
            }
        }
        /// create a new family with two persons
        public static void CreateFamilyWithTwoPersonRecords(PartnerEditTDS AMainDS)
        {
            PPartnerRow PartnerRow = CreateNewFamilyPartner(AMainDS);

            CreateNewLocation(PartnerRow.PartnerKey, AMainDS);

            CreateNewPerson(AMainDS,
                PartnerRow.PartnerKey,
                AMainDS.PLocation[0].LocationKey,
                "Adam",
                "Mr",
                0);
            CreateNewPerson(AMainDS,
                PartnerRow.PartnerKey,
                AMainDS.PLocation[0].LocationKey,
                "Eve",
                "Mrs",
                1);
        }
Beispiel #34
0
        /// <summary>
        /// create PPartnerBankingDetail records for the FAMILY partner
        /// </summary>
        public static void GenerateBankDetails(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS,
            DataTable ABankKeys)
        {
            if (TXMLParser.HasAttribute(ACurrentNode, "bankaccount_bank"))
            {
                Int32 BankID =
                    Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "bankaccount_bank")) % ABankKeys.Rows.Count;
                long BankPartnerKey = Convert.ToInt64(ABankKeys.Rows[BankID].ItemArray[0]);

                PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped();

                bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1;
                bankingDetailsRow.BankKey = BankPartnerKey;
                bankingDetailsRow.BankAccountNumber = TXMLParser.GetAttribute(ACurrentNode, "bankaccount_account");
                bankingDetailsRow.BankingType = MPartnerConstants.BANKINGTYPE_BANKACCOUNT;
                bankingDetailsRow.AccountName = AFamilyRow.FirstName + " " + AFamilyRow.FamilyName;

                AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow);

                PPartnerBankingDetailsRow partnerBankingRow = AMainDS.PPartnerBankingDetails.NewRowTyped();
                partnerBankingRow.PartnerKey = AFamilyRow.PartnerKey;
                partnerBankingRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey;
                AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingRow);

                PBankingDetailsUsageRow bankingUsageRow = AMainDS.PBankingDetailsUsage.NewRowTyped();
                bankingUsageRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey;
                bankingUsageRow.PartnerKey = AFamilyRow.PartnerKey;
                bankingUsageRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN;
                AMainDS.PBankingDetailsUsage.Rows.Add(bankingUsageRow);
            }
        }
Beispiel #35
0
        /// <summary>
        /// generate a family record
        /// </summary>
        public static PFamilyRow GenerateFamilyRecord(XmlNode ACurrentNode, string APrefix, PartnerEditTDS AMainDS)
        {
            PFamilyRow FamilyRow = AMainDS.PFamily.NewRowTyped();
            PPartnerRow PartnerRow = AMainDS.PPartner.NewRowTyped();

            if (NumberOfPartnerKeysReserved == 0)
            {
                NumberOfPartnerKeysReserved = 100;
                NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved);
            }

            long PartnerKey = NextPartnerKey;
            NextPartnerKey++;
            NumberOfPartnerKeysReserved--;

            PartnerRow.PartnerKey = PartnerKey;
            FamilyRow.PartnerKey = PartnerRow.PartnerKey;

            FamilyRow.FirstName = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FirstName");
            FamilyRow.FamilyName = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FamilyName");
            FamilyRow.Title = TXMLParser.GetAttribute(ACurrentNode, APrefix + "Title");

            PartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(
                FamilyRow.FamilyName,
                FamilyRow.Title,
                FamilyRow.FirstName);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY;
            PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE;

            AMainDS.PFamily.Rows.Add(FamilyRow);
            AMainDS.PPartner.Rows.Add(PartnerRow);

            return FamilyRow;
        }
Beispiel #36
0
        /// <summary>
        /// generate a person record and update the associated family partner
        /// </summary>
        /// <param name="ACurrentNode"></param>
        /// <param name="AFamilyRow"></param>
        /// <param name="APrefix"></param>
        /// <param name="AMainDS"></param>
        public static void GeneratePersonRecord(XmlNode ACurrentNode, PFamilyRow AFamilyRow, string APrefix, PartnerEditTDS AMainDS)
        {
            PPersonRow  PersonRow  = AMainDS.PPerson.NewRowTyped();
            PPartnerRow PartnerRow = AMainDS.PPartner.NewRowTyped();

            if (NumberOfPartnerKeysReserved == 0)
            {
                NumberOfPartnerKeysReserved = 100;
                NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved);
            }

            long PartnerKey = NextPartnerKey;

            NextPartnerKey++;
            NumberOfPartnerKeysReserved--;

            PartnerRow.PartnerKey = PartnerKey;
            PersonRow.PartnerKey  = PartnerRow.PartnerKey;
            PersonRow.FamilyKey   = AFamilyRow.PartnerKey;

            // create family id: count existing family members
            DataView FamilyView = new DataView(AMainDS.PPerson);

            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort      = PPersonTable.GetFamilyIdDBName();

            PersonRow.FamilyId = FamilyView.Count;

            PersonRow.FirstName   = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FirstName");
            PersonRow.MiddleName1 = TXMLParser.GetAttribute(ACurrentNode, APrefix + "MiddleName");
            PersonRow.FamilyName  = AFamilyRow.FamilyName;

            if (FamilyView.Count == 1)
            {
                PartnerRow.PreviousName = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FamilyName");
            }

            PersonRow.Title = TXMLParser.GetAttribute(ACurrentNode, APrefix + "Title");

            PartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(
                PersonRow.FamilyName,
                PersonRow.Title,
                PersonRow.FirstName);
            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_PERSON;
            PartnerRow.StatusCode   = MPartnerConstants.PARTNERSTATUS_ACTIVE;

            PersonRow.DateOfBirth = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, APrefix + "DateOfBirth"));

            string gender = TXMLParser.GetAttribute(ACurrentNode, APrefix + "Gender");

            if ((APrefix == "Male") || (gender == "MALE"))
            {
                PersonRow.Gender             = MPartnerConstants.GENDER_MALE;
                PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_MALE;
            }
            else if ((APrefix == "Female") || (gender == "FEMALE"))
            {
                PersonRow.Gender             = MPartnerConstants.GENDER_FEMALE;
                PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FEMALE;
            }

            PPartnerRow FamilyPartnerRow = (PPartnerRow)AMainDS.PPartner.Rows.Find(AFamilyRow.PartnerKey);

            if (FamilyView.Count == 0)
            {
                FamilyPartnerRow.AddresseeTypeCode = PartnerRow.AddresseeTypeCode;
            }
            else if (FamilyView.Count == 1)
            {
                // this is a couple
                PersonRow.MaritalStatus = MPartnerConstants.MARITALSTATUS_MARRIED;

                // find first person record as well
                PPersonRow Husband = (PPersonRow)FamilyView[0].Row;
                Husband.MaritalStatus = MPartnerConstants.MARITALSTATUS_MARRIED;

                AFamilyRow.MaritalStatus = MPartnerConstants.MARITALSTATUS_MARRIED;

                AFamilyRow.FirstName = Husband.FirstName + " and " + PersonRow.FirstName;
                AFamilyRow.Title     = Husband.Title + " and " + PersonRow.Title;

                // update family shortname
                FamilyPartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_COUPLE;
                FamilyPartnerRow.PartnerShortName  = Calculations.DeterminePartnerShortName(
                    AFamilyRow.FamilyName,
                    AFamilyRow.Title,
                    AFamilyRow.FirstName);
            }
            else if (FamilyView.Count > 1)
            {
                FamilyPartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FAMILY;
            }

            AMainDS.PPerson.Rows.Add(PersonRow);
            AMainDS.PPartner.Rows.Add(PartnerRow);
        }
        /// create a new person
        public static PPersonRow CreateNewPerson(PartnerEditTDS AMainDS,
            Int64 AFamilyKey,
            Int32 ALocationKey,
            string AFirstName,
            string ATitle,
            int AFamilyID)
        {
            PPartnerRow PartnerRow = CreateNewPartner(AMainDS);

            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_PERSON;
            PartnerRow.PartnerShortName = AFamilyKey.ToString() + ", " + AFirstName + ", " + ATitle;

            PPersonRow PersonRow = AMainDS.PPerson.NewRowTyped();
            PersonRow.PartnerKey = PartnerRow.PartnerKey;
            PersonRow.FamilyKey = AFamilyKey;
            PersonRow.FamilyName = AFamilyKey.ToString();
            PersonRow.FirstName = AFirstName;
            PersonRow.FamilyId = AFamilyID;
            PersonRow.Title = ATitle;
            AMainDS.PPerson.Rows.Add(PersonRow);

            PPartnerLocationRow PartnerLocationRow = AMainDS.PPartnerLocation.NewRowTyped();
            PartnerLocationRow.SiteKey = DomainManager.GSiteKey;
            PartnerLocationRow.PartnerKey = PartnerRow.PartnerKey;
            PartnerLocationRow.LocationKey = ALocationKey;
            AMainDS.PPartnerLocation.Rows.Add(PartnerLocationRow);

            return PersonRow;
        }
Beispiel #38
0
        /// <summary>
        /// generate the partners from a text file that was generated with Benerator
        /// </summary>
        /// <param name="AInputBeneratorFile"></param>
        public static void GenerateFamilyPartners(string AInputBeneratorFile)
        {
            // get a list of banks (all class BANK)
            string    sqlGetBankPartnerKeys = "SELECT p_partner_key_n FROM PUB_p_bank";
            DataTable BankKeys = DBAccess.GDBAccessObj.SelectDT(sqlGetBankPartnerKeys, "keys", null);

            PartnerEditTDS MainDS = new PartnerEditTDS();

            // AlanP: May 2016 - We may no longer need the UTF8 because the method now automatically discovers the encoding even with no BOM
            XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml(AInputBeneratorFile, ",", Encoding.UTF8);

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            while (RecordNode != null)
            {
                string familySituation = TXMLParser.GetAttribute(RecordNode, "familySituation");

                PFamilyRow  familyRecord     = null;
                PPartnerRow FamilyPartnerRow = null;

                if (familySituation == "singleMan")
                {
                    familyRecord = SampleDataWorkers.GenerateFamilyRecord(RecordNode, "Male", MainDS);
                    SampleDataWorkers.GeneratePersonRecord(RecordNode, familyRecord, "Male", MainDS);
                }
                else if (familySituation == "singleWoman")
                {
                    familyRecord = SampleDataWorkers.GenerateFamilyRecord(RecordNode, "Female", MainDS);
                    SampleDataWorkers.GeneratePersonRecord(RecordNode, familyRecord, "Female", MainDS);
                }
                else if (familySituation == "family")
                {
                    familyRecord = SampleDataWorkers.GenerateFamilyRecord(RecordNode, "Male", MainDS);
                    SampleDataWorkers.GeneratePersonRecord(RecordNode, familyRecord, "Male", MainDS);
                    SampleDataWorkers.GeneratePersonRecord(RecordNode, familyRecord, "Female", MainDS);

                    int NumberOfChildren = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "numberOfChildren"));

                    if (NumberOfChildren > 0)
                    {
                        FamilyPartnerRow = (PPartnerRow)MainDS.PPartner.Rows.Find(familyRecord.PartnerKey);
                        FamilyPartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FAMILY;
                    }
                }

                FamilyPartnerRow = (PPartnerRow)MainDS.PPartner.Rows.Find(familyRecord.PartnerKey);
                FamilyPartnerRow.ReceiptEachGift        = false;
                FamilyPartnerRow.ReceiptLetterFrequency = "Annual";

                SampleDataWorkers.GenerateAddressForFamily(RecordNode, familyRecord, MainDS);

                SampleDataWorkers.GenerateBankDetails(RecordNode, familyRecord, MainDS, BankKeys);

                if (MainDS.PFamily.Rows.Count % 100 == 0)
                {
                    TLogging.Log("created donor " + MainDS.PFamily.Rows.Count.ToString() + " " + familyRecord.FamilyName);
                }

                RecordNode = RecordNode.NextSibling;
            }

            // we do not save person records for normal family partners
            MainDS.PPerson.Clear();

            // need to clear all partner records of the PERSON partners as well
            DataView PersonPartners = new DataView(MainDS.PPartner);

            PersonPartners.RowFilter =
                string.Format("{0} = '{1}'",
                              PPartnerTable.GetPartnerClassDBName(),
                              MPartnerConstants.PARTNERCLASS_PERSON);

            DataView PartnerLocations = new DataView(MainDS.PPartnerLocation);

            foreach (DataRowView rv in PersonPartners)
            {
                PPartnerRow partnerRow = (PPartnerRow)rv.Row;

                PartnerLocations.RowFilter =
                    string.Format("{0} = {1}",
                                  PPartnerLocationTable.GetPartnerKeyDBName(),
                                  partnerRow.PartnerKey);

                PartnerLocations[0].Row.Delete();

                partnerRow.Delete();
            }

            MainDS.ThrowAwayAfterSubmitChanges = true;

            PartnerEditTDSAccess.SubmitChanges(MainDS);

            TLogging.Log("after saving donors");
        }
Beispiel #39
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;
        }
Beispiel #40
0
        public void TestDeleteOrganisation()
        {
            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;
            String TextMessage;
            Boolean CanDeletePartner;
            PPartnerRow OrganisationPartnerRow;
            TSubmitChangesResult result;
            Int64 PartnerKey;

            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            OrganisationPartnerRow = TCreateTestPartnerData.CreateNewOrganisationPartner(MainDS);
            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create organisation record");

            // check if organisation partner can be deleted (still needs to be possible at this point)
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(OrganisationPartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(CanDeletePartner);

            // now test actual deletion of Organisation partner
            PartnerKey = OrganisationPartnerRow.PartnerKey;
            Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult));

            // check that Organisation record is really deleted
            Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey));
        }
Beispiel #41
0
        /// <summary>
        /// generate a person record and update the associated family partner
        /// </summary>
        /// <param name="ACurrentNode"></param>
        /// <param name="AFamilyRow"></param>
        /// <param name="APrefix"></param>
        /// <param name="AMainDS"></param>
        public static void GeneratePersonRecord(XmlNode ACurrentNode, PFamilyRow AFamilyRow, string APrefix, PartnerEditTDS AMainDS)
        {
            PPersonRow PersonRow = AMainDS.PPerson.NewRowTyped();
            PPartnerRow PartnerRow = AMainDS.PPartner.NewRowTyped();

            if (NumberOfPartnerKeysReserved == 0)
            {
                NumberOfPartnerKeysReserved = 100;
                NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved);
            }

            long PartnerKey = NextPartnerKey;
            NextPartnerKey++;
            NumberOfPartnerKeysReserved--;

            PartnerRow.PartnerKey = PartnerKey;
            PersonRow.PartnerKey = PartnerRow.PartnerKey;
            PersonRow.FamilyKey = AFamilyRow.PartnerKey;

            // create family id: count existing family members
            DataView FamilyView = new DataView(AMainDS.PPerson);
            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort = PPersonTable.GetFamilyIdDBName();

            PersonRow.FamilyId = FamilyView.Count;

            PersonRow.FirstName = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FirstName");
            PersonRow.MiddleName1 = TXMLParser.GetAttribute(ACurrentNode, APrefix + "MiddleName");
            PersonRow.FamilyName = AFamilyRow.FamilyName;

            if (FamilyView.Count == 1)
            {
                PartnerRow.PreviousName = TXMLParser.GetAttribute(ACurrentNode, APrefix + "FamilyName");
            }

            PersonRow.Title = TXMLParser.GetAttribute(ACurrentNode, APrefix + "Title");

            PartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(
                PersonRow.FamilyName,
                PersonRow.Title,
                PersonRow.FirstName);
            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_PERSON;
            PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE;

            PersonRow.DateOfBirth = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, APrefix + "DateOfBirth"));

            string gender = TXMLParser.GetAttribute(ACurrentNode, APrefix + "Gender");

            if ((APrefix == "Male") || (gender == "MALE"))
            {
                PersonRow.Gender = MPartnerConstants.GENDER_MALE;
                PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_MALE;
            }
            else if ((APrefix == "Female") || (gender == "FEMALE"))
            {
                PersonRow.Gender = MPartnerConstants.GENDER_FEMALE;
                PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FEMALE;
            }

            PPartnerRow FamilyPartnerRow = (PPartnerRow)AMainDS.PPartner.Rows.Find(AFamilyRow.PartnerKey);

            if (FamilyView.Count == 0)
            {
                FamilyPartnerRow.AddresseeTypeCode = PartnerRow.AddresseeTypeCode;
            }
            else if (FamilyView.Count == 1)
            {
                // this is a couple
                PersonRow.MaritalStatus = MPartnerConstants.MARITALSTATUS_MARRIED;

                // find first person record as well
                PPersonRow Husband = (PPersonRow)FamilyView[0].Row;
                Husband.MaritalStatus = MPartnerConstants.MARITALSTATUS_MARRIED;

                AFamilyRow.MaritalStatus = MPartnerConstants.MARITALSTATUS_MARRIED;

                AFamilyRow.FirstName = Husband.FirstName + " and " + PersonRow.FirstName;
                AFamilyRow.Title = Husband.Title + " and " + PersonRow.Title;

                // update family shortname
                FamilyPartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_COUPLE;
                FamilyPartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(
                    AFamilyRow.FamilyName,
                    AFamilyRow.Title,
                    AFamilyRow.FirstName);
            }
            else if (FamilyView.Count > 1)
            {
                FamilyPartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FAMILY;
            }

            AMainDS.PPerson.Rows.Add(PersonRow);
            AMainDS.PPartner.Rows.Add(PartnerRow);
        }
Beispiel #42
0
        public void TestDeleteBank()
        {
            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;
            String TextMessage;
            Boolean CanDeletePartner;
            PPartnerRow BankPartnerRow;
            TSubmitChangesResult result;
            Int64 PartnerKey;

            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            BankPartnerRow = TCreateTestPartnerData.CreateNewBankPartner(MainDS);
            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create bank record");

            // check if Bank partner can be deleted (still needs to be possible at this point)
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(BankPartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(CanDeletePartner);

            // set up details (e.g. bank account) for this Bank so deletion is not allowed
            PBankingDetailsTable BankingDetailsTable = new PBankingDetailsTable();
            PBankingDetailsRow BankingDetailsRow = BankingDetailsTable.NewRowTyped();
            BankingDetailsRow.BankKey = BankPartnerRow.PartnerKey;
            BankingDetailsRow.BankingType = 0;
            BankingDetailsRow.BankingDetailsKey = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_bank_details));
            BankingDetailsTable.Rows.Add(BankingDetailsRow);

            PBankingDetailsAccess.SubmitChanges(BankingDetailsTable, DBAccess.GDBAccessObj.Transaction);

            // now deletion must not be possible since a bank account is set up for the bank
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(BankPartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(!CanDeletePartner);

            // now test actual deletion of venue partner
            BankPartnerRow = TCreateTestPartnerData.CreateNewBankPartner(MainDS);
            PartnerKey = BankPartnerRow.PartnerKey;
            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create bank partner for deletion");

            // check if Venue record is being deleted
            Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult));

            // check that Bank record is really deleted
            Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey));
        }
Beispiel #43
0
        private static void GenerateCommitmentRecord(
            XmlNode ACurrentNode,
            PFamilyRow AFamilyRow,
            PartnerEditTDS AMainDS,
            PersonnelTDS APersonnelDS,
            DataTable AFieldKeys)
        {
            DataView FamilyView = new DataView(AMainDS.PPerson);

            FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString();
            FamilyView.Sort = PPersonTable.GetFamilyIdDBName();
            PPersonRow firstPerson = (PPersonRow)FamilyView[0].Row;

            int FieldID =
                Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "fieldCommitment")) % AFieldKeys.Rows.Count;
            long FieldPartnerKey = Convert.ToInt64(AFieldKeys.Rows[FieldID].ItemArray[0]);

            PPartnerGiftDestinationRow giftDestination = AMainDS.PPartnerGiftDestination.NewRowTyped();

            if (NextKeyForGiftDestination == -1)
            {
                NextKeyForGiftDestination = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination();
            }
            else
            {
                NextKeyForGiftDestination++;
            }

            giftDestination.Key = NextKeyForGiftDestination;
            giftDestination.FieldKey = FieldPartnerKey;
            giftDestination.PartnerKey = AFamilyRow.PartnerKey;
            giftDestination.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY;
            giftDestination.DateEffective = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment"));

            PmStaffDataRow staffData = APersonnelDS.PmStaffData.NewRowTyped();
            staffData.SiteKey = DomainManager.GSiteKey;
            staffData.Key = (APersonnelDS.PmStaffData.Count + 1) * -1;
            staffData.PartnerKey = firstPerson.PartnerKey;
            staffData.ReceivingField = FieldPartnerKey;

            // TODO: could add foreign nationals
            staffData.HomeOffice = DomainManager.GSiteKey;
            staffData.OfficeRecruitedBy = DomainManager.GSiteKey;

            staffData.StartOfCommitment = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment"));
            int LengthCommitment = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "lengthCommitment"));

            staffData.StatusCode = "LONG-TERMER";

            if (LengthCommitment > 0)
            {
                string LengthCommitmentUnit = TXMLParser.GetAttribute(ACurrentNode, "lengthCommitmentUnit");

                if (LengthCommitmentUnit == "week")
                {
                    staffData.StatusCode = "SHORT-TERMER";
                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddDays(7 * LengthCommitment);
                }
                else if (LengthCommitmentUnit == "month")
                {
                    staffData.StatusCode = "SHORT-TERMER";
                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddMonths(LengthCommitment);
                }
                else if (LengthCommitmentUnit == "year")
                {
                    if (LengthCommitment < 3)
                    {
                        staffData.StatusCode = "WORKER";
                    }

                    staffData.EndOfCommitment = staffData.StartOfCommitment.AddYears(LengthCommitment);
                }
            }

            APersonnelDS.PmStaffData.Rows.Add(staffData);

            giftDestination.DateExpires = staffData.EndOfCommitment;

            if (AMainDS.PPartnerGiftDestination == null)
            {
                AMainDS.PPartnerGiftDestination.Merge(new PPartnerGiftDestinationTable());
            }

            AMainDS.PPartnerGiftDestination.Rows.Add(giftDestination);

            // TODO depending on start and end date of commitment, set EX-WORKER or no special type yet at all
            string SpecialType = MPartnerConstants.PARTNERTYPE_WORKER;

            if (!staffData.IsEndOfCommitmentNull() && (staffData.EndOfCommitment < DateTime.Today))
            {
                SpecialType = MPartnerConstants.PARTNERTYPE_EX_WORKER;
            }

            if (SpecialType != string.Empty)
            {
                // create special type for family partner
                PPartnerTypeRow PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped();
                PartnerTypeRow.PartnerKey = AFamilyRow.PartnerKey;
                PartnerTypeRow.TypeCode = SpecialType;
                AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);

                // set special type WORKER for the parents
                for (int countPerson = 0; countPerson < FamilyView.Count && countPerson < 2; countPerson++)
                {
                    PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row;

                    // create special type for the person partners
                    PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped();
                    PartnerTypeRow.PartnerKey = personRow.PartnerKey;
                    PartnerTypeRow.TypeCode = SpecialType;
                    AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);
                }
            }
        }
Beispiel #44
0
        public void TestDeleteVenue()
        {
            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;
            String TextMessage;
            Boolean CanDeletePartner;
            PPartnerRow VenuePartnerRow;
            TSubmitChangesResult result;
            Int64 PartnerKey;

            TPartnerEditUIConnector connector = new TPartnerEditUIConnector();

            PartnerEditTDS MainDS = new PartnerEditTDS();

            VenuePartnerRow = TCreateTestPartnerData.CreateNewVenuePartner(MainDS);
            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create venue record");

            // check if Venue partner can be deleted (still needs to be possible at this point)
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(VenuePartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(CanDeletePartner);

            // set up buildings for this venue so deletion is not allowed
            PcBuildingTable BuildingTable = new PcBuildingTable();
            PcBuildingRow BuildingRow = BuildingTable.NewRowTyped();
            BuildingRow.VenueKey = VenuePartnerRow.PartnerKey;
            BuildingRow.BuildingCode = "Test";
            BuildingTable.Rows.Add(BuildingRow);

            PcBuildingAccess.SubmitChanges(BuildingTable, DBAccess.GDBAccessObj.Transaction);

            // now deletion must not be possible since a building is linked to the venue
            CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(VenuePartnerRow.PartnerKey, out TextMessage);

            if (TextMessage.Length > 0)
            {
                TLogging.Log(TextMessage);
            }

            Assert.IsTrue(!CanDeletePartner);

            // now test actual deletion of venue partner
            VenuePartnerRow = TCreateTestPartnerData.CreateNewVenuePartner(MainDS);
            PartnerKey = VenuePartnerRow.PartnerKey;
            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create venue record for deletion");

            // check if Venue record is being deleted
            Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult));

            // check that Venue record is really deleted
            Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey));
        }
Beispiel #45
0
        /// <summary>
        /// generate the partners from a text file that was generated with Benerator
        /// </summary>
        /// <param name="AInputBeneratorFile"></param>
        public static void GenerateWorkers(string AInputBeneratorFile)
        {
            PartnerEditTDS MainDS = new PartnerEditTDS();
            PersonnelTDS PersonnelDS = new PersonnelTDS();

            // get a list of fields (all class UNIT, with unit type F)
            string sqlGetFieldPartnerKeys = "SELECT p_partner_key_n, p_unit_name_c FROM PUB_p_unit WHERE u_unit_type_code_c = 'F'";
            DataTable FieldKeys = DBAccess.GDBAccessObj.SelectDT(sqlGetFieldPartnerKeys, "keys", null);

            // get a list of banks (all class BANK)
            string sqlGetBankPartnerKeys = "SELECT p_partner_key_n FROM PUB_p_bank";
            DataTable BankKeys = DBAccess.GDBAccessObj.SelectDT(sqlGetBankPartnerKeys, "keys", null);

            XmlDocument doc = TCsv2Xml.ParseCSV2Xml(AInputBeneratorFile, ",", Encoding.UTF8);

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            while (RecordNode != null)
            {
                string familySituation = TXMLParser.GetAttribute(RecordNode, "familySituation");

                PFamilyRow familyRecord = null;

                if (familySituation == "singleMan")
                {
                    familyRecord = GenerateFamilyRecord(RecordNode, "Male", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Male", MainDS);
                }
                else if (familySituation == "singleWoman")
                {
                    familyRecord = GenerateFamilyRecord(RecordNode, "Female", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Female", MainDS);
                }
                else if (familySituation == "family")
                {
                    familyRecord = GenerateFamilyRecord(RecordNode, "Male", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Male", MainDS);
                    GeneratePersonRecord(RecordNode, familyRecord, "Female", MainDS);

                    int AgeDifferenceSpouse = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "AgeDifferenceSpouse"));
                    DataView FamilyView = new DataView(MainDS.PPerson);
                    FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + familyRecord.PartnerKey.ToString();
                    FamilyView.Sort = PPersonTable.GetFamilyIdDBName();

                    PPersonRow HusbandPersonRow = (PPersonRow)FamilyView[0].Row;
                    PPersonRow WifePersonRow = (PPersonRow)FamilyView[1].Row;
                    WifePersonRow.DateOfBirth =
                        WifePersonRow.DateOfBirth.Value.AddYears(
                            AgeDifferenceSpouse - (WifePersonRow.DateOfBirth.Value.Year - HusbandPersonRow.DateOfBirth.Value.Year));

                    if (DateTime.Today.Year - WifePersonRow.DateOfBirth.Value.Year < 19)
                    {
                        WifePersonRow.DateOfBirth.Value.AddYears(
                            19 - (DateTime.Today.Year - WifePersonRow.DateOfBirth.Value.Year));
                    }

                    int NumberOfChildren = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "numberOfChildren"));

                    for (int countChild = 0; countChild < NumberOfChildren; countChild++)
                    {
                        DateTime DateOfBirthChild = Convert.ToDateTime(
                            TXMLParser.GetAttribute(RecordNode,
                                "Child" + (countChild + 1).ToString() + "DateOfBirth"));

                        // mother must have been 19 when the child was born
                        if (DateOfBirthChild.Year < WifePersonRow.DateOfBirth.Value.Year + 19)
                        {
                            continue;
                        }

                        GeneratePersonRecord(RecordNode, familyRecord, "Child" + (countChild + 1).ToString(), MainDS);
                    }
                }

                GenerateAddressForFamily(RecordNode, familyRecord, MainDS);

                GenerateCommitmentRecord(RecordNode, familyRecord, MainDS, PersonnelDS, FieldKeys);

                GenerateBankDetails(RecordNode, familyRecord, MainDS, BankKeys);

                if (MainDS.PFamily.Rows.Count % 100 == 0)
                {
                    TLogging.Log("created worker " + MainDS.PFamily.Rows.Count.ToString() + " " + familyRecord.FamilyName);
                }

                RecordNode = RecordNode.NextSibling;
            }

            MainDS.ThrowAwayAfterSubmitChanges = true;

            PartnerEditTDSAccess.SubmitChanges(MainDS);

            PersonnelDS.ThrowAwayAfterSubmitChanges = true;
            PersonnelTDSAccess.SubmitChanges(PersonnelDS);

            TLogging.Log("after saving workers");
        }
        /// <summary>
        /// return an XmlDocument with all partner info;
        /// the partners are grouped by class, country, status, and sitekey
        /// </summary>
        /// <returns></returns>
        public static string ExportPartners()
        {
            PartnerEditTDS MainDS = new PartnerEditTDS();

            LoadDataFromDB(ref MainDS);

            // Group partners into categories.
            //
            // A partner's category is defined by his: class, country, status, and sitekey
            // It is stored as a string e.g. "FAMILY,DE,ACTIVE,0".
            //
            SortedList <string, List <long> > PartnerCategories = GroupPartnersIntoCategories(MainDS);

            // create XML structure for each category
            XmlDocument PartnerData = TYml2Xml.CreateXmlDocument();
            XmlNode     rootNode    = PartnerData.FirstChild.NextSibling;

            Int32 groupCounter = 0;

            foreach (string category in PartnerCategories.Keys)
            {
                // get category data
                groupCounter++;
                XmlElement groupNode = PartnerData.CreateElement("PartnerGroup" + groupCounter.ToString());
                rootNode.AppendChild(groupNode);

                Int32    partnerCounter  = 0;
                string[] categoryDetails = category.Split(new char[] { ',' });
                // may want to skip the categories with sitekey = -1
                // right now, we still export them and ignore the partners 0 and 1000000 later

                groupNode.SetAttribute("class", categoryDetails[0]);
                groupNode.SetAttribute("Country", categoryDetails[1]);
                groupNode.SetAttribute("status", categoryDetails[2]);
                groupNode.SetAttribute("SiteKey", categoryDetails[3]);

                List <long> partnerKeys = PartnerCategories[category];

                foreach (long partnerKey in partnerKeys)
                {
                    if ((partnerKey != 0) && (partnerKey != 1000000)) // skip organization root and the 0 when exporting
                    {
                        MainDS.PPartner.DefaultView.RowFilter = PPartnerTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();
                        PPartnerRow partnerRow = (PPartnerRow)MainDS.PPartner.DefaultView[0].Row;

                        PFamilyRow familyRow = null;

                        if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY)
                        {
                            MainDS.PFamily.DefaultView.RowFilter = PFamilyTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();
                            familyRow = (PFamilyRow)MainDS.PFamily.DefaultView[0].Row;
                        }

                        PPersonRow personRow = null;

                        if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON)
                        {
                            MainDS.PPerson.DefaultView.RowFilter = PPersonTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();
                            personRow = (PPersonRow)MainDS.PPerson.DefaultView[0].Row;
                        }

                        POrganisationRow organisationRow = null;

                        if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION)
                        {
                            MainDS.POrganisation.DefaultView.RowFilter = POrganisationTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();
                            organisationRow = (POrganisationRow)MainDS.POrganisation.DefaultView[0].Row;
                        }

                        PUnitRow           unitRow          = null;
                        UmUnitStructureRow unitStructureRow = null;

                        if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT)
                        {
                            MainDS.PUnit.DefaultView.RowFilter = PUnitTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();
                            unitRow = (PUnitRow)MainDS.PUnit.DefaultView[0].Row;
                            MainDS.UmUnitStructure.DefaultView.RowFilter = UmUnitStructureTable.GetChildUnitKeyDBName() + " = " + partnerKey.ToString();

                            long numParents = MainDS.UmUnitStructure.DefaultView.Count;

                            if (numParents == 1)
                            {
                                unitStructureRow = (UmUnitStructureRow)MainDS.UmUnitStructure.DefaultView[0].Row;
                            }
                            else
                            {
                                throw new Exception(
                                          "Units must have exactly one ParentUnit. " +
                                          "The unit with partnerKey " + partnerKey.ToString() + " has " +
                                          numParents.ToString() + ".");
                            }
                        }

                        PBankRow BankRow = null;

                        if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_BANK)
                        {
                            MainDS.PBank.DefaultView.RowFilter = PBankTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();
                            BankRow = (PBankRow)MainDS.PBank.DefaultView[0].Row;
                        }

                        partnerCounter++;
                        XmlElement partnerNode = PartnerData.CreateElement("Partner" + partnerCounter.ToString());
                        groupNode.AppendChild(partnerNode);

                        partnerNode.SetAttribute("PartnerKey", partnerRow.PartnerKey.ToString());

                        //groupNode.SetAttribute("ShortName", partnerRow.PartnerShortName.ToString());

                        if (personRow != null)
                        {
                            partnerNode.SetAttribute("FirstName", personRow.FirstName.ToString());
                            partnerNode.SetAttribute("LastName", personRow.FamilyName.ToString());
                            partnerNode.SetAttribute("Title", personRow.Title.ToString());
                        }
                        else if (familyRow != null)
                        {
                            partnerNode.SetAttribute("FirstName", familyRow.FirstName.ToString());
                            partnerNode.SetAttribute("LastName", familyRow.FamilyName.ToString());
                            partnerNode.SetAttribute("Title", familyRow.Title.ToString());
                        }
                        else if (organisationRow != null)
                        {
                            partnerNode.SetAttribute("Name", organisationRow.OrganisationName.ToString());
                        }
                        else if (unitRow != null)
                        {
                            partnerNode.SetAttribute("Name", unitRow.UnitName.ToString());
                            partnerNode.SetAttribute("UnitTypeCode", unitRow.UnitTypeCode.ToString());

                            if (unitStructureRow != null)
                            {
                                partnerNode.SetAttribute("ParentUnitKey", unitStructureRow.ParentUnitKey.ToString());
                            }
                        }

                        if (BankRow != null)
                        {
                            partnerNode.SetAttribute("BranchName", BankRow.BranchName);
                            partnerNode.SetAttribute("BranchCode", BankRow.BranchCode);
                            partnerNode.SetAttribute("BranchBic", BankRow.Bic);
                            partnerNode.SetAttribute("EpFormatFile", BankRow.EpFormatFile);
                        }

                        partnerNode.SetAttribute("CreatedAt", partnerRow.DateCreated.Value.ToString("yyyy-MM-dd HH:mm:ss"));

                        // special types
                        string specialTypes = "";
                        MainDS.PPartnerType.DefaultView.RowFilter = PPartnerTypeTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString();

                        foreach (DataRowView rv in MainDS.PPartnerType.DefaultView)
                        {
                            if (specialTypes.Length > 0)
                            {
                                specialTypes += ", ";
                            }

                            specialTypes += ((PPartnerTypeRow)rv.Row).TypeCode;
                        }

                        if (specialTypes.Length > 0)
                        {
                            partnerNode.SetAttribute("SpecialTypes", specialTypes);
                        }

                        // addresses
                        DataView partnerLocationView = MainDS.PPartnerLocation.DefaultView;
                        partnerLocationView.RowFilter =
                            PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerRow.PartnerKey.ToString() +
                            "AND " + PPartnerLocationTable.GetLocationKeyDBName() + " <> 0 "; // ignore invalid addresses
                        Int32 addressCounter = 0;

                        foreach (DataRowView rv in partnerLocationView)
                        {
                            XmlElement addressNode = PartnerData.CreateElement("Address" + (addressCounter > 0 ? addressCounter.ToString() : ""));
                            addressCounter++;
                            partnerNode.AppendChild(addressNode);

                            PPartnerLocationRow partnerLocationRow = (PPartnerLocationRow)rv.Row;

                            DataView locationView = MainDS.PLocation.DefaultView;
                            locationView.RowFilter =
                                PLocationTable.GetSiteKeyDBName() + "=" + partnerLocationRow.SiteKey.ToString() + " AND " +
                                PLocationTable.GetLocationKeyDBName() + "=" + partnerLocationRow.LocationKey.ToString();

                            if (locationView.Count > 0)
                            {
                                PLocationRow locationRow = (PLocationRow)locationView[0].Row;

                                addressNode.SetAttribute("Street", locationRow.StreetName);
                                addressNode.SetAttribute("City", locationRow.City);
                                addressNode.SetAttribute("PostCode", locationRow.PostalCode);
                            }

                            addressNode.SetAttribute("Email", partnerLocationRow.EmailAddress);
                            addressNode.SetAttribute("Phone", partnerLocationRow.TelephoneNumber);
                            addressNode.SetAttribute("MobilePhone", partnerLocationRow.MobileNumber);
                        }

                        // TODO: notes
                        // TODO: This doesn't export as much data as it should?
                    }
                }
            }

            return(TXMLParser.XmlToString(PartnerData));
        }