private void LookupExchangeRate(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate setupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal selectedExchangeRate;
            DateTime selectedEffectiveDate;
            int selectedEffectiveTime;

            if (setupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    DateTime.Now,
                    txtCurrency.Text,
                    1.0m,
                    out selectedExchangeRate,
                    out selectedEffectiveDate,
                    out selectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            txtExchangeRate.NumberValueDecimal = selectedExchangeRate;

            // Put the rate in our client-side cache
            if (FLedgerRow != null)
            {
                TExchangeRateCache.SetDailyExchangeRate(txtCurrency.Text, FLedgerRow.BaseCurrency, selectedEffectiveDate, selectedExchangeRate);
            }
        }
        private void LookupExchangeRate(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate setupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal selectedExchangeRate;
            DateTime selectedEffectiveDate;
            int selectedEffectiveTime;

            if (setupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    DateTime.Now,
                    txtCurrency.Text,
                    1.0m,
                    out selectedExchangeRate,
                    out selectedEffectiveDate,
                    out selectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            txtExchangeRate.NumberValueDecimal = selectedExchangeRate;
        }
Example #3
0
        public void SaveAndCancel()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Save and New buttons
            ToolStripButtonTester btnSave = new ToolStripButtonTester("tbbSave", mainScreen);
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;

            // Add new row, save and close
            btnNew.Click();
            txtExchangeRate.NumberValueDecimal = 10m;
            btnSave.Click();
            mainScreen.Close();

            // Create the screen a second time
            TFrmSetupDailyExchangeRate mainScreen2 = new TFrmSetupDailyExchangeRate(null);
            mainScreen2.Show();

            // make sure the data really got saved
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen2).Properties);
            Assert.AreEqual(3, grdDetails.Rows.Count);

            btnNew = new ButtonTester("btnNew", mainScreen2);
            txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen2)).Properties;

            // Add another row, but this time close without saving
            btnNew.Click();

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.No);
            };

            mainScreen2.Close();

            // Create the screen a third time
            TFrmSetupDailyExchangeRate mainScreen3 = new TFrmSetupDailyExchangeRate(null);
            mainScreen3.Show();

            // make sure the data did not get saved
            grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen3).Properties);
            Assert.AreEqual(3, grdDetails.Rows.Count);

            btnNew = new ButtonTester("btnNew", mainScreen3);
            txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen3)).Properties;

            // Add another row, but this time close AND save
            btnNew.Click();

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };

            mainScreen3.Close();

            // Create the screen a fourth time!
            TFrmSetupDailyExchangeRate mainScreen4 = new TFrmSetupDailyExchangeRate(null);
            mainScreen4.Show();

            // make sure the data was saved last time
            grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen4).Properties);
            Assert.AreEqual(5, grdDetails.Rows.Count);

            mainScreen4.Close();
        }
            public override void OnMouseUp(SourceGrid.CellContext sender, MouseEventArgs e)
            {
                base.OnMouseUp(sender, e);
                int iRow = sender.Position.Row - 1;

                if (iRow < 0)
                {
                    return;
                }

                TFrmSetupDailyExchangeRate frmExchangeRate = new TFrmSetupDailyExchangeRate(mainForm);

                decimal selectedExchangeRate;
                DateTime selectedEffectiveDate;
                int selectedEffectiveTime;

                if (frmExchangeRate.ShowDialog(
                        mainForm.FLedgerNumber,
                        dteStart,
                        dteEnd,
                        currencyExchangeList[iRow].Currency,
                        currencyExchangeList[iRow].mExchangeRate,
                        out selectedExchangeRate,
                        out selectedEffectiveDate,
                        out selectedEffectiveTime) != DialogResult.Cancel)
                {
                    currencyExchangeList[iRow].updateExchangeRate(selectedExchangeRate, selectedEffectiveDate);
                    sender.Grid.InvalidateRange(new SourceGrid.Range(sender.Position.Row, 1, sender.Position.Row, 4));
                }
            }
        private void SetExchangeRateValue(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate SetupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal SelectedExchangeRate;
            DateTime SelectedEffectiveDate;
            int SelectedEffectiveTime;

            string CurrencyCode = txtDetailTransactionCurrency.Text;

            if (SetupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    dtpEffectiveDate.Date.Value,
                    CurrencyCode,
                    DEFAULT_CURRENCY_EXCHANGE,
                    out SelectedExchangeRate,
                    out SelectedEffectiveDate,
                    out SelectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            if (SelectedExchangeRate > 0.0m)
            {
                FPreviouslySelectedDetailRow.ExchangeRateToBase = SelectedExchangeRate;
                txtDetailExchangeRateToBase.NumberValueDecimal = SelectedExchangeRate;
                SetRateForSameCurrency(CurrencyCode, SelectedExchangeRate, FPreviouslySelectedDetailRow.JournalNumber);
            }
        }
        public void ExchangeRateUsage()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardModalRows();
            FMainDS.SaveChanges();

            FGiftAndJournal.InitialiseData("load-data.sql");

            decimal selectedRate;
            DateTime selectedDate;
            int selectedTime;

            // Open the screen modally on our test ledger and a from currency of GBP
            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.ShowUsedRates();

            DialogBoxHandler = delegate(string name, IntPtr hWnd)
            {
                ExchangeRateUsageHandler();
            };

            DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER,
                FStandardEffectiveDate,
                "GBP",
                1.0m,
                out selectedRate,
                out selectedDate,
                out selectedTime);

            if (dlgResult == DialogResult.Abort)
            {
                Assert.Fail(FModalAssertResult);
            }

            Assert.AreEqual(DialogResult.OK, dlgResult);
        }
