* UIEditForm:动态生成表单,增加校验方法。
This commit is contained in:
parent
adb456db32
commit
e17f202fce
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -58,13 +58,14 @@ namespace Sunny.UI.Demo.Forms
|
|||||||
option.AutoLabelWidth = true;
|
option.AutoLabelWidth = true;
|
||||||
option.Text = "增加";
|
option.Text = "增加";
|
||||||
option.AddText("Name", "姓名", "", true);
|
option.AddText("Name", "姓名", "", true);
|
||||||
option.AddInteger("Age", "年龄", 20);
|
option.AddInteger("Age", "年龄", 16);
|
||||||
option.AddDate("Birthday", "生日", DateTime.Now);
|
option.AddDate("Birthday", "生日", DateTime.Now);
|
||||||
option.AddCombobox("Sex", "性别", sex, 1, true, true);
|
option.AddCombobox("Sex", "性别", sex, 1, true, true);
|
||||||
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
||||||
option.AddSwitch("Switch", "选择", false);
|
option.AddSwitch("Switch", "选择", false);
|
||||||
|
|
||||||
UIEditForm frm = new UIEditForm(option);
|
UIEditForm frm = new UIEditForm(option);
|
||||||
|
frm.CheckedData += Frm_CheckedData;
|
||||||
frm.ShowDialog();
|
frm.ShowDialog();
|
||||||
|
|
||||||
if (frm.IsOK)
|
if (frm.IsOK)
|
||||||
@ -79,6 +80,18 @@ namespace Sunny.UI.Demo.Forms
|
|||||||
|
|
||||||
frm.Dispose();
|
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
|
public class Person
|
||||||
|
@ -283,6 +283,14 @@ namespace Sunny.UI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CheckedData != null)
|
||||||
|
{
|
||||||
|
if (!CheckedData.Invoke(this, new EditFormEventArgs(this)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ButtonOkClick != null)
|
if (ButtonOkClick != null)
|
||||||
{
|
{
|
||||||
ButtonOkClick.Invoke(sender, e);
|
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()
|
protected virtual bool CheckData()
|
||||||
{
|
{
|
||||||
if (Option != null)
|
if (Option != null)
|
||||||
@ -377,6 +392,25 @@ namespace Sunny.UI
|
|||||||
return true;
|
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)
|
protected override void OnSizeChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnSizeChanged(e);
|
base.OnSizeChanged(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user