Ejemplo n.º 1
0
        public static void ImportPartner(PartnerEditTDS AMainDS)
        {
            TDBTransaction ReadTransaction             = null;
            TDBTransaction SubmitChangesTransaction    = null;
            bool           SubmissionOK                = false;
            bool           ImportDefaultAcquCodeExists = false;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref ReadTransaction,
                                                           delegate
            {
                ImportDefaultAcquCodeExists = PAcquisitionAccess.Exists(MPartnerConstants.PARTNERIMPORT_AQUISITION_DEFAULT,
                                                                        ReadTransaction);
            });

            if (!ImportDefaultAcquCodeExists)
            {
                PAcquisitionTable AcqTable = new PAcquisitionTable();
                PAcquisitionRow   row      = AcqTable.NewRowTyped();
                row.AcquisitionCode        = MPartnerConstants.PARTNERIMPORT_AQUISITION_DEFAULT;
                row.AcquisitionDescription = Catalog.GetString("Imported Data");
                AcqTable.Rows.Add(row);

                DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref SubmitChangesTransaction, ref SubmissionOK,
                                                           delegate
                {
                    PAcquisitionAccess.SubmitChanges(AcqTable, SubmitChangesTransaction);

                    SubmissionOK = true;
                });
            }

            PartnerEditTDSAccess.SubmitChanges(AMainDS);
        }
Ejemplo n.º 2
0
        public static Int64 FindOrCreateBank(string ABIC, string ABankName)
        {
            Int64          PartnerKey  = -1;
            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(ref Transaction,
                                     delegate
            {
                string sql = "SELECT p_partner_key_n FROM PUB_p_bank WHERE p_bic_c = ?";

                OdbcParameter[] parameters = new OdbcParameter[1];
                parameters[0]       = new OdbcParameter("bic", OdbcType.VarChar);
                parameters[0].Value = ABIC;

                DataTable result = Transaction.DataBaseObj.SelectDT(sql, "bank", Transaction, parameters);

                if (result.Rows.Count >= 1)
                {
                    PartnerKey = Convert.ToInt64(result.Rows[0][0]);
                }
            });

            if (PartnerKey != -1)
            {
                return(PartnerKey);
            }

            // we need to create a bank with this BIC
            List <string> Subscriptions;
            List <string> PartnerTypes;
            string        DefaultEmailAddress;
            string        DefaultPhoneMobile;
            string        DefaultPhoneLandline;

            PartnerEditTDS MainDS = CreateNewPartner(MPartnerConstants.PARTNERCLASS_BANK,
                                                     out Subscriptions,
                                                     out PartnerTypes,
                                                     out DefaultEmailAddress,
                                                     out DefaultPhoneMobile,
                                                     out DefaultPhoneLandline);

            PBankRow bankRow = MainDS.PBank[0];

            bankRow.Bic        = ABIC;
            bankRow.BranchName = ABankName;

            try
            {
                PartnerEditTDSAccess.SubmitChanges(MainDS);
                return(bankRow.PartnerKey);
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
            }

            return(-1);
        }
