/// <summary> /// generate the gift batches from a text file that was generated with Benerator, for a specific period /// </summary> public static void CreateGiftBatches(int APeriodNumber) { GiftBatchTDS MainDS = CreateGiftBatches(GiftsPerDate, APeriodNumber); MainDS.ThrowAwayAfterSubmitChanges = true; GiftBatchTDSAccess.SubmitChanges(MainDS); }
public static TSubmitChangesResult SaveMotivationDetails(ref GiftBatchTDS AInspectDS) { if (AInspectDS != null) { // TODO make sure new motivation groups are created. at the moment only 1 existing motivation group is supported GiftBatchTDSAccess.SubmitChanges(AInspectDS); return(TSubmitChangesResult.scrOK); } return(TSubmitChangesResult.scrError); }
public void UpdateRecord() { TDBTransaction ReadTransaction = new TDBTransaction(); GiftBatchTDS MainDS = new GiftBatchTDS(); TDataBase db = DBAccess.Connect("test"); db.ReadTransaction(ref ReadTransaction, delegate { ALedgerAccess.LoadAll(MainDS, ReadTransaction); }); ReadTransaction.Rollback(); MainDS.ALedger[0].LastGiftBatchNumber++; AGiftBatchRow batch = MainDS.AGiftBatch.NewRowTyped(); batch.LedgerNumber = MainDS.ALedger[0].LedgerNumber; batch.BatchNumber = MainDS.ALedger[0].LastGiftBatchNumber; batch.BankAccountCode = "6000"; batch.BatchYear = 0; batch.BatchPeriod = 1; batch.CurrencyCode = "EUR"; batch.BatchDescription = "test"; batch.BankCostCentre = (MainDS.ALedger[0].LedgerNumber * 100).ToString("0000"); batch.LastGiftNumber = 0; batch.HashTotal = 83; MainDS.AGiftBatch.Rows.Add(batch); GiftBatchTDSAccess.SubmitChanges(MainDS); MainDS.AcceptChanges(); MainDS.AGiftBatch[0].BatchDescription = "test2"; GiftBatchTDSAccess.SubmitChanges(MainDS); TDBTransaction transaction = new TDBTransaction(); AGiftBatchTable batches = null; db.ReadTransaction( ref transaction, delegate { batches = AGiftBatchAccess.LoadByPrimaryKey(batch.LedgerNumber, batch.BatchNumber, transaction); }); // some problems with sqlite and datagrid Assert.AreEqual(typeof(decimal), batches[0][AGiftBatchTable.ColumnHashTotalId].GetType(), "type decimal"); Assert.AreEqual(83.0m, batches[0].HashTotal, "gift batch hashtotal does not equal"); }
public static bool MaintainMotivationGroups(string action, Int32 ALedgerNumber, String AMotivationGroupCode, String AMotivationGroupDescription, bool AGroupStatus, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); GiftBatchTDS MainDS = new GiftBatchTDS(); if (action == "create") { AMotivationGroupRow row = MainDS.AMotivationGroup.NewRowTyped(); row.LedgerNumber = ALedgerNumber; row.MotivationGroupCode = AMotivationGroupCode.ToUpper(); row.MotivationGroupDescription = AMotivationGroupDescription; row.GroupStatus = AGroupStatus; MainDS.AMotivationGroup.Rows.Add(row); try { GiftBatchTDSAccess.SubmitChanges(MainDS); } catch (Exception) { return(false); } } else if (action == "update") { MainDS = LoadMotivationDetails(ALedgerNumber, AMotivationGroupCode); foreach (AMotivationGroupRow row in MainDS.AMotivationGroup.Rows) { if (row.MotivationGroupCode == AMotivationGroupCode) { row.MotivationGroupDescription = AMotivationGroupDescription; row.GroupStatus = AGroupStatus; } } try { GiftBatchTDSAccess.SubmitChanges(MainDS); } catch (Exception) { return(false); } } else if (action == "delete") { MainDS = LoadMotivationDetails(ALedgerNumber, AMotivationGroupCode); foreach (AMotivationGroupRow row in MainDS.AMotivationGroup.Rows) { if (row.MotivationGroupCode == AMotivationGroupCode) { row.Delete(); } } foreach (AMotivationDetailRow row in MainDS.AMotivationDetail.Rows) { if (row.MotivationGroupCode == AMotivationGroupCode) { row.Delete(); } } try { GiftBatchTDSAccess.SubmitChanges(MainDS); } catch (Exception) { return(false); } } else { return(false); } return(true); }
public static void InitRecurringGiftBatchForSponsorship(Int32 ALedgerNumber, string ABankAccountCode) { TDataBase db = DBAccess.Connect("InitRecurringGiftBatchForSponsorship"); TDBTransaction Transaction = new TDBTransaction(); Int32 BatchNumber = -1; string CurrencyCode = String.Empty; GiftBatchTDS GiftDS = new GiftBatchTDS(); DBAccess.ReadTransaction(ref Transaction, delegate { BatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction); if ((BatchNumber == -1) && (ABankAccountCode == String.Empty)) { // bank account is not defined: use the first active bank account by default. // we don't support foreign currency accounts at the moment string sql = "SELECT MAX(a.a_account_code_c) FROM a_account AS a, a_account_property AS p " + "WHERE a.a_ledger_number_i = p.a_ledger_number_i " + "AND a.a_account_code_c = p.a_account_code_c " + "AND a.a_ledger_number_i = " + ALedgerNumber.ToString() + " " + "AND p.a_property_code_c = '" + MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT + "' " + "AND p.a_property_value_c = 'true' " + "AND a.a_foreign_currency_flag_l = false"; object result = Transaction.DataBaseObj.ExecuteScalar(sql, Transaction); // if no bank account exists, the result will be System.DBNull if (!(result is System.DBNull)) { ABankAccountCode = result.ToString(); } } if (CurrencyCode == String.Empty) { string sql = "SELECT a_base_currency_c FROM a_ledger WHERE a_ledger_number_i = " + ALedgerNumber.ToString(); object result = Transaction.DataBaseObj.ExecuteScalar(sql, Transaction); // if no ledger exists, the result will be System.DBNull if (!(result is System.DBNull)) { CurrencyCode = result.ToString(); } } TGiftBatchFunctions.CreateANewRecurringGiftBatchRow(ref GiftDS, ref Transaction, ALedgerNumber); }); if (BatchNumber != -1) { return; } ARecurringGiftBatchRow b = GiftDS.ARecurringGiftBatch[0]; b.BankAccountCode = ABankAccountCode; b.BatchDescription = BATCHNAME_SPONSORSHIP; b.CurrencyCode = CurrencyCode; GiftBatchTDSAccess.SubmitChanges(GiftDS, db); db.CloseDBConnection(); }
public void TestDeleteSavedGiftBatch() { Int64 donorKey = 43005001; Int64 recipKey = 43000000; int giftTransNumber = 1; int giftTranDetailNumber = 1; decimal giftAmount = 100.50M; string motivationGroupCode = "GIFT"; string motivationDetailCode = "SUPPORT"; //Create the recurring gift batch FMainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber); FRecurringBatchNumberToDelete = FMainDS.ARecurringGiftBatch[0].BatchNumber; //Create the recurring gift batch's single gift header ARecurringGiftRow newRow = FMainDS.ARecurringGift.NewRowTyped(true); newRow.LedgerNumber = FLedgerNumber; newRow.BatchNumber = FRecurringBatchNumberToDelete; newRow.DonorKey = donorKey; newRow.GiftTransactionNumber = giftTransNumber; newRow.LastDetailNumber = giftTransNumber; FMainDS.ARecurringGift.Rows.Add(newRow); //Create the recurring gift batch's single gift detail ARecurringGiftDetailRow newDetailRow = FMainDS.ARecurringGiftDetail.NewRowTyped(true); newDetailRow = FMainDS.ARecurringGiftDetail.NewRowTyped(true); newDetailRow.LedgerNumber = FLedgerNumber; newDetailRow.BatchNumber = FRecurringBatchNumberToDelete; newDetailRow.GiftTransactionNumber = giftTransNumber; newDetailRow.DetailNumber = giftTranDetailNumber; newDetailRow.RecipientKey = recipKey; newDetailRow.GiftAmount = giftAmount; newDetailRow.MotivationGroupCode = motivationGroupCode; newDetailRow.MotivationDetailCode = motivationDetailCode; FMainDS.ARecurringGiftDetail.Rows.Add(newDetailRow); //Save changes GiftBatchTDSAccess.SubmitChanges(FMainDS); FMainDS.AcceptChanges(); // Delete the associated recurring gift detail rows. DataView viewGiftDetail = new DataView(FMainDS.ARecurringGiftDetail); viewGiftDetail.RowFilter = string.Empty; foreach (DataRowView row in viewGiftDetail) { row.Delete(); } Assert.AreNotEqual(0, FMainDS.ARecurringGiftDetail.Rows.Count, "after deletion the row should still exist"); // Delete the associated recurring gift rows. DataView viewGift = new DataView(FMainDS.ARecurringGift); viewGift.RowFilter = string.Empty; foreach (DataRowView row in viewGift) { row.Delete(); } Assert.AreNotEqual(0, FMainDS.ARecurringGiftBatch.Rows.Count, "after deletion the batch row should still exist"); // Delete the recurring batch row. FMainDS.ARecurringGiftBatch.Rows[0].Delete(); Assert.AreNotEqual(0, FMainDS.ARecurringGiftBatch.Rows.Count, "after deletion the batch row should still exist"); //Save changes GiftBatchTDSAccess.SubmitChanges(FMainDS); }
public static bool MaintainMotivationDetails(string action, Int32 ALedgerNumber, String AMotivationGroupCode, String AMotivationDetailCode, String AMotivationDetailDesc, String AAccountCode, String ACostCentreCode, bool AMotivationStatus, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); GiftBatchTDS MainDS = new GiftBatchTDS(); if (action == "create") { AMotivationDetailRow row = MainDS.AMotivationDetail.NewRowTyped(); row.LedgerNumber = ALedgerNumber; row.MotivationGroupCode = AMotivationGroupCode.ToUpper(); row.MotivationDetailCode = AMotivationDetailCode.ToUpper(); row.MotivationDetailDesc = AMotivationDetailDesc; row.AccountCode = AAccountCode; row.CostCentreCode = ACostCentreCode; row.MotivationStatus = AMotivationStatus; MainDS.AMotivationDetail.Rows.Add(row); try { GiftBatchTDSAccess.SubmitChanges(MainDS); } catch (Exception) { return(false); } } else if (action == "update") { string Dummy1, Dummy2; MainDS = LoadMotivationDetails(ALedgerNumber, AMotivationGroupCode, out Dummy1, out Dummy2); foreach (AMotivationDetailRow row in MainDS.AMotivationDetail.Rows) { if (row.MotivationGroupCode == AMotivationGroupCode && row.MotivationDetailCode == AMotivationDetailCode) { row.MotivationDetailDesc = AMotivationDetailDesc; row.AccountCode = AAccountCode; row.CostCentreCode = ACostCentreCode; row.MotivationStatus = AMotivationStatus; } } try { GiftBatchTDSAccess.SubmitChanges(MainDS); } catch (Exception) { return(false); } } else if (action == "delete") { string Dummy1, Dummy2; MainDS = LoadMotivationDetails(ALedgerNumber, AMotivationGroupCode, out Dummy1, out Dummy2); foreach (AMotivationDetailRow row in MainDS.AMotivationDetail.Rows) { if (row.MotivationGroupCode == AMotivationGroupCode && row.MotivationDetailCode == AMotivationDetailCode) { row.Delete(); } } foreach (AMotivationDetailFeeRow row in MainDS.AMotivationDetailFee.Rows) { if (row.MotivationGroupCode == AMotivationGroupCode && row.MotivationDetailCode == AMotivationDetailCode) { row.Delete(); } } try { GiftBatchTDSAccess.SubmitChanges(MainDS); } catch (Exception) { return(false); } } else { return(false); } return(true); }