private void SetJournalDefaultView() { string DVRowFilter = string.Format("{0}={1}", AJournalTable.GetBatchNumberDBName(), FBatchNumber); FMainDS.AJournal.DefaultView.RowFilter = DVRowFilter; FMainDS.AJournal.DefaultView.Sort = String.Format("{0} DESC", AJournalTable.GetJournalNumberDBName() ); FFilterAndFindObject.FilterPanelControls.SetBaseFilter(DVRowFilter, true); FFilterAndFindObject.CurrentActiveFilter = DVRowFilter; }
/// <summary> /// Re-show the specified row /// </summary> /// <param name="ACurrentBatch"></param> /// <param name="AJournalToCancel"></param> /// <param name="ARedisplay"></param> public void PrepareJournalDataForCancelling(Int32 ACurrentBatch, Int32 AJournalToCancel, Boolean ARedisplay) { //This code will only be called when the Journal tab is active. DataView JournalDV = new DataView(FMainDS.AJournal); DataView TransDV = new DataView(FMainDS.ATransaction); DataView TransAnalDV = new DataView(FMainDS.ATransAnalAttrib); JournalDV.RowFilter = String.Format("{0}={1} And {2}={3}", AJournalTable.GetBatchNumberDBName(), ACurrentBatch, AJournalTable.GetJournalNumberDBName(), AJournalToCancel); TransDV.RowFilter = String.Format("{0}={1} And {2}={3}", ATransactionTable.GetBatchNumberDBName(), ACurrentBatch, ATransactionTable.GetJournalNumberDBName(), AJournalToCancel); TransAnalDV.RowFilter = String.Format("{0}={1} And {2}={3}", ATransAnalAttribTable.GetBatchNumberDBName(), ACurrentBatch, ATransAnalAttribTable.GetJournalNumberDBName(), AJournalToCancel); //Work from lowest level up if (TransAnalDV.Count > 0) { TransAnalDV.Sort = String.Format("{0}, {1}", ATransAnalAttribTable.GetTransactionNumberDBName(), ATransAnalAttribTable.GetAnalysisTypeCodeDBName()); foreach (DataRowView drv in TransAnalDV) { ATransAnalAttribRow transAnalRow = (ATransAnalAttribRow)drv.Row; if (transAnalRow.RowState == DataRowState.Added) { //Do nothing } else if (transAnalRow.RowState != DataRowState.Unchanged) { transAnalRow.RejectChanges(); } } } if (TransDV.Count > 0) { TransDV.Sort = String.Format("{0}", ATransactionTable.GetTransactionNumberDBName()); foreach (DataRowView drv in TransDV) { ATransactionRow transRow = (ATransactionRow)drv.Row; if (transRow.RowState == DataRowState.Added) { //Do nothing } else if (transRow.RowState != DataRowState.Unchanged) { transRow.RejectChanges(); } } } if (JournalDV.Count > 0) { GLBatchTDSAJournalRow journalRow = (GLBatchTDSAJournalRow)JournalDV[0].Row; //No need to check for Added state as new journals are always saved // on creation if (journalRow.RowState != DataRowState.Unchanged) { journalRow.RejectChanges(); } if (ARedisplay) { ShowDetails(journalRow); } } if (TransDV.Count == 0) { //Load all related data for journal ready to delete/cancel FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionAndRelatedTablesForJournal(FLedgerNumber, ACurrentBatch, AJournalToCancel)); } }
/// <summary> /// Update the specified Batch's LastJournal number. Assumes all necessary data is loaded for Batch /// </summary> /// <param name="AMainDS"></param> /// <param name="ACurrentBatchRow"></param> /// <returns>false if no change to batch totals</returns> public static bool UpdateBatchLastJournal(ref GLBatchTDS AMainDS, ref ABatchRow ACurrentBatchRow) { #region Validate Arguments if (AMainDS == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString("Function:{0} - The GL Batch dataset is null!"), Utilities.GetMethodName(true))); } else if (ACurrentBatchRow == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The GL Batch data row is null!"), Utilities.GetMethodName(true))); } else if (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED) { TLogging.Log(String.Format("Function:{0} - Tried to update totals for non-Unposted Batch:{1}", Utilities.GetMethodName(true), ACurrentBatchRow.BatchNumber)); return(false); } #endregion Validate Arguments bool RowUpdated = false; int ActualLastJournalNumber = 0; DataView JournalDV = new DataView(AMainDS.AJournal); JournalDV.RowFilter = String.Format("{0}={1}", AJournalTable.GetBatchNumberDBName(), ACurrentBatchRow.BatchNumber); //Highest Journal number first JournalDV.Sort = String.Format("{0} DESC", AJournalTable.GetJournalNumberDBName()); foreach (DataRowView journalView in JournalDV) { GLBatchTDSAJournalRow journalRow = (GLBatchTDSAJournalRow)journalView.Row; //Run once only if (ActualLastJournalNumber == 0) { ActualLastJournalNumber = journalRow.JournalNumber; } if (UpdateJournalLastTransaction(ref AMainDS, ref journalRow)) { RowUpdated = true; } } if (ACurrentBatchRow.LastJournal != ActualLastJournalNumber) { ACurrentBatchRow.LastJournal = ActualLastJournalNumber; RowUpdated = true; } return(RowUpdated); }
/// <summary> /// load the journals into the grid /// </summary> /// <param name="ACurrentBatchRow"></param> public void LoadJournals(ABatchRow ACurrentBatchRow) { FJournalsLoaded = false; FBatchRow = ACurrentBatchRow; if (FBatchRow == null) { return; } Int32 CurrentLedgerNumber = FBatchRow.LedgerNumber; Int32 CurrentBatchNumber = FBatchRow.BatchNumber; string CurrentBatchStatus = FBatchRow.BatchStatus; bool BatchIsUnposted = (FBatchRow.BatchStatus == MFinanceConstants.BATCH_UNPOSTED); bool FirstRun = (FLedgerNumber != CurrentLedgerNumber); bool BatchChanged = (FBatchNumber != CurrentBatchNumber); bool BatchStatusChanged = (!BatchChanged && (FBatchStatus != CurrentBatchStatus)); if (FirstRun) { FLedgerNumber = CurrentLedgerNumber; } if (BatchChanged) { FBatchNumber = CurrentBatchNumber; } if (BatchStatusChanged) { FBatchStatus = CurrentBatchStatus; } //Create object to control deletion FCancelLogicObject = new TUC_GLJournals_Cancel(FPetraUtilsObject, FLedgerNumber, FMainDS); //Make sure the current effective date for the Batch is correct DateTime BatchDateEffective = FBatchRow.DateEffective; //Check if need to load Journals if (!(FirstRun || BatchChanged || BatchStatusChanged)) { //Need to reconnect FPrev in some circumstances if (FPreviouslySelectedDetailRow == null) { DataRowView rowView = (DataRowView)grdDetails.Rows.IndexToDataSourceRow(FPrevRowChangedRow); if (rowView != null) { FPreviouslySelectedDetailRow = (GLBatchTDSAJournalRow)(rowView.Row); } } // The journals are the same and we have loaded them already if (BatchIsUnposted) { if (GetSelectedRowIndex() > 0) { GetDetailsFromControls(GetSelectedDetailRow()); } } } else { // a different journal SetJournalDefaultView(); FPreviouslySelectedDetailRow = null; //Load Journals if (FMainDS.AJournal.DefaultView.Count == 0) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, FBatchNumber)); } if (BatchIsUnposted) { if (!dtpDetailDateEffective.Date.HasValue || (dtpDetailDateEffective.Date.Value != BatchDateEffective)) { dtpDetailDateEffective.Date = BatchDateEffective; } } //Check if DateEffective has changed and then update all foreach (DataRowView drv in FMainDS.AJournal.DefaultView) { AJournalRow jr = (AJournalRow)drv.Row; if (jr.DateEffective != BatchDateEffective) { ((TFrmGLBatch)ParentForm).GetTransactionsControl().UpdateTransactionTotals(TGLBatchEnums.eGLLevel.Batch, true); break; } } ShowData(); // Now set up the complete current filter FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FMainDS.AJournal.DefaultView.RowFilter, true); FFilterAndFindObject.ApplyFilter(); } int nRowToSelect = 1; TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; if (myParentForm.InitialBatchFound) { DataView myView = (grdDetails.DataSource as DevAge.ComponentModel.BoundDataView).DataView; for (int counter = 0; (counter < myView.Count); counter++) { int myViewJournalNumber = (int)myView[counter][AJournalTable.GetJournalNumberDBName()]; if (myViewJournalNumber == myParentForm.InitialJournalNumber) { nRowToSelect = counter + 1; break; } } } else { nRowToSelect = (BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow; } //This will also call UpdateChangeableStatus SelectRowInGrid(nRowToSelect); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); txtControl.CurrencyCode = TTxtCurrencyTextBox.CURRENCY_STANDARD_2_DP; txtCredit.CurrencyCode = FLedgerBaseCurrency; txtDebit.CurrencyCode = FLedgerBaseCurrency; FJournalsLoaded = true; }
/// <summary> /// load the journals into the grid /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="ABatchNumber"></param> /// <param name="ABatchStatus"></param> public void LoadJournals(Int32 ALedgerNumber, Int32 ABatchNumber, string ABatchStatus = MFinanceConstants.BATCH_UNPOSTED) { FJournalsLoaded = false; FBatchRow = GetBatchRow(); if (FBatchRow == null) { return; } FCancelLogicObject = new TUC_GLJournals_Cancel(FPetraUtilsObject, FLedgerNumber, FMainDS); //Make sure the current effective date for the Batch is correct DateTime BatchDateEffective = FBatchRow.DateEffective; bool FirstRun = (FLedgerNumber != ALedgerNumber); bool BatchChanged = (FBatchNumber != ABatchNumber); bool BatchStatusChanged = (!BatchChanged && FBatchStatus != ABatchStatus); //Check if need to load Journals if (FirstRun || BatchChanged || BatchStatusChanged) { FLedgerNumber = ALedgerNumber; FBatchNumber = ABatchNumber; FBatchStatus = ABatchStatus; SetJournalDefaultView(); FPreviouslySelectedDetailRow = null; //Load Journals if (FMainDS.AJournal.DefaultView.Count == 0) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournalAndContent(FLedgerNumber, FBatchNumber)); } if (FBatchStatus == MFinanceConstants.BATCH_UNPOSTED) { if (!dtpDetailDateEffective.Date.HasValue || (dtpDetailDateEffective.Date.Value != BatchDateEffective)) { dtpDetailDateEffective.Date = BatchDateEffective; } } foreach (DataRowView drv in FMainDS.AJournal.DefaultView) { AJournalRow jr = (AJournalRow)drv.Row; if (jr.DateEffective != BatchDateEffective) { ((TFrmGLBatch)ParentForm).GetTransactionsControl().UpdateTransactionTotals("BATCH", true); break; } } ShowData(); // Now set up the complete current filter FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FMainDS.AJournal.DefaultView.RowFilter, true); FFilterAndFindObject.ApplyFilter(); } else { // The journals are the same and we have loaded them already if (FBatchRow.BatchStatus == MFinanceConstants.BATCH_UNPOSTED) { if (GetSelectedRowIndex() > 0) { GetDetailsFromControls(GetSelectedDetailRow()); } } } int nRowToSelect = 1; TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; if (myParentForm.InitialBatchFound) { string filter = String.Format("{0}={1}", AJournalTable.GetJournalNumberDBName(), myParentForm.InitialJournalNumber); DataView dv = new DataView(FMainDS.AJournal, filter, "", DataViewRowState.CurrentRows); if (dv.Count > 0) { nRowToSelect = grdDetails.DataSourceRowToIndex2(dv[0].Row) + 1; } } else { nRowToSelect = (BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow; } //This will also call UpdateChangeableStatus SelectRowInGrid(nRowToSelect); UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); FJournalsLoaded = true; }