Example #7
0
        public void AddRowToEmptyTable()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties;
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;

            Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded");
            btnNew.Click();
            Assert.IsTrue(btnSave.Enabled, "The Save button should be enabled after adding a new row");

            // Work out our expectations
            string baseCurrency = GetDefaultBaseCurrency();
            string expectedFromCurrency = "USD";

            if (baseCurrency == "USD")
            {
                expectedFromCurrency = "GBP";
            }

            DateTime expectedDate = DateTime.Today;

            // Check the details panel after adding the new row
            Assert.AreEqual(expectedFromCurrency, cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(baseCurrency, cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal);

            // Set a valid exchange rate and save
            txtExchangeRate.NumberValueDecimal = 2.0m;
            mainScreen.SaveChanges();
            Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled after the new row has been saved");

            // Check the row count in the grid
            Assert.AreEqual(3, grdDetails.Rows.Count, "There should be 2 rows in the grid after saving a new row");

            // Even though an inverse row has been added we should still be highlighting the newly added row
            Assert.AreEqual(expectedFromCurrency, cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(baseCurrency, cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal);

            // Now select the inverese row
            SelectRowInGrid(2);

            // Check the details are, in fact, the inverse
            Assert.AreEqual(baseCurrency, cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(expectedFromCurrency, cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(0.5m, txtExchangeRate.NumberValueDecimal);

            mainScreen.Close();
        }
        public void LoadModalTableWithData()
        {
            // Initialse data
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardModalRows();
            FMainDS.SaveChanges();
            FLedgerDS.CreateTestLedger();

            decimal selectedRate;
            DateTime selectedDate;
            int selectedTime;

            // Open the screen modally on our test ledger and a from currency of GBP
            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);

            DialogBoxHandler = delegate(string name, IntPtr hWnd)
            {
                LoadModalTableHandler();
            };

            DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER,
                FStandardEffectiveDate,
                "GBP",
                1.0m,
                out selectedRate,
                out selectedDate,
                out selectedTime);

            if (dlgResult == DialogResult.Abort)
            {
                Assert.Fail(FModalAssertResult);
            }

            Assert.AreEqual(DialogResult.OK, dlgResult);
            Assert.AreEqual(new DateTime(1900, 7, 1), selectedDate);
            Assert.AreEqual(0.51m, selectedRate);
        }
Example #9
0
        public void LoadEmptyTable()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties;
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            CheckBox chkHideOthers = (new CheckBoxTester("chkHideOthers", mainScreen)).Properties;

            Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded");
            Assert.IsFalse(pnlDetails.Enabled, "The Details Panel should be disabled on initial load");
            Assert.IsFalse(dtpEffectiveDate.Date.HasValue, "The date control should be empty on initial load");

            Assert.AreEqual(1, grdDetails.Rows.Count, "The grid should be empty");

            mainScreen.Close();
        }
