treeelement.cs
来自「《精通ASP.NET2.0网络应用系统开发》书中的源码」· CS 代码 · 共 725 行 · 第 1/2 页
CS
725 行
}
}
/// <summary>
/// Gets or sets the default CssClass for the element when OnMouseOver client event occure.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 26 January, 2003
/// </author>
[
Bindable( true ),
DefaultValue( "" ),
PersistenceMode( PersistenceMode.Attribute )
]
public string CssClassOver
{
get {
string _cssClassOver = (string) ViewState["CssClassOver"];
return ( ( _cssClassOver == null ) ? String.Empty : _cssClassOver );
}
set {
ViewState["CssClassOver"] = value;
}
}
/// <summary>
/// Gets or sets the image index to be showen before the element in the tree.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 2 February, 2003
/// </author>
[
Bindable( true ),
DefaultValue( -1 ),
PersistenceMode( PersistenceMode.Attribute )
]
public int ImageIndex
{
get {
object _index = ViewState["ImageIndex"];
return( ( _index == null ) ? -1 : (int)_index );
}
set {
ViewState["ImageIndex"] = value;
}
}
#endregion
#region TreeElement private properties
/// <summary>
/// Gets the writer object for the tree element.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 04 January, 2003
/// </author>
private ITreeElementWriter ElementWriter
{
get {
return new TreeElementWriter();
}
}
#endregion
#region TreeElement internal properties
/// <summary>
/// Internaly gets the control StateBag object. The StateBag object is case sensitive.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
internal StateBag ViewState
{
get {
if( _state == null )
{
_state = new StateBag( true );
if( ((IStateManager)this).IsTrackingViewState )
((IStateManager)_state).TrackViewState();
}
return _state;
}
}
/// <summary>
/// Internaly gets or sets the type of the element. (i.e. design time or run time added)
/// </summary>
/// <author>
/// Created by Iulian Iuga; 19 January, 2003
/// </author>
internal _ElementType ElementType
{
get {
return _elementType;
}
set {
_elementType = value;
}
}
#endregion
#region TreeElement public methods
/// <summary>
///
/// </summary>
/// <author>
/// Created by Iulian Iuga; 27 December, 2002
/// </author>
public TreeElement()
{}
/// <summary>
///
/// </summary>
/// <author>
/// Created by Iulian Iuga; 28 December, 2002
/// </author>
public TreeElement( string text )
{
if( text == null )
throw new ArgumentNullException();
((IStateManager)this).TrackViewState();
Text = text;
}
/// <summary>
///
/// </summary>
/// <author>
/// Created by Iulian Iuga; 18 January, 2003
/// </author>
public TreeElement( string text, string navigateUrl )
{
if( text == null || navigateUrl == null )
throw new ArgumentNullException();
((IStateManager)this).TrackViewState();
Text = text;
NavigateUrl = navigateUrl;
}
/// <summary>
/// Expand current element, it has effect only if it has elements.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
public void Expand()
{
if( HasElements )
{
ViewState["IsExpanded"] = true;
TreeWeb.OnExpand( new TreeWeb.TreeWebEventArgs( this ) );
}
}
/// <summary>
/// Collapse current element, it has effect only if it has elements.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
public void Collapse()
{
if( HasElements )
{
ViewState["IsExpanded"] = false;
TreeWeb.OnCollapse( new TreeWeb.TreeWebEventArgs( this ) );
}
}
/// <summary>
/// Finds a specified child element of current tree element.
///
/// Note: The search algorithm can be optimized.
/// </summary>
/// <param name="ID">The searched element id.</param>
/// <returns>The child element coresponding to the ID parameter value.</returns>
/// <author>
/// Created by Iulian Iuga; 04 January, 2003
/// </author>
public TreeElement FindElement( string ID )
{
// TODO: optimize the search algorithm.
foreach( TreeElement element in Elements )
{
if( element.ID == ID )
return element;
}
foreach( TreeElement element in Elements )
{
TreeElement _found = element.FindElement( ID );
if( _found != null )
return _found;
}
return null;
}
/// <summary>
///
/// </summary>
/// <param name="writer"></param>
/// <author>
/// Created by Iulian Iuga; 27 December, 2002
/// </author>
public virtual void Render( HtmlTextWriter writer ) //, TreeRenderState treeState
{
ElementWriter.RenderElement( writer, this );
}
/// <summary>
/// (IStateManager.SaveViewState)
/// Saves the changes of TreeElement's view state to an Object.
/// </summary>
/// <returns></returns>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
object IStateManager.SaveViewState()
{
// save _state state
object _stateState = null;
if( _state != null )
_stateState = ((IStateManager)_state).SaveViewState();
// save _elements state
object _elementsState = null;
if( _elements != null )
_elementsState = ((IStateManager)_elements).SaveViewState();
if ( _stateState == null && _elementsState == null)
return null;
object[] _newState = new object[2];
_newState[0] = _stateState;
_newState[1] = _elementsState;
return _newState;
}
/// <summary>
/// (IStateManager.TrackViewState)
/// Instructs the TreeElement to track changes to its view state.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
void IStateManager.TrackViewState()
{
_marked = true;
if( _state != null )
((IStateManager)_state).TrackViewState();
if( _elements != null )
((IStateManager)_elements).TrackViewState();
}
/// <summary>
/// (IStateManager.LoadViewState)
/// Loads the TreeElement's previously saved view state.
/// </summary>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
void IStateManager.LoadViewState( object state )
{
if( state != null )
{
object[] _newState = (object[])state;
if( _newState[0] != null )
((IStateManager)ViewState).LoadViewState( _newState[0] );
if( _newState[1] != null )
((IStateManager)Elements).LoadViewState( _newState[1] );
}
}
/// <summary>
///
/// </summary>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
bool IStateManager.IsTrackingViewState
{
get {
return _marked;
}
}
#endregion
#region TreeElement internal methods
/// <summary>
/// Internaly sets the element id.
/// </summary>
/// <param name="elementID"></param>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
internal void SetElementID( string elementID )
{
_id = elementID;
}
/// <summary>
/// Internaly sets the node parent.
/// </summary>
/// <param name="parent"></param>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
internal void SetParent( TreeElement parent )
{
_parent = parent;
}
/// <summary>
/// Internaly sets the TreeWeb control which contains the node.
/// </summary>
/// <param name="treeWeb"></param>
/// <author>
/// Created by Iulian Iuga; 01 January, 2003
/// </author>
internal void SetTreeWeb( TreeWeb treeWeb )
{
_treeWeb = treeWeb;
}
/// <summary>
/// Internaly sets the level where the node is in the tree.
/// </summary>
/// <param name="level"></param>
/// <author>
/// Created by Iulian Iuga; 04 January, 2003
/// </author>
internal void SetLevel( int level )
{
_level = level;
}
#endregion
#region TreeElement private methods
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?