|
8#
楼主 |
发表于 2017-5-13 15:34:12
|
只看该作者
下面是根据表结构动态的构建XML,绑定到树
private void LoadData()
{
int i = 0;
string systemname = "INFOWEB"; //AppConfiguration.SYSTEM_FLAG
string sql0 = "select distinct action_id from vw_power where action_systemno='" + systemname + "' and user_no='" + sCookieName + "' and action_pid=0 and action_menu=1";
string sql = "select distinct action_id,action_name,action_order from vw_power where user_no='" + sCookieName + "' and action_pid in (" + sql0 + ") order by action_order";
DataTable dt_MN = DBConnSql.GetDataTable(AppConfiguration.PowerConn, sql);
string cmdText = "select distinct user_no,action_id,action_name,action_no,action_folder,action_url,action_order from vw_power where action_menu=1 and user_no='" + sCookieName + "' order by action_order";
DataTable dt_TR = DBConnSql.GetDataTable(AppConfiguration.PowerConn, cmdText);
//string strsel = "SELECT action_id as TREENODE_ID,action_name as TEXT,action_url as NAVIGATEURL,'' as ISNEW,action_pid as TREENODE_ID_0,action_order FROM Power_Action where action_systemno='INFOWEB' order by action_order,action_id";
string strsel = "SELECT action_id as TREENODE_ID,action_name as TEXT,case right(action_url,5) when '.aspx' then '/'+substring(action_url,0,len(action_url)-4) else action_url end as NAVIGATEURL,'' as ISNEW,action_pid as TREENODE_ID_0,action_order FROM Power_Action where action_systemno='INFOWEB' order by action_order,action_id";
dtmenu = DBConnSql.GetDataTable(AppConfiguration.PowerConn, strsel);
//为OA3管理绑定树数据源
XmlDocument xdoc_OA3 = new XmlDocument();
xmlContent.Clear();
xmlContent.AppendLine("<?xml version='1.0' encoding='utf-8' ?> ");
xmlContent.AppendLine("<Tree> ");
DataRow[] dr_OA3 = dtmenu.Select(" TREENODE_ID_0='55' ", " action_order ");
MakeXML(dr_OA3); //为OA3管理生成XML文件
xmlContent.AppendLine("</Tree> ");
xdoc_OA3.LoadXml(xmlContent.ToString());
ViewBag.Tree_OA3DataSource = xdoc_OA3;
//为研发管理绑定树数据源
XmlDocument xdoc_YF = new XmlDocument();
xmlContent.Clear();
xmlContent.AppendLine("<?xml version='1.0' encoding='utf-8' ?> ");
xmlContent.AppendLine("<Tree> ");
DataRow[] dr_YF = dtmenu.Select(" TREENODE_ID_0='98' ", " action_order ");
MakeXML(dr_YF); //为研发管理生成XML文件
//xmlContent += "</Tree> ";
xmlContent.AppendLine("</Tree> ");
xdoc_YF.LoadXml(xmlContent.ToString());
ViewBag.Tree_YFDataSource = xdoc_YF;
////为销售管理绑定树数据源
//XmlDocument xdoc_Sale = new XmlDocument();
//xmlContent.Clear();
//xmlContent.AppendLine("<?xml version='1.0' encoding='utf-8' ?> ");
//xmlContent.AppendLine("<Tree> ");
//DataRow[] dr_Sale = dtmenu.Select(" TREENODE_ID_0='67' ", " action_order ");
//MakeXML(dr_Sale); //为销售管理生成XML文件
//xmlContent.AppendLine("</Tree> ");
//xdoc_Sale.LoadXml(xmlContent.ToString());
//ViewBag.Tree_SaleDataSource = xdoc_Sale;
//为系统管理绑定树数据源
XmlDocument xdoc_Sys = new XmlDocument();
xmlContent.Clear();
xmlContent.AppendLine("<?xml version='1.0' encoding='utf-8' ?> ");
xmlContent.AppendLine("<Tree> ");
DataRow[] dr_Sys = dtmenu.Select(" TREENODE_ID_0='10' ", " action_order ");
MakeXML(dr_Sys); //为系统管理生成XML文件
xmlContent.AppendLine("</Tree> ");
xdoc_Sys.LoadXml(xmlContent.ToString());
ViewBag.Tree_SysDataSource = xdoc_Sys;
//UIHelper.
}
public void MakeXML(DataRow[] DR_Sle)
{
foreach (DataRow DR in DR_Sle)
{
if (DR.ItemArray.Length > 0)
{
xmlContent.AppendLine("<TreeNode ");
xmlContent.AppendLine(" Text='" + DR.ItemArray[1].ToString().Trim() + "' ");
if (DR.ItemArray[2].ToString().Trim() != "")
{ xmlContent.AppendLine(" NavigateUrl='" + DR.ItemArray[2].ToString().Trim() + "' "); }
xmlContent.AppendLine("> ");
string p_id = DR.ItemArray[0].ToString().Trim();
DataRow[] dr_chd = dtmenu.Select(" TREENODE_ID_0='" + p_id + "' ", " action_order ");
MakeXML(dr_chd);
xmlContent.AppendLine("</TreeNode> ");
}
}
} |
|