Example #10
0
        public void LoadTableContainingData()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Modal controls
            Button btnClose = (new ButtonTester("btnClose", FModalFormName)).Properties;
            Button btnCancel = (new ButtonTester("btnCancel", FModalFormName)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties;
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            CheckBox chkHideOthers = (new CheckBoxTester("chkHideOthers", mainScreen)).Properties;

            // Start of testing...
            Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded");
            Assert.IsTrue(pnlDetails.Enabled, "The Details Panel should be enabled on initial load");
            Assert.IsFalse(btnClose.Visible, "The Accept button should not be visible on a modeless form");
            Assert.IsFalse(btnCancel.Visible, "The Cancel but should not be visible on a modeless form");

            // Check the number of rows in the grid
            Assert.AreEqual(FAllRowCount + 1, grdDetails.Rows.Count);

            FCurrentDataId = Row2DataId(1);

            // Check the content of the details panel matches the last item in standard data (because sorting will have put it first)
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId),
                cmbFromCurrency.GetSelectedString(), "The From currency on row 1 should be {0}", EffectiveCurrency(FFromCurrencyId));
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId),
                cmbToCurrency.GetSelectedString(), "The To currency on row 1 should be {0}", EffectiveCurrency(FToCurrencyId));
            Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row 1 should be {0}", EffectiveDate().ToString());

            // Select the second row - which will be the last but one item of standard data
            SelectRowInGrid(2);

            // Check the details again for this row
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId),
                cmbFromCurrency.GetSelectedString(), "The From currency on row 2 should be {0}", EffectiveCurrency(FFromCurrencyId));
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId),
                cmbToCurrency.GetSelectedString(), "The To currency on row 2 should be {0}", EffectiveCurrency(FToCurrencyId));
            Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row 2 should be {0}", EffectiveDate().ToString());

            // Now hide the other currencies
            chkHideOthers.Checked = true;

            // The number of rows in the grid should have changed
            Assert.AreEqual(FHiddenRowCount + 1,
                grdDetails.Rows.Count,
                "The grid should have {0} rows when the checkbox is checked",
                FHiddenRowCount + 1);

            // But the details should still be the same
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId),
                cmbFromCurrency.GetSelectedString(), "The From currency on row 2 should be {0}", EffectiveCurrency(FFromCurrencyId));
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId),
                cmbToCurrency.GetSelectedString(), "The To currency on row 2 should be {0}", EffectiveCurrency(FToCurrencyId));
            Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row 2 should be {0}", EffectiveDate().ToString());
            Assert.IsFalse(cmbToCurrency.Enabled, "The To Currency should be disabled when the checkbox is checked");

            // Uncheck the box and select the last row
            chkHideOthers.Checked = false;
            SelectRowInGrid(FAllRowCount);

            // Check the details - should be the first item of standard data
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId),
                cmbFromCurrency.GetSelectedString(), "The From currency on row {0} should be {1}", FAllRowCount, EffectiveCurrency(FFromCurrencyId));
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId),
                cmbToCurrency.GetSelectedString(), "The To currency on row {0} should be {1}", FAllRowCount, EffectiveCurrency(FToCurrencyId));
            Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row {0} should be {1}", FAllRowCount,
                EffectiveDate().ToString());

            // Hide other To currencies again - now the selected row will have jumped higher
            chkHideOthers.Checked = true;
            Assert.AreEqual(FHiddenRowCount,
                mainScreen.GetSelectedRowIndex(), "When the checkbox is checked the selected row should be {0}", FHiddenRowCount);

            // But the details should again be the same as before the checkbox check
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId),
                cmbFromCurrency.GetSelectedString(), "The From currency on row {0} should be {1}", FHiddenRowCount, EffectiveCurrency(FFromCurrencyId));
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId),
                cmbToCurrency.GetSelectedString(), "The To currency on row {0} should be {1}", FHiddenRowCount, EffectiveCurrency(FToCurrencyId));
            Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row {0} should be {1}", FHiddenRowCount,
                EffectiveDate().ToString());

            mainScreen.Close();
        }
