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 私有方法 /// /// DataRow转model实体类对象 /// /// /// /// /// 把DataRow行转成树节点实体类对象 /// 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; } /// /// 把DataTable行转成实体类List集合 /// private List DataTableToTreeList(DataTable dt) { List modellist = new List(); if (dt.Rows.Count > 0) { foreach (DataRow myRow in dt.Rows) { modellist.Add(DataRowToTreeNodeModel(myRow)); } } return modellist; } #endregion #region 基本方法 /// /// 获取记录数 /// 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; } } /// /// 获取列表 /// /// 查询条件 /// public List GetTree(string treeid, string treepid, string name, string table, string strwhere, List treelist) { List 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; } /// /// 获取树 根据单位ID获取本节点及所有级子节点树 /// /// 查询条件 /// public List GetTree2(string treeid, string treepid, string name, string table, string strwhere, List treelist) { List list = GetTreeNodeModelToList2(treeid, treepid, name, table, strwhere); if (list != null && list.Count > 0) { treelist.AddRange(list); } return treelist; } /// /// 获取树 只查询一遍 /// /// 查询条件 /// public List GetTree3(string treeid, string treepid, string name, string table, string strwhere, List treelist) { List list = GetTreeNodeModelToList(treeid, treepid, name, table, strwhere); if (list != null && list.Count > 0) { treelist.AddRange(list); } return treelist; } /// /// 获取列表 /// /// 查询条件 /// public List GetNodeTree(string treeid, string treepid, string name, string table, string strwhere) { List 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; } /// /// 获取列表 /// /// 查询条件 /// public List GetTreeNodeModelToList(string treeid, string treepid, string name, string table, string strwhere) { return DataTableToTreeList(GetTreeNodeModel(treeid, treepid, name, table, strwhere)); } /// /// 获取列表 /// /// 查询条件 /// public List GetTreeNodeModelToList2(string treeid, string treepid, string name, string table, string strwhere) { return DataTableToTreeList(GetTreeNodeModel2(treeid, treepid, name, table, strwhere)); } /// /// 获取列表 /// /// 查询条件 /// 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); } /// /// 获取列表 /// /// 查询条件 /// 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 } }