Ejemplo n.º 1
0
        /// <summary>
        /// Handler for ModalEmptyTable test
        /// </summary>
        public void LoadModalEmptyTableHandler()
        {
            // Controls
            ButtonTester btnNewTester    = new ButtonTester("btnNew", FModalFormName);
            ButtonTester btnCloseTester  = new ButtonTester("btnClose", FModalFormName);
            ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName);

            Button             btnNew            = btnNewTester.Properties;
            Button             btnClose          = btnCloseTester.Properties;
            Button             btnDelete         = (new ButtonTester("btnDelete", FModalFormName)).Properties;
            TSgrdDataGrid      grdDetails        = (TSgrdDataGrid)((new TSgrdDataGridPagedTester("grdDetails", FModalFormName)).Properties);
            Panel              pnlDetails        = (new PanelTester("pnlDetails", FModalFormName)).Properties;
            TCmbAutoPopulated  cmbFromCurrency   = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", FModalFormName)).Properties;
            TCmbAutoPopulated  cmbToCurrency     = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", FModalFormName)).Properties;
            TtxtPetraDate      dtpDateEffective  = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties;
            TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties;

            // These should be the states on an empty modal screen (as loaded)
            try
            {
                Assert.IsFalse(btnClose.Enabled);
                Assert.IsFalse(btnDelete.Enabled);
                Assert.IsFalse(dtpDateEffective.Date.HasValue);
                Assert.IsFalse(pnlDetails.Enabled);
                Assert.AreEqual(1, grdDetails.Rows.Count);

                // Now create a new row
                btnNewTester.Click();

                // These should be the states after adding a new row
                Assert.AreEqual("GBP", cmbFromCurrency.GetSelectedString());                    // GBP passed in as a ShowDialog parameter
                Assert.AreEqual(STANDARD_TEST_CURRENCY, cmbToCurrency.GetSelectedString());
                Assert.AreEqual(FStandardEffectiveDate, dtpDateEffective.Date);
                Assert.IsFalse(cmbFromCurrency.Enabled);
                Assert.IsFalse(cmbToCurrency.Enabled);
                Assert.IsTrue(btnClose.Enabled);
                Assert.IsTrue(btnDelete.Enabled);
                Assert.IsTrue(pnlDetails.Enabled);
                Assert.AreEqual(2, grdDetails.Rows.Count);

                // Rate should be 0.0m - we will need to set it to something else
                Assert.AreEqual(0.0m, txtRateOfExchange.NumberValueDecimal);
                txtRateOfExchange.NumberValueDecimal = STANDARD_RATE_OF_EXCHANGE;

                // Save this as our rate and quit
                btnCloseTester.Click();
            }
            catch (Exception ex)
            {
                // Handle the exception and abort without saving
                HandleModalException(ex);
                btnCancelTester.Properties.DialogResult = DialogResult.Abort;
                btnCancelTester.Click();
            }
        }
Ejemplo n.º 2
0
        public void Validation()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            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;

            btnNew.Click();

            // Set up some bad entries
            dtpEffectiveDate.Text = "";
            txtExchangeRate.NumberValueDecimal = 0.0m;

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

            // 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
            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_NOUNDEFINEDDATE));
            Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_INVALIDNUMBER));

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

            mainScreen.Close();
        }
Ejemplo n.º 3
0
        public void InvertRate()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            // 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 enabled and test that it works
            btnNew.Click();
            Assert.IsTrue(btnInvert.Properties.Enabled);
            txtExchangeRate.NumberValueDecimal = 5.0m;
            btnInvert.Click();
            Assert.AreEqual(0.2m, txtExchangeRate.NumberValueDecimal);
            btnInvert.Click();
            Assert.AreEqual(5.0m, txtExchangeRate.NumberValueDecimal);

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

            mainScreen.SaveChanges();
            mainScreen.Close();
        }
Ejemplo n.º 4
0
        public void TestDoubleValues()
        {
            // See IMPORTANT NOTE at the top of this file
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            TTxtNumericTextBox txtBox = new TTxtNumericTextBox();

            txtBox.ControlMode   = TTxtNumericTextBox.TNumericTextBoxMode.Decimal;
            txtBox.DecimalPlaces = 2;

            txtBox.NumberValueDouble = 1410.95;
            Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in british culture");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            txtBox.Culture           = Thread.CurrentThread.CurrentCulture;
            txtBox.NumberValueDouble = 0.0;
            txtBox.NumberValueDouble = 1410.95;
            Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in german culture, switching culture, same txt object");
            Assert.AreEqual("1.410,95",
                            txtBox.Text,
                            "After changing Culture, so decimal text should be formatted according to new culture.");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            TTxtNumericTextBox txtDEBox = new TTxtNumericTextBox();

            txtDEBox.ControlMode       = TTxtNumericTextBox.TNumericTextBoxMode.Decimal;
            txtDEBox.DecimalPlaces     = 2;
            txtDEBox.NumberValueDouble = 0.0;
            txtDEBox.NumberValueDouble = 1410.95;
            Assert.AreEqual("1.410,95", txtDEBox.Text, "text value stored in german culture");
            Assert.AreEqual(1410.95, txtDEBox.NumberValueDouble, "double value stored in german culture");
            txtDEBox.NumberValueDouble = 1234410.95;
            Assert.AreEqual("1.234.410,95", txtDEBox.Text, "huge number text value stored in german culture");

            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            txtBox.NumberValueDouble = 0.0;
            txtBox.NumberValueDouble = 30.00;
            Assert.AreEqual(30.00, txtBox.NumberValueDouble, "double value stored in english culture, with english UI");

            Thread.CurrentThread.CurrentCulture   = new CultureInfo("de-DE");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            txtBox.NumberValueDouble = 0.0;
            txtBox.NumberValueDouble = 1410.95;
            Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in german culture, but english UI");
        }
