private int GetChangedRecordCountManual(out string AMessage) { //For Gift Batch we will get a mix of some batches, gifts and gift details. // Only check relevant tables. List <string> TablesToCheck = new List <string>(); TablesToCheck.Add(FMainDS.AGiftBatch.TableName); TablesToCheck.Add(FMainDS.AGift.TableName); TablesToCheck.Add(FMainDS.AGiftDetail.TableName); List <Tuple <string, int> > TableAndCountList = new List <Tuple <string, int> >(); int AllChangesCount = 0; if (FMainDS.HasChanges()) { foreach (DataTable dt in FMainDS.GetChanges().Tables) { string currentTableName = dt.TableName; if ((dt != null) && TablesToCheck.Contains(currentTableName) && (dt.Rows.Count > 0)) { int tableChangesCount = 0; DataTable dtChanges = dt.GetChanges(); foreach (DataRow dr in dtChanges.Rows) { if (DataUtilities.DataRowColumnsHaveChanged(dr)) { tableChangesCount++; AllChangesCount++; } } if (tableChangesCount > 0) { TableAndCountList.Add(new Tuple <string, int>(currentTableName, tableChangesCount)); } } } } // Now build up a sensible message AMessage = String.Empty; if (TableAndCountList.Count > 0) { if (TableAndCountList.Count == 1) { Tuple <string, int> TableAndCount = TableAndCountList[0]; string tableName = TableAndCount.Item1; if (TableAndCount.Item1.Equals(AGiftBatchTable.GetTableName())) { AMessage = String.Format(Catalog.GetString(" You have made changes to the details of {0} {1}.{2}"), TableAndCount.Item2, Catalog.GetPluralString("batch", "batches", TableAndCount.Item2), Environment.NewLine); } else if (TableAndCount.Item1.Equals(AGiftTable.GetTableName())) { AMessage = String.Format(Catalog.GetString(" You have made changes to the details of {0} {1}.{2}"), TableAndCount.Item2, Catalog.GetPluralString("gift", "gifts", TableAndCount.Item2), Environment.NewLine); } else //if (TableAndCount.Item1.Equals(AGiftDetailTable.GetTableName())) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1}.{2}"), TableAndCount.Item2, Catalog.GetPluralString("gift detail", "gift details", TableAndCount.Item2), Environment.NewLine); } } else { int nBatches = 0; int nGifts = 0; int nGiftDetails = 0; foreach (Tuple <string, int> TableAndCount in TableAndCountList) { if (TableAndCount.Item1.Equals(AGiftBatchTable.GetTableName())) { nBatches = TableAndCount.Item2; } else if (TableAndCount.Item1.Equals(AGiftTable.GetTableName())) { nGifts = TableAndCount.Item2; } else //if (TableAndCount.Item1.Equals(AGiftDetailTable.GetTableName())) { nGiftDetails = TableAndCount.Item2; } } if ((nBatches > 0) && (nGifts > 0) && (nGiftDetails > 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1}, {2} {3} and {4} {5}.{6}"), nBatches, Catalog.GetPluralString("batch", "batches", nBatches), nGifts, Catalog.GetPluralString("gift", "gifts", nGifts), nGiftDetails, Catalog.GetPluralString("gift detail", "gift details", nGiftDetails), Environment.NewLine); } else if ((nBatches > 0) && (nGifts > 0) && (nGiftDetails == 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1} and {2} {3}.{4}"), nBatches, Catalog.GetPluralString("batch", "batches", nBatches), nGifts, Catalog.GetPluralString("gift", "gifts", nGifts), Environment.NewLine); } else if ((nBatches > 0) && (nGifts == 0) && (nGiftDetails > 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1} and {2} {3}.{4}"), nBatches, Catalog.GetPluralString("batch", "batches", nBatches), nGiftDetails, Catalog.GetPluralString("gift detail", "gift details", nGiftDetails), Environment.NewLine); } else if ((nBatches > 0) && (nGifts == 0) && (nGiftDetails == 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1}.{2}"), nBatches, Catalog.GetPluralString("batch", "batches", nBatches), Environment.NewLine); } else if ((nBatches == 0) && (nGifts > 0) && (nGiftDetails > 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1} and {2} {3}.{4}"), nGifts, Catalog.GetPluralString("gift", "gifts", nGifts), nGiftDetails, Catalog.GetPluralString("gift detail", "gift details", nGiftDetails), Environment.NewLine); } else if ((nBatches == 0) && (nGifts > 0) && (nGiftDetails == 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1}.{2}"), nGifts, Catalog.GetPluralString("gift", "gifts", nGiftDetails), Environment.NewLine); } else if ((nBatches == 0) && (nGifts == 0) && (nGiftDetails > 0)) { AMessage = String.Format(Catalog.GetString(" You have made changes to {0} {1}.{2}"), nGiftDetails, Catalog.GetPluralString("gift detail", "gift details", nGiftDetails), Environment.NewLine); } } AMessage += Catalog.GetString("(some of the changes may include related background items)"); AMessage += Environment.NewLine; AMessage += String.Format(TFrmPetraEditUtils.StrConsequenceIfNotSaved, Environment.NewLine); } return(AllChangesCount); }
private int GetChangedRecordCountManual(out string AMessage) { // For GL Batch we will get some mix of batches, journals and transactions // Only check relevant tables. List <string> TablesToCheck = new List <string>(); TablesToCheck.Add(FMainDS.ABatch.TableName); TablesToCheck.Add(FMainDS.AJournal.TableName); TablesToCheck.Add(FMainDS.ATransaction.TableName); TablesToCheck.Add(FMainDS.ATransAnalAttrib.TableName); List <Tuple <string, int> > TableAndCountList = new List <Tuple <string, int> >(); int AllChangesCount = 0; if (FMainDS.HasChanges()) { // Work out how many changes in each table foreach (DataTable dt in FMainDS.GetChanges().Tables) { string currentTableName = dt.TableName; if ((dt != null) && TablesToCheck.Contains(currentTableName) && (dt.Rows.Count > 0)) { int tableChangesCount = 0; DataTable dtChanges = dt.GetChanges(); foreach (DataRow dr in dtChanges.Rows) { if (DataUtilities.DataRowColumnsHaveChanged(dr)) { tableChangesCount++; AllChangesCount++; } } if (tableChangesCount > 0) { TableAndCountList.Add(new Tuple <string, int>(currentTableName, tableChangesCount)); } } } } // Now build up a sensible message AMessage = String.Empty; if (TableAndCountList.Count > 0) { int nBatches = 0; int nJournals = 0; int nTransactions = 0; foreach (Tuple <string, int> TableAndCount in TableAndCountList) { if (TableAndCount.Item1.Equals(ABatchTable.GetTableName())) { nBatches = TableAndCount.Item2; } else if (TableAndCount.Item1.Equals(AJournalTable.GetTableName())) { nJournals = TableAndCount.Item2; } else if (TableAndCount.Item2 > nTransactions) { nTransactions = TableAndCount.Item2; } } AMessage = Catalog.GetString(" You have made changes to "); string strBatches = String.Empty; string strJournals = String.Empty; string strTransactions = String.Empty; if (nBatches > 0) { strBatches = String.Format("{0} {1}", nBatches, Catalog.GetPluralString("batch", "batches", nBatches)); } if (nJournals > 0) { strJournals = String.Format("{0} {1}", nJournals, Catalog.GetPluralString("journal", "journals", nJournals)); } if (nTransactions > 0) { strTransactions = String.Format("{0} {1}", nTransactions, Catalog.GetPluralString("transaction", "transactions", nTransactions)); } bool bGotAll = (nBatches > 0) && (nJournals > 0) && (nTransactions > 0); if (nBatches > 0) { AMessage += strBatches; } if (nJournals > 0) { if (bGotAll) { AMessage += ", "; } else if (nBatches > 0) { AMessage += " and "; } AMessage += strJournals; } if (nTransactions > 0) { if ((nBatches > 0) || (nJournals > 0)) { AMessage += " and "; } AMessage += strTransactions; } AMessage += Environment.NewLine + Catalog.GetString("(some of the changes may include related background items)"); AMessage += Environment.NewLine; AMessage += String.Format(TFrmPetraEditUtils.StrConsequenceIfNotSaved, Environment.NewLine); } return(AllChangesCount); }
/// <summary> /// load the gifts into the grid /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="ABatchNumber"></param> /// <param name="ABatchStatus"></param> /// <param name="AForceLoadFromServer">Set to true to get data from the server even though it is apparently the current batch number and status</param> /// <returns>True if gift transactions were loaded from server, false if transactions had been loaded already.</returns> public bool LoadGifts(Int32 ALedgerNumber, Int32 ABatchNumber, string ABatchStatus, bool AForceLoadFromServer = false) { //Set key flags bool FirstGiftTransLoad = (FLedgerNumber == -1); bool SameCurrentBatch = ((FLedgerNumber == ALedgerNumber) && (FBatchNumber == ABatchNumber) && (FBatchStatus == ABatchStatus) && !AForceLoadFromServer); FBatchRow = GetBatchRow(); if ((FBatchRow == null) && (GetAnyBatchRow(ABatchNumber) == null)) { MessageBox.Show(String.Format("Cannot load transactions for Gift Batch {0} as the batch is not currently loaded!", ABatchNumber)); return(false); } //Set key values from Batch FLedgerNumber = ALedgerNumber; FBatchNumber = ABatchNumber; FBatchCurrencyCode = FBatchRow.CurrencyCode; FBatchMethodOfPayment = FBatchRow.MethodOfPaymentCode; FBatchStatus = ABatchStatus; FBatchUnpostedFlag = (FBatchStatus == MFinanceConstants.BATCH_UNPOSTED); if (FirstGiftTransLoad) { InitialiseControls(); } UpdateCurrencySymbols(FBatchCurrencyCode); //Check if the same batch is selected, so no need to apply filter if (SameCurrentBatch) { //Same as previously selected and we have not been asked to force a full refresh if (FBatchUnpostedFlag && (GetSelectedRowIndex() > 0)) { if (FGLEffectivePeriodHasChangedFlag) { //Just in case for the currently selected row, the date field has not been updated FGLEffectivePeriodHasChangedFlag = false; GetSelectedDetailRow().DateEntered = FBatchRow.GlEffectiveDate; dtpDateEntered.Date = FBatchRow.GlEffectiveDate; } GetDetailsFromControls(GetSelectedDetailRow()); } UpdateControlsProtection(); if (FBatchUnpostedFlag && ((FBatchCurrencyCode != FBatchRow.CurrencyCode) || (FBatchExchangeRateToBase != FBatchRow.ExchangeRateToBase))) { UpdateBaseAmount(false); } return(false); } //New Batch FCurrentGiftInBatch = 0; //New set of transactions to be loaded TFrmStatusDialog dlgStatus = new TFrmStatusDialog(FPetraUtilsObject.GetForm()); if (FShowStatusDialogOnLoadFlag == true) { dlgStatus.Show(); FShowStatusDialogOnLoadFlag = false; dlgStatus.Heading = String.Format(Catalog.GetString("Batch {0}"), ABatchNumber); dlgStatus.CurrentStatus = Catalog.GetString("Loading transactions ..."); } FGiftTransactionsLoadedFlag = false; FSuppressListChangedFlag = false; //Apply new filter FPreviouslySelectedDetailRow = null; grdDetails.DataSource = null; // if this form is readonly, then we need all codes, because old (inactive) codes might have been used if (FirstGiftTransLoad || (FActiveOnlyFlag == (ViewMode || !FBatchUnpostedFlag))) { FActiveOnlyFlag = !(ViewMode || !FBatchUnpostedFlag); dlgStatus.CurrentStatus = Catalog.GetString("Initialising controls ..."); try { //Without this, the Save button enables even for Posted batches! FPetraUtilsObject.SuppressChangeDetection = true; TFinanceControls.InitialiseMotivationGroupList(ref cmbDetailMotivationGroupCode, FLedgerNumber, FActiveOnlyFlag); TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetailCode, FLedgerNumber, FActiveOnlyFlag); TFinanceControls.InitialiseMethodOfGivingCodeList(ref cmbDetailMethodOfGivingCode, FActiveOnlyFlag); TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, FActiveOnlyFlag); TFinanceControls.InitialisePMailingList(ref cmbDetailMailingCode, FActiveOnlyFlag); } finally { FPetraUtilsObject.SuppressChangeDetection = false; } } // This sets the incomplete filter but does check the panel enabled state ShowData(); // This sets the main part of the filter but excluding the additional items set by the user GUI // It gets the right sort order SetGiftDetailDefaultView(); // only load from server if there are no transactions loaded yet for this batch // otherwise we would overwrite transactions that have already been modified if (FMainDS.AGiftDetail.DefaultView.Count == 0) { dlgStatus.CurrentStatus = Catalog.GetString("Requesting transactions from server ..."); //Load all partners in Batch FMainDS.DonorPartners.Merge(TRemote.MFinance.Gift.WebConnectors.LoadAllPartnerDataForBatch(ALedgerNumber, ABatchNumber)); //LoadAllPartnerDataForBatch(); //Include Donor fields LoadGiftDataForBatch(ALedgerNumber, ABatchNumber); } //Check if need to update batch period in each gift if (FBatchUnpostedFlag) { dlgStatus.CurrentStatus = Catalog.GetString("Updating batch period ..."); ((TFrmGiftBatch)ParentForm).GetBatchControl().UpdateBatchPeriod(); } // Now we set the full filter FFilterAndFindObject.ApplyFilter(); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); SelectRowInGrid(1); UpdateControlsProtection(); dlgStatus.CurrentStatus = Catalog.GetString("Updating totals for the batch ..."); UpdateTotals(); if ((FPreviouslySelectedDetailRow != null) && (FBatchUnpostedFlag)) { bool disableSave = (FBatchRow.RowState == DataRowState.Unchanged && !FPetraUtilsObject.HasChanges); if (disableSave && FPetraUtilsObject.HasChanges && !DataUtilities.DataRowColumnsHaveChanged(FBatchRow)) { FPetraUtilsObject.DisableSaveButton(); } } FGiftTransactionsLoadedFlag = true; dlgStatus.Close(); return(true); }