📄 getxml.cs
字号:
using System;
using System.Xml;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
namespace lib.classes
{
/// <summary>
/// 结构,字段对应结构
/// </summary>
public class duiyingjiegou//对应结构
{
public string name;//字段名
public SqlDbType sertype;//服务器端类型
public int serlarge;//服务器端长度
public bool not_null;//服务器端是否能为空,true 表示可以为不能为空
public string appname;//本地类中名称,加下划线的那组
public DbType apptype;//本地类中的属性
}
/// <summary>
/// getxml,通过读取xml文件,确定各个表的中字段对应的类型。
/// </summary>
public class getxml
{
public string tablename;//数据库表名
public XmlNode root;//xml文件的根
public ArrayList jigou=new ArrayList();
public getxml(){}
public getxml(string _tablename)
{
this.tablename=_tablename;
}
/// <summary>
/// 读取资源里的xml 文件,并定义根
/// </summary>
/// <returns></returns>
public bool getxmldata()
{
bool back=false;
try
{
char[] c={','};
System.IO.Stream k=this.GetType().Assembly.GetManifestResourceStream(this.GetType().Assembly.ToString().Split(c,10)[0]+"." + tablename +".xml");
XmlDocument x=new XmlDocument();
x.Load(k);
root=x.DocumentElement;
back=true;
}
catch
{
back=false;
}
return back;
}
public bool getduiyingbiao()
{
bool back=false;
if(getxmldata())
{
jigou.Clear();
//访问所有节点,定义临时变量
XmlNode nodepoint=root.FirstChild;
XmlElement datatype;
duiyingbiao bianhuan=new duiyingbiao();
while(nodepoint!=null)
{
//得到节点
datatype=(XmlElement)nodepoint;
//赋植
duiyingjiegou lis=new duiyingjiegou();
lis.name=datatype.GetAttribute("name");
lis.sertype=bianhuan.SqlDbTypeByStr(datatype.GetAttribute("type"));
lis.serlarge=Convert.ToInt32(datatype.GetAttribute("length"));
lis.not_null=bianhuan.TypeNullTrueorFalse(datatype.GetAttribute("not-null"));
lis.appname=datatype.GetAttribute("appname");
lis.apptype=bianhuan.DbTypeByStr(datatype.GetAttribute("apptype"));
//加入到arraylist中
jigou.Add(lis);
nodepoint=nodepoint.NextSibling;
}
back=true;
}
else
{
back=false;
}
return back;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -