* UIEditForm:代码生成增加Combobox类型
This commit is contained in:
parent
3215b5ba46
commit
c91f03f3bd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Sunny.UI.Demo.Forms
|
namespace Sunny.UI.Demo.Forms
|
||||||
{
|
{
|
||||||
@ -43,12 +44,24 @@ namespace Sunny.UI.Demo.Forms
|
|||||||
|
|
||||||
private void uiSymbolButton1_Click(object sender, EventArgs e)
|
private void uiSymbolButton1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
List<FCombobox.Info> infoList = new List<FCombobox.Info>();
|
||||||
|
FCombobox.Info info1 = new FCombobox.Info() { Id = "1", Name = "张三" };
|
||||||
|
FCombobox.Info info2 = new FCombobox.Info() { Id = "2", Name = "李四" };
|
||||||
|
FCombobox.Info info3 = new FCombobox.Info() { Id = "3", Name = "王五" };
|
||||||
|
infoList.Add(info1);
|
||||||
|
infoList.Add(info2);
|
||||||
|
infoList.Add(info3);
|
||||||
|
|
||||||
|
string[] sex = new[] { "男", "女" };
|
||||||
|
|
||||||
UIEditOption option = new UIEditOption();
|
UIEditOption option = new UIEditOption();
|
||||||
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", "年龄", 20);
|
||||||
option.AddDate("Birthday", "生日", DateTime.Now);
|
option.AddDate("Birthday", "生日", DateTime.Now);
|
||||||
|
option.AddCombobox("Sex", "性别", sex, 1, true, true);
|
||||||
|
option.AddCombobox("Info", "关联", infoList, "Name", "Id", "2");
|
||||||
|
|
||||||
UIEditForm frm = new UIEditForm(option);
|
UIEditForm frm = new UIEditForm(option);
|
||||||
frm.ShowDialog();
|
frm.ShowDialog();
|
||||||
@ -58,6 +71,8 @@ namespace Sunny.UI.Demo.Forms
|
|||||||
Console.WriteLine("姓名: " + frm["Name"]);
|
Console.WriteLine("姓名: " + frm["Name"]);
|
||||||
Console.WriteLine("年龄: " + frm["Age"]);
|
Console.WriteLine("年龄: " + frm["Age"]);
|
||||||
Console.WriteLine("生日: " + frm["Birthday"]);
|
Console.WriteLine("生日: " + frm["Birthday"]);
|
||||||
|
Console.WriteLine("性别: " + sex[(int)frm["Sex"]]);
|
||||||
|
Console.WriteLine("关联: " + frm["Info"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
frm.Dispose();
|
frm.Dispose();
|
||||||
|
@ -164,6 +164,40 @@ namespace Sunny.UI
|
|||||||
ctrls.Add(edit);
|
ctrls.Add(edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.EditType == EditType.Combobox)
|
||||||
|
{
|
||||||
|
UIComboBox edit = new UIComboBox();
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
object[] items = (object[])info.DataSource;
|
||||||
|
if (items != null)
|
||||||
|
{
|
||||||
|
edit.Items.AddRange(items);
|
||||||
|
int index = info.Value.ToString().ToInt();
|
||||||
|
if (index < items.Length)
|
||||||
|
edit.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
edit.DisplayMember = info.DisplayMember;
|
||||||
|
edit.ValueMember = info.ValueMember;
|
||||||
|
edit.DataSource = info.DataSource;
|
||||||
|
edit.SelectedValue = info.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ctrls.Add(edit);
|
||||||
|
}
|
||||||
|
|
||||||
top += 29 + 10;
|
top += 29 + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,6 +342,13 @@ namespace Sunny.UI
|
|||||||
if (edit == null) continue;
|
if (edit == null) continue;
|
||||||
info.Value = edit.Value;
|
info.Value = edit.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info.EditType == EditType.Combobox)
|
||||||
|
{
|
||||||
|
UIComboBox edit = this.GetControl<UIComboBox>("Edit_" + info.DataPropertyName);
|
||||||
|
if (edit == null) continue;
|
||||||
|
info.Value = edit.ValueMember.IsValid() ? edit.SelectedValue : edit.SelectedIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -33,7 +34,8 @@ namespace Sunny.UI
|
|||||||
Double,
|
Double,
|
||||||
Date,
|
Date,
|
||||||
DateTime,
|
DateTime,
|
||||||
Password
|
Password,
|
||||||
|
Combobox
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EditInfo
|
public class EditInfo
|
||||||
@ -51,6 +53,10 @@ namespace Sunny.UI
|
|||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
|
|
||||||
public bool HalfWidth { get; set; }
|
public bool HalfWidth { get; set; }
|
||||||
|
|
||||||
|
public object DataSource { get; set; }
|
||||||
|
public string DisplayMember { get; set; }
|
||||||
|
public string ValueMember { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UIEditOption
|
public class UIEditOption
|
||||||
@ -180,5 +186,48 @@ namespace Sunny.UI
|
|||||||
Infos.Add(info);
|
Infos.Add(info);
|
||||||
Dictionary.TryAdd(info.DataPropertyName, info);
|
Dictionary.TryAdd(info.DataPropertyName, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddCombobox(string dataPropertyName, string text, IList dataSource, string displayMember,
|
||||||
|
string valueMember, object value, bool enabled = true, bool halfWidth = false)
|
||||||
|
{
|
||||||
|
if (Dictionary.ContainsKey(dataPropertyName))
|
||||||
|
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
|
||||||
|
|
||||||
|
EditInfo info = new EditInfo()
|
||||||
|
{
|
||||||
|
DataPropertyName = dataPropertyName,
|
||||||
|
EditType = EditType.Combobox,
|
||||||
|
Text = text,
|
||||||
|
Value = value,
|
||||||
|
Enabled = enabled,
|
||||||
|
HalfWidth = halfWidth,
|
||||||
|
DataSource = dataSource,
|
||||||
|
DisplayMember = displayMember,
|
||||||
|
ValueMember = valueMember
|
||||||
|
};
|
||||||
|
|
||||||
|
Infos.Add(info);
|
||||||
|
Dictionary.TryAdd(info.DataPropertyName, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddCombobox(string dataPropertyName, string text, string[] items, int selectedIndex = -1, bool enabled = true, bool halfWidth = false)
|
||||||
|
{
|
||||||
|
if (Dictionary.ContainsKey(dataPropertyName))
|
||||||
|
throw new DuplicateNameException(dataPropertyName + ": 已经存在");
|
||||||
|
|
||||||
|
EditInfo info = new EditInfo()
|
||||||
|
{
|
||||||
|
DataPropertyName = dataPropertyName,
|
||||||
|
EditType = EditType.Combobox,
|
||||||
|
Text = text,
|
||||||
|
Value = selectedIndex,
|
||||||
|
Enabled = enabled,
|
||||||
|
HalfWidth = halfWidth,
|
||||||
|
DataSource = items
|
||||||
|
};
|
||||||
|
|
||||||
|
Infos.Add(info);
|
||||||
|
Dictionary.TryAdd(info.DataPropertyName, info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user