<?xml version="1.0" encoding="GB2312"?>
<Head>
<Column DisTitle="报表名" DisWidth="150">
<Field>tableCName</Field>
<Type>string</Type>
<Visible>true</Visible>
</Column>
<Column DisTitle="表英文名" DisWidth="0">
<Field>tableEName</Field>
<Type>string</Type>
<Visible>false</Visible>
</Column>
<Column DisTitle="数据开始时间" DisWidth="150">
<Field>databtime</Field>
<Type>string</Type>
<Visible>true</Visible>
</Column>
<Column DisTitle="数据结束时间" DisWidth="150">
<Field>dataetime</Field>
<Type>string</Type>
<Visible>true</Visible>
</Column>
<Column DisTitle="汇总是否成功" DisWidth="300">
<Field>collectSuccess</Field>
<Type>string</Type>
<Visible>true</Visible>
</Column>
<Column DisTitle="是否存在风险" DisWidth="100">
<Field>containDanger</Field>
<Type>string</Type>
<Visible>true</Visible>
</Column>
<Column DisTitle="表描述" DisWidth="300">
<Field>discription</Field>
<Type>string</Type>
<Visible>true</Visible>
</Column>
</Head>
public static List<MyColumn> GetColumnInfo(string fileName, string Node)
{
try
{
string xmlFile = String.Format("{0}\\{1}", System.Windows.Forms.Application.StartupPath, fileName);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlFile);
if (xmldoc != null)
{
XmlNode colnode = xmldoc.SelectSingleNode(Node);
if (colnode != null)
{
List<MyColumn> cols = new List<MyColumn>();
foreach (XmlNode headnode in colnode.ChildNodes)
{
MyColumn col = new MyColumn();
col.Caption = headnode.Attributes["DisTitle"].Value;
col.Width = Convert.ToInt32(headnode.Attributes["DisWidth"].Value);
col.FieldName = headnode.SelectSingleNode("Field").InnerText;
col.Visible = Convert.ToBoolean(headnode.SelectSingleNode("Visible").InnerText);
string type = headnode.SelectSingleNode("Type").InnerText;
if (String.Compare(type, "int", true) == 0 || String.Compare(type, "long", true) == 0 || String.Compare(type, "short", true) == 0)
{
col.colType = Type.GetType("System.Int64");
}
else if (String.Compare(type, "double", true) == 0)
{
col.colType = Type.GetType("System.Double");
}
else
{
col.colType = Type.GetType("System.String");
}
cols.Add(col);
}
return cols;
}
}
return null;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
return null;
}
}
posted on 2010-04-23 12:00
天书 阅读(450)
评论(0) 编辑 收藏 引用