You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
433 lines
12 KiB
Plaintext
433 lines
12 KiB
Plaintext
using System;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using BP.DA;
|
|
|
|
namespace BP.En
|
|
{
|
|
/// <summary>
|
|
/// 属性列表
|
|
/// </summary>
|
|
public class EntityTreeAttr
|
|
{
|
|
/// <summary>
|
|
/// 树结构编号
|
|
/// </summary>
|
|
public const string No = "No";
|
|
/// <summary>
|
|
/// 名称
|
|
/// </summary>
|
|
public const string Name = "Name";
|
|
/// <summary>
|
|
/// 父节编号
|
|
/// </summary>
|
|
public const string ParentNo = "ParentNo";
|
|
/// <summary>
|
|
/// 顺序号
|
|
/// </summary>
|
|
public const string Idx = "Idx";
|
|
/// <summary>
|
|
/// 控制参数
|
|
/// </summary>
|
|
public const string CtrlWayPara = "CtrlWayPara";
|
|
/// <summary>
|
|
/// 图标
|
|
/// </summary>
|
|
public const string ICON = "ICON";
|
|
/// <summary>
|
|
/// 节点类型
|
|
/// </summary>
|
|
public const string MenuType = "MenuType";
|
|
}
|
|
/// <summary>
|
|
/// 树实体
|
|
/// </summary>
|
|
abstract public class EntityTree : Entity
|
|
{
|
|
#region 属性
|
|
public bool ItIsRoot
|
|
{
|
|
get
|
|
{
|
|
if (this.ParentNo == "-1" || this.ParentNo == "0")
|
|
return true;
|
|
|
|
if (this.ParentNo == this.No)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 唯一标示
|
|
/// </summary>
|
|
public string No
|
|
{
|
|
get
|
|
{
|
|
return this.GetValStringByKey(EntityTreeAttr.No);
|
|
}
|
|
set
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.No, value);
|
|
}
|
|
}
|
|
public void setNo(string val)
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.No, val);
|
|
}
|
|
/// <summary>
|
|
/// 名称
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return this.GetValStringByKey(EntityTreeAttr.Name);
|
|
}
|
|
set
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.Name, value);
|
|
}
|
|
}
|
|
public void setName(string val)
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.Name, val);
|
|
}
|
|
/// <summary>
|
|
/// 父节点编号
|
|
/// </summary>
|
|
public string ParentNo
|
|
{
|
|
get
|
|
{
|
|
return this.GetValStringByKey(EntityTreeAttr.ParentNo);
|
|
}
|
|
set
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.ParentNo, value);
|
|
}
|
|
}
|
|
public void setParentNo(string val)
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.ParentNo, val);
|
|
}
|
|
/// <summary>
|
|
/// 图标
|
|
/// </summary>
|
|
public string ICON
|
|
{
|
|
get
|
|
{
|
|
return this.GetValStringByKey(EntityTreeAttr.ICON);
|
|
}
|
|
set
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.ICON, value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 顺序号
|
|
/// </summary>
|
|
public int Idx
|
|
{
|
|
get
|
|
{
|
|
return this.GetValIntByKey(EntityTreeAttr.Idx);
|
|
}
|
|
set
|
|
{
|
|
this.SetValByKey(EntityTreeAttr.Idx, value);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 构造函数
|
|
/// <summary>
|
|
/// 主键
|
|
/// </summary>
|
|
public override string PK
|
|
{
|
|
get
|
|
{
|
|
return EntityTreeAttr.No;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 树结构编号
|
|
/// </summary>
|
|
public EntityTree()
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// 树结构编号
|
|
/// </summary>
|
|
/// <param name="no">编号</param>
|
|
public EntityTree(string no)
|
|
{
|
|
if (DataType.IsNullOrEmpty(no))
|
|
throw new Exception(this.EnDesc + "@对表[" + this.EnDesc + "]进行查询前必须指定编号。");
|
|
|
|
this.No = no;
|
|
if (this.Retrieve() == 0)
|
|
throw new Exception("@没有" + this._enMap.PhysicsTable + ", No = " + this.No + "的记录。");
|
|
}
|
|
#endregion
|
|
|
|
#region 业务逻辑处理
|
|
/// <summary>
|
|
/// 重新设置treeNo
|
|
/// </summary>
|
|
public void ResetTreeNo()
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// 检查名称的问题.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override bool beforeInsert()
|
|
{
|
|
if (this.EnMap.ItIsAllowRepeatName == false)
|
|
{
|
|
if (this.PKCount == 1)
|
|
{
|
|
if (this.ExitsValueNum("Name", this.Name) >= 1)
|
|
throw new Exception("@插入失败[" + this.EnMap.EnDesc + "] 编号[" + this.No + "]名称[" + Name + "]重复.");
|
|
}
|
|
}
|
|
|
|
if (DataType.IsNullOrEmpty(this.No))
|
|
this.No = this.GenerNewNoByKey("No");
|
|
|
|
return base.beforeInsert();
|
|
}
|
|
protected override bool beforeUpdate()
|
|
{
|
|
if (this.EnMap.ItIsAllowRepeatName == false)
|
|
{
|
|
if (this.PKCount == 1)
|
|
{
|
|
if (this.ExitsValueNum("Name", this.Name) >= 2)
|
|
throw new Exception("@更新失败[" + this.EnMap.EnDesc + "] 编号[" + this.No + "]名称[" + Name + "]重复.");
|
|
}
|
|
}
|
|
return base.beforeUpdate();
|
|
}
|
|
#endregion
|
|
|
|
#region 可让子类调用的方法
|
|
/// <summary>
|
|
/// 新建同级节点
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public EntityTree DoCreateSameLevelNode(string name = null)
|
|
{
|
|
|
|
EntityTree en = this.CreateInstance() as EntityTree;
|
|
if (this.ClassID.Contains("FlowSort") || this.ClassID.Contains("SysFormTree"))
|
|
en.No = DBAccess.GenerGUID();
|
|
else
|
|
en.No = DBAccess.GenerOID(this.ToString()).ToString(); // en.GenerNewNoByKey(EntityTreeAttr.No);
|
|
if (name == null)
|
|
en.Name = "新建节点" + en.No;
|
|
else
|
|
en.Name = name;
|
|
|
|
en.ParentNo = this.ParentNo;
|
|
en.Insert();
|
|
|
|
return en;
|
|
}
|
|
/// <summary>
|
|
/// 新建子节点
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public EntityTree DoCreateSubNode(string name = null)
|
|
{
|
|
EntityTree en = this.CreateInstance() as EntityTree;
|
|
en.Copy(this);
|
|
if (this.ClassID.Contains("FlowSort") || this.ClassID.Contains("SysFormTree"))
|
|
en.No = DBAccess.GenerGUID(10, null, null);
|
|
else
|
|
en.No = DBAccess.GenerOID(this.ToString()).ToString();
|
|
if (name == null)
|
|
en.Name = "新建节点" + en.No;
|
|
else
|
|
en.Name = name;
|
|
|
|
en.ParentNo = this.No;
|
|
en.Insert();
|
|
|
|
return en;
|
|
}
|
|
/// <summary>
|
|
/// 上移
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string DoUp()
|
|
{
|
|
this.DoOrderUp(EntityTreeAttr.ParentNo, this.ParentNo, EntityTreeAttr.Idx);
|
|
return "执行成功.";
|
|
}
|
|
/// <summary>
|
|
/// 下移
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string DoDown()
|
|
{
|
|
this.DoOrderDown(EntityTreeAttr.ParentNo, this.ParentNo, EntityTreeAttr.Idx);
|
|
return "执行成功.";
|
|
}
|
|
#endregion
|
|
}
|
|
/// <summary>
|
|
/// 树实体s
|
|
/// </summary>
|
|
abstract public class EntitiesTree : Entities
|
|
{
|
|
#region 转化为树结构的tree.
|
|
private StringBuilder appendMenus = null;
|
|
private StringBuilder appendMenuSb = null;
|
|
/// <summary>
|
|
/// 转化为json树
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string ToJsonOfTree(string rootNo = "0")
|
|
{
|
|
appendMenus = new StringBuilder();
|
|
appendMenuSb = new StringBuilder();
|
|
EntityTree root = this.GetEntityByKey(EntityTreeAttr.ParentNo, rootNo) as EntityTree;
|
|
if (root == null)
|
|
return "err@没有找到rootNo=" + rootNo + "的entity.";
|
|
|
|
appendMenus.Append("[{");
|
|
appendMenus.Append("'id':'" + root.No + "',");
|
|
appendMenus.Append("'pid':'" + root.ParentNo + "',");
|
|
appendMenus.Append("'text':'" + root.Name + "'");
|
|
// appendMenus.Append(IsPermissionsNodes(ens, dms, root.No));
|
|
|
|
// 增加它的子级.
|
|
appendMenus.Append(",'children':");
|
|
AddChildren(root, this);
|
|
appendMenus.Append(appendMenuSb);
|
|
appendMenus.Append("}]");
|
|
|
|
return ReplaceIllgalChart(appendMenus.ToString());
|
|
}
|
|
public void AddChildren(EntityTree parentEn, EntitiesTree ens)
|
|
{
|
|
appendMenus.Append(appendMenuSb);
|
|
appendMenuSb.Clear();
|
|
|
|
appendMenuSb.Append("[");
|
|
foreach (EntityTree item in ens)
|
|
{
|
|
if (item.ParentNo != parentEn.No)
|
|
continue;
|
|
|
|
appendMenuSb.Append("{'id':'" + item.No + "','pid':'" + item.ParentNo + "','text':'" + item.Name + "'");
|
|
//appendMenuSb.Append(IsPermissionsNodes(ens, dms, item.No));
|
|
EntityTree treeNode = item as EntityTree;
|
|
// 增加它的子级.
|
|
appendMenuSb.Append(",'children':");
|
|
AddChildren(item, ens);
|
|
appendMenuSb.Append("},");
|
|
}
|
|
if (appendMenuSb.Length > 1)
|
|
appendMenuSb = appendMenuSb.Remove(appendMenuSb.Length - 1, 1);
|
|
appendMenuSb.Append("]");
|
|
appendMenus.Append(appendMenuSb);
|
|
appendMenuSb.Clear();
|
|
}
|
|
public string ReplaceIllgalChart(string s)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0, j = s.Length; i < j; i++)
|
|
{
|
|
|
|
char c = s[i];
|
|
switch (c)
|
|
{
|
|
case '\"':
|
|
sb.Append("\\\"");
|
|
break;
|
|
case '\\':
|
|
sb.Append("\\\\");
|
|
break;
|
|
case '/':
|
|
sb.Append("\\/");
|
|
break;
|
|
case '\b':
|
|
sb.Append("\\b");
|
|
break;
|
|
case '\f':
|
|
sb.Append("\\f");
|
|
break;
|
|
case '\n':
|
|
sb.Append("\\n");
|
|
break;
|
|
case '\r':
|
|
sb.Append("\\r");
|
|
break;
|
|
case '\t':
|
|
sb.Append("\\t");
|
|
break;
|
|
default:
|
|
sb.Append(c);
|
|
break;
|
|
}
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
#endregion 转化为树结构的tree.
|
|
|
|
#region 构造.
|
|
/// <summary>
|
|
/// 查询他的子节点
|
|
/// </summary>
|
|
/// <param name="en"></param>
|
|
/// <returns></returns>
|
|
public int RetrieveHisChinren(EntityTree en)
|
|
{
|
|
int i = this.Retrieve(EntityTreeAttr.ParentNo, en.No);
|
|
this.AddEntity(en);
|
|
return i + 1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取它的子节点
|
|
/// </summary>
|
|
/// <param name="en"></param>
|
|
/// <returns></returns>
|
|
public EntitiesTree GenerHisChinren(EntityTree en)
|
|
{
|
|
EntitiesTree ens = this.CreateInstance() as EntitiesTree;
|
|
foreach (EntityTree item in ens)
|
|
{
|
|
if (en.ParentNo == en.No)
|
|
ens.AddEntity(item);
|
|
}
|
|
return ens;
|
|
}
|
|
/// <summary>
|
|
/// 根据位置取得数据
|
|
/// </summary>
|
|
public new EntityTree this[int index]
|
|
{
|
|
get
|
|
{
|
|
return (EntityTree)this.InnerList[index];
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 构造
|
|
/// </summary>
|
|
public EntitiesTree()
|
|
{
|
|
}
|
|
#endregion 构造.
|
|
}
|
|
}
|