123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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 不知道控件的级次进行赋值
- /// <summary>
- /// 不知道控件的级次进行赋值
- /// </summary>
- /// <param name="page"></param>
- /// <param name="enty"></param>
- /// <param name="lbl"></param>
- /// <returns></returns>
- public static void SetControlValue(Control page, object enty)
- {
- List<Control> conlist = new List<Control>(); List<object> obj = new List<object>();
- if (!object.Equals(enty, null))
- obj.Add(enty);
- foreach (Control ctrol in page.Controls)
- {
- conlist.Add(ctrol);
- }
- GetCollection(conlist, obj, "");
- }
- /// <summary>
- /// 不知道控件的级次进行赋值
- /// </summary>
- /// <param name="page">控件集合</param>
- /// <param name="enty">单个实体</param>
- /// <param name="lbl"></param>
- /// <returns></returns>
- public static void SetControlValue(Control page, object enty, string lbl)
- {
- List<Control> conlist = new List<Control>(); List<object> obj = new List<object>();
- if (!object.Equals(enty, null))
- obj.Add(enty);
- foreach (Control ctrol in page.Controls)
- {
- conlist.Add(ctrol);
- }
- GetCollection(conlist, obj, lbl);
- }
- /// <summary>
- /// 给多个实体的控件赋值
- /// </summary>
- /// <param name="page">控件集合</param>
- /// <param name="enty">实体集合</param>
- /// <param name="lbl"></param>
- public static void SetControlValue(Control page, List<object> enty, string lbl)
- {
- List<Control> conlist = new List<Control>();
- foreach (Control ctrol in page.Controls)
- {
- conlist.Add(ctrol);
- }
- GetCollection(conlist, enty, lbl);
- }
- /// <summary>
- ///不知道控件的级次进行赋值
- /// </summary>
- /// <param name="pages"></param>
- /// <param name="enty"></param>
- public static void SetControlValue(List<Control> pages, List<object> enty)
- {
- GetCollection(pages, enty, "");
- }
- private static void GetCollection(List<Control> page, List<object> enty, string lbl)
- {
- int level = 0;
- level = ControlCollection(page, level, enty, lbl);
- }
- private static int ControlCollection(List<Control> oldMenus, int level, List<object> 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<Control> conlist = new List<Control>();
- foreach (Control ctrol in con.Controls)
- {
- conlist.Add(ctrol);
- }
- level += ControlCollection(conlist, level, entity, lbl);
- }
- }
- return level;
- }
- #endregion
- #region 知道控件的级次,对控件下面的所有控件进行赋值
- /// <summary>
- /// 知道控件的级次,对控件下面的所有控件进行赋值
- /// </summary>
- /// <param name="page"></param>
- /// <param name="enty"></param>
- public static void SetValueControl(Control page, List<object> enty)
- {
- int level = 0;
- List<Control> conlist = new List<Control>();
- foreach (Control ctrol in page.Controls)
- {
- conlist.Add(ctrol);
- }
- ControlSet(conlist, level, enty, "");
- }
- /// <summary>
- /// 知道控件的级次,对控件下面的所有控件进行赋值
- /// </summary>
- /// <param name="pages">控件集合</param>
- /// <param name="enty">实体集合</param>
- public static void SetValueControl(List<Control> pages, List<object> enty, string lbl)
- {
- try
- {
- int level = 0;
- level = ControlSet(pages, level, enty, lbl);
- }
- catch (Exception ex) { }
- }
- /// <summary>
- /// 知道控件的级次,对控件下面的所有控件进行赋值
- /// </summary>
- /// <param name="oldMenus">控件集合</param>
- /// <param name="level">循环次数</param>
- /// <param name="entity">实体集合</param>
- /// <param name="lbl">标签</param>
- /// <returns></returns>
- private static int ControlSet(List<Control> oldMenus, int level, List<object> 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
- }
- }
|