Example #11
0
        public void Validation()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;
            TextBox txtTimeEffective = (new TextBoxTester("txtDetailTimeEffectiveFrom", mainScreen)).Properties;

            btnNew.Click();

            string dlgText = String.Empty;
            bool dlgDisplayed = false;

            // Set up some bad entries
            // We already have an invalid rate (it will be 0.0)

            // Click the New button and discover what validation errors we have
            // Note - we do not put assert's inside the delegate because we want the dialog to close.
            //   If the dialog is left hanging this might do bad stuff to automated testing
            // Also note that dialogs with long text content get their text clipped in Tester.Text.
            // For that reason we are going to have to run three tests here instead of just one to do them all
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                dlgText = tester.Text;
                dlgDisplayed = true;
                tester.SendCommand(MessageBoxTester.Command.OK);
            };

            btnNew.Click();

            // Check that we did display the dialog and that we picked up the validation errors we predicted
            Assert.IsTrue(dlgDisplayed);
            Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_INVALIDNUMBER), dlgText);

            // Set up second bad entry
            txtExchangeRate.NumberValueDecimal = 2.0m;
            string prevDateText = dtpEffectiveDate.Text;
            dtpEffectiveDate.Text = "";
            dlgDisplayed = false;
            dlgText = String.Empty;

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                dlgText = tester.Text;
                dlgDisplayed = true;
                tester.SendCommand(MessageBoxTester.Command.OK);
            };

            btnNew.Click();

            Assert.IsTrue(dlgDisplayed);
            Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_NOUNDEFINEDDATE), dlgText);

            // Set up third bad entry
            dtpEffectiveDate.Text = prevDateText;
            txtTimeEffective.Text = "09:80";
            dlgDisplayed = false;
            dlgText = String.Empty;

            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                dlgText = tester.Text;
                dlgDisplayed = true;
                tester.SendCommand(MessageBoxTester.Command.OK);
            };

            btnNew.Click();

            Assert.IsTrue(dlgDisplayed);
            Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_INVALIDINTEGERTIME), dlgText);

            // Close without saving
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.No);
            };

            mainScreen.Close();
        }
            public override void OnClick(SourceGrid.CellContext sender, EventArgs e)
            {
                base.OnClick(sender, e);

                ++ix;
                System.Diagnostics.Debug.WriteLine(sender.Position.Row.ToString());

                int iRow = sender.Position.Row - 1;

                TFrmSetupDailyExchangeRate frmExchangeRate =
                    new TFrmSetupDailyExchangeRate(mainForm);

                decimal selectedExchangeRate;
                DateTime selectedEffectiveDate;
                int selectedEffectiveTime;

                if (frmExchangeRate.ShowDialog(
                        mainForm.FLedgerNumber,
                        dteStart,
                        dteEnd,
                        currencyExchangeList[iRow].Currency,
                        currencyExchangeList[iRow].ExchangeRate,
                        out selectedExchangeRate,
                        out selectedEffectiveDate,
                        out selectedEffectiveTime) == DialogResult.Cancel)
                {
                    return;
                }

                currencyExchangeList[iRow].updateExchangeRate(selectedExchangeRate);
            }
        private String GetListOfRevaluationCurrencies()
        {
            TFrmSetupDailyExchangeRate frmExchangeRate =
                new TFrmSetupDailyExchangeRate(this);

            DataTable table = TDataCache.TMFinance.GetCacheableFinanceTable(
                TCacheableFinanceTablesEnum.AccountList, FLedgerNumber);

            int ic = 0;
            String strRevaluationCurrencies = "";

            foreach (DataRow row in table.Rows)
            {
                bool blnIsLedger = (FLedgerNumber == (int)row["a_ledger_number_i"]);
                bool blnAccountActive = (bool)row["a_account_active_flag_l"];
                bool blnAccountForeign = (bool)row["a_foreign_currency_flag_l"];
                bool blnAccountHasPostings = (bool)row["a_posting_status_l"];

                if (blnIsLedger && blnAccountActive
                    && blnAccountForeign && blnAccountHasPostings)
                {
                    if (strRevaluationCurrencies == "")
                    {
                        strRevaluationCurrencies =
                            "[" + (string)row["a_foreign_currency_code_c"];
                    }
                    else
                    {
                        strRevaluationCurrencies = strRevaluationCurrencies +
                                                   "|" + (string)row["a_foreign_currency_code_c"];
                    }

                    string strCurrencyCode = (string)row["a_foreign_currency_code_c"];
                    decimal decExchangeRate = frmExchangeRate.GetLastExchangeValueOfInterval(FLedgerNumber,
                        FperiodStart, FperiodEnd, strCurrencyCode);
                    AddADataRow(ic, strCurrencyCode, decExchangeRate);
                    ++ic;
                }
            }

            if (strRevaluationCurrencies != "")
            {
                strRevaluationCurrencies = strRevaluationCurrencies + "]";
            }

            return strRevaluationCurrencies;
        }
        public void GetRateForDate()
        {
            // First test is with empty data
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();
            FLedgerDS.CreateTestLedger();

            // define our working date range
            DateTime dtStart = new DateTime(2000, 01, 01);
            DateTime dtEnd = new DateTime(2000, 12, 31);

            // First test is with empty data - should return 1.0m
            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            decimal result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP");
            Assert.AreEqual(1.0m, result, "The result should be 1.0m when the table contains no data");

            // Repeat test with data but outside the date range - again should return 1.0m
            FMainDS.InsertStandardModalRows();
            FMainDS.SaveChanges();

            mainScreen = new TFrmSetupDailyExchangeRate(null);
            result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP");
            Assert.AreEqual(1.0m, result, "The result should be 1.0m because there is no data in the date range");

            // Repeat again with data inside the range
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 1), 2.0m);
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 10), 2.05m);
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 30), 2.15m);           // This is the latest
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 20), 2.10m);
            FMainDS.SaveChanges();

            mainScreen = new TFrmSetupDailyExchangeRate(null);
            result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP");
            Assert.AreEqual(2.15m, result);
        }