Ejemplo n.º 5
0
        public void TestDoubleValues()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            TTxtNumericTextBox txtBox = new TTxtNumericTextBox();

            txtBox.ControlMode   = TTxtNumericTextBox.TNumericTextBoxMode.Decimal;
            txtBox.DecimalPlaces = 2;

            txtBox.NumberValueDouble = 1410.95;
            Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in british culture");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            txtBox.NumberValueDouble            = 0.0;
            txtBox.NumberValueDouble            = 1410.95;
            Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in german culture, switching culture, same txt object");
            Assert.AreEqual("1,410.95",
                            txtBox.Text,
                            "text value stored in german culture, switching culture, same txt object, therefore still british format");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            TTxtNumericTextBox txtDEBox = new TTxtNumericTextBox();

            txtDEBox.ControlMode       = TTxtNumericTextBox.TNumericTextBoxMode.Decimal;
            txtDEBox.DecimalPlaces     = 2;
            txtDEBox.NumberValueDouble = 0.0;
            txtDEBox.NumberValueDouble = 1410.95;
            Assert.AreEqual("1.410,95", txtDEBox.Text, "text value stored in german culture");
            Assert.AreEqual(1410.95, txtDEBox.NumberValueDouble, "double value stored in german culture");
            txtDEBox.NumberValueDouble = 1234410.95;
            Assert.AreEqual("1.234.410,95", txtDEBox.Text, "huge number text value stored in german culture");

            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            txtBox.NumberValueDouble = 0.0;
            txtBox.NumberValueDouble = 30.00;
            Assert.AreEqual(30.00, txtBox.NumberValueDouble, "double value stored in english culture, with english UI");

            Thread.CurrentThread.CurrentCulture   = new CultureInfo("de-DE");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            txtBox.NumberValueDouble = 0.0;
            txtBox.NumberValueDouble = 1410.95;
            Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in german culture, but english UI");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handler for LoadModalTableWithData test
        /// </summary>
        public void LoadModalTableHandler()
        {
            // Controls
            ButtonTester btnCloseTester  = new ButtonTester("btnClose", FModalFormName);
            ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName);

            Button             btnClose          = btnCloseTester.Properties;
            Button             btnDelete         = (new ButtonTester("btnDelete", FModalFormName)).Properties;
            TSgrdDataGrid      grdDetails        = (TSgrdDataGrid)((new TSgrdDataGridPagedTester("grdDetails", FModalFormName)).Properties);
            Panel              pnlDetails        = (new PanelTester("pnlDetails", FModalFormName)).Properties;
            TCmbAutoPopulated  cmbFromCurrency   = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", FModalFormName)).Properties;
            TCmbAutoPopulated  cmbToCurrency     = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", FModalFormName)).Properties;
            TtxtPetraDate      dtpDateEffective  = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties;
            TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties;

            // These should be the states given the standard modal data we loaded
            try
            {
                Assert.AreEqual("GBP", cmbFromCurrency.GetSelectedString());                    // GBP passed in as a ShowDialog parameter
                Assert.AreEqual(STANDARD_TEST_CURRENCY, cmbToCurrency.GetSelectedString());     // The ledger currency for the ledger passed in as parameter
                Assert.AreEqual(new DateTime(1900, 7, 1), dtpDateEffective.Date);
                Assert.AreEqual(0.51m, txtRateOfExchange.NumberValueDecimal);
                Assert.IsFalse(cmbFromCurrency.Enabled);
                Assert.IsFalse(cmbToCurrency.Enabled);
                Assert.IsTrue(btnClose.Enabled);
                Assert.IsTrue(btnClose.Visible);
                Assert.IsTrue(btnCancelTester.Properties.Visible);
                Assert.IsTrue(btnDelete.Enabled);
                Assert.IsTrue(pnlDetails.Enabled);
                Assert.AreEqual(3, grdDetails.Rows.Count);

                // select this item and close
                btnCloseTester.Click();
            }
            catch (Exception ex)
            {
                // Handle the exception and abort without saving
                HandleModalException(ex);
                btnCancelTester.Properties.DialogResult = DialogResult.Abort;
                btnCancelTester.Click();
            }
        }
