树结构 - TreeItem
2017-02-20 16:00:17 访问(1383) 赞(0) 踩(0)
using System;
using System.Collections.Generic;
using System.Text;
namespace SlowX.Class.Classess
{
/// <summary>
/// 树结构 - TreeItem +
/// </summary>
[Serializable]
public class TreeItem
{
/// <summary>
/// 树结构
/// </summary>
public TreeItem()
{
}
#region 属性
#region ID ~ ID
/// <summary>
/// ID ~ ID
/// </summary>
protected string m_ID = "";
/// <summary>
/// ID ~ ID
/// </summary>
public string ID
{
get
{
return m_ID;
}
set
{
m_ID = value;
}
}
#endregion ID ~ ID
#region TheName ~ 名称
/// <summary>
/// TheName ~ 名称
/// </summary>
protected string m_TheName = "";
/// <summary>
/// TheName ~ 名称
/// </summary>
public string TheName
{
get
{
return m_TheName;
}
set
{
m_TheName = value;
}
}
#endregion TheName ~ 名称
#region Url ~ Url地址
/// <summary>
/// Url ~ Url地址
/// </summary>
protected string m_Url = "";
/// <summary>
/// Url ~ Url地址
/// </summary>
public string Url
{
get
{
return m_Url;
}
set
{
m_Url = value;
}
}
#endregion Url ~ Url地址
#region LinkTarget ~ 链接方式
/// <summary>
/// LinkTarget ~ 链接方式
/// </summary>
protected string m_LinkTarget = "";
/// <summary>
/// LinkTarget ~ 链接方式
/// </summary>
public string LinkTarget
{
get
{
return m_LinkTarget;
}
set
{
m_LinkTarget = value;
}
}
#endregion LinkTarget ~ 链接方式
#region Title ~ 标题
/// <summary>
/// Title ~ 标题
/// </summary>
protected string m_Title = null;
/// <summary>
/// Title ~ 标题
/// </summary>
public string Title
{
get
{
return m_Title;
}
set
{
m_Title = value;
}
}
#endregion Title ~ 标题
#region CssClass ~ 样式
/// <summary>
/// CssClass ~ 样式
/// </summary>
protected string m_CssClass = null;
/// <summary>
/// CssClass ~ 样式
/// </summary>
public string CssClass
{
get
{
return m_CssClass;
}
set
{
m_CssClass = value;
}
}
#endregion CssClass ~ 样式
#region Parent ~ 父节点
/// <summary>
/// Parent ~ 父节点
/// </summary>
protected TreeItem m_Parent = null;
/// <summary>
/// Parent ~ 父节点
/// </summary>
public TreeItem ParentGet()
{
return m_Parent;
}
public void ParentSet(TreeItem theValue)
{
m_Parent = theValue;
}
#endregion Parent ~ 父节点
#region SonList ~ 子记录
/// <summary>
/// SonList ~ 子记录
/// </summary>
protected List<TreeItem> m_SonList = null;
/// <summary>
/// SonList ~ 子记录
/// </summary>
public List<TreeItem> SonListGet()
{
return m_SonList;
}
/// <summary>
///
/// </summary>
/// <param name="theValue"></param>
public void SonListSet(List<TreeItem> theValue)
{
m_SonList = theValue;
}
#endregion SonList ~ 子记录
#region Tag
/// <summary>
/// Tag
/// </summary>
protected object m_Tag = null;
/// <summary>
/// Tag
/// </summary>
/// <returns></returns>
public object TagGet()
{
return m_Tag;
}
/// <summary>
///
/// </summary>
/// <param name="theValue"></param>
public void TagSet(object theValue)
{
m_Tag = theValue;
}
#endregion Tag
#endregion 属性
/// <summary>
/// 是否叶子节点
/// </summary>
/// <returns></returns>
public bool IsLeaf()
{
List<TreeItem> theList = SonListGet();
if (theList == null || theList.Count == 0)
return true;
return false;
}
/// <summary>
/// 是否第一节点
/// </summary>
/// <returns></returns>
public bool IsFirst()
{
if (ParentGet() == null)
return false;
List<TreeItem> theList = ParentGet().SonListGet();
if (theList == null || theList.Count==0)
return false;
return theList[0] == this;
}
/// <summary>
/// 是否第一节点
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public bool IsFirst(List<TreeItem> theList)
{
if (theList == null || theList.Count == 0)
return false;
return theList[0] == this;
}
/// <summary>
/// 是否最后节点
/// </summary>
/// <returns></returns>
public bool IsLast()
{
if (ParentGet() == null)
return false;
List<TreeItem> theList = ParentGet().SonListGet();
if (theList == null )
return false;
int theCount = theList.Count;
if (theCount == 0)
return false;
return theList[theCount-1] == this;
}
/// <summary>
/// 是否最后节点
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public bool IsLast(List<TreeItem> theList)
{
if (theList == null)
return false;
int theCount = theList.Count;
if (theCount == 0)
return false;
return theList[theCount - 1] == this;
}
/// <summary>
/// 是否第一节点
/// </summary>
/// <returns></returns>
public bool IsOnlyChild()
{
if (ParentGet() == null)
return false;
List<TreeItem> theList = ParentGet().SonListGet();
int theCount = theList.Count;
if (theCount != 1)
return false;
return theList[0] == this;
}
/// <summary>
/// 是否第一节点
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public bool IsOnlyChild(List<TreeItem> theList)
{
if (theList == null || theList.Count == 0)
return false;
int theCount = theList.Count;
if (theCount != 1)
return false;
return theList[0] == this;
}
/// <summary>
/// <para>转换"成"</para>
/// <para>如:canoe"best,结果为canoe"best</para>
/// </summary>
/// <param name="obj">传入的字符串(canoe"best)</param>
/// <returns>输出的结果,如(canoe"best)</returns>
private string StringConvertQuot(string obj)
{
if (obj == null)
return string.Empty;
return obj.Replace("\"", """);
}
/// <summary>
/// 获得Href的HTML表达式
/// </summary>
/// <returns></returns>
public string GetHref()
{
StringBuilder theResult = new StringBuilder();
theResult.Append("<a href=\"" + StringConvertQuot(Url) + "\"");
if (Title != null && Title.Length > 0)
theResult.Append(" title=\"" + StringConvertQuot(Title) + "\"");
if (LinkTarget != null && LinkTarget.Length > 0)
theResult.Append(" target=\"" + StringConvertQuot(LinkTarget) + "\"");
if (CssClass != null && CssClass.Length > 0)
theResult.Append(" class=\"" + StringConvertQuot(CssClass) + "\"");
theResult.Append(">" + TheName + "</a>");
return theResult.ToString();
}
}
}
标签:
树结构 - TreeItem 


上一条:
下一条:
相关评论
发表评论