/// <summary> /// store the AP supplier /// /// All DataTables contained in the Typed DataSet are inspected for added, /// changed or deleted rows by submitting them to the DataStore. /// </summary> /// <param name="AInspectDS">Typed DataSet that needs to contain known DataTables</param> /// <returns>TSubmitChangesResult.scrOK in case everything went fine, otherwise throws an Exception.</returns> public TSubmitChangesResult SubmitChanges(ref AccountsPayableTDS AInspectDS) { TDBTransaction SubmitChangesTransaction; if (AInspectDS != null) { // I won't allow any null fields related to discount: if (AInspectDS.AApSupplier[0].IsDefaultDiscountDaysNull()) { AInspectDS.AApSupplier[0].DefaultDiscountDays = 0; } if (AInspectDS.AApSupplier[0].IsDefaultDiscountPercentageNull()) { AInspectDS.AApSupplier[0].DefaultDiscountPercentage = 0; } bool NewTransaction; SubmitChangesTransaction = FDataBase.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction); try { AApSupplierAccess.SubmitChanges(AInspectDS.AApSupplier, SubmitChangesTransaction); if (NewTransaction) { SubmitChangesTransaction.Commit(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the storing of the AP Supplier):" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { SubmitChangesTransaction.Rollback(); } throw; } } return(TSubmitChangesResult.scrOK); }
/// <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); }
/// <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(); }