Ejemplo n.º 7
0
        public void TestIntegerValues()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            TTxtNumericTextBox txtBox = new TTxtNumericTextBox();

            txtBox.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer;

            txtBox.NumberValueInt = 1410;
            Assert.AreEqual(1410, txtBox.NumberValueInt, "integer value stored in british culture");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            txtBox.NumberValueInt = 0;
            txtBox.NumberValueInt = 1410;
            Assert.AreEqual(1410, txtBox.NumberValueInt, "integer value stored in german culture, switching culture, same txt object");
            Assert.AreEqual("1410",
                            txtBox.Text,
                            "text value stored in german culture, switching culture, same txt object, therefore still british format");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
            TTxtNumericTextBox txtDEBox = new TTxtNumericTextBox();

            txtDEBox.ControlMode    = TTxtNumericTextBox.TNumericTextBoxMode.Integer;
            txtDEBox.NumberValueInt = 0;
            txtDEBox.NumberValueInt = 1410;
            Assert.AreEqual("1410", txtDEBox.Text, "text value stored in german culture");
            Assert.AreEqual(1410, txtDEBox.NumberValueInt, "integer value stored in german culture");
            txtDEBox.NumberValueInt = 1234410;
            Assert.AreEqual("1234410", txtDEBox.Text, "huge number text value stored in german culture");

            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            txtBox.NumberValueInt = 0;
            txtBox.NumberValueInt = 30;
            Assert.AreEqual(30, txtBox.NumberValueInt, "integer value stored in english culture, with english UI");

            Thread.CurrentThread.CurrentCulture   = new CultureInfo("de-DE");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            txtBox.NumberValueInt = 0;
            txtBox.NumberValueInt = 1410;
            Assert.AreEqual(1410, txtBox.NumberValueInt, "integer value stored in german culture, but english UI");
        }
Ejemplo n.º 8
0
        private void HashTotalChanged(object sender, EventArgs e)
        {
            TTxtNumericTextBox txn = (TTxtNumericTextBox)sender;

            if (txn.NumberValueDecimal == null)
            {
                return;
            }

            Decimal HashTotal = Convert.ToDecimal(txtDetailHashTotal.NumberValueDecimal);
            Form    p         = ParentForm;

            if (p != null)
            {
                TUC_RecurringGiftTransactions t = ((TFrmRecurringGiftBatch)ParentForm).GetTransactionsControl();

                if (t != null)
                {
                    t.UpdateHashTotal(HashTotal);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Performs actions that need to happen once the user changes the value of the 'Charge Option' ComboBox.
        /// </summary>
        /// <param name="AAChargeOptionComboBox">'Charge Option' ComboBox Control</param>
        /// <param name="ADetailChargeAmountLabel">'Charge Amount' Label Control</param>
        /// <param name="ADetailChargeAmountTextBox">'Charge Amount' TextBox Control</param>
        /// <param name="ADetailChargePercentageTextBox">'Charge Percentage' TextBox Control</param>
        public static void ChargeOptionComboChanged(TCmbAutoComplete AAChargeOptionComboBox, Label ADetailChargeAmountLabel,
                                                    TTxtNumericTextBox ADetailChargeAmountTextBox, TTxtNumericTextBox ADetailChargePercentageTextBox)
        {
            ADetailChargeAmountLabel.Text          = AAChargeOptionComboBox.GetSelectedString() + Catalog.GetString(" Amount:");
            ADetailChargeAmountTextBox.Enabled     = true;
            ADetailChargePercentageTextBox.Enabled = true;

            switch (AAChargeOptionComboBox.SelectedIndex)
            {
            case 2:
                ADetailChargePercentageTextBox.Enabled            = false;
                ADetailChargePercentageTextBox.NumberValueDecimal = (decimal)0.0;

                break;

            case 3:
                ADetailChargeAmountLabel.Text                 = Catalog.GetString("Amount:"); // overwrite what was assigned earlier on
                ADetailChargeAmountTextBox.Enabled            = false;                        // overwrite what was assigned earlier on
                ADetailChargeAmountTextBox.NumberValueDecimal = (decimal)0.0;

                break;
            }
        }
Ejemplo n.º 10
0
        public void SaveAndCancel()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            // 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
            TFrmSetupCorporateExchangeRate mainScreen2 = new TFrmSetupCorporateExchangeRate(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
            TFrmSetupCorporateExchangeRate mainScreen3 = new TFrmSetupCorporateExchangeRate(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!
            TFrmSetupCorporateExchangeRate mainScreen4 = new TFrmSetupCorporateExchangeRate(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();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Handler for the GiftBatchUsage test
        /// </summary>
        public void ModalValidationHandler()
        {
            // Controls
            ButtonTester btnNewTester    = new ButtonTester("btnNew", FModalFormName);
            ButtonTester btnCloseTester  = new ButtonTester("btnClose", FModalFormName);
            ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName);

            TtxtPetraDate      dtpDateEffective  = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties;
            TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties;

            try
            {
                // Create a new row and set the rate
                btnNewTester.Click();
                txtRateOfExchange.NumberValueDecimal = 2.0m;
                string dlgText      = String.Empty;
                bool   dlgDisplayed = false;

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

                // Try setting the date to the day after the end and then clicking New
                dtpDateEffective.Date = FStandardEffectiveDate.AddDays(1.0);
                btnNewTester.Click();
                Assert.IsTrue(dlgDisplayed, "The date chosen for the test should have raised a validation errror");
                Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_DATENOTINDATERANGE));

                // Set up another popup handler
                dlgText          = String.Empty;
                dlgDisplayed     = false;
                ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
                {
                    MessageBoxTester tester = new MessageBoxTester(hWnd);
                    dlgText      = tester.Text;
                    dlgDisplayed = true;
                    tester.SendCommand(MessageBoxTester.Command.OK);
                };

                // Try setting the date to the day before the start and then clicking New
                dtpDateEffective.Date = FStandardEffectiveDate.AddDays(-11.0);
                btnNewTester.Click();
                Assert.IsTrue(dlgDisplayed, "The date chosen for the test should have raised a validation errror");
                Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_DATENOTINDATERANGE));

                // Set the date to a valid date and close (and save)
                dtpDateEffective.Date = FStandardEffectiveDate;
                btnCloseTester.Click();
            }
            catch (Exception ex)
            {
                HandleModalException(ex);
                btnCancelTester.Properties.DialogResult = DialogResult.Abort;
                btnCancelTester.Click();
            }
        }
Ejemplo n.º 12
0
        public void AddRowToTable()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            // 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;

            // 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
            Assert.IsFalse(cmbFromCurrency.Enabled);
            Assert.IsFalse(cmbToCurrency.Enabled);
            Assert.IsTrue(dtpEffectiveDate.ReadOnly);

            // Check that the controls are enabled
            Assert.IsTrue(txtExchangeRate.Enabled);

            // Click the 'New' button
            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");
            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 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            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
            decimal newRate = 0.667m;

            txtExchangeRate.NumberValueDecimal = newRate;

            // click the 'New' button again - this time the date should be first of next month
            btnNew.Click();
            expectedDate = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).AddMonths(1);

            // 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(newRate, txtExchangeRate.NumberValueDecimal.Value);
            Assert.AreEqual(FAllRowCount - 1, mainScreen.GetSelectedRowIndex());

            // Save the changes and check the number of rows now
            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();
        }