Example #15
0
        public void AddRowToTable()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties;
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;
            TextBox txtTimeEffective = (new TextBoxTester("txtDetailTimeEffectiveFrom", mainScreen)).Properties;

            // Select the bottom row - when we get a new row it should be based on StandardData[1]
            SelectRowInGrid(FAllRowCount, 1);

            // Check that the controls are disabled.  But the exchange rate itself can be edited because the rows are unused.
            Assert.IsFalse(cmbFromCurrency.Enabled);
            Assert.IsFalse(cmbToCurrency.Enabled);
            Assert.IsFalse(dtpEffectiveDate.Enabled);
            Assert.IsTrue(txtExchangeRate.Enabled);
            Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded");

            // Click the 'New' button
            btnNew.Click();
            Assert.IsTrue(btnSave.Enabled, "The Save button should be enabled after adding a new row");
            Assert.IsTrue(cmbFromCurrency.Enabled);
            Assert.IsTrue(cmbToCurrency.Enabled);
            Assert.IsTrue(dtpEffectiveDate.Enabled);
            Assert.IsTrue(txtExchangeRate.Enabled);

            // The effective date should be 1st of current month
            DateTime expectedDate = DateTime.Today;

            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal.Value);

            // The row number of the new row should be at row 7
            Assert.AreEqual(FAllRowCount - 1, mainScreen.GetSelectedRowIndex());

            // Change the rate to a new value - more than 10% different
            decimal newRate = 0.667m;
            txtExchangeRate.NumberValueDecimal = newRate;

            // click the 'New' button again - this time the date should be the same but the time should be 7800
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.No);
            };
            btnNew.Click();

            string expectedTime = "02:10";

            // The details should be the same as before except for the new date and the rate being what we just set
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(expectedTime, txtTimeEffective.Text);
            Assert.AreEqual(newRate, txtExchangeRate.NumberValueDecimal.Value);
            Assert.AreEqual(FAllRowCount - 1, mainScreen.GetSelectedRowIndex());

            // Save the changes and check the number of rows now (we will get our rate alert warning dialog again)
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.No);
            };
            mainScreen.SaveChanges();
            Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled after the new row has been saved");
            Assert.AreEqual(13, grdDetails.Rows.Count, "There should be 12 rows in the grid after saving 2 new rows");

            mainScreen.Close();
        }
        public void LoadModalEmptyTable()
        {
            // Initialise data - create an empty table and our test ledger
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();
            FLedgerDS.CreateTestLedger();

            // variables to hold the dialog result output
            decimal selectedRate;
            DateTime selectedDate;
            int selectedTime;

            // Open the screen modally on our test ledger using a 'from' currency of GBP
            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);

            DialogBoxHandler = delegate(string name, IntPtr hWnd)
            {
                LoadModalEmptyTableHandler();
            };

            DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER,
                FStandardEffectiveDate,
                "GBP",
                1.0m,
                out selectedRate,
                out selectedDate,
                out selectedTime);

            // Check the result for any assertions
            if (dlgResult == DialogResult.Abort)
            {
                Assert.Fail(FModalAssertResult);
            }

            // Check we returned the correct data to the caller
            Assert.AreEqual(DialogResult.OK, dlgResult);
            Assert.AreEqual(STANDARD_RATE_OF_EXCHANGE, selectedRate);
            Assert.AreEqual(FStandardEffectiveDate, selectedDate);
            Assert.AreEqual(7200, selectedTime);

            // Check we did also save the result
            FMainDS.LoadAll();
            ADailyExchangeRateRow row =
                (ADailyExchangeRateRow)FMainDS.ADailyExchangeRate.Rows.Find(new object[] { "GBP", STANDARD_TEST_CURRENCY, FStandardEffectiveDate,
                                                                                           7200 });
            Assert.IsNotNull(row, "The selected exchange rate was not saved");
            Assert.AreEqual(STANDARD_RATE_OF_EXCHANGE, row.RateOfExchange);
        }
