예제 #1
0
        public void TestEvents()
        {
            TtxtPetraDate dtpDate = new TtxtPetraDate();

            dtpDate.Name = "dtpDate";
            dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged);
            dtpDate.TextChanged += new EventHandler(TextChanged);

            Form TestForm = new Form();
            TestForm.Controls.Add(dtpDate);

            TestForm.Show();

            TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate");

            TextChangedCalled = 0;
            DateChangedCalled = 0;
            tester.Properties.Text = "31-12-2012";

            Assert.AreEqual(new DateTime(2012, 12, 31), tester.Properties.Date.Value, "date should be set");
            Assert.AreEqual(1, DateChangedCalled, "event DateChanged should have been called once");
            Assert.AreEqual(1, TextChangedCalled, "event TextChanged should have been called once");

            tester.Properties.Text = "30-12-2012";

            TextChangedCalled = 0;
            DateChangedCalled = 0;
            tester.Properties.Text = "31-DEC-2012";

            Assert.AreEqual(new DateTime(2012, 12, 31), tester.Properties.Date.Value, "date should be set, Test With DEC");
            Assert.AreEqual(1, DateChangedCalled, "event DateChanged should have been called once, Test With DEC");
            Assert.AreEqual(1, TextChangedCalled, "event TextChanged should have been called once, Test With DEC");

            TextChangedCalled = 0;
            DateChangedCalled = 0;
            tester.Properties.Text = "31-12-2012";

            Assert.AreEqual(new DateTime(2012, 12, 31), tester.Properties.Date.Value, "date should be set, test resetting");
            Assert.AreEqual(0, DateChangedCalled, "event DateChanged should not have been called, test resetting");
            Assert.AreEqual(0, TextChangedCalled, "event TextChanged should not have been called, test resetting");
        }
예제 #2
0
        /// <summary>
        /// Gets the filter string from the specified set of panels
        /// </summary>
        /// <param name="AFilterPanelControls">The panel set (standard or extra)</param>
        /// <returns></returns>
        private string GetCurrentFilter(List <TIndividualFilterFindPanel> AFilterPanelControls)
        {
            string filter = String.Empty;

            for (int i = 0; i < AFilterPanelControls.Count; i++)
            {
                if (AFilterPanelControls[i].FilterComparison == null)
                {
                    continue;
                }

                string value;

                if (AFilterPanelControls[i].PanelControl is CheckBox)
                {
                    CheckBox ctrlAsCheckBox = (CheckBox)AFilterPanelControls[i].PanelControl;

                    switch (ctrlAsCheckBox.CheckState)
                    {
                    case CheckState.Checked:
                        value = "1";
                        break;

                    case CheckState.Unchecked:
                        value = "0";
                        break;

                    default:
                        value = String.Empty;
                        break;
                    }
                }
                else if (AFilterPanelControls[i].PanelControl is TtxtPetraDate)
                {
                    TtxtPetraDate ctrlAsDtp = (TtxtPetraDate)AFilterPanelControls[i].PanelControl;

                    if (ctrlAsDtp.Date.HasValue)
                    {
                        value = ctrlAsDtp.Date.Value.ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        value = String.Empty;
                    }
                }
                else
                {
                    value = AFilterPanelControls[i].PanelControl.Text;

                    // certain text characters mess up a LIKE SQL statement
                    value = value.Replace("[", "");
                    value = value.Replace("]", "");
                }

                if (value != String.Empty)
                {
                    if (filter.Length > 0)
                    {
                        filter += " AND ";
                    }

                    filter += AFilterPanelControls[i].DBColumnName;
                    filter += String.Format(AFilterPanelControls[i].FilterComparison, value);
                }
            }

            return(filter);
        }
        /// <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
        public void EnterInvalidDates()
        {
            TtxtPetraDate dtpDate = new TtxtPetraDate();

            dtpDate.Name = "dtpDate";
            dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged);
            dtpDate.TextChanged += new EventHandler(TextChanged);

            Form TestForm = new Form();
            TestForm.Controls.Add(dtpDate);

            TestForm.Show();

            TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate");

            TextChangedCalled = 0;
            DateChangedCalled = 0;
            NumberOfMessageBoxes = 0;

            DialogBoxHandler = HandleMessageBox;
            tester.Properties.Text = "30";

            Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once");
            Assert.IsTrue(TVerificationHelper.AreVerificationResultsIdentical(tester.Properties.DateVerificationResult,
                    Ict.Common.Verification.TDateChecks.GetInvalidDateVerificationResult("Date", null), false, false));

            TextChangedCalled = 0;
            DateChangedCalled = 0;
            NumberOfMessageBoxes = 0;

            DialogBoxHandler = HandleMessageBox;
            tester.Properties.Text = "301210000";

            Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once: year 10000");

            DialogBoxHandler = null;

            NumberOfMessageBoxes = 0;

            DialogBoxHandler = HandleMessageBox;

            tester.Properties.AllowEmpty = false;
            tester.Properties.Text = "01-JAN-2010";
            tester.Properties.Text = "";

            Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once: year 10000");
            Assert.IsTrue(TVerificationHelper.AreVerificationResultsIdentical(tester.Properties.DateVerificationResult,
                    new TVerificationResult(null, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE,
                            CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine +
                            "{0} must not be empty.", new string[] { "'Date'" }))));

            DialogBoxHandler = null;
        }
예제 #5
0
        public void TestCulture()
        {
            TtxtPetraDate dtpDate = new TtxtPetraDate();

            dtpDate.Name = "dtpDate";
            dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged);
            dtpDate.TextChanged += new EventHandler(TextChanged);

            Form TestForm = new Form();
            TestForm.Controls.Add(dtpDate);

            TestForm.Show();

            TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate");

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            tester.Properties.Text = "30-JAN-2012";
            Assert.AreEqual(new DateTime(2012, 1, 30), tester.Properties.Date.Value, "date should be set, 30-JAN-2012");
            tester.Properties.Text = "30-JANUARY-2012";
            Assert.AreEqual(new DateTime(2012, 1, 30), tester.Properties.Date.Value, "date should be set, 30-JANUARY-2012");
            tester.Properties.Text = "30-SEPTEMBER-2012";
            Assert.AreEqual(new DateTime(2012, 9, 30), tester.Properties.Date.Value, "date should be set, 30-SEPTEMBER-2012");
            tester.Properties.Text = "30-APR-2012";
            Assert.AreEqual(new DateTime(2012, 4, 30), tester.Properties.Date.Value, "date should be set, 30-APR-2012");
            tester.Properties.Text = "30-NOV-2012";
            Assert.AreEqual(new DateTime(2012, 11, 30), tester.Properties.Date.Value, "date should be set, 30-NOV-2012");
        }