⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 widget.cs

📁 一种.net实现ajax方法的类库
💻 CS
📖 第 1 页 / 共 3 页
字号:
                {                    return;                    //ClientArguments[Name] = Value.ToString();                }                if (pi.PropertyType == typeof(String) || pi.PropertyType == typeof(object))                {                    pi.SetValue(this, Value, null);                }                else                {                    TypeConverter converter = TypeDescriptor.GetConverter(pi.PropertyType);                    if (!converter.CanConvertFrom(typeof(string)))                    {                        throw new Exception(string.Format("Cannot convert to {0} from a string.", pi.PropertyType.Name));                    }                    pi.SetValue(this, converter.ConvertFrom(Value), null);                }            }		}		public object GetAttribute( string Name )		{			PropertyInfo pi = null;            try            {                pi = this.GetType().GetProperty(Name);            }            catch (System.Reflection.AmbiguousMatchException)            {                pi = this.GetType().GetProperty(Name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);            }			if( pi == null )			{				throw new Exception("Invalid property specified.");			}			return pi.GetValue( this, null );		}		public Type DiscoverType( string SimpleName )		{			if( SimpleName.IndexOf(".") == -1 )			{				SimpleName = RootContext.DefaultNamespace + "." + SimpleName;			}            return TypeLoader.GetType(SimpleName);		}		public virtual void Add( Widget c )		{			if( widgets == null )			{				widgets = new WidgetCollection();			}			if( ClientEvents == null )			{				ClientEvents = new System.Collections.Queue();			}            c.Parent = this;			c.root = this.root;			Widgets[ c.Id ] = c;            if (RootContext == null || RootContext.CometClient == null || this.parent == null || !this.parent.rendered)            {                ClientEvents.Enqueue(c);            }            else            {                try                {                    c.RenderSelfAndChildren(RootContext.CometClient);                }                catch                {                    ClientEvents.Enqueue(c);                }            }		}		public void Add( params Widget[] widgets )		{            foreach (Widget c in widgets)            {                if (c != null)                    Add(c);            }		}		public virtual void InsertBefore( Widget c )		{            int thisIndex = Parent.widgets.IndexOf(this);            Parent.widgets.Insert(thisIndex, c);			c.Parent = this.Parent;			c.root = root;			c.position = thisIndex;            if (root == null || root.CometClient == null || this.Parent == null)                Parent.ClientEvents.Enqueue(c);            else                try                {                    c.RenderSelfAndChildren(root.CometClient);                }                catch                {                    ClientEvents.Enqueue(c);                }		}        public void Remove()        {            RootContext.RemoveWidget(this);        }		public bool IsParent		{			get { if( widgets == null ) return false; if( widgets.Count == 0 ) return false; return true; }		}		public void ParseXml( XmlNode node )		{			for( int i = 0; i < node.ChildNodes.Count; i++ )			{                XmlNode n = node.ChildNodes[i];                if (n.Name == "#text" || n.Name == "#cdata-section")                {                    PropertyDescriptor defaultProperty = TypeDescriptor.GetDefaultProperty(this);                    if (defaultProperty == null)                    {                        Label label = RootContext.CreateWidget<Label>();                        label["Text"] = n.InnerText; //can't set directly to property, b/c we won't trigger property actions, like                        //databinding tests, etc.                        Add(label);                    }                    else                    {                        this[defaultProperty.Name] = n.InnerText;                    }                }				else                    ParseElement( node.ChildNodes[i] );			}		}        public virtual void ParseElement( XmlNode n )		{			string typeName = n.Name;            Type t = TypeLoader.GetType(typeName);            if( t == null && typeName.IndexOf(".") == -1 )			{				typeName = RootContext.DefaultNamespace + "." + typeName;                t = TypeLoader.GetType(typeName);			}            if (t == null)            {                throw new System.TypeLoadException("Could not find type for " + typeName);            }            if( t.IsGenericType )            {                string modelName = n.Attributes["Model"].Value;                Type typeParameter = TypeLoader.GetType(modelName);                if (typeParameter == null)                {                    if (t.GetInterface("IDataSourced") != null )                    {                        typeParameter = XmlTypeBuilder.CreateType(modelName);                    }                    else if (modelName.IndexOf(".") == -1)                    {                        modelName = RootContext.DefaultNamespace + "." + modelName;                        typeParameter = TypeLoader.GetType(modelName);                    }                }                if (typeParameter.IsSubclassOf(typeof(XmlRecord)))                {                    ColumnInfoManager.RegisterColumns(typeParameter, XmlTypeBuilder.ReadColumnInfos(modelName));                }                t = t.MakeGenericType(typeParameter);            }            Widget ctrl = root.CreateUnkownWidget(t);            ctrl.Parent = this;                        if (n.Attributes["DataSource"] != null && ctrl is IDataSourced )            {                (ctrl as IDataSourced).DataSource = RootContext.RecordLists[n.Attributes["DataSource"].Value];                n.Attributes.Remove(n.Attributes["DataSource"]);            }            			ctrl.ParseAttributes( n );			Add( ctrl );			ctrl.ParseXml( n );		}        protected void ParseRecordList(XmlNode n)        {            string modelName = n.Attributes["Type"].Value;            Type recordType = TypeLoader.GetType(modelName);            if (recordType == null)                recordType = XmlTypeBuilder.CreateType(modelName);            string Id = n.Attributes["Id"].Value;            List<FilterInfo> filters = new List<FilterInfo>();            List<SortInfo> sorts = new List<SortInfo>();            for (int i = 0; i < n.ChildNodes.Count; i++ )            {                XmlNode child = n.ChildNodes[i];                switch (child.Name)                {                    case "FilterInfo":                        filters.Add(new FilterInfo(                            child.Attributes["Name"].Value,                            child.Attributes["Value"].Value,                            (FilterOperation)Enum.Parse(typeof(FilterOperation), child.Attributes["Operation"].Value)));                        break;                    case "SortInfo":                        SortDirection direction = SortDirection.Ascending;                        if (child.Attributes["Direction"] != null)                            direction = (SortDirection)Enum.Parse(typeof(SortDirection), child.Attributes["Direction"].Value);                        sorts.Add(new SortInfo(                            child.Attributes["Name"].Value,                            direction));                        break;                }            }            MethodInfo mi = typeof(DataProvider).GetMethod("LoadList", BindingFlags.Public | BindingFlags.Static, null,                new Type[] { typeof(FilterInfo[]), typeof(SortInfo[]) }, null);            IRecordList newList = mi.MakeGenericMethod(recordType).Invoke(null, new object[] { filters.ToArray(), sorts.ToArray() }) as IRecordList ;            if (n.Attributes["Live"] != null && Convert.ToBoolean(n.Attributes["Live"].Value))            {                newList.Live = true;            }            RootContext.RecordLists[Id] = newList;        }		public void ParseAttributes( XmlNode n )		{			foreach( XmlAttribute att in n.Attributes )			{				SetAttribute( att.Name, att.Value );			}		}        public void DataBindWidget()        {            DataBindWidget(this.record);        }		public void DataBindWidget( Model.AbstractRecord data )		{			record = data;			if( DataBoundAttributes != null )                foreach (string DataBoundAttribute in DataBoundAttributes.Keys)                {                    Bind(DataBoundAttribute, data, (string)DataBoundAttributes[DataBoundAttribute]);                }			if( Widgets != null )                for (int i = 0; i < widgets.Count; i++)                {                    Widget c = widgets[i];                    if ( ! ( c is IDataSourced ) )                        c.DataBindWidget(data);                }		}        public T Find<T>(string ID) where T : Widget        {            return Find(ID) as T;        }		public Widget Find( string ID )		{			if( Widgets != null )			{				return Widgets.Find( ID );			}			return null;		}		public void ClearChildren()		{			if( Widgets != null )				while( Widgets.Count > 0 )					RemoveChild( Widgets[0] );            if( Widgets != null ) Widgets.Clear();		}		public void RemoveChild( Widget row )		{			RootContext.RemoveWidget( row );			this.Widgets.Remove( row );		}        virtual protected void RaisePropertyChangedNotification(string property)        {            if (notifyPropertyChangedHandlers != null && notifyPropertyChangedHandlers.ContainsKey(property))                notifyPropertyChangedHandlers[property]();        }		#region ICloneable Members		public virtual object Clone()		{			Widget newWidget = this.MemberwiseClone() as Widget;			//newWidget.widgetsToRender = new Queue();			newWidget.ClientEvents = null;            newWidget.Parent = null;			newWidget.widgets = null;            if(clientArguments != null )                newWidget.clientArguments = new Dictionary<string,string>(clientArguments);            if(elementArguments != null)                newWidget.elementArguments = new Dictionary<string, string>(elementArguments);			if( Widgets != null )				for( int i = 0; i < Widgets.Count; i++ )				{					newWidget.Add( Widgets[i].Clone() as Widget );				}			return newWidget;		}		#endregion        public List<T> GetChildrenByType<T>() where T : class        {            List<T> l = new List<T>();            GetChildrenByType<T>(l);            return l;        }        public void GetChildrenByType<T>(List<T> list) where T : class        {            if (list == null || Widgets == null || Widgets.Count == 0 ) return;            foreach (Widget c in Widgets)            {                if (typeof(T).IsInstanceOfType(c))                {                    list.Add(c as T);                }                c.GetChildrenByType(list);            }        }        private event DelayedMouseOverHandler onDelayedMouseOver;        public event DelayedMouseOverHandler OnDelayedMouseOver        {            add { onDelayedMouseOver += value; ClientArguments["onDelayedMouseOver"] = "1"; }            remove { onDelayedMouseOver -= value; }        }        private event DelayedMouseOutHandler onDelayedMouseOut;        public event DelayedMouseOutHandler OnDelayedMouseOut        {            add { onDelayedMouseOut += value; ClientArguments["onDelayedMouseOut"] = "1"; }            remove { onDelayedMouseOut -= value; }        }        private event ReceiveDropHandler onReceiveDrop;        public event ReceiveDropHandler OnReceiveDrop        {            add { onReceiveDrop += value; ClientArguments["onReceiveDrop"] = "1"; }            remove { onReceiveDrop -= value; }        }        private event OnClickHandler onClick;        public event OnClickHandler OnClick        {            add { onClick += value; ClientArguments["onClick"] = "1"; }            remove { onClick -= value; }        }        #region IDataBindable Members        virtual public object Value        {            get            {                return Id;            }            set            {                Id = value.ToString();            }        }        virtual public string DefaultProperty        {            get { return "Id"; }            set { }        }        #endregion    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -