|
/*menulist 类开始*/
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml; using Singcn.SQL; using System.Data.SqlClient; using System.IO; using System.Text;
namespace myfunc.Common { /// <summary> /// PubFunc 的摘要说明 /// </summary> public class menulist { public XmlWriterSettings settings = new XmlWriterSettings(); public XmlWriter writer = null; public string buf = ""; public SqlShell objShell; public SqlCommand objCommand; public DataTable objDataTable;
public menulist(string userid) { objShell = new SqlShell(); objCommand = new SqlCommand("select * from qxdmb order by jb,px,qxdm"); objCommand.CommandType = CommandType.Text; objDataTable = objShell.executeDataSet(ref objCommand).Tables[0];
StringWriter writerstr = new StringWriter(); settings.Indent = true; settings.Encoding = Encoding.GetEncoding("utf-8"); try { writer = XmlWriter.Create(writerstr, settings);
writer.WriteStartDocument(); writer.WriteStartElement("DSTreeRoot"); writer.WriteAttributeString("text", "后台管理系统-["+userid+"]"); writer.WriteAttributeString("treeId", "0000"); writer.WriteAttributeString("open", "true");
readqxdmb("0");
writer.WriteEndElement(); writer.WriteEndDocument(); } finally { if (writer != null) writer.Close(); } buf = writerstr.ToString(); buf = buf.Replace(@"encoding=""utf-16""", @"encoding=""utf-8""");//在使用StringWriter 作为xml输出时XML自动为“utf-16”,此处用Replace方法处理,如有更好的方法请指教!
}
private void readqxdmb(string sjdm)//生成XML树的方法 { DataTable mytable = objDataTable.Copy(); DataRow[] foundRows; foundRows = mytable.Select("sjdm='" + sjdm + "'"); if (foundRows.Length > 0) { //写子节点 for (int i = 0; i < foundRows.Length; i++) { writer.WriteStartElement("DSTree"); writer.WriteAttributeString("text", foundRows[i]["qxsm"].ToString().Trim()); writer.WriteAttributeString("treeId", foundRows[i]["qxdm"].ToString().Trim()); writer.WriteAttributeString("open", "false"); //处理下级节点 readqxdmb((string)foundRows[i]["qxdm"]); writer.WriteEndElement(); } } mytable.Dispose(); }
} }
/*menulist 结束*/ |