private void InitializeManualCode() { Type DataTableType; DataTable CacheRegionDT = TDataCache.GetCacheableDataTableFromCache("PostcodeRegionList", String.Empty, null, out DataTableType); DataTable CacheRegionRangeDT = TDataCache.GetCacheableDataTableFromCache("PostcodeRegionRangeList", String.Empty, null, out DataTableType); PPostcodeRangeTable RangeTable = (PPostcodeRangeTable)TDataCache.GetCacheableDataTableFromCache("PostcodeRangeList", String.Empty, null, out DataTableType); FMainDS.PPostcodeRegion.Merge(CacheRegionDT); FMainDS.PPostcodeRegionRange.Merge(CacheRegionRangeDT); foreach (PostcodeRegionsTDSPPostcodeRegionRangeRow Row in FMainDS.PPostcodeRegionRange.Rows) { PPostcodeRangeRow RangeRow = (PPostcodeRangeRow)RangeTable.Rows.Find(new object[] { Row.Range }); Row.From = RangeRow.From; Row.To = RangeRow.To; } FMainDS.AcceptChanges(); FPetraUtilsObject.ApplySecurity(TSecurityChecks.SecurityPermissionsSetupScreensEditingAndSaving); }
private void InitialiseLedgerControls() { // Load Motivation detail in this central place; it will be used by UC_GiftTransactions AMotivationDetailTable motivationDetail = (AMotivationDetailTable)TDataCache.TMFinance.GetCacheableFinanceTable( TCacheableFinanceTablesEnum.MotivationList, FLedgerNumber); motivationDetail.TableName = FMainDS.AMotivationDetail.TableName; FMainDS.Merge(motivationDetail); FMainDS.AcceptChanges(); FMainDS.ARecurringGiftBatch.DefaultView.Sort = String.Format("{0}, {1} DESC", ARecurringGiftBatchTable.GetLedgerNumberDBName(), ARecurringGiftBatchTable.GetBatchNumberDBName() ); SetupExtraGridFunctionality(); RefreshBankAccountAndCostCentreData(); // if this form is readonly, then we need all codes, because old codes might have been used bool ActiveOnly = this.Enabled; SetupAccountAndCostCentreCombos(ActiveOnly); cmbDetailMethodOfPaymentCode.AddNotSetRow("", ""); TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, ActiveOnly); }
/// <summary> /// Deletes the current row and optionally populates a completion message /// </summary> /// <param name="ARowToDelete">the currently selected row to delete</param> /// <param name="ACompletionMessage">if specified, is the deletion completion message</param> /// <returns>true if row deletion is successful</returns> private bool DeleteRowManual(ARecurringGiftBatchRow ARowToDelete, ref string ACompletionMessage) { bool deletionSuccessful = false; int batchNumber = ARowToDelete.BatchNumber; bool newBatch = (ARowToDelete.RowState == DataRowState.Added); // first save any changes if (!((TFrmRecurringGiftBatch)FPetraUtilsObject.GetForm()).SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.DELETING)) { return(false); } try { ACompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} deleted successfully."), batchNumber); //clear any transactions currently being editied in the Transaction Tab ((TFrmRecurringGiftBatch)ParentForm).GetTransactionsControl().ClearCurrentSelection(); if (!newBatch) { //Load tables afresh FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadRecurringGiftTransactionsForBatch(FLedgerNumber, batchNumber)); FMainDS.AcceptChanges(); } ((TFrmRecurringGiftBatch)ParentForm).GetTransactionsControl().DeleteCurrentRecurringBatchGiftData(batchNumber); //Affect a change in the batch row, required by deletion process. ARowToDelete.DateModified = DateTime.Now; // Delete the recurring batch row. ARowToDelete.Delete(); //FMainDS.AcceptChanges(); FPreviouslySelectedDetailRow = null; deletionSuccessful = true; } catch (Exception ex) { ACompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Deletion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateRecordNumberDisplay(); return(deletionSuccessful); }
/// <summary> /// Loads Extract Master Data from Petra Server into FMainDS. /// </summary> /// <param name="AExtractNameFilter"></param> /// <param name="AAllUsers"></param> /// <param name="ACreatedByUser"></param> /// <param name="AModifiedByUser"></param> /// <returns>true if successful, otherwise false.</returns> private Boolean LoadData(String AExtractNameFilter, Boolean AAllUsers, String ACreatedByUser, String AModifiedByUser) { Boolean ReturnValue; // Load Extract Headers, if not already loaded try { // Make sure that Typed DataTables are already there at Client side if (FMainDS.MExtractMaster == null) { FMainDS.Tables.Add(new MExtractMasterTable()); FMainDS.InitVars(); } else { // clear table so a load also works if records on the server have been removed FMainDS.MExtractMaster.Clear(); } // add filter data FMainDS.Merge(TRemote.MPartner.Partner.WebConnectors.GetAllExtractHeaders(AExtractNameFilter, AAllUsers, ACreatedByUser, AModifiedByUser)); // Make DataRows unchanged if (FMainDS.MExtractMaster.Rows.Count > 0) { FMainDS.MExtractMaster.AcceptChanges(); FMainDS.AcceptChanges(); } if (FMainDS.MExtractMaster.Rows.Count != 0) { ReturnValue = true; } else { ReturnValue = false; } } catch (System.NullReferenceException) { return(false); } catch (Exception) { throw; } return(ReturnValue); }
/// <summary> /// Loads Extract Master Data from Petra Server into FMainDS. /// </summary> /// <returns>true if successful, otherwise false.</returns> private Boolean LoadData() { Boolean ReturnValue; // Load Extract Headers, if not already loaded try { // Make sure that MasterTyped DataTables are already there at Client side if (FMainDS.MExtract == null) { FMainDS.Tables.Add(new ExtractTDSMExtractTable()); FMainDS.InitVars(); } FMainDS.Merge(TRemote.MPartner.Partner.WebConnectors.GetExtractRowsWithPartnerData(FExtractId)); // Make DataRows unchanged if (FMainDS.MExtract.Rows.Count > 0) { FMainDS.MExtract.AcceptChanges(); FMainDS.AcceptChanges(); } if (FMainDS.MExtract.Rows.Count != 0) { ReturnValue = true; } else { ReturnValue = false; } } catch (System.NullReferenceException) { return(false); } catch (Exception) { throw; } return(ReturnValue); }
private void InitializeManualCode() { Type DataTableType; DataTable CacheRegionDT = TDataCache.GetCacheableDataTableFromCache("PostcodeRegionList", String.Empty, null, out DataTableType); DataTable CacheRegionRangeDT = TDataCache.GetCacheableDataTableFromCache("PostcodeRegionRangeList", String.Empty, null, out DataTableType); PPostcodeRangeTable RangeTable = (PPostcodeRangeTable)TDataCache.GetCacheableDataTableFromCache("PostcodeRangeList", String.Empty, null, out DataTableType); FMainDS.PPostcodeRegion.Merge(CacheRegionDT); FMainDS.PPostcodeRegionRange.Merge(CacheRegionRangeDT); foreach (PostcodeRegionsTDSPPostcodeRegionRangeRow Row in FMainDS.PPostcodeRegionRange.Rows) { PPostcodeRangeRow RangeRow = (PPostcodeRangeRow)RangeTable.Rows.Find(new object[] { Row.Range }); Row.From = RangeRow.From; Row.To = RangeRow.To; } FMainDS.AcceptChanges(); }
private void InitialiseLedgerControls() { // Load Motivation detail in this central place; it will be used by UC_GiftTransactions AMotivationDetailTable motivationDetail = (AMotivationDetailTable)TDataCache.TMFinance.GetCacheableFinanceTable( TCacheableFinanceTablesEnum.MotivationList, FLedgerNumber); motivationDetail.TableName = FMainDS.AMotivationDetail.TableName; FMainDS.Merge(motivationDetail); FMainDS.AcceptChanges(); FMainDS.AGiftBatch.DefaultView.Sort = String.Format("{0}, {1} DESC", AGiftBatchTable.GetLedgerNumberDBName(), AGiftBatchTable.GetBatchNumberDBName() ); SetupExtraGridFunctionality(); FAccountAndCostCentreLogicObject.RefreshBankAccountAndCostCentreData(FLoadAndFilterLogicObject); // if this form is readonly, then we need all codes, because old codes might have been used bool ActiveOnly = this.Enabled; SetupAccountAndCostCentreCombos(ActiveOnly); cmbDetailMethodOfPaymentCode.AddNotSetRow("", ""); TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, ActiveOnly); TLedgerSelection.GetCurrentPostingRangeDates(FLedgerNumber, out FStartDateCurrentPeriod, out FEndDateLastForwardingPeriod, out FDefaultDate); lblValidDateRange.Text = String.Format(Catalog.GetString("Valid between {0} and {1}"), FStartDateCurrentPeriod.ToShortDateString(), FEndDateLastForwardingPeriod.ToShortDateString()); FLoadAndFilterLogicObject.InitialiseDataSources(cmbDetailBankCostCentre, cmbDetailBankAccountCode); }
private bool OnDeleteRowManual(GiftBatchTDSAGiftDetailRow ARowToDelete, ref string ACompletionMessage) { bool deletionSuccessful = false; string originatingDetailRef = string.Empty; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(deletionSuccessful); } // temporarily disable New Donor Warning ((TFrmGiftBatch)this.ParentForm).NewDonorWarning = false; if ((ARowToDelete.RowState != DataRowState.Added) && !((TFrmGiftBatch)this.ParentForm).SaveChangesManual()) { MessageBox.Show("Error in trying to save prior to deleting current gift detail!"); return(deletionSuccessful); } ((TFrmGiftBatch)this.ParentForm).NewDonorWarning = true; //Backup the Dataset for reversion purposes GiftBatchTDS FTempDS = (GiftBatchTDS)FMainDS.Copy(); FTempDS.Merge(FMainDS); if (ARowToDelete.RowState != DataRowState.Added) { //Required to deal with concurrency errors FMainDS.AcceptChanges(); } int selectedDetailNumber = ARowToDelete.DetailNumber; int giftToDeleteTransNo = 0; string filterAllGiftsOfBatch = String.Empty; string filterAllGiftDetailsOfBatch = String.Empty; int detailRowCount = FGiftDetailView.Count; try { //Speeds up deletion of larger gift sets FMainDS.EnforceConstraints = false; if (ARowToDelete.ModifiedDetailKey != null) { originatingDetailRef = ARowToDelete.ModifiedDetailKey; } //Delete current detail row ARowToDelete.Delete(); //If there existed (before the delete row above) more than one detail row, then no need to delete gift header row if (detailRowCount > 1) { FGiftSelectedForDeletion = false; foreach (DataRowView rv in FGiftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; if (row.DetailNumber > selectedDetailNumber) { row.DetailNumber--; } } FGift.LastDetailNumber--; FPetraUtilsObject.SetChangedFlag(); } else { giftToDeleteTransNo = FGift.GiftTransactionNumber; TLogging.Log("Delete row: " + giftToDeleteTransNo.ToString()); // Reduce all Gift Detail row Transaction numbers by 1 if they are greater then gift to be deleted filterAllGiftDetailsOfBatch = String.Format("{0}={1} And {2}>{3}", AGiftDetailTable.GetBatchNumberDBName(), FBatchNumber, AGiftDetailTable.GetGiftTransactionNumberDBName(), giftToDeleteTransNo); DataView giftDetailView = new DataView(FMainDS.AGiftDetail); giftDetailView.RowFilter = filterAllGiftDetailsOfBatch; giftDetailView.Sort = String.Format("{0} ASC", AGiftDetailTable.GetGiftTransactionNumberDBName()); foreach (DataRowView rv in giftDetailView) { GiftBatchTDSAGiftDetailRow row = (GiftBatchTDSAGiftDetailRow)rv.Row; row.GiftTransactionNumber--; } //Cannot delete the gift row, just copy the data of rows above down by 1 row // and then mark the top row for deletion //In other words, bubble the gift row to be deleted to the top filterAllGiftsOfBatch = String.Format("{0}={1} And {2}>={3}", AGiftTable.GetBatchNumberDBName(), FBatchNumber, AGiftTable.GetGiftTransactionNumberDBName(), giftToDeleteTransNo); DataView giftView = new DataView(FMainDS.AGift); giftView.RowFilter = filterAllGiftsOfBatch; giftView.Sort = String.Format("{0} ASC", AGiftTable.GetGiftTransactionNumberDBName()); AGiftRow giftRowToReceive = null; AGiftRow giftRowToCopyDown = null; AGiftRow giftRowCurrent = null; int currentGiftTransNo = 0; foreach (DataRowView gv in giftView) { giftRowCurrent = (AGiftRow)gv.Row; currentGiftTransNo = giftRowCurrent.GiftTransactionNumber; if (currentGiftTransNo > giftToDeleteTransNo) { giftRowToCopyDown = giftRowCurrent; //Copy column values down for (int j = 3; j < giftRowToCopyDown.Table.Columns.Count; j++) { //Update all columns except the pk fields that remain the same if (!giftRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text")) { giftRowToReceive[j] = giftRowToCopyDown[j]; } } } if (currentGiftTransNo == FBatchRow.LastGiftNumber) { //Mark last record for deletion giftRowCurrent.GiftStatus = MFinanceConstants.MARKED_FOR_DELETION; } //Will always be previous row giftRowToReceive = giftRowCurrent; } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); FGiftSelectedForDeletion = true; FBatchRow.LastGiftNumber--; } //Force a change in the batch row to make sure it exists in the dataset to save FBatchRow.DateModified = DateTime.Now; //Check if deleting a reversed gift detail if (originatingDetailRef.StartsWith("|")) { bool ok = TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, originatingDetailRef); if (!ok) { throw new Exception("Error in trying to reset Modified Detail field of the originating gift detail."); } } //Try to save changes if (((TFrmGiftBatch)this.ParentForm).SaveChangesManual()) { //Clear current batch's gift data and reload from server RefreshCurrentBatchGiftData(FBatchNumber); } else { throw new Exception("Unable to save after deleting a gift!"); } ACompletionMessage = Catalog.GetString("Gift row deleted successfully!"); deletionSuccessful = true; } catch (Exception ex) { ACompletionMessage = ex.Message; MessageBox.Show(ex.Message, "Gift Deletion Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(FTempDS); } finally { FMainDS.EnforceConstraints = true; SetGiftDetailDefaultView(); FFilterAndFindObject.ApplyFilter(); } UpdateRecordNumberDisplay(); return(deletionSuccessful); }
/// <summary> /// Clear the gift data of the current batch without marking records for delete /// </summary> private bool RefreshBatchGiftData(Int32 ABatchNumber, bool AAcceptChanges = false, bool AHandleDataSetBackup = false) { bool RetVal = false; //Copy and backup the current dataset GiftBatchTDS BackupDS = null; GiftBatchTDS TempDS = (GiftBatchTDS)FMainDS.Copy(); TempDS.Merge(FMainDS); if (AHandleDataSetBackup) { BackupDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); } try { this.Cursor = Cursors.WaitCursor; //Remove current batch gift data DataView giftDetailView = new DataView(TempDS.AGiftDetail); giftDetailView.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), ABatchNumber); giftDetailView.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView dr in giftDetailView) { dr.Delete(); } DataView giftView = new DataView(TempDS.AGift); giftView.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), ABatchNumber); giftView.Sort = String.Format("{0} DESC", AGiftTable.GetGiftTransactionNumberDBName()); foreach (DataRowView dr in giftView) { dr.Delete(); } TempDS.AcceptChanges(); //Clear all gift data from Main dataset gift tables FMainDS.AGiftDetail.Clear(); FMainDS.AGift.Clear(); //Bring data back in from other batches if it exists if (TempDS.AGift.Count > 0) { FMainDS.AGift.Merge(TempDS.AGift); FMainDS.AGiftDetail.Merge(TempDS.AGiftDetail); } //TODO: Confirm I need to AcceptChanges FMainDS.Merge(TRemote.MFinance.Gift.WebConnectors.LoadGiftTransactionsForBatch(FLedgerNumber, ABatchNumber)); if (AAcceptChanges) { FMainDS.AcceptChanges(); } RetVal = true; } catch (Exception ex) { //If not revert on error then calling method will if (AHandleDataSetBackup) { RevertDataSet(FMainDS, BackupDS); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { this.Cursor = Cursors.Default; } return(RetVal); }