* UIEditForm:动态生成表单,增加校验方法。

This commit is contained in:
Sunny 2021-05-19 14:03:36 +08:00
parent adb456db32
commit e17f202fce
7 changed files with 48 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -58,13 +58,14 @@ namespace Sunny.UI.Demo.Forms
option.AutoLabelWidth = true;
option.Text = "增加";
option.AddText("Name", "姓名", "", true);
option.AddInteger("Age", "年龄", 20);
option.AddInteger("Age", "年龄", 16);
option.AddDate("Birthday", "生日", DateTime.Now);
option.AddCombobox("Sex", "性别", sex, 1, true, true);
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
option.AddSwitch("Switch", "选择", false);
UIEditForm frm = new UIEditForm(option);
frm.CheckedData += Frm_CheckedData;
frm.ShowDialog();
if (frm.IsOK)
@ -79,6 +80,18 @@ namespace Sunny.UI.Demo.Forms
frm.Dispose();
}
private bool Frm_CheckedData(object sender, UIEditForm.EditFormEventArgs e)
{
if (e.Form["Age"].ToString().ToInt() < 18 || e.Form["Age"].ToString().ToInt() > 60)
{
e.Form.SetEditorFocus("Age");
ShowWarningTip("年龄范围为18到60岁");
return false;
}
return true;
}
}
public class Person

View File

@ -283,6 +283,14 @@ namespace Sunny.UI
return;
}
if (CheckedData != null)
{
if (!CheckedData.Invoke(this, new EditFormEventArgs(this)))
{
return;
}
}
if (ButtonOkClick != null)
{
ButtonOkClick.Invoke(sender, e);
@ -309,6 +317,13 @@ namespace Sunny.UI
}
}
public void SetEditorFocus(string dataPropertyName)
{
Control editor = this.GetControl<UITextBox>("Edit_" + dataPropertyName);
if (editor != null)
editor.Focus();
}
protected virtual bool CheckData()
{
if (Option != null)
@ -377,6 +392,25 @@ namespace Sunny.UI
return true;
}
public delegate bool OnCheckedData(object sender, EditFormEventArgs e);
public event OnCheckedData CheckedData;
public class EditFormEventArgs : EventArgs
{
public EditFormEventArgs()
{
}
public EditFormEventArgs(UIEditForm editor)
{
Form = editor;
}
public UIEditForm Form { get; set; }
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);