Example #17
0
        public void AddRowFromCorporateToEmptyTable()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            // Work out our currency expectations
            string baseCurrency = GetDefaultBaseCurrency();
            string expectedFromCurrency = "USD";

            if (baseCurrency == "USD")
            {
                expectedFromCurrency = "GBP";
            }

            // Create a corporate rate valid from yesterday
            FCorporateDS.CreateCorporateRate(expectedFromCurrency, baseCurrency, DateTime.Today.AddDays(-1), 2.0m);

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Controls
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;

            // Create a new row
            btnNew.Click();

            Assert.AreEqual(expectedFromCurrency, cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(baseCurrency, cmbToCurrency.GetSelectedString());
            Assert.AreEqual(DateTime.Today, dtpEffectiveDate.Date);
            Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal, "The rate should be the rate from the corporate excahnge rate table");

            // change the date to an earlier date - the rate hould revert to 0.0,
            dtpEffectiveDate.Focus();
            dtpEffectiveDate.Date = DateTime.Today.AddYears(-1);
            txtExchangeRate.Focus();
            Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal, "After changing the date the rate should now be 0.0m");
        }
        public void ModalValidation()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();
            FLedgerDS.CreateTestLedger();

            decimal selectedRate;
            DateTime selectedDate;
            int selectedTime;

            // Open the screen modally on our test ledger and a from currency of GBP
            // This test sets up a date range
            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);

            DialogBoxHandler = delegate(string name, IntPtr hWnd)
            {
                ModalValidationHandler();
            };

            DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER, FStandardEffectiveDate.AddDays(
                    -10), FStandardEffectiveDate, "GBP", 1.0m, out selectedRate, out selectedDate, out selectedTime);

            if (dlgResult == DialogResult.Abort)
            {
                Assert.Fail(FModalAssertResult);
            }

            // Make sure we did save
            Assert.AreEqual(DialogResult.OK, dlgResult);
            Assert.IsFalse((new ToolStripButtonTester("tbbSave", mainScreen)).Properties.Enabled);
            FMainDS.LoadAll();
            Assert.AreEqual(2, FMainDS.ADailyExchangeRate.Rows.Count, "The data table should have 2 rows after a successful save operation");
        }
Example #19
0
        public void AddRowFromCorporate()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            // Create a corporate rate valid from yesterday
            FCorporateDS.CreateCorporateRate("GBP", "USD", DateTime.Today.AddDays(-1), 0.515m);

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Controls
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;

            mainScreen.ShowUnusedRates();

            // Create a new row based on the last row
            SelectRowInGrid(8);
            btnNew.Click();

            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString());
            Assert.AreEqual(DateTime.Today, dtpEffectiveDate.Date);
            Assert.AreEqual(0.515m, txtExchangeRate.NumberValueDecimal, "The rate should be the rate from the corporate exchange rate table");

            // change the date to an earlier date - the rate hould revert to the prior daily rate,
            dtpEffectiveDate.Focus();
            dtpEffectiveDate.Date = DateTime.Today.AddYears(-1);
            txtExchangeRate.Focus();
            Assert.AreEqual(StandardData[Row2DataId(
                                             7),
                                         FRateOfExchangeId], txtExchangeRate.NumberValueDecimal,
                "After changing the date the rate should now be based on previous daily rates");
        }
        private void LookupExchangeRate(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate setupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal selectedExchangeRate;
            DateTime selectedEffectiveDate;
            int selectedEffectiveTime;

            if (setupDailyExchangeRate.ShowDialog(
                    FDocumentLedgerNumber,
                    DateTime.Now,
                    txtSupplierCurrency.Text,
                    1.0m,
                    out selectedExchangeRate,
                    out selectedEffectiveDate,
                    out selectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            if (txtExchangeRateToBase.NumberValueDecimal != selectedExchangeRate)
            {
                //Enforce save needed condition
                FPetraUtilsObject.SetChangedFlag();
            }

            txtExchangeRateToBase.NumberValueDecimal = selectedExchangeRate;
        }
Example #21
0
        public void EditRow()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties;
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;
            TextBox txtTimeEffective = (new TextBoxTester("txtDetailTimeEffectiveFrom", mainScreen)).Properties;

            // Select the first row in the grid.  New rows should be based on data row 5
            SelectRowInGrid(1, 5);

            // Add three rows
            btnNew.Click();
            btnNew.Click();
            btnNew.Click();

            DateTime expectedDate = DateTime.Today;
            string expectedT1 = "02:00";
            //string expectedT2 = "02:10";
            string expectedT3 = "02:20";

            // Check the data first
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(expectedT3, txtTimeEffective.Text);
            Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal.Value);
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // Focus on the from currency, then change it to 'BEF'
            cmbFromCurrency.Focus();
            cmbFromCurrency.SetSelectedString(STANDARD_TEST_CURRENCY);
            cmbToCurrency.Focus();

            // Now check the date and rate.  Time should be back to O2:00 and rate should be 0.00 because this currency has never been used
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value);
            Assert.AreEqual(expectedT1, txtTimeEffective.Text);
            Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual(1, mainScreen.GetSelectedRowIndex());

            // Reset the currency and confirm we go back to where we were
            cmbFromCurrency.Focus();
            cmbFromCurrency.SetSelectedString(EffectiveCurrency(FFromCurrencyId));
            cmbToCurrency.Focus();

            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value);
            Assert.AreEqual(expectedT3, txtTimeEffective.Text);
            Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // Repeat for the To currency
            cmbToCurrency.Focus();
            cmbToCurrency.SetSelectedString(STANDARD_TEST_CURRENCY);
            dtpEffectiveDate.Focus();

            // Now check the date and rate.  Date should be back to this month and rate should be 0.00 because this currency has never been used
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value);
            Assert.AreEqual(expectedT1, txtTimeEffective.Text);
            Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual(1, mainScreen.GetSelectedRowIndex());

            // Reset the currency and confirm we go back to where we were
            cmbToCurrency.Focus();
            cmbToCurrency.SetSelectedString(EffectiveCurrency(FToCurrencyId));
            dtpEffectiveDate.Focus();

            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value);
            Assert.AreEqual(expectedT3, txtTimeEffective.Text);
            Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // Finally check what happens when editing the date
            SelectRowInGrid(5);
            txtExchangeRate.NumberValueDecimal = 1.95m;             // 02:00 today
            FixUnvalidatedChanges();
            SelectRowInGrid(4);
            txtExchangeRate.NumberValueDecimal = 1.96m;
            dtpEffectiveDate.Date = DateTime.Today.AddDays(1);      // 02.00 tomorrow
            FixUnvalidatedChanges();
            SelectRowInGrid(3);
            txtExchangeRate.NumberValueDecimal = 1.97m;
            dtpEffectiveDate.Date = DateTime.Today.AddDays(2);     // 02:00 next day
            FixUnvalidatedChanges();

            SelectRowInGrid(5);
            Assert.AreEqual(1.95m, txtExchangeRate.NumberValueDecimal);
            dtpEffectiveDate.Focus();
            dtpEffectiveDate.Date = DateTime.Today.AddDays(10);
            grdDetails.Focus();
            Assert.AreEqual(1.97m, txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual("02:00", txtTimeEffective.Text);

            mainScreen.SaveChanges();
            mainScreen.Close();
        }
        private void SetExchangeRateValue(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate SetupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal SelectedExchangeRate;
            DateTime SelectedEffectiveDate;
            int SelectedEffectiveTime;

            if (SetupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    dtpDetailDateEffective.Date.HasValue ? dtpDetailDateEffective.Date.Value : DateTime.Today,
                    cmbDetailTransactionCurrency.GetSelectedString(),
                    DEFAULT_CURRENCY_EXCHANGE,
                    out SelectedExchangeRate,
                    out SelectedEffectiveDate,
                    out SelectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            if (FPreviouslySelectedDetailRow.ExchangeRateToBase != SelectedExchangeRate)
            {
                //Enforce save needed condition
                FPetraUtilsObject.SetChangedFlag();
            }

            FPreviouslySelectedDetailRow.ExchangeRateToBase = SelectedExchangeRate;

            RefreshCurrencyAndExchangeRate();
        }
Example #23
0
        public void DeleteRows()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButtonTester btnSaveTester = new ToolStripButtonTester("tbbSave", mainScreen);
            ButtonWithFocusTester btnNewTester = new ButtonWithFocusTester("btnNew", mainScreen);
            ButtonWithFocusTester btnDeleteTester = new ButtonWithFocusTester("btnDelete", mainScreen);
            //ButtonWithFocusTester btnEnableEdit = new ButtonWithFocusTester("btnEnableEdit", mainScreen);
            TSgrdDataGridPagedTester grdTester = new TSgrdDataGridPagedTester("grdDetails", mainScreen);
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)grdTester.Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;
            TtxtPetraDate txtDateEffective = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;

            // All rows in grid should be deletable because they are unused
            Assert.AreEqual(9, grdDetails.Rows.Count);
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);

            // Create 3 new rows
            btnNewTester.Click();
            btnNewTester.Click();
            btnNewTester.Click();

            Assert.AreEqual(12, grdDetails.Rows.Count);
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // New rows should be deletable
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();

            Assert.IsFalse(cmbFromCurrency.Enabled);
            Assert.IsFalse(cmbToCurrency.Enabled);
            Assert.IsFalse(txtDateEffective.Enabled);
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);

            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // Now we should be back to being able to delete a unused row
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            Assert.AreEqual(9, grdDetails.Rows.Count);
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);

            // Activate deletion of saved rows
            //btnEnableEdit.Click();
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);

            // Now we should be able to delete the row we could not delete before
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);

            // Change to the first row
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);
            SelectRowInGrid(1);
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);
            Assert.AreEqual(1, mainScreen.GetSelectedRowIndex());

            // So now we should have our 2 rows far in the future at the top which are not used anywhere
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();
            Assert.IsTrue(txtDateEffective.Date.Value.Year < 1910 || txtDateEffective.Date.Value.Year > 2980);

            // Should still be on row 1 with 7 grid rows now that 2 have gone
            Assert.AreEqual(1, mainScreen.GetSelectedRowIndex());
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            Assert.AreEqual(7, grdDetails.Rows.Count);

            // Delete rows starting at the bottom
            SelectRowInGrid(6);
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();
            ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
            {
                MessageBoxTester tester = new MessageBoxTester(hWnd);
                tester.SendCommand(MessageBoxTester.Command.Yes);
            };
            btnDeleteTester.Click();

            Assert.AreEqual(4, mainScreen.GetSelectedRowIndex());
            Assert.IsTrue(btnDeleteTester.Properties.Enabled);
            Assert.AreEqual(5, grdDetails.Rows.Count);

            // Save the new settings - deleting does not remove inverse rows when saved
            Assert.IsTrue(btnSaveTester.Properties.Enabled);
            btnSaveTester.Click();
            Assert.IsFalse(btnSaveTester.Properties.Enabled);
            Assert.AreEqual(5, grdDetails.Rows.Count);
        }
        private void SetExchangeRateValue(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate setupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal selectedExchangeRate;
            DateTime selectedEffectiveDate;
            int selectedEffectiveTime;

            if (setupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    dtpEffectiveDate.Date.Value,
                    txtCurrencyCodeFrom.Text,
                    DEFAULT_CURRENCY_EXCHANGE,
                    out selectedExchangeRate,
                    out selectedEffectiveDate,
                    out selectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            FExchangeRateToBase = selectedExchangeRate;
            txtExchangeRateToBase.Text = FExchangeRateToBase.ToString();
        }
Example #25
0
        public void InvertRate()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            mainScreen.Show();
            mainScreen.ShowUnusedRates();

            // Toolstrip
            ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties;

            // Grid
            TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties;

            // Panel and controls
            Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties;
            ButtonTester btnNew = new ButtonTester("btnNew", mainScreen);
            TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties;
            TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties;
            TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties;
            TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties;
            ButtonTester btnInvert = new ButtonTester("btnInvertExchangeRate", mainScreen);

            // Select the first row in the grid.  New rows should be based on data row 5
            SelectRowInGrid(1, 5);

            // Check that Invert is enabled, then add one new row and check it is also enabled
            Assert.IsTrue(btnInvert.Properties.Enabled);
            btnNew.Click();
            Assert.IsTrue(btnInvert.Properties.Enabled);
            txtExchangeRate.NumberValueDecimal = 2.0m;
            btnInvert.Click();
            Assert.AreEqual(0.5m, txtExchangeRate.NumberValueDecimal);
            btnInvert.Click();
            Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal);

            mainScreen.SaveChanges();
            mainScreen.Close();
        }
        private void SetExchangeRateValue(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate setupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal selectedExchangeRate;
            DateTime selectedEffectiveDate;
            int selectedEffectiveTime;

            if (setupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    dtpDetailGlEffectiveDate.Date.Value,
                    cmbDetailCurrencyCode.GetSelectedString(),
                    (txtDetailExchangeRateToBase.NumberValueDecimal == null) ? 0.0m : txtDetailExchangeRateToBase.NumberValueDecimal.Value,
                    out selectedExchangeRate,
                    out selectedEffectiveDate,
                    out selectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            if (FPreviouslySelectedDetailRow.ExchangeRateToBase != selectedExchangeRate)
            {
                FPreviouslySelectedDetailRow.ExchangeRateToBase = selectedExchangeRate;

                RefreshCurrencyAndExchangeRateControls();
                RecalculateTransactionAmounts(selectedExchangeRate);

                FPetraUtilsObject.VerificationResultCollection.Clear();
            }
        }
        private void SetExchangeRateValue(Object sender, EventArgs e)
        {
            TFrmSetupDailyExchangeRate setupDailyExchangeRate =
                new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm());

            decimal selectedExchangeRate;
            DateTime selectedEffectiveDate;
            int selectedEffectiveTime;

            if (setupDailyExchangeRate.ShowDialog(
                    FLedgerNumber,
                    dtpDetailGlEffectiveDate.Date.Value,
                    cmbDetailCurrencyCode.GetSelectedString(),
                    DEFAULT_CURRENCY_EXCHANGE,
                    out selectedExchangeRate,
                    out selectedEffectiveDate,
                    out selectedEffectiveTime) == DialogResult.Cancel)
            {
                return;
            }

            if (FPreviouslySelectedDetailRow.ExchangeRateToBase != selectedExchangeRate)
            {
                FPreviouslySelectedDetailRow.ExchangeRateToBase = selectedExchangeRate;
                RecalculateTransactionAmounts(selectedExchangeRate);

                //Enforce save needed condition
                FPetraUtilsObject.SetChangedFlag();
            }

            RefreshCurrencyAndExchangeRateControls();
        }