* UIEditForm:代码生成增加ComboCheckedListBox类型
This commit is contained in:
parent
224e619b0e
commit
51f7a3c6af
Binary file not shown.
Binary file not shown.
@ -54,6 +54,13 @@ namespace Sunny.UI.Demo
|
|||||||
infoList.Add(info3);
|
infoList.Add(info3);
|
||||||
|
|
||||||
string[] sex = new[] { "男", "女" };
|
string[] sex = new[] { "男", "女" };
|
||||||
|
ComboCheckedListBoxItem[] checkedItems = new ComboCheckedListBoxItem[4]
|
||||||
|
{
|
||||||
|
new ComboCheckedListBoxItem("AAA",false),
|
||||||
|
new ComboCheckedListBoxItem("BBB",false),
|
||||||
|
new ComboCheckedListBoxItem("CCC",true),
|
||||||
|
new ComboCheckedListBoxItem("DDD",false)
|
||||||
|
};
|
||||||
|
|
||||||
TreeNode[] nodes = new TreeNode[3];
|
TreeNode[] nodes = new TreeNode[3];
|
||||||
nodes[0] = new TreeNode("AA");
|
nodes[0] = new TreeNode("AA");
|
||||||
@ -75,6 +82,7 @@ namespace Sunny.UI.Demo
|
|||||||
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
||||||
option.AddSwitch("Switch", "选择", false, "打开", "关闭");
|
option.AddSwitch("Switch", "选择", false, "打开", "关闭");
|
||||||
option.AddComboTreeView("ComboTree", "选择", nodes, nodes[1].Nodes[1]);
|
option.AddComboTreeView("ComboTree", "选择", nodes, nodes[1].Nodes[1]);
|
||||||
|
option.AddComboCheckedListBox("checkedList", "选择", checkedItems);
|
||||||
|
|
||||||
UIEditForm frm = new UIEditForm(option);
|
UIEditForm frm = new UIEditForm(option);
|
||||||
frm.CheckedData += Frm_CheckedData;
|
frm.CheckedData += Frm_CheckedData;
|
||||||
@ -89,6 +97,12 @@ namespace Sunny.UI.Demo
|
|||||||
Console.WriteLine("关联: " + frm["Info"]);
|
Console.WriteLine("关联: " + frm["Info"]);
|
||||||
Console.WriteLine("选择: " + frm["Switch"]);
|
Console.WriteLine("选择: " + frm["Switch"]);
|
||||||
Console.WriteLine("选择: " + frm["ComboTree"]);
|
Console.WriteLine("选择: " + frm["ComboTree"]);
|
||||||
|
|
||||||
|
var outCheckedItems = (ComboCheckedListBoxItem[])frm["checkedList"];
|
||||||
|
foreach (var item in outCheckedItems)
|
||||||
|
{
|
||||||
|
Console.WriteLine(item.Text, item.Checked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frm.Dispose();
|
frm.Dispose();
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* 2021-04-26: V3.0.3 代码生成增加Switch类型,代码生成增加Combobox类型
|
* 2021-04-26: V3.0.3 代码生成增加Switch类型,代码生成增加Combobox类型
|
||||||
* 2021-05-19: V3.0.3 动态生成表单,增加校验方法
|
* 2021-05-19: V3.0.3 动态生成表单,增加校验方法
|
||||||
* 2021-10-26: V3.0.8 代码生成增加ComboTreeView类型
|
* 2021-10-26: V3.0.8 代码生成增加ComboTreeView类型
|
||||||
|
* 2021-10-28: V3.0.8 代码生成增加ComboCheckedListBox类型
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -83,102 +84,64 @@ namespace Sunny.UI
|
|||||||
label.TextAlign = ContentAlignment.MiddleRight;
|
label.TextAlign = ContentAlignment.MiddleRight;
|
||||||
label.Parent = this;
|
label.Parent = this;
|
||||||
|
|
||||||
|
Control ctrl = null;
|
||||||
|
|
||||||
if (info.EditType == EditType.Text)
|
if (info.EditType == EditType.Text)
|
||||||
{
|
{
|
||||||
UITextBox edit = new UITextBox();
|
ctrl = new UITextBox();
|
||||||
edit.Left = option.LabelWidth;
|
var edit = (UITextBox)ctrl;
|
||||||
edit.Width = option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.Text = info.Value?.ToString();
|
edit.Text = info.Value?.ToString();
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.EnterAsTab = true;
|
edit.EnterAsTab = true;
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.Password)
|
if (info.EditType == EditType.Password)
|
||||||
{
|
{
|
||||||
UITextBox edit = new UITextBox();
|
ctrl = new UITextBox();
|
||||||
edit.Left = option.LabelWidth;
|
var edit = (UITextBox)ctrl;
|
||||||
edit.Width = option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.Text = info.Value?.ToString();
|
edit.Text = info.Value?.ToString();
|
||||||
edit.Parent = this;
|
|
||||||
edit.PasswordChar = '*';
|
edit.PasswordChar = '*';
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.EnterAsTab = true;
|
edit.EnterAsTab = true;
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.Integer)
|
if (info.EditType == EditType.Integer)
|
||||||
{
|
{
|
||||||
UITextBox edit = new UITextBox();
|
ctrl = new UITextBox();
|
||||||
|
var edit = (UITextBox)ctrl;
|
||||||
edit.Type = UITextBox.UIEditType.Integer;
|
edit.Type = UITextBox.UIEditType.Integer;
|
||||||
edit.Left = option.LabelWidth;
|
|
||||||
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.IntValue = info.Value.ToString().ToInt();
|
edit.IntValue = info.Value.ToString().ToInt();
|
||||||
edit.Parent = this;
|
edit.EnterAsTab = true;
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.Double)
|
if (info.EditType == EditType.Double)
|
||||||
{
|
{
|
||||||
UITextBox edit = new UITextBox();
|
ctrl = new UITextBox();
|
||||||
|
var edit = (UITextBox)ctrl;
|
||||||
edit.Type = UITextBox.UIEditType.Double;
|
edit.Type = UITextBox.UIEditType.Double;
|
||||||
edit.Left = option.LabelWidth;
|
|
||||||
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.DoubleValue = info.Value.ToString().ToDouble();
|
edit.DoubleValue = info.Value.ToString().ToDouble();
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.EnterAsTab = true;
|
edit.EnterAsTab = true;
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.Date)
|
if (info.EditType == EditType.Date)
|
||||||
{
|
{
|
||||||
UIDatePicker edit = new UIDatePicker();
|
ctrl = new UIDatePicker();
|
||||||
edit.Left = option.LabelWidth;
|
var edit = (UIDatePicker)ctrl;
|
||||||
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.Value = (DateTime)info.Value;
|
edit.Value = (DateTime)info.Value;
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.DateTime)
|
if (info.EditType == EditType.DateTime)
|
||||||
{
|
{
|
||||||
UIDatetimePicker edit = new UIDatetimePicker();
|
ctrl = new UIDatetimePicker();
|
||||||
edit.Left = option.LabelWidth;
|
var edit = (UIDatetimePicker)ctrl;
|
||||||
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.Value = (DateTime)info.Value;
|
edit.Value = (DateTime)info.Value;
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.Switch)
|
if (info.EditType == EditType.Switch)
|
||||||
{
|
{
|
||||||
UISwitch edit = new UISwitch();
|
ctrl = new UISwitch();
|
||||||
|
var edit = (UISwitch)ctrl;
|
||||||
edit.SwitchShape = UISwitch.UISwitchShape.Square;
|
edit.SwitchShape = UISwitch.UISwitchShape.Square;
|
||||||
edit.Left = option.LabelWidth - 1;
|
|
||||||
edit.Width = 75;
|
|
||||||
edit.Height = 29;
|
edit.Height = 29;
|
||||||
edit.Top = top;
|
|
||||||
edit.Active = (bool)info.Value;
|
edit.Active = (bool)info.Value;
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
|
|
||||||
if (info.DataSource != null)
|
if (info.DataSource != null)
|
||||||
{
|
{
|
||||||
@ -189,20 +152,13 @@ namespace Sunny.UI
|
|||||||
SizeF sf2 = GDI.MeasureString(items[0], edit.Font);
|
SizeF sf2 = GDI.MeasureString(items[0], edit.Font);
|
||||||
edit.Width = (int)Math.Max(sf1.Width, sf2.Width) + edit.Height + 16;
|
edit.Width = (int)Math.Max(sf1.Width, sf2.Width) + edit.Height + 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.Combobox)
|
if (info.EditType == EditType.Combobox)
|
||||||
{
|
{
|
||||||
UIComboBox edit = new UIComboBox();
|
ctrl = new UIComboBox();
|
||||||
|
var edit = (UIComboBox)ctrl;
|
||||||
edit.DropDownStyle = UIDropDownStyle.DropDownList;
|
edit.DropDownStyle = UIDropDownStyle.DropDownList;
|
||||||
edit.Left = option.LabelWidth;
|
|
||||||
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
|
|
||||||
if (info.DisplayMember.IsNullOrEmpty())
|
if (info.DisplayMember.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
@ -222,28 +178,47 @@ namespace Sunny.UI
|
|||||||
edit.DataSource = info.DataSource;
|
edit.DataSource = info.DataSource;
|
||||||
edit.SelectedValue = info.Value;
|
edit.SelectedValue = info.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrls.Add(edit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.EditType == EditType.ComboTreeView)
|
if (info.EditType == EditType.ComboTreeView)
|
||||||
{
|
{
|
||||||
UIComboTreeView edit = new UIComboTreeView();
|
ctrl = new UIComboTreeView();
|
||||||
|
var edit = (UIComboTreeView)ctrl;
|
||||||
edit.CanSelectRootNode = true;
|
edit.CanSelectRootNode = true;
|
||||||
edit.ShowLines = true;
|
edit.ShowLines = true;
|
||||||
edit.DropDownStyle = UIDropDownStyle.DropDownList;
|
edit.DropDownStyle = UIDropDownStyle.DropDownList;
|
||||||
edit.Left = option.LabelWidth;
|
|
||||||
edit.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
|
||||||
edit.Top = top;
|
|
||||||
edit.Parent = this;
|
|
||||||
edit.Name = "Edit_" + info.DataPropertyName;
|
|
||||||
edit.Enabled = info.Enabled;
|
|
||||||
|
|
||||||
edit.TreeView.Nodes.Clear();
|
edit.TreeView.Nodes.Clear();
|
||||||
edit.TreeView.Nodes.AddRange((TreeNode[])info.DataSource);
|
edit.TreeView.Nodes.AddRange((TreeNode[])info.DataSource);
|
||||||
edit.TreeView.SelectedNode = (TreeNode)info.Value;
|
edit.TreeView.SelectedNode = (TreeNode)info.Value;
|
||||||
|
}
|
||||||
|
|
||||||
ctrls.Add(edit);
|
if (info.EditType == EditType.ComboCheckedListBox)
|
||||||
|
{
|
||||||
|
ctrl = new UIComboTreeView();
|
||||||
|
var edit = (UIComboTreeView)ctrl;
|
||||||
|
edit.CanSelectRootNode = true;
|
||||||
|
edit.CheckBoxes = true;
|
||||||
|
edit.DropDownStyle = UIDropDownStyle.DropDownList;
|
||||||
|
edit.TreeView.Nodes.Clear();
|
||||||
|
var obj = (ComboCheckedListBoxItem[])info.DataSource;
|
||||||
|
foreach (var item in obj)
|
||||||
|
{
|
||||||
|
TreeNode node = edit.TreeView.Nodes.Add(item.Text);
|
||||||
|
node.Tag = item;
|
||||||
|
node.Checked = item.Checked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctrl != null)
|
||||||
|
{
|
||||||
|
ctrl.Left = option.LabelWidth;
|
||||||
|
if (info.EditType != EditType.Switch)
|
||||||
|
ctrl.Width = info.HalfWidth ? option.ValueWidth / 2 : option.ValueWidth;
|
||||||
|
ctrl.Top = top;
|
||||||
|
ctrl.Parent = this;
|
||||||
|
ctrl.Name = "Edit_" + info.DataPropertyName;
|
||||||
|
ctrl.Enabled = info.Enabled;
|
||||||
|
ctrls.Add(ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
top += 29 + 10;
|
top += 29 + 10;
|
||||||
@ -426,6 +401,21 @@ namespace Sunny.UI
|
|||||||
if (edit == null) continue;
|
if (edit == null) continue;
|
||||||
info.Value = edit.TreeView.SelectedNode;
|
info.Value = edit.TreeView.SelectedNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.EditType == EditType.ComboCheckedListBox)
|
||||||
|
{
|
||||||
|
UIComboTreeView edit = this.GetControl<UIComboTreeView>("Edit_" + info.DataPropertyName);
|
||||||
|
if (edit == null) continue;
|
||||||
|
List<ComboCheckedListBoxItem> result = new List<ComboCheckedListBoxItem>();
|
||||||
|
foreach (TreeNode item in edit.Nodes)
|
||||||
|
{
|
||||||
|
ComboCheckedListBoxItem obj = (ComboCheckedListBoxItem)item.Tag;
|
||||||
|
obj.Checked = item.Checked;
|
||||||
|
if (obj.Checked) result.Add(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
info.Value = result.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,25 @@ namespace Sunny.UI
|
|||||||
Password,
|
Password,
|
||||||
Combobox,
|
Combobox,
|
||||||
Switch,
|
Switch,
|
||||||
ComboTreeView
|
ComboTreeView,
|
||||||
|
ComboCheckedListBox
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ComboCheckedListBoxItem
|
||||||
|
{
|
||||||
|
public bool Checked;
|
||||||
|
public string Text;
|
||||||
|
|
||||||
|
public ComboCheckedListBoxItem()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComboCheckedListBoxItem(string text, bool isChecked)
|
||||||
|
{
|
||||||
|
Checked = isChecked;
|
||||||
|
Text = text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EditInfo
|
public class EditInfo
|
||||||
@ -204,7 +221,8 @@ namespace Sunny.UI
|
|||||||
EditType = EditType.Switch,
|
EditType = EditType.Switch,
|
||||||
Text = text,
|
Text = text,
|
||||||
Value = value,
|
Value = value,
|
||||||
Enabled = enabled
|
Enabled = enabled,
|
||||||
|
HalfWidth = true
|
||||||
};
|
};
|
||||||
|
|
||||||
Infos.Add(info);
|
Infos.Add(info);
|
||||||
@ -223,7 +241,8 @@ namespace Sunny.UI
|
|||||||
Text = text,
|
Text = text,
|
||||||
Value = value,
|
Value = value,
|
||||||
Enabled = enabled,
|
Enabled = enabled,
|
||||||
DataSource = new string[2] { activeText, inActiveText }
|
DataSource = new string[2] { activeText, inActiveText },
|
||||||
|
HalfWidth = true
|
||||||
};
|
};
|
||||||
|
|
||||||
Infos.Add(info);
|
Infos.Add(info);
|
||||||
@ -292,5 +311,25 @@ namespace Sunny.UI
|
|||||||
Infos.Add(info);
|
Infos.Add(info);
|
||||||
Dictionary.TryAdd(info.DataPropertyName, info);
|
Dictionary.TryAdd(info.DataPropertyName, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddComboCheckedListBox(string dataPropertyName, string text, ComboCheckedListBoxItem[] nodes, bool enabled = true, bool halfWidth = false)
|
||||||
|
{
|
||||||
|
if (Dictionary.ContainsKey(dataPropertyName))
|
||||||
|
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
|
||||||
|
|
||||||
|
EditInfo info = new EditInfo()
|
||||||
|
{
|
||||||
|
DataPropertyName = dataPropertyName,
|
||||||
|
EditType = EditType.ComboCheckedListBox,
|
||||||
|
Text = text,
|
||||||
|
Value = nodes,
|
||||||
|
Enabled = enabled,
|
||||||
|
HalfWidth = halfWidth,
|
||||||
|
DataSource = nodes
|
||||||
|
};
|
||||||
|
|
||||||
|
Infos.Add(info);
|
||||||
|
Dictionary.TryAdd(info.DataPropertyName, info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user