Ejemplo n.º 13
0
        public void EditRow()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.InsertStandardRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.Show();

            // 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;

            // 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 dt1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            //DateTime dt2 = dt1.AddMonths(1);
            DateTime dt3 = dt1.AddMonths(2);

            // Check the data first
            Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString());
            Assert.AreEqual(dt3, dtpEffectiveDate.Date);
            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("BEF");
            cmbToCurrency.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(dt1, dtpEffectiveDate.Date.Value);
            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(dt3, dtpEffectiveDate.Date.Value);
            Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // Repeat for the To currency
            cmbToCurrency.Focus();
            cmbToCurrency.SetSelectedString("BEF");
            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(dt1, dtpEffectiveDate.Date.Value);
            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(dt3, dtpEffectiveDate.Date.Value);
            Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal);
            Assert.AreEqual(3, mainScreen.GetSelectedRowIndex());

            // Finally check what happens when editing the date
            SelectRowInGrid(5);
            txtExchangeRate.NumberValueDecimal = 8.0m;      // Today
            FixUnvalidatedChanges();
            SelectRowInGrid(4);
            txtExchangeRate.NumberValueDecimal = 9.0m;      // Today + 1m
            FixUnvalidatedChanges();
            SelectRowInGrid(3);
            txtExchangeRate.NumberValueDecimal = 10.0m;     // Today +2m
            FixUnvalidatedChanges();

            SelectRowInGrid(5);
            Assert.AreEqual(8.0m, txtExchangeRate.NumberValueDecimal);
            dtpEffectiveDate.Focus();
            dtpEffectiveDate.Date = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).AddMonths(6);
            grdDetails.Focus();
            Assert.AreEqual(10.0m, txtExchangeRate.NumberValueDecimal);

            mainScreen.SaveChanges();
            mainScreen.Close();
        }
