private void CancelRow(System.Object sender, EventArgs e) { if (FPreviouslySelectedDetailRow == null) { MessageBox.Show(Catalog.GetString("Select the row to cancel first")); return; } TFrmGLBatch MainForm = (TFrmGLBatch)this.ParentForm; int CurrentlySelectedRow = grdDetails.GetFirstHighlightedRowIndex(); try { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.CANCELLINGJOURNAL; if (FCancelLogicObject.CancelRow(FPreviouslySelectedDetailRow)) { UpdateHeaderTotals(FBatchRow); SelectRowInGrid(CurrentlySelectedRow); UpdateRecordNumberDisplay(); SetJournalDefaultView(); FFilterAndFindObject.ApplyFilter(); UpdateChangeableStatus(); MainForm.DisableTransactions(); } } finally { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
private void InitialiseLedgerControls() { //Set the valid date range label TLedgerSelection.GetCurrentPostingRangeDates(FLedgerNumber, out FStartDateCurrentPeriod, out FEndDateLastForwardingPeriod, out FDefaultDate); lblValidDateRange.Text = String.Format(Catalog.GetString("Valid between {0} and {1}"), StringHelper.DateToLocalizedString(FStartDateCurrentPeriod, false, false), StringHelper.DateToLocalizedString(FEndDateLastForwardingPeriod, false, false)); // Get the current year/period and pass on to the filter logic object ALedgerRow LedgerRow = ((ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails, FLedgerNumber))[0]; FCurrentLedgerYear = LedgerRow.CurrentFinancialYear; FCurrentLedgerPeriod = LedgerRow.CurrentPeriod; FLoadAndFilterLogicObject.CurrentLedgerYear = FCurrentLedgerYear; FLoadAndFilterLogicObject.CurrentLedgerPeriod = FCurrentLedgerPeriod; TFrmGLBatch myParentForm = (TFrmGLBatch)this.ParentForm; myParentForm.GetJournalsControl().LedgerBaseCurrency = LedgerRow.BaseCurrency; }
private void RunOnceOnParentActivationManual() { try { ParentForm.Cursor = Cursors.WaitCursor; grdDetails.DoubleClickCell += new TDoubleClickCellEventHandler(this.ShowJournalTab); grdDetails.DataSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(DataSource_ListChanged); LoadBatchesForCurrentYear(); txtDetailBatchControlTotal.CurrencyCode = TTxtCurrencyTextBox.CURRENCY_STANDARD_2_DP; SetInitialFocus(); // Select the Journal tab if the screen opener specified a Journal Number TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; if (myParentForm.InitialBatchFound && (myParentForm.InitialJournalNumber != -1)) { myParentForm.SelectTab(TFrmGLBatch.eGLTabs.Journals); } FInactiveValuesWarningOnGLPosting = TUserDefaults.GetBooleanDefault(TUserDefaults.FINANCE_GL_WARN_OF_INACTIVE_VALUES_ON_POSTING, true); } finally { ParentForm.Cursor = Cursors.Default; } }
private void BtnView_Click(object sender, EventArgs e) { // get the currently selected row DataRow CurrentlySelectedRow = GetCurrentDataRow(); if (CurrentlySelectedRow != null) { try { this.Cursor = Cursors.WaitCursor; TFrmGLBatch GLb = new TFrmGLBatch(this); GLb.LedgerNumber = FLedgerNumber; GLb.ShowDetailsOfOneBatch(FLedgerNumber, (int)CurrentlySelectedRow["a_batch_number_i"], (int)CurrentlySelectedRow["a_journal_number_i"], (int)CurrentlySelectedRow["a_batch_year_i"], (int)CurrentlySelectedRow["a_batch_period_i"]); GLb.SelectTab(TFrmGLBatch.eGLTabs.Journals); GLb.SelectTab(TFrmGLBatch.eGLTabs.Transactions); GLb.FindGLTransaction((int)CurrentlySelectedRow["a_batch_number_i"], (int)CurrentlySelectedRow["a_journal_number_i"], (int)CurrentlySelectedRow["a_transaction_number_i"]); } finally { this.Cursor = Cursors.Default; } } }
private void CancelRow(System.Object sender, EventArgs e) { if (FPreviouslySelectedDetailRow == null) { MessageBox.Show(Catalog.GetString("Select the row to cancel first")); return; } TFrmGLBatch MainForm = (TFrmGLBatch)this.ParentForm; try { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.CANCELLING; int currentlySelectedRow = grdDetails.GetFirstHighlightedRowIndex(); if (FCancelLogicObject.CancelBatch(FPreviouslySelectedDetailRow)) { //Reset row to fire events SelectRowInGrid(currentlySelectedRow); UpdateRecordNumberDisplay(); //If no row exists in current view after cancellation if (grdDetails.Rows.Count < 2) { EnableButtonControl(false); ClearDetailControls(); } } } finally { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
/// <summary> /// Constructor /// </summary> public TUC_GLBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GLBatchTDS AMainDS) { FPetraUtilsObject = APetraUtilsObject; FLedgerNumber = ALedgerNumber; FMainDS = AMainDS; FMyForm = (TFrmGLBatch)FPetraUtilsObject.GetForm(); }
/// <summary> /// Constructor /// </summary> public TUC_GLBatches_Post(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GLBatchTDS AMainDS, IUC_GLBatches AUserControl) { FPetraUtilsObject = APetraUtilsObject; FLedgerNumber = ALedgerNumber; FMainDS = AMainDS; FMyUserControl = AUserControl; FMyForm = (TFrmGLBatch)FPetraUtilsObject.GetForm(); }
/// <summary> /// load the batches into the grid /// </summary> public void LoadBatchesForCurrentYear() { FBatchesLoaded = false; TFrmGLBatch myParentForm = (TFrmGLBatch)this.ParentForm; myParentForm.InitialBatchFound = false; bool performStandardLoad = true; if (myParentForm.InitialBatchYear >= 0) { FLoadAndFilterLogicObject.StatusAll = true; int yearIndex = FLoadAndFilterLogicObject.FindYearAsIndex(myParentForm.InitialBatchYear); if (yearIndex >= 0) { FLoadAndFilterLogicObject.YearIndex = yearIndex; FLoadAndFilterLogicObject.PeriodIndex = (myParentForm.InitialBatchYear == FCurrentLedgerYear) ? 1 : 0; performStandardLoad = false; } // Reset the start-up value myParentForm.InitialBatchYear = -1; } if (performStandardLoad) { // Set up for current year with current and forwarding periods (on initial load this will already be set so will not fire a change) FLoadAndFilterLogicObject.YearIndex = 0; FLoadAndFilterLogicObject.PeriodIndex = 0; } // This call will get the first year's data and update the display. // Note: If the first year data has already been loaded once there will be no trip to the server to get any updates. // if you know updates are available, you need to merge them afterwards or clear the data table first UpdateDisplay(); if (myParentForm.LoadForImport) { // We have been launched from the Import Batches main menu screen as opposed to the regular GL Batches menu // Call the logic object to import: this will request a CSV file and merge the batches on the server. // Finally it will call back to ReloadBatches() in this class, which merges the server data into FMainDS and selects the first row FImportLogicObject.ImportBatches(TUC_GLBatches_Import.TImportDataSourceEnum.FromFile); // Reset the flag myParentForm.LoadForImport = false; } FBatchesLoaded = true; }
private void PostBatch(System.Object sender, EventArgs e) { // Although the screen can be used with FINANCE-1, Posting requires FINANCE-2 TSecurityChecks.CheckUserModulePermissions("FINANCE-2", "PostBatch [raised by Client Proxy for ModuleAccessManager]"); if ((GetSelectedRowIndex() < 0) || (FPreviouslySelectedDetailRow == null)) { MessageBox.Show(Catalog.GetString("Please select a GL Batch before posting!")); return; } //get index position of row to post int NewCurrentRowPos = GetSelectedRowIndex(); TFrmGLBatch MainForm = (TFrmGLBatch)this.ParentForm; try { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.POSTING; if (FPostLogicObject.PostBatch(FPreviouslySelectedDetailRow, dtpDetailDateEffective.Date.Value, FStartDateCurrentPeriod, FEndDateLastForwardingPeriod)) { // AlanP - commenting out most of this because it should be unnecessary - or should move to ShowDetailsManual() ////Select unposted batch row in same index position as batch just posted //grdDetails.DataSource = null; //grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(FMainDS.ABatch.DefaultView); if (grdDetails.Rows.Count > 1) { //Needed because posting process forces grid events which sets FDetailGridRowsCountPrevious = FDetailGridRowsCountCurrent // such that a removal of a row is not detected SelectRowInGrid(NewCurrentRowPos); } else { EnableButtonControl(false); ClearDetailControls(); btnNew.Focus(); pnlDetails.Enabled = false; } UpdateRecordNumberDisplay(); FFilterAndFindObject.SetRecordNumberDisplayProperties(); } } finally { MainForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
private void RunOnceOnParentActivationManual() { grdDetails.DoubleClickCell += new TDoubleClickCellEventHandler(this.ShowJournalTab); grdDetails.DataSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(DataSource_ListChanged); SetInitialFocus(); // Select the Journal tab if the screen opener specified a Journal Number TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; if (myParentForm.InitialBatchFound && (myParentForm.InitialJournalNumber != -1)) { myParentForm.SelectTab(TFrmGLBatch.eGLTabs.Journals); } }
/// <summary> /// Updates the data display. Call this after the DataSet has changed. /// </summary> public void UpdateDisplay() { TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; Cursor prevCursor = myParentForm.Cursor; try { myParentForm.Cursor = Cursors.WaitCursor; // Remember our current row position int nCurrentRowIndex = GetSelectedRowIndex(); // This single call will fire the event that loads data and populates the grid FFilterAndFindObject.ApplyFilter(); // Did the start-up specify a batch to select? if (myParentForm.InitialBatchNumber > 0) { nCurrentRowIndex = 1; string filter = String.Format("{0}={1}", ABatchTable.GetBatchNumberDBName(), myParentForm.InitialBatchNumber); DataView dv = new DataView(FMainDS.ABatch, filter, "", DataViewRowState.CurrentRows); if (dv.Count > 0) { int rowToSelect = grdDetails.DataSourceRowToIndex2(dv[0].Row) + 1; if (rowToSelect > 0) { nCurrentRowIndex = rowToSelect; myParentForm.InitialBatchFound = true; } } // Reset the start-up value myParentForm.InitialBatchNumber = -1; } // Now we can select the row index we had before (if it exists) SelectRowInGrid(nCurrentRowIndex); UpdateRecordNumberDisplay(); } finally { myParentForm.Cursor = prevCursor; } }
/// <summary> /// Opens the GL Batch screen. /// </summary> /// <param name="AParameter">LedgerNumber (as String!).</param> public override void OpenGLBatchScreen(String AParameter) { //MessageBox.Show("Entering OpenGLBatchScreen..."); int LedgerNumberParamPos; int NextParameterStart; int LedgerNumberLength; Int32 LedgerNumber; LedgerNumberParamPos = AParameter.IndexOf(TTestWinForm.LEDGERNUMBER_PARAM); if (LedgerNumberParamPos != -1) { NextParameterStart = AParameter.IndexOf(TTestWinForm.PARAM_SEPARATOR, LedgerNumberParamPos + TTestWinForm.LEDGERNUMBER_PARAM.Length + 1); if (NextParameterStart == -1) { LedgerNumberLength = AParameter.Length - LedgerNumberParamPos - TTestWinForm.LEDGERNUMBER_PARAM.Length - 1; // MessageBox.Show("LedgerNumberLength #1: " + LedgerNumberLength.ToString()); } else { LedgerNumberLength = AParameter.Length - LedgerNumberParamPos - 1 - NextParameterStart; // MessageBox.Show("LedgerNumberLength #2: " + LedgerNumberLength.ToString()); } // MessageBox.Show("LedgerNumberLength: " + LedgerNumberLength.ToString()); // MessageBox.Show("Parsed 'LedgerNumber' parameter: " + "Startpos.: " + LedgerNumberParamPos.ToString() + "; Contents: " + // AParameter.Substring(LedgerNumberParamPos + TTestWinForm.LEDGERNUMBER_PARAM.Length + 1, LedgerNumberLength)); LedgerNumber = Convert.ToInt32( AParameter.Substring(LedgerNumberParamPos + TTestWinForm.LEDGERNUMBER_PARAM.Length + 1, LedgerNumberLength)); } else { LedgerNumber = Convert.ToInt32(AParameter); } Ict.Petra.Client.MFinance.Gui.GL.TFrmGLBatch GLBatchForm = new Ict.Petra.Client.MFinance.Gui.GL.TFrmGLBatch(null); GLBatchForm.LedgerNumber = LedgerNumber; GLBatchForm.Show(); }
public void TestCreateBatchAndSave() { TFrmGLBatch frmBatch = new TFrmGLBatch(null); frmBatch.LedgerNumber = FLedgerNumber; frmBatch.Show(); ToolStripButtonTester btnSave = new ToolStripButtonTester("tbbSave"); ButtonTester btnNewBatch = new ButtonTester("ucoBatches.btnNew"); Assert.AreEqual(false, btnSave.Properties.Enabled, "Save button should be disabled since there are no changes"); btnNewBatch.Click(); TextBoxTester txtDetailBatchDescription = new TextBoxTester("txtDetailBatchDescription"); txtDetailBatchDescription.Properties.Text = "Created by test TestCreateBatchAndSave"; Assert.AreEqual(true, btnSave.Properties.Enabled, "Save button should be enabled since there was a change"); btnSave.Click(); }
private void RunOnceOnParentActivationManual() { grdDetails.DoubleClickCell += new TDoubleClickCellEventHandler(this.ShowJournalTab); grdDetails.DataSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(DataSource_ListChanged); LoadBatchesForCurrentYear(); txtDetailBatchControlTotal.CurrencyCode = TTxtCurrencyTextBox.CURRENCY_STANDARD_2_DP; SetInitialFocus(); // Select the Journal tab if the screen opener specified a Journal Number TFrmGLBatch myParentForm = (TFrmGLBatch)ParentForm; if (myParentForm.InitialBatchFound && (myParentForm.InitialJournalNumber != -1)) { myParentForm.SelectTab(TFrmGLBatch.eGLTabs.Journals); } }
/// <summary> /// add a new journal /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void NewRow(System.Object sender, EventArgs e) { TFrmGLBatch MainForm = (TFrmGLBatch)this.ParentForm; if (FPetraUtilsObject.HasChanges && !MainForm.SaveChanges()) { return; } FPetraUtilsObject.VerificationResultCollection.Clear(); this.CreateNewAJournal(); //Copy description from Batch txtDetailJournalDescription.Text = FBatchRow.BatchDescription; //Needed as GL journals can not be deleted MainForm.SaveChanges(); MainForm.EnableTransactions(); txtDetailJournalDescription.Focus(); }
/// <summary> /// this function calculates the balances of the accounts involved, if this batch would be posted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TestPostBatch(System.Object sender, EventArgs e) { if (FPreviouslySelectedDetailRow == null) { MessageBox.Show(Catalog.GetString("There is no current Batch row selected!"), Catalog.GetString("Test Post Batch"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } TFrmGLBatch GLBatchForm = (TFrmGLBatch)this.ParentForm; try { GLBatchForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.TESTING; FPostLogicObject.TestPostBatch(FPreviouslySelectedDetailRow); } finally { GLBatchForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
/// <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> /// The main method that handles all filtering. Every change on the filter panel causes this event to fire. /// It is important to manage the fact that this method may be called recursively and so nesting can be tricky! /// </summary> /// <param name="AFilterString">On entry this parameter contains the filter control's best guess for the current filter. /// The code can modify this string in the light of current control values.</param> public void ApplyFilterManual(ref string AFilterString) { if ((FCurrentLedgerYear < 0) || (FCurrentLedgerPeriod < 0)) { return; } string workingFilter = String.Empty; string additionalFilter = String.Empty; bool showingAllPeriods = false; // Remove the old base filter if (FPrevBaseFilter.Length > 0) { additionalFilter = AFilterString.Substring(FPrevBaseFilter.Length); if (additionalFilter.StartsWith(CommonJoinString.JOIN_STRING_SQL_AND)) { additionalFilter = additionalFilter.Substring(CommonJoinString.JOIN_STRING_SQL_AND.Length); } } int newYear = FcmbYearEnding.GetSelectedInt32(); if (newYear != FPrevYearEnding) { FPrevYearEnding = newYear; //TLogging.Log(String.Format("RefreshPeriods for Year {0}", newYear)); RefreshPeriods(newYear); // Apply the last good filter as we unwind the nesting AFilterString = FPrevFilter; return; } int newPeriod = FcmbPeriod.GetSelectedInt32(); if (newYear == -1) { newYear = FCurrentLedgerYear; workingFilter = String.Format("{0}={1}", ABatchTable.GetBatchYearDBName(), newYear); showingAllPeriods = true; } else { workingFilter = String.Format( "{0}={1}", ABatchTable.GetBatchYearDBName(), newYear); if (newPeriod == 0) //All periods for year { //Nothing to add to filter showingAllPeriods = true; } else if (newPeriod == -1) { workingFilter += String.Format(" AND {0} >= {1}", ABatchTable.GetBatchPeriodDBName(), FCurrentLedgerPeriod); } else if (newPeriod > 0) { workingFilter += String.Format(" AND {0}={1}", ABatchTable.GetBatchPeriodDBName(), newPeriod); } } if (!BatchYearIsLoaded(newYear)) { FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatch(FLedgerNumber, newYear, newPeriod)); // Set the flag on the transaction tab to show the status dialog again when the transactions are loaded for a new year TFrmGLBatch glBatchForm = (TFrmGLBatch)FPetraUtilsObject.GetForm(); glBatchForm.GetTransactionsControl().ShowStatusDialogOnLoad = true; } if (FrbtEditing.Checked) { StringHelper.JoinAndAppend(ref workingFilter, String.Format("{0}='{1}'", ABatchTable.GetBatchStatusDBName(), MFinanceConstants.BATCH_UNPOSTED), CommonJoinString.JOIN_STRING_SQL_AND); } else if (FrbtPosting.Checked) { StringHelper.JoinAndAppend(ref workingFilter, String.Format("({0}='{1}') AND ({2}={3}) AND ({2}<>0) AND (({4}=0) OR ({4}={2}))", ABatchTable.GetBatchStatusDBName(), MFinanceConstants.BATCH_UNPOSTED, ABatchTable.GetBatchCreditTotalDBName(), ABatchTable.GetBatchDebitTotalDBName(), ABatchTable.GetBatchControlTotalDBName()), CommonJoinString.JOIN_STRING_SQL_AND); } else //(FrbtAll.Checked) { } FFilterFindPanelObject.FilterPanelControls.SetBaseFilter(workingFilter, FrbtAll.Checked && showingAllPeriods); FPrevBaseFilter = workingFilter; AFilterString = workingFilter; StringHelper.JoinAndAppend(ref AFilterString, additionalFilter, CommonJoinString.JOIN_STRING_SQL_AND); FPrevFilter = AFilterString; }
/// <summary> /// update amount in other currencies (optional) and recalculate all totals for current batch and journal /// </summary> /// <param name="AUpdateLevel"></param> /// <param name="AUpdateTransDates"></param> public void UpdateTransactionTotals(TFrmGLBatch.eGLLevel AUpdateLevel = TFrmGLBatch.eGLLevel.Transaction, bool AUpdateTransDates = false) { bool OriginalSaveButtonState = false; bool TransactionRowActive = false; bool TransactionDataChanged = false; bool JournalDataChanged = false; int CurrentTransBatchNumber = 0; int CurrentTransJournalNumber = 0; int CurrentTransNumber = 0; decimal AmtCreditTotal = 0.0M; decimal AmtDebitTotal = 0.0M; decimal AmtCreditTotalBase = 0.0M; decimal AmtDebitTotalBase = 0.0M; decimal AmtInBaseCurrency = 0.0M; decimal AmtInIntlCurrency = 0.0M; string LedgerBaseCurrency = string.Empty; string LedgerIntlCurrency = string.Empty; decimal IntlRateToBaseCurrency = 0; bool IsTransactionInIntlCurrency = false; int LedgerNumber = 0; int CurrentBatchNumber = 0; int CurrentJournalNumber = 0; DataView JournalsToUpdateDV = null; DataView TransactionsToUpdateDV = null; bool BatchLevel = (AUpdateLevel == TFrmGLBatch.eGLLevel.Batch); bool JournalLevel = (AUpdateLevel == TFrmGLBatch.eGLLevel.Journal); bool TransLevel = (AUpdateLevel == TFrmGLBatch.eGLLevel.Transaction); if (AUpdateLevel == TFrmGLBatch.eGLLevel.Analysis) { TLogging.Log(String.Format("{0} called with wrong first argument!", Utilities.GetMethodSignature())); return; } ABatchRow CurrentBatchRow = GetBatchRow(); AJournalRow CurrentJournalRow = null; if (CurrentBatchRow == null) { return; } bool UnpostedBatch = CurrentBatchRow.BatchStatus == MFinanceConstants.BATCH_UNPOSTED; //Set inital values after confirming not null OriginalSaveButtonState = FPetraUtilsObject.HasChanges; LedgerBaseCurrency = FMainDS.ALedger[0].BaseCurrency; LedgerIntlCurrency = FMainDS.ALedger[0].IntlCurrency; LedgerNumber = CurrentBatchRow.LedgerNumber; CurrentBatchNumber = CurrentBatchRow.BatchNumber; JournalsToUpdateDV = new DataView(FMainDS.AJournal); TransactionsToUpdateDV = new DataView(FMainDS.ATransaction); //If called at the batch level, clear the current selections if (BatchLevel) { FPetraUtilsObject.SuppressChangeDetection = true; ClearCurrentSelection(); ((TFrmGLBatch) this.ParentForm).GetJournalsControl().ClearCurrentSelection(); FPetraUtilsObject.SuppressChangeDetection = false; //Ensure that when the Journal and Trans tab is opened, the data is reloaded. FBatchNumber = -1; ((TFrmGLBatch) this.ParentForm).GetJournalsControl().FBatchNumber = -1; } else { CurrentJournalRow = GetJournalRow(); CurrentJournalNumber = CurrentJournalRow.JournalNumber; } if (JournalLevel) { ClearCurrentSelection(); //Ensure that when the Trans tab is opened, the data is reloaded. FBatchNumber = -1; } else if (TransLevel && (FPreviouslySelectedDetailRow != null)) { TransactionRowActive = true; CurrentTransBatchNumber = FPreviouslySelectedDetailRow.BatchNumber; CurrentTransJournalNumber = FPreviouslySelectedDetailRow.JournalNumber; CurrentTransNumber = FPreviouslySelectedDetailRow.TransactionNumber; } //Get the corporate exchange rate ((TFrmGLBatch) this.ParentForm).WarnAboutMissingIntlExchangeRate = false; IntlRateToBaseCurrency = ((TFrmGLBatch) this.ParentForm).GetInternationalCurrencyExchangeRate(); if (!EnsureGLDataPresent(LedgerNumber, CurrentBatchNumber, CurrentJournalNumber, ref JournalsToUpdateDV, TransactionRowActive)) { //No transactions exist to process or corporate exchange rate not found return; } //Iterate through journals foreach (DataRowView drv in JournalsToUpdateDV) { GLBatchTDSAJournalRow jr = (GLBatchTDSAJournalRow)drv.Row; IsTransactionInIntlCurrency = (jr.TransactionCurrency == LedgerIntlCurrency); if (BatchLevel) { //Journal row is active if (jr.DateEffective != CurrentBatchRow.DateEffective) { jr.DateEffective = CurrentBatchRow.DateEffective; } } TransactionsToUpdateDV.RowFilter = String.Format("{0}={1} And {2}={3}", ATransactionTable.GetBatchNumberDBName(), jr.BatchNumber, ATransactionTable.GetJournalNumberDBName(), jr.JournalNumber); //If all rows deleted if (TransactionsToUpdateDV.Count == 0) { if ((txtCreditAmountBase.NumberValueDecimal != 0) || (txtCreditAmount.NumberValueDecimal != 0) || (txtDebitAmountBase.NumberValueDecimal != 0) || (txtDebitAmount.NumberValueDecimal != 0) || (txtCreditTotalAmount.NumberValueDecimal != 0) || (txtDebitTotalAmount.NumberValueDecimal != 0) || (txtCreditTotalAmountBase.NumberValueDecimal != 0) || (txtDebitTotalAmountBase.NumberValueDecimal != 0)) { txtCreditAmountBase.NumberValueDecimal = 0; txtCreditAmount.NumberValueDecimal = 0; txtDebitAmountBase.NumberValueDecimal = 0; txtDebitAmount.NumberValueDecimal = 0; txtCreditTotalAmount.NumberValueDecimal = 0; txtDebitTotalAmount.NumberValueDecimal = 0; txtCreditTotalAmountBase.NumberValueDecimal = 0; txtDebitTotalAmountBase.NumberValueDecimal = 0; } } // NOTE: AlanP changed this code in Feb 2015. Before that the code used the DataView directly. // We did a foreach on the DataView and modified the international currency amounts in the rows of the DataRowView. // Amazingly the effect of this was that each iteration of the loop took longer and longer. We had a set of 70 transactions // that we worked with and the first row took 50ms and then the times increased linearly until row 70 took 410ms! // Overall the 70 rows CONSISTENTLY took just over 15 seconds. But the scary thing was that if we had, say, 150 rows (which // would easily be possible), we would be looking at more than 1 minute to execute this loop. // So the code now converts the view to a Working Table, then operates on the data in that table and finally merges the // working table back into FMainDS. By doing this the time for the 70 rows goes from 15 seconds to 300ms. DataTable dtWork = TransactionsToUpdateDV.ToTable(); //Iterate through all transactions in Journal for (int i = dtWork.Rows.Count - 1; i >= 0; i--) { DataRow drWork = dtWork.Rows[i]; // Only if an unposted batch (this updates the database) if (UnpostedBatch) { TransactionDataChanged = false; drWork.BeginEdit(); bool IsCurrentActiveTransRow = (TransactionRowActive && Convert.ToInt32(drWork[ATransactionTable.ColumnTransactionNumberId]) == CurrentTransNumber && Convert.ToInt32(drWork[ATransactionTable.ColumnBatchNumberId]) == CurrentTransBatchNumber && Convert.ToInt32(drWork[ATransactionTable.ColumnJournalNumberId]) == CurrentTransJournalNumber); if (AUpdateTransDates && (Convert.ToDateTime(drWork[ATransactionTable.ColumnTransactionDateId]) != CurrentBatchRow.DateEffective)) { //TODO: add if drWork[ATransactionTable.ColumnTransactionDateId] = CurrentBatchRow.DateEffective; TransactionDataChanged = true; } if (IsCurrentActiveTransRow) { if (FPreviouslySelectedDetailRow.DebitCreditIndicator) { if ((txtCreditAmountBase.NumberValueDecimal != 0) || (txtCreditAmount.NumberValueDecimal != 0) || (FPreviouslySelectedDetailRow.TransactionAmount != Convert.ToDecimal(txtDebitAmount.NumberValueDecimal))) { txtCreditAmountBase.NumberValueDecimal = 0; txtCreditAmount.NumberValueDecimal = 0; FPreviouslySelectedDetailRow.TransactionAmount = Convert.ToDecimal(txtDebitAmount.NumberValueDecimal); } } else { if ((txtDebitAmountBase.NumberValueDecimal != 0) || (txtDebitAmount.NumberValueDecimal != 0) || (FPreviouslySelectedDetailRow.TransactionAmount != Convert.ToDecimal(txtCreditAmount.NumberValueDecimal))) { txtDebitAmountBase.NumberValueDecimal = 0; txtDebitAmount.NumberValueDecimal = 0; FPreviouslySelectedDetailRow.TransactionAmount = Convert.ToDecimal(txtCreditAmount.NumberValueDecimal); } } } // recalculate the amount in base currency if (jr.TransactionTypeCode != CommonAccountingTransactionTypesEnum.REVAL.ToString()) { //TODO: add if AmtInBaseCurrency = GLRoutines.Divide(Convert.ToDecimal( drWork[ATransactionTable.ColumnTransactionAmountId]), jr.ExchangeRateToBase); if (AmtInBaseCurrency != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId])) { //TODO: add if drWork[ATransactionTable.ColumnAmountInBaseCurrencyId] = AmtInBaseCurrency; TransactionDataChanged = true; } if (IsTransactionInIntlCurrency) { if (Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInIntlCurrencyId]) != Convert.ToDecimal(drWork[ATransactionTable.ColumnTransactionAmountId])) { drWork[ATransactionTable.ColumnAmountInIntlCurrencyId] = drWork[ATransactionTable.ColumnTransactionAmountId]; TransactionDataChanged = true; } } else { // TODO: Instead of hard coding the number of decimals to 2 (for US cent) it should come from the database. AmtInIntlCurrency = (IntlRateToBaseCurrency == 0) ? 0 : GLRoutines.Divide(Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]), IntlRateToBaseCurrency, 2); if (Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInIntlCurrencyId]) != AmtInIntlCurrency) { drWork[ATransactionTable.ColumnAmountInIntlCurrencyId] = AmtInIntlCurrency; TransactionDataChanged = true; } } } if (Convert.ToBoolean(drWork[ATransactionTable.ColumnDebitCreditIndicatorId]) == true) { AmtDebitTotal += Convert.ToDecimal(drWork[ATransactionTable.ColumnTransactionAmountId]); AmtDebitTotalBase += Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); if (IsCurrentActiveTransRow) { if ((FPreviouslySelectedDetailRow.AmountInBaseCurrency != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId])) || (FPreviouslySelectedDetailRow.AmountInIntlCurrency != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInIntlCurrencyId])) || (txtDebitAmountBase.NumberValueDecimal != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId])) || (txtCreditAmountBase.NumberValueDecimal != 0)) { FPreviouslySelectedDetailRow.AmountInBaseCurrency = Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); FPreviouslySelectedDetailRow.AmountInIntlCurrency = Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInIntlCurrencyId]); txtDebitAmountBase.NumberValueDecimal = Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); txtCreditAmountBase.NumberValueDecimal = 0; } } } else { AmtCreditTotal += Convert.ToDecimal(drWork[ATransactionTable.ColumnTransactionAmountId]); AmtCreditTotalBase += Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); if (IsCurrentActiveTransRow) { if ((FPreviouslySelectedDetailRow.AmountInBaseCurrency != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId])) || (FPreviouslySelectedDetailRow.AmountInIntlCurrency != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInIntlCurrencyId])) || (txtCreditAmountBase.NumberValueDecimal != Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId])) || (txtDebitAmountBase.NumberValueDecimal != 0)) { FPreviouslySelectedDetailRow.AmountInBaseCurrency = Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); FPreviouslySelectedDetailRow.AmountInIntlCurrency = Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInIntlCurrencyId]); txtCreditAmountBase.NumberValueDecimal = Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); txtDebitAmountBase.NumberValueDecimal = 0; } } } if (TransactionDataChanged == true) { drWork.EndEdit(); } else { drWork.CancelEdit(); drWork.Delete(); } } else // e.g. a posted batch { if (Convert.ToBoolean(drWork[ATransactionTable.ColumnDebitCreditIndicatorId]) == true) { AmtDebitTotal += Convert.ToDecimal(drWork[ATransactionTable.ColumnTransactionAmountId]); AmtDebitTotalBase += Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); } else { AmtCreditTotal += Convert.ToDecimal(drWork[ATransactionTable.ColumnTransactionAmountId]); AmtCreditTotalBase += Convert.ToDecimal(drWork[ATransactionTable.ColumnAmountInBaseCurrencyId]); } } } // Next transaction // only make changes if unposted if ((dtWork.Rows.Count > 0) && UnpostedBatch) { FMainDS.ATransaction.Merge(dtWork); JournalDataChanged = true; } if (TransactionRowActive && (jr.BatchNumber == CurrentTransBatchNumber) && (jr.JournalNumber == CurrentTransJournalNumber) && ((txtCreditTotalAmount.NumberValueDecimal != AmtCreditTotal) || (txtDebitTotalAmount.NumberValueDecimal != AmtDebitTotal) || (txtCreditTotalAmountBase.NumberValueDecimal != AmtCreditTotalBase) || (txtDebitTotalAmountBase.NumberValueDecimal != AmtDebitTotalBase))) { txtCreditTotalAmount.NumberValueDecimal = AmtCreditTotal; txtDebitTotalAmount.NumberValueDecimal = AmtDebitTotal; txtCreditTotalAmountBase.NumberValueDecimal = AmtCreditTotalBase; txtDebitTotalAmountBase.NumberValueDecimal = AmtDebitTotalBase; } } // next journal //Update totals of Batch if (UnpostedBatch) { GLRoutines.UpdateBatchTotals(ref FMainDS, ref CurrentBatchRow); } //In trans loading txtCreditTotalAmount.NumberValueDecimal = AmtCreditTotal; txtDebitTotalAmount.NumberValueDecimal = AmtDebitTotal; txtCreditTotalAmountBase.NumberValueDecimal = AmtCreditTotalBase; txtDebitTotalAmountBase.NumberValueDecimal = AmtDebitTotalBase; // refresh the currency symbols if (TransactionRowActive) { ShowDataManual(); } if (!JournalDataChanged && (OriginalSaveButtonState != FPetraUtilsObject.HasChanges)) { ((TFrmGLBatch)ParentForm).SaveChanges(); } else if (JournalDataChanged) { // Automatically save the changes to Totals?? // For now we will just enable the save button which will give the user a surprise! FPetraUtilsObject.SetChangedFlag(); } }
/// Open screen for importing Batches public static void LoadGLBatchesFormForImport(Form AParentForm, int ALedger) { TFrmGLBatch frmBatch = new TFrmGLBatch(AParentForm); frmBatch.LoadForImport = true; frmBatch.LedgerNumber = ALedger; frmBatch.Show(); }
public void TestCancelBatchBug121() { TFrmGLBatch frmBatch = new TFrmGLBatch(null); frmBatch.LedgerNumber = FLedgerNumber; frmBatch.Show(); // create a new batch and save ToolStripButtonTester btnSave = new ToolStripButtonTester("tbbSave"); ButtonTester btnNewBatch = new ButtonTester("ucoBatches.btnNew"); btnNewBatch.Click(); TextBoxTester txtDetailBatchDescription = new TextBoxTester("txtDetailBatchDescription"); txtDetailBatchDescription.Properties.Text = "Created by test TestCancelBatchBug121"; btnSave.Click(); // cancel that batch. no saving necessary ButtonTester btnCancelBatch = new ButtonTester("ucoBatches.btnCancel"); ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); Assert.AreEqual("Form Contains Invalid Data", tester.Title); // there is a second message box after confirming the cancellation, telling the user the cancellation was successful. // because the ModalFormHandler is reset after handling the first message box, we need to set up a new handler. ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { MessageBoxTester tester2 = new MessageBoxTester(hWnd2); // Assert.AreEqual("Success", tester.Title); tester2.SendCommand(MessageBoxTester.Command.Yes); }; tester.SendCommand(MessageBoxTester.Command.Yes); }; btnCancelBatch.Click(); // add a new batch btnNewBatch.Click(); txtDetailBatchDescription.Properties.Text = "Created by test TestCancelBatchBug121, not cancelled"; // save: the bug caused exception "Forgot to call AcceptChanges" btnSave.Click(); Assert.AreEqual(false, btnSave.Properties.Enabled, "Save button should be disabled because all changes have been saved"); }
public void TestImportExportGLBatch() { // create two test batches, with some strange figures, to test problem with double values // export the 2 test batches, with summarize option // compare the exported text file string TestFile = TAppSettingsManager.GetValue("Testing.Path") + "/MFinance/GLForm/TestData/BatchImportFloatTest.csv"; TestFile = Path.GetFullPath(TestFile); Assert.IsTrue(File.Exists(TestFile), "File does not exist: " + TestFile); TFrmGLBatch frmBatch = new TFrmGLBatch(null); frmBatch.LedgerNumber = FLedgerNumber; frmBatch.Show(); ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { OpenFileDialogTester tester = new OpenFileDialogTester(hWnd); ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { TDlgSelectCSVSeparatorTester tester2 = new TDlgSelectCSVSeparatorTester(hWnd2); TextBoxTester txtDateFormat = new TextBoxTester("txtDateFormat"); txtDateFormat.Properties.Text = "MM/dd/yyyy"; RadioButtonTester rbtSemicolon = new RadioButtonTester("rbtSemicolon"); rbtSemicolon.Properties.Checked = true; ButtonTester btnOK = new ButtonTester("btnOK", tester2.Properties.Name); btnOK.Click(); }; tester.OpenFile(TestFile); }; ToolStripButtonTester btnImport = new ToolStripButtonTester("tbbImportBatches"); btnImport.Click(); ToolStripButtonTester btnSave = new ToolStripButtonTester("tbbSave"); Assert.IsTrue(btnSave.Properties.Enabled, "Save button has not been activated"); btnSave.Click(); // go to Journal tab TabControlTester tabGLBatch = new TabControlTester("tabGLBatch"); tabGLBatch.SelectTab(1); TextBoxTester txtBatchNumber = new TextBoxTester("ucoJournals.txtBatchNumber"); // get the batch number from the journal tab int ImportedBatchNumber = Convert.ToInt32(txtBatchNumber.Properties.Text); TFrmGLBatchExport frmBatchExport = new TFrmGLBatchExport(null); frmBatch.Close(); // export that batch, summarize the transactions // compare the result with the expected file frmBatchExport.LedgerNumber = FLedgerNumber; frmBatchExport.Show(); CheckBoxTester chkIncludeUnposted = new CheckBoxTester("chkIncludeUnposted"); chkIncludeUnposted.Properties.Checked = true; RadioButtonTester rbtSummary = new RadioButtonTester("rbtSummary"); rbtSummary.Properties.Checked = false; RadioButtonTester rbtBatchNumberSelection = new RadioButtonTester("rbtBatchNumberSelection"); rbtBatchNumberSelection.Properties.Checked = true; TextBoxTester txtFilename = new TextBoxTester("txtFilename"); ToolStripButtonTester tbbExportBatches = new ToolStripButtonTester("tbbExportBatches"); TTxtNumericTextBoxTester txtBatchNumberStart = new TTxtNumericTextBoxTester("txtBatchNumberStart"); txtBatchNumberStart.Properties.NumberValueInt = ImportedBatchNumber; TTxtNumericTextBoxTester txtBatchNumberEnd = new TTxtNumericTextBoxTester("txtBatchNumberEnd"); txtBatchNumberEnd.Properties.NumberValueInt = ImportedBatchNumber; // Test simple export of batches, no summary TestFile = TAppSettingsManager.GetValue("Testing.Path") + "/MFinance/GLForm/TestData/BatchExportFloatTest.csv"; TestFile = Path.GetFullPath(TestFile); Assert.IsTrue(File.Exists(TestFile), "File does not exist: " + TestFile); txtFilename.Properties.Text = TestFile + ".new"; ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { MessageBoxTester tester2 = new MessageBoxTester(hWnd2); // Assert.AreEqual("Success", tester.Title); tester2.SendCommand(MessageBoxTester.Command.OK); }; tbbExportBatches.Click(); Assert.AreEqual(true, TTextFile.SameContent(TestFile, TestFile + ".new"), "the files should be the same: " + TestFile); System.IO.File.Delete(TestFile + ".new"); // Test export of batches, summarizing the transactions TestFile = TAppSettingsManager.GetValue("Testing.Path") + "/MFinance/GLForm/TestData/BatchExportFloatTestSummary.csv"; TestFile = Path.GetFullPath(TestFile); Assert.IsTrue(File.Exists(TestFile), "File does not exist: " + TestFile); txtFilename.Properties.Text = TestFile + ".new"; rbtSummary.Properties.Checked = true; ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { MessageBoxTester tester2 = new MessageBoxTester(hWnd2); // Assert.AreEqual("Success", tester.Title); tester2.SendCommand(MessageBoxTester.Command.OK); }; tbbExportBatches.Click(); Assert.AreEqual(true, TTextFile.SameContent(TestFile, TestFile + ".new"), "the files should be the same: " + TestFile); System.IO.File.Delete(TestFile + ".new"); frmBatchExport.Close(); }
public void TestImportGLTransactions() { // create a test batch and journal and then import transactions string TestFile = TAppSettingsManager.GetValue("Testing.Path") + "/MFinance/GLForm/TestData/TransactionsImport.csv"; TestFile = Path.GetFullPath(TestFile); Assert.IsTrue(File.Exists(TestFile), "File does not exist: " + TestFile); TFrmGLBatch frmBatch = new TFrmGLBatch(null); frmBatch.LedgerNumber = FLedgerNumber; frmBatch.Show(); // create a new batch and save ButtonTester btnNewBatch = new ButtonTester("ucoBatches.btnNew"); btnNewBatch.Click(); TextBoxTester txtDetailBatchDescription = new TextBoxTester("txtDetailBatchDescription"); txtDetailBatchDescription.Properties.Text = "Created by test TestImportGLTransactions"; TabControlTester tabGLBatch = new TabControlTester("tabGLBatch"); // go to Journal tab tabGLBatch.SelectTab(1); ButtonTester btnNewJournal = new ButtonTester("ucoJournals.btnAdd"); btnNewJournal.Click(); // go to transaction tab tabGLBatch.SelectTab(2); ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { OpenFileDialogTester tester = new OpenFileDialogTester(hWnd); ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { TDlgSelectCSVSeparatorTester tester2 = new TDlgSelectCSVSeparatorTester(hWnd2); TextBoxTester txtDateFormat = new TextBoxTester("txtDateFormat"); txtDateFormat.Properties.Text = "dd/MM/yyyy"; RadioButtonTester rbtSemicolon = new RadioButtonTester("rbtSemicolon"); rbtSemicolon.Properties.Checked = true; ButtonTester btnOK = new ButtonTester("btnOK", tester2.Properties.Name); btnOK.Click(); }; tester.OpenFile(TestFile); }; ToolStripButtonTester btnImport = new ToolStripButtonTester("tbbImportTransactions"); btnImport.Click(); TSgrdDataGridPagedTester grdDetails = new TSgrdDataGridPagedTester("grdDetails"); Assert.AreNotEqual(1, grdDetails.Count, "The grid should be populated"); }
public void TestImportGLBatch() { int NumberOfBatches = 0; string TestFile = TAppSettingsManager.GetValue("Testing.Path") + "/MFinance/GLForm/TestData/BatchImportFloatTest.csv"; TestFile = Path.GetFullPath(TestFile); Assert.IsTrue(File.Exists(TestFile), "File does not exist: " + TestFile); TFrmGLBatch frmBatch = new TFrmGLBatch(null); TFrmGLBatch frmBatch1 = new TFrmGLBatch(null); //Open the batch form and count no. of batches frmBatch.LedgerNumber = FLedgerNumber; frmBatch.Show(); TSgrdDataGridPagedTester grdDetails = new TSgrdDataGridPagedTester("grdDetails"); NumberOfBatches = grdDetails.Count - 1; TLogging.Log("NumberOfBatches: " + NumberOfBatches.ToString()); //Close the form frmBatch.Close(); ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { OpenFileDialogTester tester = new OpenFileDialogTester(hWnd); ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { TDlgSelectCSVSeparatorTester tester2 = new TDlgSelectCSVSeparatorTester(hWnd2); TextBoxTester txtDateFormat = new TextBoxTester("txtDateFormat"); txtDateFormat.Properties.Text = "MM/dd/yyyy"; RadioButtonTester rbtSemicolon = new RadioButtonTester("rbtSemicolon"); rbtSemicolon.Properties.Checked = true; ButtonTester btnOK = new ButtonTester("btnOK", tester2.Properties.Name); btnOK.Click(); }; tester.OpenFile(TestFile); }; //Set the batch form to open with importing batches dialog frmBatch1.LoadForImport = true; frmBatch1.LedgerNumber = FLedgerNumber; frmBatch1.Show(); TSgrdDataGridPagedTester grdDetails1 = new TSgrdDataGridPagedTester("grdDetails"); TLogging.Log("grdDetails.Count after import: " + grdDetails1.Count.ToString()); Assert.AreNotEqual(NumberOfBatches, grdDetails1.Count, "The grid should include imported batches"); frmBatch1.Close(); }
/// <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; }
public void TestViewPostedBatchTransactionsAndAddBatch() { //This test adds a new batch, saves and posts it, then views it and then tries to add a new batch TFrmGLBatch frmBatch = new TFrmGLBatch(null); frmBatch.LedgerNumber = FLedgerNumber; frmBatch.Show(); // create a new batch and save ButtonTester btnNewBatch = new ButtonTester("ucoBatches.btnNew"); btnNewBatch.Click(); TextBoxTester txtDetailBatchDescription = new TextBoxTester("txtDetailBatchDescription"); txtDetailBatchDescription.Properties.Text = "Created by test TestExportGLBatch"; TabControlTester tabGLBatch = new TabControlTester("tabGLBatch"); // go to Journal tab tabGLBatch.SelectTab(1); ButtonTester btnNewJournal = new ButtonTester("ucoJournals.btnAdd"); btnNewJournal.Click(); // go to transaction tab tabGLBatch.SelectTab(2); ButtonTester btnNewTransaction = new ButtonTester("ucoTransactions.btnNew"); btnNewTransaction.Click(); TextBoxTester txtDetailNarrative = new TextBoxTester("txtDetailNarrative"); txtDetailNarrative.Properties.Text = "test"; TextBoxTester txtDetailReference = new TextBoxTester("txtDetailReference"); txtDetailReference.Properties.Text = "test"; TTxtCurrencyTextBoxTester txtDebitAmount = new TTxtCurrencyTextBoxTester("txtDebitAmount"); decimal Amount = 1111.44M; txtDebitAmount.Properties.NumberValueDecimal = Amount; TCmbAutoPopulatedTester cmbDetailAccountCode = new TCmbAutoPopulatedTester("cmbDetailAccountCode"); cmbDetailAccountCode.Properties.SetSelectedString("6000"); TCmbAutoPopulatedTester cmbDetailCostCentreCode = new TCmbAutoPopulatedTester("cmbDetailCostCentreCode"); cmbDetailCostCentreCode.Properties.SetSelectedString(FLedgerNumber.ToString("00") + "00"); btnNewTransaction.Click(); txtDetailNarrative.Properties.Text = "test"; txtDetailReference.Properties.Text = "test"; TTxtCurrencyTextBoxTester txtCreditAmount = new TTxtCurrencyTextBoxTester("txtCreditAmount"); txtDebitAmount.Properties.NumberValueDecimal = 0; txtCreditAmount.Properties.Focus(); txtCreditAmount.Properties.NumberValueDecimal = Amount; cmbDetailAccountCode.Properties.SetSelectedString("0200"); cmbDetailCostCentreCode.Properties.SetSelectedString(FLedgerNumber.ToString("00") + "00"); //ToolStripButtonTester btnSave = new ToolStripButtonTester("tbbSave"); //btnSave.Click(); // post this batch ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); Assert.IsTrue(tester.Text.StartsWith( "Are you sure you want to post batch"), "Should start with 'are you sure you want to post batch', but is '" + tester.Text + "'"); // there is a second message box after posting, telling the user about success. // because the ModalFormHandler is reset after handling the first message box, we need to set up a new handler. ModalFormHandler = delegate(string name2, IntPtr hWnd2, Form form2) { MessageBoxTester tester2 = new MessageBoxTester(hWnd2); Assert.AreEqual("Success", tester2.Title); tester2.SendCommand(MessageBoxTester.Command.Yes); }; tester.SendCommand(MessageBoxTester.Command.Yes); }; // and now try to create a new batch, bug https://sourceforge.net/apps/mantisbt/openpetraorg/view.php?id=1058 // go to Batch tab tabGLBatch.SelectTab(0); ButtonTester btnPostBatch = new ButtonTester("ucoBatches.btnPostBatch"); btnPostBatch.Click(); //Make sure the grid is clear RadioButtonTester rbtPosting = new RadioButtonTester("rbtPosting"); rbtPosting.Properties.Checked = true; //This will then select the first batch in the grid which needs to be posted RadioButtonTester rbtAll = new RadioButtonTester("rbtAll"); rbtAll.Properties.Checked = true; //TabControlTester tabGLBatch = new TabControlTester("tabGLBatch"); // go to Journal tab tabGLBatch.SelectTab(1); // go to Transaction Tab tabGLBatch.SelectTab(2); // go to Batch Tab tabGLBatch.SelectTab(0); //ButtonTester btnNewBatch = new ButtonTester("ucoBatches.btnNew"); btnNewBatch.Click(); }