示例#1
0
        public void TestCurrencyValues()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            TTxtCurrencyTextBox txtBox = new TTxtCurrencyTextBox();
            txtBox.CurrencyCode = "GBP";

            txtBox.NumberValueDecimal = 1410.95M;
            Assert.AreEqual(1410.95M, txtBox.NumberValueDecimal, "decimal value stored in British culture");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); // Changing the Culture like this is really not a good idea,
                                                                            // but there's a tweak in the CurrencyTextBox that attempts to compensate!
            txtBox.NumberValueDecimal = 0.0M;
            txtBox.NumberValueDecimal = 1410.95M;

            Assert.AreEqual("1.410,95",
                txtBox.Text,
                "After changing Culture, so text text should be formatted according to new culture.");
            Assert.AreEqual(1410.95M, txtBox.NumberValueDecimal, "Text box was created with British culture, switch culture, value can be read back.");

            TTxtCurrencyTextBox txtDEBox = new TTxtCurrencyTextBox();
            txtBox.CurrencyCode = "EUR";
            txtDEBox.NumberValueDecimal = 0.0M;
            txtDEBox.NumberValueDecimal = 1410.95M;
            Assert.AreEqual("1.410,95", txtDEBox.Text, "text value stored as Euros");
            Assert.AreEqual(1410.95M, txtDEBox.NumberValueDecimal, "decimal value stored as Euros");
            txtDEBox.NumberValueDecimal = 1234410.95M;
            Assert.AreEqual("1.234.410,95", txtDEBox.Text, "huge number text value stored as Euros");

