📄 genericfielddefinition.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Epi;
using Epi.Fields;
using Epi.Data.Services;
namespace Epi.Windows.MakeView.Dialogs.FieldDefinitionDialogs
{
public partial class GenericFieldDefinition : FieldDefinition
{
#region Protected Controls
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
#endregion //Protected Controls
#region Fields
private string originalPromptText;
#endregion //Fields
#region Constructors
/// <summary>
/// Default Constructor for exclusive use by the designer
/// </summary>
public GenericFieldDefinition()
{
InitializeComponent();
}
/// <summary>
/// Constructor for the class
/// </summary>
public GenericFieldDefinition(MainForm frm) : base(frm)
{
InitializeComponent();
}
#endregion Constructors
#region Protected Methods
/// <summary>
/// Validate user input on dialog
/// </summary>
protected override bool ValidateDialogInput()
{
bool isValid = true;
if (this.ValidateInput())
{
ValidatePromptText();
ValidateFieldName();
if (ErrorMessages.Count > 0)
{
isValid = false;
}
}
return isValid;
}
#endregion //Protected Methods
#region Event Handlers
/// <summary>
/// Sets the Field Name
/// </summary>
/// <param name="sender">Object that fired the event</param>
/// <param name="e">.NET supplied event args.</param>
private void txtPrompt_Leave(object sender, System.EventArgs e)
{
if (!txtPrompt.Text.Equals(originalPromptText))
{
if (!string.IsNullOrEmpty(txtPrompt.Text))
{
txtFieldName.Text = page.GetView().ComposeFieldNameFromPromptText(Util.Squeeze(txtPrompt.Text));
}
}
}
/// <summary>
/// Handles the change event for the Field Name textbox
/// </summary>
/// <param name="sender">Object that fired the event</param>
/// <param name="e">.NET supplied event parameters</param>
private void txtFieldName_TextChanged(object sender, System.EventArgs e)
{
btnOk.Enabled = !(string.IsNullOrEmpty(txtFieldName.Text));
}
#endregion //Event Handlers
#region Private Methods
/// <summary>
/// Sets on the focus to the Prompt Text textbox
/// </summary>
/// <param name="sender">Object that fired the event.</param>
/// <param name="e">.NET supplied event args.</param>
private void GenericFieldDefinition_Load(object sender, System.EventArgs e)
{
txtPrompt.Focus();
originalPromptText = txtPrompt.Text;
}
/// <summary>
/// Validates the prompt text on the dialog
/// </summary>
private void ValidatePromptText()
{
if (string.IsNullOrEmpty(txtPrompt.Text.Trim()))
{
ErrorMessages.Add(SharedStrings.ENTER_QUESTION_OR_PROMPT);
}
//else if (Util.Squeeze(txtPrompt.Text.Trim()).Length > 255)
else if (txtPrompt.Text.Trim().Length > 255)
{
ErrorMessages.Add(SharedStrings.INVALID_PROMPT_TEXT);
}
}
/// <summary>
/// Validates the field name on the dialog
/// </summary>
private void ValidateFieldName()
{
txtFieldName.Text = Util.Squeeze(txtFieldName.Text);
if (string.IsNullOrEmpty(txtFieldName.Text))
{
ErrorMessages.Add(SharedStrings.ENTER_FIELD_NAME);
}
else if (!txtFieldName.ReadOnly)
{
//if (page.View.Fields.Exists(txtFieldName.Text))
//{
// ErrorMessages.Add(SharedStrings.DUPLICATE_FIELD_NAME);
//}
if (AppData.Instance.IsReservedWord(txtFieldName.Text))
{
ErrorMessages.Add(SharedStrings.FIELD_NAME_IS_RESERVED);
}
}
//if (txtFieldName.Text.Length > 255)
if (txtFieldName.Text.Length > 64)
{
ErrorMessages.Add(SharedStrings.FIELD_NAME_TOO_LONG);
}
if (!Util.RemoveNonAlphaNumericCharacters(txtFieldName.Text).Equals(txtFieldName.Text))
{
ErrorMessages.Add(SharedStrings.INVALID_CHARS_IN_FIELD_NAME);
}
}
#endregion Private Methods
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -