public FormUserDataField(UserDataCategory category, UserDataField field, bool editing) { InitializeComponent(); _category = category; _field = field; _editing = editing; _existingType = field.Type; cbInteractiveInclude.Visible = cbMandatory.Visible = (_category.Scope != UserDataCategory.SCOPE.Application); InitializeForm(); }
/// <summary> /// Enable/Disable fields depending on the current Field Type /// </summary> protected void SetDisplayType() { UserDataField.FieldType fieldType = (UserDataField.FieldType)cbFieldType.SelectedItem.DataValue; pnlText.Visible = false; pnlRegistry.Visible = false; pnlPicklist.Visible = false; pnlNumeric.Visible = false; pnlEnvVar.Visible = false; switch ((int)fieldType) { case (int)UserDataField.FieldType.Text: pnlText.Visible = true; break; case (int)UserDataField.FieldType.Number: //pnlNumeric.Visible = true; break; case (int)UserDataField.FieldType.Picklist: pnlPicklist.Visible = true; break; case (int)UserDataField.FieldType.Environment: pnlEnvVar.Visible = true; //showMandatory = false; break; case (int)UserDataField.FieldType.Registry: pnlRegistry.Visible = true; //showMandatory = false; break; case (int)UserDataField.FieldType.Date: break; case (int)UserDataField.FieldType.Currency: //pnlNumeric.Visible = true; break; } }
/// <summary> /// Validate the data entered /// </summary> /// <returns></returns> private bool ValidateData() { // First ensure that we have specified the field name if (tbFieldName.Text == "") { MessageBox.Show("You must specify the name of the User Defined Data Field", "Validation Failed"); tbFieldName.Focus(); return(false); } // Ensure that this field does not duplicate an existing one within the same category foreach (UserDataField field in _category) { if ((field.Name == _field.Name) && (field.FieldID != _field.FieldID)) { MessageBox.Show("A User Defined Data Field of this name already exists within this category, please enter a unique name for this field", "Field Exists"); tbFieldName.Focus(); return(false); } } // Validate the remainder of the fields based on the field type UserDataField.FieldType fieldType = (UserDataField.FieldType)cbFieldType.SelectedItem.DataValue; switch ((int)fieldType) { // For text fields we need to the length and the Case - both must be valid anyway case (int)UserDataField.FieldType.Text: break; // Numeric fields save the minimum and maximum values as Value1 and Value2 respectively ensuring that // minimum is less than or equal to maximum case (int)UserDataField.FieldType.Number: break; // Picklist - save the name of the picklist as Value1 - there must be a picklist specified case (int)UserDataField.FieldType.Picklist: if (Picklist.SelectedIndex == -1) { MessageBox.Show("A picklist must be associated with this field", "Validation Error"); Picklist.Focus(); return(false); } break; // Environment Variable - We must have specified a name case (int)UserDataField.FieldType.Environment: if (tbEnvironmentVariableName.Text == "") { MessageBox.Show("You must specify the name of an environment variable for this field", "Validation Error"); tbEnvironmentVariableName.Focus(); return(false); } break; // Registry Key - Key at least must be specified - an empty value means recover the default value case (int)UserDataField.FieldType.Registry: if (tbRegistryKey.Text == "") { MessageBox.Show("You must specify a registry key for the field", "Validation Error"); tbRegistryKey.Focus(); return(false); } break; //// No additional values required for boolean //case (int)UserDataField.FieldType.boolean: // break; case (int)UserDataField.FieldType.Date: if (_editing && _existingType != UserDataField.FieldType.Date) { if (MessageBox.Show("Please ensure any existing dates are stored in the format 'YYYY-MM-DD'." + Environment.NewLine + Environment.NewLine + "Any data not in this format may be lost. Do you wish to proceed?", "Change data type", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } } break; case (int)UserDataField.FieldType.Currency: if (_editing && _existingType != UserDataField.FieldType.Currency) { if (MessageBox.Show("Please ensure any existing currency data is stored in numeric format only." + Environment.NewLine + Environment.NewLine + "Any data not in this format may be lost. Do you wish to proceed?", "Change data type", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } } break; } return(true); }