/*
 *          Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
 *          Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
 *          txtBox.NumberValueDecimal = 0.0M;
 *          txtBox.NumberValueDecimal = 30.00M;
 *          Assert.AreEqual(30.00M, txtBox.NumberValueDecimal, "decimal value stored in English culture, with English UI");
 *          Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
 *          Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
 *          txtBox.NumberValueDecimal = 0.0M;
 *          txtBox.NumberValueDecimal = 770.00M;
 *          Assert.AreEqual(770.00M,
 *              txtBox.NumberValueDecimal,
 *              "decimal value stored in English culture, with english UI, thousand separator problem");
 *          Assert.AreEqual("770.00", txtBox.Text, "testing problem with thousand separator");
 *          txtBox.NumberValueDecimal = 1234410.95M;
 *          Assert.AreEqual("1,234,410.95", txtBox.Text, "huge number text value stored in British culture");
 *
 *          Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
 *          Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
 *          txtBox.NumberValueDecimal = 0.0M;
 *          txtBox.NumberValueDecimal = 1410.95M;
 *          Assert.AreEqual(1410.95M, txtBox.NumberValueDecimal, "decimal value stored in German culture, but English UI");
 */
        }
        private void CheckAmounts(TTxtCurrencyTextBox ATxtCurrencyTextBox)
        {
            bool debitChanged = (ATxtCurrencyTextBox.Name == "txtDebitAmount");

            if (!debitChanged && (ATxtCurrencyTextBox.Name != "txtCreditAmount"))
            {
                return;
            }
            else if ((ATxtCurrencyTextBox.NumberValueDecimal == null) || !ATxtCurrencyTextBox.NumberValueDecimal.HasValue)
            {
                ATxtCurrencyTextBox.NumberValueDecimal = 0;
            }

            decimal valDebit = txtDebitAmount.NumberValueDecimal.Value;
            decimal valCredit = txtCreditAmount.NumberValueDecimal.Value;

            //If no changes then proceed no further
            if (debitChanged && (FDebitAmount == valDebit))
            {
                return;
            }
            else if (!debitChanged && (FCreditAmount == valCredit))
            {
                return;
            }

            if (debitChanged && ((valDebit > 0) && (valCredit > 0)))
            {
                txtCreditAmount.NumberValueDecimal = 0;
            }
            else if (!debitChanged && ((valDebit > 0) && (valCredit > 0)))
            {
                txtDebitAmount.NumberValueDecimal = 0;
            }
            else if (valDebit < 0)
            {
                txtDebitAmount.NumberValueDecimal = 0;
            }
            else if (valCredit < 0)
            {
                txtCreditAmount.NumberValueDecimal = 0;
            }

            //Reset class variables
            FDebitAmount = txtDebitAmount.NumberValueDecimal.Value;
            FCreditAmount = txtCreditAmount.NumberValueDecimal.Value;
        }
        /// <summary>
        /// Sets up the value cell(s) for a specific data label
        ///
        /// </summary>
        /// <returns>void</returns>
        private void SetupGridValueCell(Int32 ARowIndex, PDataLabelRow ADataLabelRow)
        {
            Control cellControl;

            System.Windows.Forms.TextBox TextBoxEditor;
            TtxtPetraDate DateEditor;
            System.Windows.Forms.CheckBox CheckBoxEditor;
            TTxtNumericTextBox TextBoxNumericEditor;
            TTxtCurrencyTextBox TextBoxCurrencyEditor;
            TCmbAutoPopulated LookupValueEditor;
            TtxtAutoPopulatedButtonLabel PartnerKeyEditor;
            SourceGrid.Cells.Views.Cell ValueModel;
            SourceGrid.Cells.Views.Cell SuffixModel;
            PDataLabelValuePartnerRow DataLabelValuePartnerRow;
            PDataLabelValueApplicationRow DataLabelValueApplicationRow;

            // prepare model for the value cells
            ValueModel = new SourceGrid.Cells.Views.Cell();
            ValueModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
            ValueModel.Font = new Font(FLocalDataLabelValuesGrid.Font.FontFamily.Name, FLocalDataLabelValuesGrid.Font.Size, FontStyle.Bold);

            // prepare model for suffix cells (e.g. for currency)
            SuffixModel = new SourceGrid.Cells.Views.Cell();
            SuffixModel.BackColor = FLocalDataLabelValuesGrid.BackColor;
            SuffixModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;

            // In this case the data value rows will only be created once a value is entered
            GetOrCreateDataLabelValueRow(false, ADataLabelRow, out DataLabelValuePartnerRow, out DataLabelValueApplicationRow);

            // initialize cell control
            cellControl = null;

            // Create field, according to specified data type
            // Create character field
            if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CHAR)
            {
                TextBoxEditor = new System.Windows.Forms.TextBox();
                cellControl = TextBoxEditor;

                if (DataLabelValuePartnerRow != null)
                {
                    TextBoxEditor.Text = DataLabelValuePartnerRow.ValueChar;
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    TextBoxEditor.Text = DataLabelValueApplicationRow.ValueChar;
                }
                else
                {
                    // Default value if no Label data exists for the Partner
                    TextBoxEditor.Text = "";
                }

                // enable save button in editor when cell contents have changed
                TextBoxEditor.TextChanged += new EventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxEditor;
            }
            // Create float field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_FLOAT)
            {
                TextBoxNumericEditor = new TTxtNumericTextBox();

                if (ADataLabelRow.NumDecimalPlaces == 0)
                {
                    TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.LongInteger;
                    TextBoxNumericEditor.MaxLength = 14;
                }
                else
                {
                    TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Decimal;
                    TextBoxNumericEditor.DecimalPlaces = ADataLabelRow.NumDecimalPlaces;

                    // limit text length. 14 for number of digits, 5 for decimal and thousands separators
                    TextBoxNumericEditor.MaxLength = 14 + 5 + ADataLabelRow.NumDecimalPlaces;
                }

                TextBoxNumericEditor.NullValueAllowed = true;
                cellControl = TextBoxNumericEditor;

                if (ADataLabelRow.NumDecimalPlaces == 0)
                {
                    if (DataLabelValuePartnerRow != null)
                    {
                        TextBoxNumericEditor.NumberValueLongInt = (long)DataLabelValuePartnerRow.ValueNum;
                    }
                    else if (DataLabelValueApplicationRow != null)
                    {
                        TextBoxNumericEditor.NumberValueLongInt = (long)DataLabelValueApplicationRow.ValueNum;
                    }
                    else
                    {
                        // Default value if no Label data exists for the Partner
                        TextBoxNumericEditor.NumberValueLongInt = null;
                    }
                }
                else
                {
                    if (DataLabelValuePartnerRow != null)
                    {
                        TextBoxNumericEditor.NumberValueDecimal = DataLabelValuePartnerRow.ValueNum;
                    }
                    else if (DataLabelValueApplicationRow != null)
                    {
                        TextBoxNumericEditor.NumberValueDecimal = DataLabelValueApplicationRow.ValueNum;
                    }
                    else
                    {
                        // Default value if no Label data exists for the Partner
                        TextBoxNumericEditor.NumberValueDecimal = null;
                    }
                }

                // enable save button in editor when cell contents have changed
                TextBoxNumericEditor.TextChanged += new EventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxNumericEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxNumericEditor;
            }
            // Create data field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_DATE)
            {
                DateEditor = new TtxtPetraDate();
                DateEditor.Date = null;
                cellControl = DateEditor;

                if (DataLabelValuePartnerRow != null)
                {
                    if (!DataLabelValuePartnerRow.IsValueDateNull())
                    {
                        DateEditor.Date = DataLabelValuePartnerRow.ValueDate;
                    }
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    if (!DataLabelValueApplicationRow.IsValueDateNull())
                    {
                        DateEditor.Date = DataLabelValueApplicationRow.ValueDate;
                    }
                }

                // enable save button in editor when cell contents have changed
                DateEditor.DateChanged += new TPetraDateChangedEventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)DateEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = DateEditor;
            }
            // Create integer field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_INTEGER)
            {
                TextBoxNumericEditor = new TTxtNumericTextBox();
                TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer;
                TextBoxNumericEditor.NullValueAllowed = true;
                cellControl = TextBoxNumericEditor;

                if (DataLabelValuePartnerRow != null)
                {
                    TextBoxNumericEditor.NumberValueInt = DataLabelValuePartnerRow.ValueInt;
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    TextBoxNumericEditor.NumberValueInt = DataLabelValueApplicationRow.ValueInt;
                }
                else
                {
                    // Default value if no Label data exists for the Partner
                    TextBoxNumericEditor.NumberValueInt = null;
                }

                // enable save button in editor when cell contents have changed
                TextBoxNumericEditor.TextChanged += new EventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxNumericEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxNumericEditor;
            }
            // Create currency field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CURRENCY)
            {
                TextBoxCurrencyEditor = new TTxtCurrencyTextBox();
                TextBoxCurrencyEditor.DecimalPlaces = 2;
                TextBoxCurrencyEditor.CurrencyCode = ADataLabelRow.CurrencyCode;
                TextBoxCurrencyEditor.NullValueAllowed = true;
                cellControl = TextBoxCurrencyEditor;

                if (DataLabelValuePartnerRow != null)
                {
                    TextBoxCurrencyEditor.NumberValueDecimal = DataLabelValuePartnerRow.ValueCurrency;
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    TextBoxCurrencyEditor.NumberValueDecimal = DataLabelValueApplicationRow.ValueCurrency;
                }
                else
                {
                    // Default value if no Label data exists for the Partner
                    TextBoxCurrencyEditor.NumberValueDecimal = null;
                }

                // enable save button in editor when cell contents have changed
                TextBoxCurrencyEditor.TextChanged += new EventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxCurrencyEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxCurrencyEditor;
            }
            // Create boolean field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_BOOLEAN)
            {
                CheckBoxEditor = new System.Windows.Forms.CheckBox();
                cellControl = CheckBoxEditor;

                if (DataLabelValuePartnerRow != null)
                {
                    CheckBoxEditor.Checked = DataLabelValuePartnerRow.ValueBool;
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    CheckBoxEditor.Checked = DataLabelValueApplicationRow.ValueBool;
                }
                else
                {
                    // Default value if no Label data exists for the Partner
                    CheckBoxEditor.Checked = false;
                }

                // enable save button in editor when cell contents have changed
                CheckBoxEditor.CheckedChanged += new EventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)CheckBoxEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = CheckBoxEditor;
            }
            // Create partner key field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_PARTNERKEY)
            {
                PartnerKeyEditor = new TtxtAutoPopulatedButtonLabel();
                PartnerKeyEditor.ASpecialSetting = true;
                PartnerKeyEditor.ButtonText = ADataLabelRow.Text + ':';
                PartnerKeyEditor.ButtonTextAlign = System.Drawing.ContentAlignment.MiddleRight;
                PartnerKeyEditor.ListTable = TtxtAutoPopulatedButtonLabel.TListTableEnum.PartnerKey;
                PartnerKeyEditor.TabStop = false;
                cellControl = PartnerKeyEditor;

                // AutomaticallyUpdateDataSource: very rare, but needed here
                PartnerKeyEditor.AutomaticallyUpdateDataSource = true;

                if (DataLabelValuePartnerRow != null)
                {
                    PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(DataLabelValuePartnerRow.ValuePartnerKey);
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(DataLabelValueApplicationRow.ValuePartnerKey);
                }
                else
                {
                    // Default value if no Label data exists for the Partner
                    PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(0);
                }

                // display partner name linked to partner key
                PartnerKeyEditor.ResetLabelText();

                // enable save button in editor when cell contents have changed
                PartnerKeyEditor.ValueChanged += new TDelegatePartnerChanged(this.PartnerKeyControlValueHasChanged);
                PartnerKeyEditor.TextChanged += new System.EventHandler(this.ControlValueHasChanged);


                FLocalDataLabelValuesGrid[ARowIndex, 0] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue(PartnerKeyEditor, new Position(ARowIndex, 0)));
                FLocalDataLabelValuesGrid[ARowIndex, 0].Tag = PartnerKeyEditor;
                FLocalDataLabelValuesGrid[ARowIndex, 0].ColumnSpan = 3;
            }
            // Create lookup field
            else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_LOOKUP)
            {
                // Get the instance of the combobox (created in the actual user interface class)
                LookupValueEditor = new TCmbAutoPopulated();
                LookupValueEditor.Filter = PDataLabelLookupTable.GetCategoryCodeDBName() + " = '" + ADataLabelRow.LookupCategoryCode + "'";
                LookupValueEditor.ListTable = TCmbAutoPopulated.TListTableEnum.DataLabelLookupList;
                LookupValueEditor.InitialiseUserControl();
                cellControl = LookupValueEditor;

                if (DataLabelValuePartnerRow != null)
                {
                    LookupValueEditor.SetSelectedString(DataLabelValuePartnerRow.ValueLookup);
                }
                else if (DataLabelValueApplicationRow != null)
                {
                    LookupValueEditor.SetSelectedString(DataLabelValueApplicationRow.ValueLookup);
                }
                else
                {
                    // Default value if no Label data exists for the Partner
                    LookupValueEditor.Text = "";
                }

                // enable save button in editor when cell contents have changed
                LookupValueEditor.SelectedValueChanged += new EventHandler(this.ControlValueHasChanged);
                LookupValueEditor.TextChanged += new EventHandler(this.ControlValueHasChanged);

                FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell();
                FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)LookupValueEditor, new Position(ARowIndex, 1)));
                FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = LookupValueEditor;
                FLocalDataLabelValuesGrid[ARowIndex, 1].ColumnSpan = 2;
            }

            // perform actions that need to be done for each control
            if (cellControl != null)
            {
                // remember the added control to get the value back lateron
                FGridRowInfo.SetControl(ARowIndex, cellControl);

                // handle focus change when field is entered
                cellControl.Enter += new EventHandler(this.UpdateGridFocusFromExternalControl);

                // set help text for control
                PetraUtilsObject.SetStatusBarText(cellControl, ADataLabelRow.Description);
            }

            // check if value is editable
            if (!ADataLabelRow.Editable)
            {
                FLocalDataLabelValuesGrid[ARowIndex, 1].Editor.EnableEdit = false;
            }
        }
示例#4
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,
            TTxtCurrencyTextBox 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;
            }
        }