Ejemplo n.º 3
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);

            // 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");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// generate the partners from a text file that was generated with Benerator
        /// </summary>
        /// <param name="AInputBeneratorFile"></param>
        public static void GenerateOrganisationPartners(string AInputBeneratorFile)
        {
            PartnerEditTDS   MainDS        = new PartnerEditTDS();
            AApSupplierTable supplierTable = new AApSupplierTable();

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

            XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild;

            Int32 NumberOfPartnerKeysReserved = 100;
            Int64 NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved);

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

                long OrgPartnerKey = NextPartnerKey;
                NextPartnerKey++;
                NumberOfPartnerKeysReserved--;

                POrganisationRow organisationRecord = MainDS.POrganisation.NewRowTyped();
                organisationRecord.PartnerKey       = OrgPartnerKey;
                organisationRecord.OrganisationName = TXMLParser.GetAttribute(RecordNode, "OrganisationName");
                MainDS.POrganisation.Rows.Add(organisationRecord);

                PPartnerRow PartnerRow = MainDS.PPartner.NewRowTyped();
                PartnerRow.PartnerKey        = organisationRecord.PartnerKey;
                PartnerRow.PartnerClass      = MPartnerConstants.PARTNERCLASS_ORGANISATION;
                PartnerRow.StatusCode        = MPartnerConstants.PARTNERSTATUS_ACTIVE;
                PartnerRow.PartnerShortName  = organisationRecord.OrganisationName;
                PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION;
                MainDS.PPartner.Rows.Add(PartnerRow);

                PLocationRow locationRow = MainDS.PLocation.NewRowTyped();

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

                MainDS.PLocation.Rows.Add(locationRow);

                PPartnerLocationRow organisationLocationRow = MainDS.PPartnerLocation.NewRowTyped();

                organisationLocationRow.PartnerKey   = PartnerRow.PartnerKey;
                organisationLocationRow.LocationKey  = locationRow.LocationKey;
                organisationLocationRow.SiteKey      = locationRow.SiteKey;
                organisationLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_BUSINESS;
                organisationLocationRow.SendMail     = true;

                if (TXMLParser.GetAttribute(RecordNode, "IsSupplier") == "yes")
                {
                    AApSupplierRow supplierRow = supplierTable.NewRowTyped(true);

                    supplierRow.PartnerKey   = organisationRecord.PartnerKey;
                    supplierRow.CurrencyCode = TXMLParser.GetAttribute(RecordNode, "Currency");

                    if (supplierRow.CurrencyCode == "GBP")
                    {
                        supplierRow.DefaultBankAccount = "6210";
                    }
                    else
                    {
                        supplierRow.DefaultBankAccount = "6200";
                    }

                    supplierRow.DefaultApAccount  = "9100";
                    supplierRow.DefaultCostCentre = (FLedgerNumber * 100).ToString("0000");
                    supplierRow.DefaultExpAccount = "4200";

                    supplierTable.Rows.Add(supplierRow);
                }

                MainDS.PPartnerLocation.Rows.Add(organisationLocationRow);

                RecordNode = RecordNode.NextSibling;
            }

            PartnerEditTDSAccess.SubmitChanges(MainDS);

            AApSupplierAccess.SubmitChanges(supplierTable, null);
        }