Ejemplo n.º 14
0
        public void AddRowToEmptyTable()
        {
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();

            TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null);

            mainScreen.RunOnceOnActivation();
            mainScreen.Show();

            // 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 expectedToCurrency = "USD";
            string baseCurrency       = GetDefaultBaseCurrency();

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

            DateTime expectedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            // Check the details panel after adding the new row
            Assert.AreEqual(baseCurrency, cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(expectedToCurrency, 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(baseCurrency, cmbFromCurrency.GetSelectedString());
            Assert.AreEqual(expectedToCurrency, cmbToCurrency.GetSelectedString());
            Assert.AreEqual(expectedDate, dtpEffectiveDate.Date);
            Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal);

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

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

            mainScreen.Close();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Handler for the ExchangeRateUsage1 test
        /// </summary>
        public void ExchangeRateUsageHandler()
        {
            FormTester formTester = new FormTester(FModalFormName);

            // Controls
            //ButtonTester btnNewTester = new ButtonTester("btnNew", FModalFormName);
            ButtonTester btnCloseTester  = new ButtonTester("btnClose", FModalFormName);
            ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName);

            TtxtPetraDate      dtpDateEffective  = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties;
            TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties;

            try
            {
                for (int i = 7; i > 0; i--)
                {
                    SelectRowInGrid(i);
                    string Usage = ((TFrmSetupDailyExchangeRate)formTester.Properties).Usage;
                    Console.WriteLine("Grid row {0}: rate: {1}: {2}", i, txtRateOfExchange.NumberValueDecimal.Value.ToString(), Usage);
                    // Usage is of form "Ledger:{0} Batch:{1} Journal:{2} Status:{3} at Rate:{4} on Date:{5} at Time:{6}"

                    Assert.IsTrue(Usage.Contains("Ledger:9997"), "Expected a reference to Ledger #9997, but was: " + Usage);

                    switch (i)
                    {
                    case 1:                 // 0.5225
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:113"), "Expected a reference to Batch 113, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-30"), "Expected a reference to a date of 2000-10-30, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 2:                 // 0.5225
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:112"), "Expected a reference to Batch 112, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-26"), "Expected a reference to a date of 2000-10-26, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 3:                 // 0.5225
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:111"), "Expected a reference to Batch 111, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-22"), "Expected a reference to a date of 2000-10-22, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 4:                 // 0.5225
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:24"), "Expected a reference to Batch 24, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-15"), "Expected a reference to a date of 2000-10-15, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 5:                 // 0.5225
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:23"), "Expected a reference to Batch 23, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-09"), "Expected a reference to a date of 2000-10-09, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 6:                 // 0.5225
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:22"), "Expected a reference to Batch 22, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-05"), "Expected a reference to a date of 2000-10-05, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 7:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:21"), "Expected a reference to Batch 22, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-10-01"), "Expected a reference to a date of 2000-10-01, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 8:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:103"), "Expected a reference to Batch 103, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-08-28"), "Expected a reference to a date of 2000-08-28, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:60"), "Expected a reference to Time 60, but was: " + Usage);
                        break;

                    case 9:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:17"), "Expected a reference to Batch 17, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-08-28"), "Expected a reference to a date of 2000-08-28, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 10:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:102"), "Expected a reference to Batch 102, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-08-08"), "Expected a reference to a date of 2000-08-08, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:60"), "Expected a reference to Time 60, but was: " + Usage);
                        break;

                    case 11:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains("status:posted"), "Expected a posted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:16"), "Expected a reference to Batch 16, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-08-08"), "Expected a reference to a date of 2000-08-08, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    case 12:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains(
                                          "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:101"), "Expected a reference to Batch 101, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-08-08"), "Expected a reference to a date of 2000-08-08, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:60"), "Expected a reference to Time 60, but was: " + Usage);
                        break;

                    case 13:                 // 0.5155
                        Assert.IsTrue(Usage.ToLower().Contains("status:posted"), "Expected a posted row in Gift Batch table, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Batch:15"), "Expected a reference to Batch 15, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Date:2000-08-01"), "Expected a reference to a date of 2000-08-01, but was: " + Usage);
                        Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage);
                        break;

                    default:
                        break;
                    }
                }

                btnCloseTester.Click();
            }
            catch (Exception ex)
            {
                HandleModalException(ex);
                btnCancelTester.Properties.DialogResult = DialogResult.Abort;
                btnCancelTester.Click();
            }
        }
        /// <summary>
        /// Method to cancel a specified journal
        /// </summary>
        /// <param name="ACurrentJournalRow">The row to cancel</param>
        /// <param name="AJournalDescriptionTextBox">Pass a reference to a TextBox that is used to display the journal description text.  This is required
        /// to ensure that validation passes when the cancelled journal is saved.</param>
        /// <param name="AExchangeRateToBaseTextBox">Pass a reference to a TextBox that is used to display the exchange rate to base.  This is required
        /// to ensure that validation passes when the cancelled journal is saved.</param>
        /// <returns>True if the journal is cancelled.</returns>
        public bool CancelRow(GLBatchTDSAJournalRow ACurrentJournalRow,
                              TextBox AJournalDescriptionTextBox,
                              TTxtNumericTextBox AExchangeRateToBaseTextBox)
        {
            if ((ACurrentJournalRow == null) || !FMyForm.SaveChanges())
            {
                return(false);
            }

            int CurrentBatchNumber   = ACurrentJournalRow.BatchNumber;
            int CurrentJournalNumber = ACurrentJournalRow.JournalNumber;

            if ((MessageBox.Show(String.Format(Catalog.GetString(
                                                   "You have chosen to cancel this journal ({0}).\n\nDo you really want to cancel it?"),
                                               CurrentJournalNumber),
                                 Catalog.GetString("Confirm Cancel"),
                                 MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes))
            {
                try
                {
                    //clear any transactions currently being editied in the Transaction Tab
                    FMyForm.GetTransactionsControl().ClearCurrentSelection();

                    //Load any new data
                    FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionATransAnalAttrib(FLedgerNumber, CurrentBatchNumber,
                                                                                                     CurrentJournalNumber));

                    DataView dvAA = new DataView(FMainDS.ATransAnalAttrib);

                    dvAA.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                   ATransAnalAttribTable.GetBatchNumberDBName(),
                                                   CurrentBatchNumber,
                                                   ATransAnalAttribTable.GetJournalNumberDBName(),
                                                   CurrentJournalNumber);

                    //Delete Analysis Attribs
                    foreach (DataRowView dvr in dvAA)
                    {
                        dvr.Delete();
                    }

                    DataView dvTr = new DataView(FMainDS.ATransaction);

                    dvTr.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                   ATransactionTable.GetBatchNumberDBName(),
                                                   CurrentBatchNumber,
                                                   ATransactionTable.GetJournalNumberDBName(),
                                                   CurrentJournalNumber);

                    //Delete Transactions
                    foreach (DataRowView dvr in dvTr)
                    {
                        dvr.Delete();
                    }

                    ACurrentJournalRow.BeginEdit();
                    ACurrentJournalRow.JournalStatus = MFinanceConstants.BATCH_CANCELLED;

                    //Ensure validation passes
                    if (ACurrentJournalRow.JournalDescription.Length == 0)
                    {
                        AJournalDescriptionTextBox.Text = " ";
                    }

                    if (ACurrentJournalRow.ExchangeRateToBase == 0)
                    {
                        AExchangeRateToBaseTextBox.NumberValueDecimal = 1;
                    }

                    ABatchRow CurrentBatchRow = FMyForm.GetBatchControl().GetSelectedDetailRow();

                    CurrentBatchRow.BatchCreditTotal -= ACurrentJournalRow.JournalCreditTotal;
                    CurrentBatchRow.BatchDebitTotal  -= ACurrentJournalRow.JournalDebitTotal;

                    if (CurrentBatchRow.BatchControlTotal != 0)
                    {
                        CurrentBatchRow.BatchControlTotal -= ACurrentJournalRow.JournalCreditTotal;
                    }

                    ACurrentJournalRow.JournalCreditTotal = 0;
                    ACurrentJournalRow.JournalDebitTotal  = 0;
                    ACurrentJournalRow.EndEdit();

                    FPetraUtilsObject.SetChangedFlag();

                    //Need to call save
                    if (FMyForm.SaveChanges())
                    {
                        MessageBox.Show(Catalog.GetString("The journal has been cancelled successfully!"),
                                        Catalog.GetString("Success"),
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);

                        FMyForm.DisableTransactions();
                    }
                    else
                    {
                        // saving failed, therefore do not try to post
                        MessageBox.Show(Catalog.GetString(
                                            "The journal has been cancelled but there were problems during saving; ") + Environment.NewLine +
                                        Catalog.GetString("Please try and save the cancellation immediately."),
                                        Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            return(false);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Method to create and show the controls required for a particular code on the specified panel.
        /// Currently we support the following controls:
        ///    txt -> TextBox,
        ///    txt -> TTxtNumericTextBox with Format=Integer as the attribute,
        ///    cmb -> TCmbAutoComplete: content is defined in OptionalValues column: Format=yes/no turns the combo into a tri-state choice
        ///                where the OptionalValues do not have to be False and True because the result is yes or no based on SelectedIndex.
        ///    dtp -> TtxtPetraDate
        /// </summary>
        /// <param name="AControlCode">The code that is a primary key into the controls table</param>
        /// <param name="AHostPanel">The panel onto which the GUI controls will be placed</param>
        /// <param name="AInitialValue">The initial value for this 'setting'.  The value may be a comma separated list of values.</param>
        /// <param name="AReadOnly">Set to true to disable the control(s) or make them read-only as appropriate.</param>
        /// <param name="AValidationEventHandler">An event handler that will be called on validation</param>
        public void ShowControls(string AControlCode, Panel AHostPanel, string AInitialValue, bool AReadOnly, EventHandler AValidationEventHandler)
        {
            // Work out the PetraUtilsObject for the form that called us
            TFrmPetraUtils petraBase = ((IFrmPetra)AHostPanel.TopLevelControl).GetPetraUtilsObject();

            FPetraUtilsObject = (petraBase is TFrmPetraEditUtils) ? (TFrmPetraEditUtils)petraBase : null;

            // Set up a default view on the controls table that will tell us the controls we need for this code
            FDataTable.DefaultView.RowFilter = string.Format("{0}='{1}'", FCodeColumn, AControlCode);
            FDataTable.DefaultView.Sort      = string.Format("{0} ASC, {1} ASC", FCodeColumn, FControlIndexColumn);

            AHostPanel.AutoScroll = (FDataTable.DefaultView.Count > 1);
            AHostPanel.Controls.Clear();

            // Work out the value(s) that have been passed in as a comma separated list
            StringCollection values = StringHelper.GetCSVList(AInitialValue, ",", true);

            if (values.Count != FDataTable.DefaultView.Count)
            {
                return;
            }

            FCurrentHostPanel = AHostPanel;
            int id       = 0;
            int vPos     = 5;
            int tabIndex = 10;

            foreach (DataRowView drv in FDataTable.DefaultView)
            {
                // get the attributes as a dictionary
                Dictionary <string, string> attributes = new Dictionary <string, string>();
                object rowValue = drv.Row[FAttributesColumn];

                if ((rowValue != null) && rowValue.ToString().Contains("="))
                {
                    string[] attPairs = drv.Row[FAttributesColumn].ToString().Split(',');

                    foreach (string attPair in attPairs)
                    {
                        string[] att = attPair.Split('=');

                        if (att.Length == 2)
                        {
                            attributes.Add(att[0].Trim(), att[1].Trim());
                        }
                    }
                }

                // See if some of the popular attributes are defined and store their values in local variables
                string formatAttribute     = string.Empty;
                string allowBlankAttribute = string.Empty;
                string stretchAttribute    = string.Empty;
                int    widthAttribute      = -1;
                int    labelWidthAttribute = -1;

                if (attributes.ContainsKey("Format"))
                {
                    // Use lower case
                    formatAttribute = attributes["Format"].ToString().ToLower();
                }

                if (attributes.ContainsKey("Width"))
                {
                    widthAttribute = Convert.ToInt32(attributes["Width"]);
                }

                if (attributes.ContainsKey("LabelWidth"))
                {
                    labelWidthAttribute = Convert.ToInt32(attributes["LabelWidth"]);
                }

                if (attributes.ContainsKey("AllowBlankValue"))
                {
                    allowBlankAttribute = attributes["AllowBlankValue"].ToString().ToLower();
                }

                if (attributes.ContainsKey("Stretch"))
                {
                    stretchAttribute = attributes["Stretch"].ToString().ToLower();
                }

                // create the control label
                Label label = new Label();
                label.Name      = "cLabel_" + id.ToString();
                label.Text      = drv.Row[FLabelColumn].ToString() + ":";
                label.Location  = new Point(5, vPos);
                label.Size      = new Size((labelWidthAttribute > 0) ? labelWidthAttribute : (AHostPanel.Width / 2) - 10, 17);
                label.TextAlign = ContentAlignment.MiddleRight;
                label.Anchor    = AnchorStyles.Top | AnchorStyles.Left;

                AHostPanel.Controls.Add(label);

                // Create the control
                // We support text boxes, numeric (integer) text boxes, combo boxes and date boxes
                switch (drv.Row[FControlTypeColumn].ToString().Substring(0, 3))
                {
                case "txt":

                    if (formatAttribute == "integer")
                    {
                        TTxtNumericTextBox txt = new TTxtNumericTextBox();
                        txt.Context     = AHostPanel;
                        txt.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer;
                        txt.Name        = "cValue_" + id.ToString();
                        txt.Location    = new Point(label.Right + 10, vPos);
                        txt.Size        = new Size((widthAttribute > 0) ? widthAttribute : 100, 22);
                        txt.TabStop     = true;
                        txt.TabIndex    = tabIndex;

                        int iValue;

                        if (int.TryParse(values[id], out iValue))
                        {
                            txt.NumberValueInt = iValue;
                        }

                        txt.ReadOnly = AReadOnly;

                        txt.Validated   += AValidationEventHandler;
                        txt.TextChanged += new EventHandler(MultiChangeEventHandler);

                        AHostPanel.Controls.Add(txt);
                    }
                    else
                    {
                        TextBox txt = new TextBox();
                        txt.Name     = "cValue_" + id.ToString();
                        txt.Location = new Point(label.Right + 10, vPos);
                        txt.Size     = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22);
                        txt.TabStop  = true;
                        txt.TabIndex = tabIndex;
                        txt.Text     = values[id];
                        txt.ReadOnly = AReadOnly;

                        if (stretchAttribute == "horizontally")
                        {
                            txt.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                        }

                        txt.Validated   += AValidationEventHandler;
                        txt.TextChanged += new EventHandler(MultiChangeEventHandler);

                        AHostPanel.Controls.Add(txt);
                    }

                    break;

                case "cmb":

                    if (attributes.ContainsKey("List"))
                    {
                        TCmbAutoPopulated cmb = new TCmbAutoPopulated();
                        cmb.Name      = "cValue_" + id.ToString();
                        cmb.Location  = new Point(label.Right + 10, vPos);
                        cmb.Size      = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22);
                        cmb.TabStop   = true;
                        cmb.TabIndex  = tabIndex;
                        cmb.ListTable = (TCmbAutoPopulated.TListTableEnum)Enum.Parse(typeof(TCmbAutoPopulated.TListTableEnum),
                                                                                     attributes["List"].ToString(),
                                                                                     true);
                        cmb.InitialiseUserControl();
                        cmb.SetSelectedString(values[id], -1);

                        cmb.Enabled = !AReadOnly;

                        cmb.Validated            += AValidationEventHandler;
                        cmb.SelectedValueChanged += new EventHandler(MultiChangeEventHandler);

                        AHostPanel.Controls.Add(cmb);
                    }
                    else
                    {
                        TCmbAutoComplete cmb = new TCmbAutoComplete();
                        cmb.Name     = "cValue_" + id.ToString();
                        cmb.Location = new Point(label.Right + 10, vPos);
                        cmb.Size     = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22);
                        cmb.TabStop  = true;
                        cmb.TabIndex = tabIndex;

                        if (drv.Row[FOptionalValuesColumn] != null)
                        {
                            string[] optValues = drv.Row[FOptionalValuesColumn].ToString().Split(',');

                            for (int i = 0; i < optValues.Length; i++)
                            {
                                cmb.Items.Add(optValues[i].ToString().Trim());
                            }
                        }

                        if (formatAttribute == "yes/no")
                        {
                            cmb.SetSelectedYesNo(values[id]);
                            cmb.Tag = "yes/no";
                        }
                        else
                        {
                            cmb.Text = values[id];
                        }

                        if (stretchAttribute == "horizontally")
                        {
                            cmb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                        }

                        cmb.AllowBlankValue = (allowBlankAttribute == "true");
                        cmb.Enabled         = !AReadOnly;

                        cmb.Validated            += AValidationEventHandler;
                        cmb.SelectedIndexChanged += new EventHandler(MultiChangeEventHandler);
                        cmb.TextChanged          += new EventHandler(ComboBoxTextChangeEventHandler);

                        AHostPanel.Controls.Add(cmb);
                    }

                    break;

                case "dtp":
                    TtxtPetraDate dtp = new TtxtPetraDate();
                    dtp.Name     = "cValue_" + id.ToString();
                    dtp.Location = new Point(label.Right + 10, vPos);
                    dtp.Size     = new Size(94, 22);
                    dtp.TabStop  = true;
                    dtp.TabIndex = tabIndex;

                    DateTime dt;

                    if (DateTime.TryParse(values[id], out dt))
                    {
                        dtp.Date = Convert.ToDateTime(values[id]);
                    }
                    else
                    {
                        dtp.Date = null;
                    }

                    dtp.ReadOnly = AReadOnly;

                    dtp.Validated   += AValidationEventHandler;
                    dtp.DateChanged += new TPetraDateChangedEventHandler(MultiChangeEventHandler);

                    AHostPanel.Controls.Add(dtp);
                    break;

                default:
                    break;
                }

                id++;
                tabIndex += 10;
                vPos     += 30;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the value of the current state of the controls.  If there are multiple controls the value will be a comma separated list.
        /// </summary>
        /// <returns>The value formatted as a string.  If there are no controls the result will be an empty string.
        /// If there was an error in the database specification of the controls, the result will be an empty string
        /// If a control value is null we set the string representation to ? which can be validated by the client.</returns>
        public string GetCurrentValue()
        {
            string ReturnValue = "";

            if (FCurrentHostPanel == null)
            {
                return(ReturnValue);
            }

            if (FCurrentHostPanel.Controls.Count == 0)
            {
                return(CONTROL_DEFINITION_ERROR);
            }

            for (int i = 0; i < FCurrentHostPanel.Controls.Count; i++)
            {
                Control control = FCurrentHostPanel.Controls[i];

                if (control is Label)
                {
                    continue;
                }

                if (control is TTxtNumericTextBox)
                {
                    // Numeric text box returns ? if the entry is null
                    TTxtNumericTextBox txt = (TTxtNumericTextBox)control;

                    switch (txt.ControlMode)
                    {
                    case TTxtNumericTextBox.TNumericTextBoxMode.Integer:
                        ReturnValue += ((txt.NumberValueInt.HasValue ? txt.NumberValueInt.ToString() : "?") + ",");
                        break;

                    default:
                        break;
                    }
                }
                else if (control is TextBox)
                {
                    ReturnValue += (((TextBox)control).Text + ",");
                }

                if (control is TCmbAutoPopulated)
                {
                    // Returns ? if the selected index is -1
                    TCmbAutoPopulated cmb = (TCmbAutoPopulated)control;
                    string            s   = cmb.GetSelectedString();
                    ReturnValue += ((s.Length == 0 ? "?" : s) + ",");
                }

                if (control is TCmbAutoComplete)
                {
                    TCmbAutoComplete cmb = (TCmbAutoComplete)control;

                    if (Convert.ToString(control.Tag) == "yes/no")
                    {
                        ReturnValue += (cmb.GetSelectedYesNo() + ",");
                    }
                    else
                    {
                        // Returns ? if the selected index is -1
                        string s = cmb.GetSelectedString();
                        ReturnValue += ((s.Length == 0 ? "?" : s) + ",");
                    }
                }

                if (control is TtxtPetraDate)
                {
                    // Returns ? where the date value is null
                    TtxtPetraDate txt = (TtxtPetraDate)control;
                    ReturnValue += ((txt.Date.HasValue ? txt.Date.Value.ToString("yyyy-MM-dd") : "?") + ",");
                }
            }

            // Remove the trailing comma we added
            return(ReturnValue.Trim(','));
        }