You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
236 lines
8.0 KiB
236 lines
8.0 KiB
9 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using System.Data.SqlClient;
|
||
|
using System.Collections;
|
||
|
|
||
|
|
||
|
|
||
|
namespace FangYar.OracleDAL
|
||
|
{
|
||
|
public class ToTreeDAL : IDAL.ToTreeIDAL
|
||
|
{
|
||
|
#region 私有方法
|
||
|
/// <summary>
|
||
|
/// DataRow转model实体类对象
|
||
|
/// </summary>
|
||
|
/// <param name="dr"></param>
|
||
|
/// <returns></returns>
|
||
|
|
||
|
/// <summary>
|
||
|
/// 把DataRow行转成树节点实体类对象
|
||
|
/// </summary>
|
||
|
private FangYar.Model.TreeNodeModel DataRowToTreeNodeModel(DataRow dr)
|
||
|
{
|
||
|
FangYar.Model.TreeNodeModel model = new Model.TreeNodeModel();
|
||
|
if (!DBNull.Value.Equals(dr["id"]))
|
||
|
model.id = dr["id"].ToString();
|
||
|
if (!DBNull.Value.Equals(dr["name"]))
|
||
|
model.name = dr["name"].ToString();
|
||
|
if (!DBNull.Value.Equals(dr["pId"]))
|
||
|
model.pId = dr["pId"].ToString();
|
||
|
if (!DBNull.Value.Equals(dr["chkDisabled"]))
|
||
|
model.chkDisabled = dr["chkDisabled"].ToString();
|
||
|
|
||
|
return model;
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 把DataTable行转成实体类List集合
|
||
|
/// </summary>
|
||
|
private List<FangYar.Model.TreeNodeModel> DataTableToTreeList(DataTable dt)
|
||
|
{
|
||
|
List<FangYar.Model.TreeNodeModel> modellist = new List<Model.TreeNodeModel>();
|
||
|
if (dt.Rows.Count > 0)
|
||
|
{
|
||
|
foreach (DataRow myRow in dt.Rows)
|
||
|
{
|
||
|
modellist.Add(DataRowToTreeNodeModel(myRow));
|
||
|
}
|
||
|
}
|
||
|
return modellist;
|
||
|
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
#region 基本方法
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取记录数
|
||
|
/// </summary>
|
||
|
public int Count(string table, string strwhere)
|
||
|
{
|
||
|
string sql = "select count(1) from " + table;
|
||
|
if (strwhere != null && strwhere != "")
|
||
|
{
|
||
|
sql += " where " + strwhere;
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
|
||
|
return FangYar.Common.MySqlHelper.GetCount(sql);
|
||
|
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public List<FangYar.Model.TreeNodeModel> GetTree(string treeid, string treepid, string name, string table, string strwhere, List<FangYar.Model.TreeNodeModel> treelist)
|
||
|
{
|
||
|
List<FangYar.Model.TreeNodeModel> list = GetTreeNodeModelToList(treeid, treepid, name, table, strwhere);
|
||
|
if (list != null && list.Count > 0)
|
||
|
{
|
||
|
treelist.AddRange(list);
|
||
|
//if (!string.IsNullOrEmpty(strwhere))
|
||
|
//{
|
||
|
// list.ForEach(delegate(FangYar.Model.TreeNodeModel treeModel)
|
||
|
// {
|
||
|
// string where = treepid + " = '" + treeModel.id + "'";
|
||
|
// if (Count(table,where) > 0)
|
||
|
// {
|
||
|
// GetTree(treeid, treepid, name, table, where, treelist);
|
||
|
// }
|
||
|
// });
|
||
|
//}
|
||
|
}
|
||
|
return treelist;
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取树 根据单位ID获取本节点及所有级子节点树
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public List<FangYar.Model.TreeNodeModel> GetTree2(string treeid, string treepid, string name, string table, string strwhere, List<FangYar.Model.TreeNodeModel> treelist)
|
||
|
{
|
||
|
List<FangYar.Model.TreeNodeModel> list = GetTreeNodeModelToList2(treeid, treepid, name, table, strwhere);
|
||
|
if (list != null && list.Count > 0)
|
||
|
{
|
||
|
treelist.AddRange(list);
|
||
|
}
|
||
|
return treelist;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取树 只查询一遍
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public List<FangYar.Model.TreeNodeModel> GetTree3(string treeid, string treepid, string name, string table, string strwhere, List<FangYar.Model.TreeNodeModel> treelist)
|
||
|
{
|
||
|
List<FangYar.Model.TreeNodeModel> list = GetTreeNodeModelToList(treeid, treepid, name, table, strwhere);
|
||
|
if (list != null && list.Count > 0)
|
||
|
{
|
||
|
treelist.AddRange(list);
|
||
|
}
|
||
|
return treelist;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public List<FangYar.Model.TreeNodeModel> GetNodeTree(string treeid, string treepid, string name, string table, string strwhere)
|
||
|
{
|
||
|
List<FangYar.Model.TreeNodeModel> list = GetTreeNodeModelToList(treeid, treepid, name, table, strwhere);
|
||
|
if (list != null && list.Count > 0)
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(strwhere))
|
||
|
{
|
||
|
list.ForEach(delegate (FangYar.Model.TreeNodeModel treeModel)
|
||
|
{
|
||
|
string where = treepid + " = '" + treeModel.id + "'";
|
||
|
if (Count(table, where) > 0)
|
||
|
{
|
||
|
treeModel.isParent = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
treeModel.isParent = false;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public List<FangYar.Model.TreeNodeModel> GetTreeNodeModelToList(string treeid, string treepid, string name, string table, string strwhere)
|
||
|
{
|
||
|
return DataTableToTreeList(GetTreeNodeModel(treeid, treepid, name, table, strwhere));
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public List<FangYar.Model.TreeNodeModel> GetTreeNodeModelToList2(string treeid, string treepid, string name, string table, string strwhere)
|
||
|
{
|
||
|
return DataTableToTreeList(GetTreeNodeModel2(treeid, treepid, name, table, strwhere));
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public DataTable GetTreeNodeModel(string treeid, string treepid, string name, string table, string strwhere)
|
||
|
{
|
||
|
string sql = "select " + treeid + " as id ," + treepid + " as pId ," + name + " as name ," +
|
||
|
"CASE MENU_FLAG WHEN '0' THEN 'false' ELSE 'true' END as chkDisabled from " + table;
|
||
|
if (strwhere != null && strwhere != "")
|
||
|
{
|
||
|
sql += " where " + strwhere;
|
||
|
}
|
||
|
sql += " order by MENU_TYPE ,menu_level,menu_order";
|
||
|
return FangYar.Common.MySqlHelper.QueryTable(sql);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="strwhere">查询条件</param>
|
||
|
/// <returns></returns>
|
||
|
public DataTable GetTreeNodeModel2(string treeid, string treepid, string name, string table, string strwhere)
|
||
|
{
|
||
|
string sql = "select " + treeid + " as id ," + treepid + " as pId ," + name + " as name from " + table;
|
||
|
if (strwhere != null && strwhere != "")
|
||
|
{
|
||
|
sql += " ,(select get_Org_child_list('" + strwhere + "') cids ) s where find_in_set(ORG_ID,cids) ";
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
return FangYar.Common.MySqlHelper.QueryTable(sql);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 扩展业务方法
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|