using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.UI; namespace Ant.Frame { public enum ControlType { Ext, Net } public static class SetValue { #region 不知道控件的级次进行赋值 /// /// 不知道控件的级次进行赋值 /// /// /// /// /// public static void SetControlValue(Control page, object enty) { List conlist = new List(); List obj = new List(); if (!object.Equals(enty, null)) obj.Add(enty); foreach (Control ctrol in page.Controls) { conlist.Add(ctrol); } GetCollection(conlist, obj, ""); } /// /// 不知道控件的级次进行赋值 /// /// 控件集合 /// 单个实体 /// /// public static void SetControlValue(Control page, object enty, string lbl) { List conlist = new List(); List obj = new List(); if (!object.Equals(enty, null)) obj.Add(enty); foreach (Control ctrol in page.Controls) { conlist.Add(ctrol); } GetCollection(conlist, obj, lbl); } /// /// 给多个实体的控件赋值 /// /// 控件集合 /// 实体集合 /// public static void SetControlValue(Control page, List enty, string lbl) { List conlist = new List(); foreach (Control ctrol in page.Controls) { conlist.Add(ctrol); } GetCollection(conlist, enty, lbl); } /// ///不知道控件的级次进行赋值 /// /// /// public static void SetControlValue(List pages, List enty) { GetCollection(pages, enty, ""); } private static void GetCollection(List page, List enty, string lbl) { int level = 0; level = ControlCollection(page, level, enty, lbl); } private static int ControlCollection(List oldMenus, int level, List entity, string lbl) { foreach (Control con in oldMenus) { SelectControl setcon = new SelectControl(ControlType.Ext, con); setcon.SetResult(entity, lbl); int controlnum = con.Controls.Count; if (controlnum == 0) level++; else { List conlist = new List(); foreach (Control ctrol in con.Controls) { conlist.Add(ctrol); } level += ControlCollection(conlist, level, entity, lbl); } } return level; } #endregion #region 知道控件的级次,对控件下面的所有控件进行赋值 /// /// 知道控件的级次,对控件下面的所有控件进行赋值 /// /// /// public static void SetValueControl(Control page, List enty) { int level = 0; List conlist = new List(); foreach (Control ctrol in page.Controls) { conlist.Add(ctrol); } ControlSet(conlist, level, enty, ""); } /// /// 知道控件的级次,对控件下面的所有控件进行赋值 /// /// 控件集合 /// 实体集合 public static void SetValueControl(List pages, List enty, string lbl) { try { int level = 0; level = ControlSet(pages, level, enty, lbl); } catch (Exception ex) { } } /// /// 知道控件的级次,对控件下面的所有控件进行赋值 /// /// 控件集合 /// 循环次数 /// 实体集合 /// 标签 /// private static int ControlSet(List oldMenus, int level, List entity, string lbl) { foreach (Control menu in oldMenus) { foreach (Control cc in menu.Controls) { SelectControl con = new SelectControl(ControlType.Ext, cc); con.SetResult(entity, lbl); } } return level; } #endregion } }