コード例 #1
0
        /// <summary>
        /// Checks if the current data is valid.
        ///
        /// The data is valid if
        /// - the feature name is neither empty, already used or contains invalid characters
        /// - the range of values contains valid numbers and form a valid range and
        /// - the step function is in the right form
        ///
        /// If the data is not valid, the option cannot be added and an error message will be
        /// displayed.
        /// </summary>
        private void checkValidityOfData()
        {
            // Check if feature name is empty
            if (featureNameTextBox.Text == "")
            {
                errorLabel.Text         = ERROR_NAME_EMPTY;
                errorLabel.Visible      = true;
                addOptionButton.Enabled = false;
                return;
            }

            // Check if feature name already exists
            if (GlobalState.varModel.getOption(featureNameTextBox.Text) != null)
            {
                errorLabel.Text         = ERROR_NAME_EXISTS;
                errorLabel.Visible      = true;
                addOptionButton.Enabled = false;
                return;
            }

            // Check if feature name is invalid
            if (featureNameTextBox.Text != ConfigurationOption.removeInvalidCharsFromName(featureNameTextBox.Text))
            {
                errorLabel.Text         = ERROR_INVALID_NAME;
                errorLabel.Visible      = true;
                addOptionButton.Enabled = false;
                return;
            }

            if (numericRadioButton.Checked)
            {
                // Check if the range of values is invalid
                if (!isRangeValid())
                {
                    errorLabel.Text         = ERROR_INVALID_RANGE;
                    errorLabel.Visible      = true;
                    addOptionButton.Enabled = false;
                    return;
                }

                // Check if step function is valid
                if (stepSizeCheckBox.Checked && !isStepSizeValid())
                {
                    errorLabel.Text         = ERROR_INVALID_STEP_FUNCTION;
                    errorLabel.Visible      = true;
                    addOptionButton.Enabled = false;
                    return;
                }
            }

            errorLabel.Visible      = false;
            addOptionButton.Enabled = true;
        }
コード例 #2
0
        private Tuple <DialogResult, string> RenameDialog()
        {
            Form    form               = new Form();
            Label   pleaseEnterLabel   = new Label();
            TextBox featureNameTextBox = new TextBox();
            Button  okButton           = new Button();
            Button  cancelButton       = new Button();

            //
            // pleaseEnterLabel
            //
            pleaseEnterLabel.Location = new Point(9, 9);
            pleaseEnterLabel.Name     = "pleaseEnterLabel";
            pleaseEnterLabel.Size     = new Size(200, 13);
            pleaseEnterLabel.TabIndex = 0;
            pleaseEnterLabel.Text     = DESCRIPTION_CHANGE_NAME;
            //
            // featureNameTextBox
            //
            featureNameTextBox.Location = new Point(12, 25);
            featureNameTextBox.Name     = "featureNameTextBox";
            featureNameTextBox.Size     = new Size(197, 20);
            featureNameTextBox.TabIndex = 1;
            //
            // okButton
            //
            okButton.DialogResult            = DialogResult.OK;
            okButton.Location                = new Point(12, 85);
            okButton.Name                    = "okButton";
            okButton.Size                    = new Size(75, 23);
            okButton.TabIndex                = 3;
            okButton.Text                    = "Ok";
            okButton.Enabled                 = false;
            okButton.UseVisualStyleBackColor = true;
            //
            // cancelButton
            //
            cancelButton.DialogResult            = DialogResult.Cancel;
            cancelButton.Location                = new Point(134, 85);
            cancelButton.Name                    = "cancelButton";
            cancelButton.Size                    = new Size(75, 23);
            cancelButton.TabIndex                = 4;
            cancelButton.Text                    = "Cancel";
            cancelButton.UseVisualStyleBackColor = true;
            //
            // form
            //
            form.AutoScaleDimensions = new SizeF(6F, 13F);
            form.AutoScaleMode       = AutoScaleMode.Font;
            form.ClientSize          = new Size(215, 114);
            form.Controls.Add(cancelButton);
            form.Controls.Add(okButton);
            form.Controls.Add(featureNameTextBox);
            form.Controls.Add(pleaseEnterLabel);
            form.FormBorderStyle = FormBorderStyle.FixedSingle;
            form.MaximizeBox     = false;
            form.MinimizeBox     = false;
            form.AcceptButton    = okButton;
            form.CancelButton    = cancelButton;
            form.Name            = "Test";

            featureNameTextBox.TextChanged += (s, e) =>
            {
                okButton.Enabled = featureNameTextBox.Text != "" &&
                                   GlobalState.varModel.getOption(featureNameTextBox.Text) == null &&
                                   featureNameTextBox.Text == ConfigurationOption.removeInvalidCharsFromName(featureNameTextBox.Text);
            };

            DialogResult result = form.ShowDialog();

            return(new Tuple <DialogResult, string>(result, featureNameTextBox.Text));
        }