Ejemplo n.º 5
0
        public static bool SavePartner(PartnerEditTDS AMainDS,
                                       List <string> ASubscriptions,
                                       List <string> APartnerTypes)
        {
            List <string>  Dummy1, Dummy2;
            string         Dummy3, Dummy4, Dummy5;
            PartnerEditTDS SaveDS;

            if (AMainDS.PPartner[0].ModificationId == DateTime.MinValue)
            {
                // this is a new partner
                SaveDS = AMainDS;

                if (SaveDS.PPartner[0].PartnerKey == -1)
                {
                    SaveDS.PPartner[0].PartnerKey = NewPartnerKey();
                }

                if (SaveDS.PFamily.Count > 0)
                {
                    SaveDS.PFamily[0].PartnerKey = SaveDS.PPartner[0].PartnerKey;
                }
                else if (SaveDS.PPerson.Count > 0)
                {
                    SaveDS.PPerson[0].PartnerKey = SaveDS.PPartner[0].PartnerKey;
                }
                else if (SaveDS.PChurch.Count > 0)
                {
                    SaveDS.PChurch[0].PartnerKey = SaveDS.PPartner[0].PartnerKey;
                }
                else if (SaveDS.POrganisation.Count > 0)
                {
                    SaveDS.POrganisation[0].PartnerKey = SaveDS.PPartner[0].PartnerKey;
                }

                PPartnerLocationRow partnerlocation = SaveDS.PPartnerLocation.NewRowTyped();
                partnerlocation.PartnerKey  = SaveDS.PPartner[0].PartnerKey;
                partnerlocation.LocationKey = SaveDS.PLocation[0].LocationKey;
                partnerlocation.SiteKey     = SaveDS.PLocation[0].SiteKey;
                SaveDS.PPartnerLocation.Rows.Add(partnerlocation);
            }
            else
            {
                SaveDS = GetPartnerDetails(AMainDS.PPartner[0].PartnerKey, out Dummy1, out Dummy2, out Dummy3, out Dummy4, out Dummy5);
                DataUtilities.CopyDataSet(AMainDS, SaveDS);
            }

            List <string> ExistingPartnerTypes = new List <string>();

            foreach (PPartnerTypeRow partnertype in SaveDS.PPartnerType.Rows)
            {
                if (!APartnerTypes.Contains(partnertype.TypeCode))
                {
                    partnertype.Delete();
                }
                else
                {
                    ExistingPartnerTypes.Add(partnertype.TypeCode);
                }
            }

            // add new partner types
            foreach (string partnertype in APartnerTypes)
            {
                if (!ExistingPartnerTypes.Contains(partnertype))
                {
                    PPartnerTypeRow partnertypeRow = SaveDS.PPartnerType.NewRowTyped();
                    partnertypeRow.PartnerKey = AMainDS.PPartner[0].PartnerKey;
                    partnertypeRow.TypeCode   = partnertype;
                    SaveDS.PPartnerType.Rows.Add(partnertypeRow);
                }
            }

            List <string> ExistingSubscriptions = new List <string>();

            foreach (PSubscriptionRow subscription in SaveDS.PSubscription.Rows)
            {
                if (!ASubscriptions.Contains(subscription.PublicationCode))
                {
                    subscription.Delete();
                }
                else
                {
                    ExistingSubscriptions.Add(subscription.PublicationCode);
                }
            }

            // add new subscriptions
            foreach (string subscription in ASubscriptions)
            {
                if (!ExistingSubscriptions.Contains(subscription))
                {
                    PSubscriptionRow subscriptionRow = SaveDS.PSubscription.NewRowTyped();
                    subscriptionRow.PartnerKey          = AMainDS.PPartner[0].PartnerKey;
                    subscriptionRow.PublicationCode     = subscription;
                    subscriptionRow.ReasonSubsGivenCode = "FREE";
                    SaveDS.PSubscription.Rows.Add(subscriptionRow);
                }
            }

            // TODO: either reuse Partner Edit UIConnector
            // or check for changed partner key, or changed Partner Class, etc.

            // set Partner Short Name
            if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON)
            {
                SaveDS.PPartner[0].PartnerShortName =
                    Calculations.DeterminePartnerShortName(
                        SaveDS.PPerson[0].FamilyName,
                        SaveDS.PPerson[0].Title,
                        SaveDS.PPerson[0].FirstName,
                        SaveDS.PPerson[0].MiddleName1);
            }
            else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY)
            {
                SaveDS.PPartner[0].PartnerShortName =
                    Calculations.DeterminePartnerShortName(
                        SaveDS.PFamily[0].FamilyName,
                        SaveDS.PFamily[0].Title,
                        SaveDS.PFamily[0].FirstName);
            }
            else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT)
            {
                SaveDS.PPartner[0].PartnerShortName = SaveDS.PUnit[0].UnitName;
            }
            else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION)
            {
                SaveDS.PPartner[0].PartnerShortName = SaveDS.POrganisation[0].OrganisationName;
            }
            else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_BANK)
            {
                SaveDS.PPartner[0].PartnerShortName = SaveDS.PBank[0].BranchName;
            }

            // TODO: check if location 0 (no address) was changed. we don't want to overwrite that
            // alternative: check if somebody else uses that location, and split the locations. or ask if others should be updated???
            if (SaveDS.PLocation[0].RowState == DataRowState.Modified && SaveDS.PLocation[0].LocationKey == 0)
            {
                TLogging.Log("we cannot update addresses of people with location 0");
                return(false);
            }

            PartnerEditTDSAccess.SubmitChanges(SaveDS);

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// generate the partners from a text file that was generated with Benerator
        /// </summary>
        /// <param name="AInputBeneratorFile"></param>
        public static void GenerateOrganisationPartners(string AInputBeneratorFile)
        {
            PartnerEditTDS   MainDS        = new PartnerEditTDS();
            AApSupplierTable supplierTable = new AApSupplierTable();

            // 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;

            Int32 NumberOfPartnerKeysReserved = 100;
            Int64 NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved);

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

                long OrgPartnerKey = NextPartnerKey;
                NextPartnerKey++;
                NumberOfPartnerKeysReserved--;

                POrganisationRow organisationRecord = MainDS.POrganisation.NewRowTyped();
                organisationRecord.PartnerKey       = OrgPartnerKey;
                organisationRecord.OrganisationName = TXMLParser.GetAttribute(RecordNode, "OrganisationName");
                MainDS.POrganisation.Rows.Add(organisationRecord);

                PPartnerRow PartnerRow = MainDS.PPartner.NewRowTyped();
                PartnerRow.PartnerKey        = organisationRecord.PartnerKey;
                PartnerRow.PartnerClass      = MPartnerConstants.PARTNERCLASS_ORGANISATION;
                PartnerRow.StatusCode        = MPartnerConstants.PARTNERSTATUS_ACTIVE;
                PartnerRow.PartnerShortName  = organisationRecord.OrganisationName;
                PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION;
                MainDS.PPartner.Rows.Add(PartnerRow);

                PLocationRow locationRow = MainDS.PLocation.NewRowTyped();

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

                MainDS.PLocation.Rows.Add(locationRow);

                PPartnerLocationRow organisationLocationRow = MainDS.PPartnerLocation.NewRowTyped();

                organisationLocationRow.PartnerKey   = PartnerRow.PartnerKey;
                organisationLocationRow.LocationKey  = locationRow.LocationKey;
                organisationLocationRow.SiteKey      = locationRow.SiteKey;
                organisationLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_BUSINESS;
                organisationLocationRow.SendMail     = true;

                if (TXMLParser.GetAttribute(RecordNode, "IsSupplier") == "yes")
                {
                    AApSupplierRow supplierRow = supplierTable.NewRowTyped(true);

                    supplierRow.PartnerKey   = organisationRecord.PartnerKey;
                    supplierRow.CurrencyCode = TXMLParser.GetAttribute(RecordNode, "Currency");

                    if (supplierRow.CurrencyCode == "GBP")
                    {
                        supplierRow.DefaultBankAccount = "6210";
                    }
                    else
                    {
                        supplierRow.DefaultBankAccount = "6200";
                    }

                    supplierRow.DefaultApAccount  = "9100";
                    supplierRow.DefaultCostCentre = (FLedgerNumber * 100).ToString("0000");
                    supplierRow.DefaultExpAccount = "4200";

                    supplierTable.Rows.Add(supplierRow);
                }

                MainDS.PPartnerLocation.Rows.Add(organisationLocationRow);

                RecordNode = RecordNode.NextSibling;
            }

            TDataBase      db          = DBAccess.Connect("GenerateOrganisationPartners");
            TDBTransaction Transaction = new TDBTransaction();
            bool           SubmitOK    = false;

            db.WriteTransaction(
                ref Transaction,
                ref SubmitOK,
                delegate
            {
                PartnerEditTDSAccess.SubmitChanges(MainDS, db);
                AApSupplierAccess.SubmitChanges(supplierTable, Transaction);
                SubmitOK = true;
            });
            db.CloseDBConnection();
        }
        private static void GenerateRegistrationOffices(string ACountryName, Int64 APartnerKey, string ACountryCode)
        {
            if (PUnitAccess.Exists(APartnerKey, null))
            {
                TLogging.Log("Office with key " + APartnerKey.ToString() + " already exists.");
                return;
            }

            PartnerEditTDS MainDS = new PartnerEditTDS();

            PPartnerRow partnerRow = MainDS.PPartner.NewRowTyped(true);

            partnerRow.PartnerKey        = APartnerKey;
            partnerRow.PartnerShortName  = ACountryName;
            partnerRow.PartnerClass      = MPartnerConstants.PARTNERCLASS_UNIT;
            partnerRow.StatusCode        = MPartnerConstants.PARTNERSTATUS_ACTIVE;
            partnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION;
            MainDS.PPartner.Rows.Add(partnerRow);

            PUnitRow unitRow = MainDS.PUnit.NewRowTyped(true);

            unitRow.PartnerKey   = partnerRow.PartnerKey;
            unitRow.UnitName     = partnerRow.PartnerShortName;
            unitRow.CountryCode  = ACountryCode;
            unitRow.UnitTypeCode = MPartnerConstants.UNIT_TYPE_FIELD;
            MainDS.PUnit.Rows.Add(unitRow);

            PLocationRow locationRow = MainDS.PLocation.NewRowTyped();

            locationRow.SiteKey     = partnerRow.PartnerKey;
            locationRow.LocationKey = 0;
            locationRow.StreetName  = "No valid address on file";
            locationRow.CountryCode = ACountryCode;
            MainDS.PLocation.Rows.Add(locationRow);

            PPartnerLocationRow partnerlocationRow = MainDS.PPartnerLocation.NewRowTyped();

            partnerlocationRow.PartnerKey  = partnerRow.PartnerKey;
            partnerlocationRow.SiteKey     = locationRow.SiteKey;
            partnerlocationRow.LocationKey = locationRow.LocationKey;
            MainDS.PPartnerLocation.Rows.Add(partnerlocationRow);

            PPartnerTypeRow partnertypeRow = MainDS.PPartnerType.NewRowTyped();

            partnertypeRow.PartnerKey = partnerRow.PartnerKey;
            partnertypeRow.TypeCode   = MPartnerConstants.PARTNERTYPE_LEDGER;
            MainDS.PPartnerType.Rows.Add(partnertypeRow);

            UmUnitStructureRow unitStructureRow = MainDS.UmUnitStructure.NewRowTyped();

            unitStructureRow.ParentUnitKey = 1000000;
            unitStructureRow.ChildUnitKey  = partnerRow.PartnerKey;
            MainDS.UmUnitStructure.Rows.Add(unitStructureRow);

            PartnerEditTDSAccess.SubmitChanges(MainDS);

            string sqlInsertModule =
                String.Format("INSERT INTO PUB_{0}({1}, {2}) VALUES ('REG-{3:0000000000}','Registration {4}')",
                              SModuleTable.GetTableDBName(),
                              SModuleTable.GetModuleIdDBName(),
                              SModuleTable.GetModuleNameDBName(),
                              APartnerKey,
                              ACountryName);
            string sqlInsertModulePermissions =
                String.Format("INSERT INTO PUB_{0}({1}, {2}, {3}) VALUES ('DEMO', 'REG-{4:0000000000}',true)",
                              SUserModuleAccessPermissionTable.GetTableDBName(),
                              SUserModuleAccessPermissionTable.GetUserIdDBName(),
                              SUserModuleAccessPermissionTable.GetModuleIdDBName(),
                              SUserModuleAccessPermissionTable.GetCanAccessDBName(),
                              APartnerKey);

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

            try
            {
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlInsertModule, Transaction);
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlInsertModulePermissions, Transaction);
                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                DBAccess.GDBAccessObj.RollbackTransaction();
            }
        }
Ejemplo n.º 8
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)
        {
            TDataBase      db          = DBAccess.Connect("GenerateFamilyPartners");
            TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.ReadCommitted);

            // 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();

            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");
        }
Ejemplo n.º 9
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 + "\"}}");
            }
        }