📄 srxml.cs
字号:
using System;
using System.Data;
using System.Xml;
using System.IO;
using System.Text;
namespace XFMAS
{
/// <summary>
/// 存取配置文件
/// </summary>
public class SRXML
{
public SRXML()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 配置表
/// </summary>
/// <returns></returns>
public static DataTable ConfigTable(){
DataTable table = new DataTable("SystemConfig");
DataColumn col = new DataColumn("SystemName");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("SqlServer");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("SqlUser");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("SqlPWD");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("LastUser");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("LastUserID");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("LastUserPWD");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("LastUserIP");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("AutoLogin");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn("SoftVer");
col.DataType = System.Type.GetType("System.String");
table.Columns.Add(col);
DataRow row = table.NewRow();
row["SystemName"] = "消防支队食堂就餐提醒系统";
row["SqlServer"] = "";
row["SqlUser"] = "";
row["SqlPwd"] = "";
row["LastUser"] = " ";
row["LastUserID"] = "";
row["LastUserIP"] = "";
row["LastUserPWD"] = "";
row["autoLogin"] = "0";
row["SoftVer"] = " ";
table.Rows.Add(row);
return table;
}
/// <summary>
/// 保存DataTable中的数据到XML
/// </summary>
/// <returns></returns>
public static void SaveDataTableToXML(DataTable table,string path){
if(File.Exists(path)){
File.Delete(path);
}
DataSet ds = new DataSet();
ds.Tables.Add(table.Copy());
SRXML.CreateXmlFile(ds,path);
}
/// <summary>
/// 创建指定路径的Xml文件
/// </summary>
/// <param name="path"></param>
public static void CreateXmlFile(DataSet ds,string path){
StreamWriter sw = null;
try{
sw = new StreamWriter(path);
ds.WriteXml(sw);
sw.Close();
}catch{
if(sw != null) sw.Close();
}finally{
if(sw != null) sw.Close();
}
}
/// <summary>
/// 读取XML内容到DataTable
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static DataTable ReadDataTaBleFromXML(string path){
if(File.Exists(path)){
DataSet ds = SRXML.ReadXmlFile(path);
if(ds != null && ds.Tables.Count == 1) return SRXML.ReadXmlFile(path).Tables[0];
else return null;
}else{
return null;
}
}
/// <summary>
/// 读取指定路径的Xml文件并创建相应的DataSet
/// </summary>
/// <param name="path"></param>
public static DataSet ReadXmlFile(string path){
try{
DataSet ds = new DataSet();
ds.ReadXml(path);
return ds;
}catch(Exception ex){
return null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -