123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using ETDExtUI;
- using ETD.Common;
- public static class DExt
- {
- #region 设置控件值
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this Label control, string val)
- {
- if (!control.IsNull())
- {
- control.Text = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this TextBox control, string val)
- {
- if (!control.IsNull())
- {
- control.Text = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this NumberBox control, object val)
- {
- if (!control.IsNull())
- {
- control.Text = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this TextArea control, string val)
- {
- if (!control.IsNull())
- {
- control.Text = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this DatePicker control, object val)
- {
- if (!control.IsNull())
- {
- if (val is string)
- {
- control.Text = val.IfNull().Trim();
- return;
- }
- if (val is DateTime)
- {
- DateTime dt = val.ToDateTime();
- if (!dt.Equals(DObject.EMPTY_DATE_TIME))
- {
- control.SelectedDate = dt;
- }
- return;
- }
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="value">值</param>
- public static void SetValue(this CheckBox control, object val)
- {
- if (control.IsNull())
- {
- return;
- }
- if (val is bool)
- {
- control.Checked = (bool)val;
- return;
- }
- if (val.ToString().Equals(DString.NUM_1))
- {
- control.Checked = true;
- return;
- }
- control.Checked = false;
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="value">值</param>
- public static void SetValue(this DropDownList control, string val)
- {
- if (!control.IsNull())
- {
- control.SelectedValue = val;
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this ToolbarText control, string val)
- {
- if (!control.IsNull())
- {
- control.Text = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetValue(this TwinTriggerBox control, string val)
- {
- if (!control.IsNull())
- {
- control.Text = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 设置点击
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static void SetClick(this Button control, string val)
- {
- if (!control.IsNull())
- {
- control.OnClientClick = val.IfNull().Trim();
- }
- }
- /// <summary>
- /// 绑定控件数据
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="value">数据</param>
- public static void SetDllDataSource<T>(this DropDownList control, List<T> data, string selectedvalue) where T : ECustomTree, new()
- {
- if (!control.IsNull())
- {
- control.EnableSimulateTree = true;
- control.DataValueField = DColumn.Id;
- control.DataTextField = DColumn.NameD;
- control.DataSimulateTreeLevelField = DColumn.LevelD;
- control.DataEnableSelectField = DColumn.StatusD;
- control.DataSource = data;
- control.DataBind();
- control.SetValue(selectedvalue);
- }
- }
- #endregion
- #region 提取控件值
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static string GetValue(this Label control)
- {
- if (!control.IsNull())
- {
- return control.Text.IfNull().Trim();
- }
- return String.Empty;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static string GetValue(this TextBox control)
- {
- if (!control.IsNull())
- {
- return control.Text.IfNull().FilterHTML().Trim();
- }
- return String.Empty;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static int GetValue(this NumberBox control)
- {
- if (!control.IsNull())
- {
- return control.Text.ToInt32();
- }
- return 0;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static decimal GetDecValue(this NumberBox control)
- {
- if (!control.IsNull())
- {
- return control.Text.ToDec();
- }
- return 0;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static string GetValue(this TextArea control)
- {
- if (!control.IsNull())
- {
- return control.Text.IfNull().FilterHTML().Trim();
- }
- return String.Empty;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static DateTime GetValue(this DatePicker control)
- {
- if (!control.IsNull())
- {
- return control.SelectedDate.ToDateTime();
- }
- return DObject.EMPTY_DATE_TIME;
- }
- /// <summary>
- /// 提取控件值为空时返回最小
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static DateTime GetValueEmptyMin(this DatePicker control)
- {
- if (!control.IsNull() && !control.Text.IsEmpty())
- {
- return control.SelectedDate.ToDateTime();
- }
- return DObject.EMPTY_DATE_TIME;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- /// <param name="val">值</param>
- public static int GetValue(this CheckBox control)
- {
- if (control.IsNull())
- {
- return 0;
- }
- return control.Checked ? 1 : 0;
- }
- /// <summary>
- /// 提取控件值
- /// </summary>
- /// <param name="control">控件</param>
- public static string GetValue(this DropDownList control)
- {
- if (control.IsNull())
- {
- return String.Empty;
- }
- //DHelper.SetSession(control.ID, control.SelectedValue);
- return control.SelectedValue;
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- public static string GetValue(this CheckBoxList control)
- {
- string ret = String.Empty;
- if (control.IsNull())
- {
- return ret;
- }
- for (int i = 0; i < control.Items.Count; i++)
- {
- if (control.Items[i].Selected)
- {
- ret += DString.COMMA + control.Items[i].Value.Trim();
- }
- }
- if (ret.Length > 0)
- {
- ret = ret.Substring(1);
- }
- return ret;
- }
- /// <summary>
- /// 设置控件值
- /// </summary>
- /// <param name="control">控件</param>
- public static List<int> GetIntValue(this CheckBoxList control)
- {
- List<int> ret = new List<int>();
- if (control.IsNull())
- {
- return ret;
- }
- for (int i = 0; i < control.Items.Count; i++)
- {
- if (control.Items[i].Selected)
- {
- ret.Add(control.Items[i].Value.Trim().ToInt32());
- }
- }
- return ret;
- }
- /// <summary>
- /// 提取ICON图标地址
- /// </summary>
- /// <param name="icon">图标</param>
- /// <returns>图标地址</returns>
- public static string GetIconUrl(this Icon icon)
- {
- if (!icon.IsNull())
- {
- return IconHelper.GetIconUrl(icon);
- }
- return string.Empty;
- }
- #endregion
- #region 初始化
- /// <summary>
- /// 创建树节点
- /// </summary>
- /// <param name="parent">父编码</param>
- /// <param name="pnode">节点</param>
- /// <param name="featList">数据</param>
- public static void CreateTree(string parent, TreeNode pnode, List<ECustomTree> featList)
- {
- foreach (ECustomTree feat in featList.FindAll(delegate(ECustomTree p) { return p.ParentId == parent; }))
- {
- TreeNode node = new TreeNode();
- node.NodeID = feat.Id;
- // node.IconUrl = feat.PicD;
- node.Text = feat.Name;
- node.EnablePostBack = true;
- CreateTree(feat.Id, node, featList);
- //node.Expanded = true;
- pnode.Nodes.Add(node);
- }
- }
- /// <summary>
- /// 创建树节点
- /// </summary>
- /// <param name="parent">父编码</param>
- /// <param name="pnode">节点</param>
- /// <param name="featList">数据</param>
- /// <param name="featList">是否被选择</param>
- public static void CreateCheckTree(string parent, TreeNode pnode, List<ECustomTree> featList, Predicate<ECustomTree> isCheck)
- {
- foreach (ECustomTree feat in featList.FindAll(delegate(ECustomTree p) { return p.ParentId == parent; }))
- {
- TreeNode node = new TreeNode();
- node.NodeID = feat.Id;
- //node.IconUrl = feat.PicD;
- node.Text = feat.Name;
- node.AutoPostBack = true;
- node.EnableCheckBox = true;
- if (isCheck(feat))
- {
- node.Checked = true;
- }
- CreateCheckTree(feat.Id, node, featList, isCheck);
- node.Expanded = true;
- if (feat.IsTreeLeaf)
- {
- pnode.Nodes.Add(node);
- }
- }
- }
- public static List<ECustomTree> GetDataSource(string parent, List<ECustomTree> allList)
- {
- List<ECustomTree> parentList = new List<ECustomTree>();
- int leave = 0;
- bool start = false;//是否禁用
- foreach (ECustomTree featc in allList)
- {
- ECustomTree feat = new ECustomTree();
- feat.TreeLevel = featc.TreeLevel;
- feat.Id = featc.Id;
- feat.Name = featc.Name;
- feat.IsTreeLeaf = featc.IsTreeLeaf;
- //开始禁用后
- if (start)
- {
- //当前等级小于等于等级结束禁用
- if (feat.TreeLevel <= leave)
- {
- start = false;
- }
- else
- {
- feat.Enabled = false;
- }
- }
- else
- {
- //当前等级等于等级开始禁用
- if (parent.Equals(feat.Id) && !parent.IsEmpty())
- {
- feat.Enabled = false;
- start = true;
- }
- leave = feat.TreeLevel;
- }
- parentList.Add(feat);
- }
- return parentList;
- }
- #endregion
- }
|