//獲取合同信息
string projectNo = Request.QueryString["projectNo"];
string Sql="select * from tableName where projectNo='+projectNo+'";
DAL.DALSelect xx = new DALSelect();
SqlDataReader reader = xx.ExecuteReader(Sql);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("/WebTest/DocumentManage/User.xml")); //xml文件路徑
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("User");//xml所有節點的父節點
XmlNode root = xmlDoc.DocumentElement;
root.RemoveAll(); //每次寫入xml文件的時候都清空原來所有的節點,避免重複的數據寫入xml文件
while (reader.Read())
{
string ContractId = reader["ContractId"].ToString();
string ContractType = reader["ContractType"].ToString();
string PayMoneyNotId = reader["PayMoneyNotId"].ToString();
string CustName = reader["CustName"].ToString();
string PayMoney = reader["PayMoney"].ToString();
string PayMoneyLimitT = reader["PayMoneyLimitT"].ToString();
string PayMoneyLimitTUnit = reader["PayMoneyLimitTUnit"].ToString();
string ContractName = reader["ContractName"].ToString();
string ContractNo = reader["ContractNo"].ToString();
string ContractStartT = reader["ContractStartT"].ToString();
string ContractEndT = reader["ContractEndT"].ToString();
string ContractRemarks = reader["ContractRemarks"].ToString();
XmlElement el = xmlDoc.CreateElement("ContractInfo"); //添加ContractInfo節點
el.SetAttribute("Id", PayMoneyNotId); //添加ContractInfo節點的屬性"Id"
el.SetAttribute("Name", ContractName); //添加ContractInfo節點的屬性 "ContractName"
XmlElement xesub1 = xmlDoc.CreateElement("ContractType"); //添加ContractInfo節點的裏的節點
xesub1.InnerText = ContractType;//設置文本節點
el.AppendChild(xesub1);
XmlElement xesub2 = xmlDoc.CreateElement("PayMoneyNotId");
xesub2.InnerText = PayMoneyNotId;//設置文本節點
el.AppendChild(xesub2);
XmlElement xesub3 = xmlDoc.CreateElement("CustName");
xesub3.InnerText = CustName;//設置文本節點
el.AppendChild(xesub3);
XmlElement xesub4 = xmlDoc.CreateElement("PayMoney");
xesub4.InnerText = PayMoney;//設置文本節點
el.AppendChild(xesub4);
XmlElement xesub5 = xmlDoc.CreateElement("PayMoneyLimitT");
xesub5.InnerText = PayMoneyLimitT;//設置文本節點
el.AppendChild(xesub5);
XmlElement xesub6 = xmlDoc.CreateElement("PayMoneyLimitTUnit");
xesub6.InnerText = PayMoneyLimitTUnit;//設置文本節點
el.AppendChild(xesub6);
XmlElement xesub7 = xmlDoc.CreateElement("ContractName");
xesub7.InnerText = ContractName;//設置文本節點
el.AppendChild(xesub7);
XmlElement xesub8 = xmlDoc.CreateElement("ContractNo");
xesub8.InnerText = ContractNo;//設置文本節點
el.AppendChild(xesub8);
XmlElement xesub9 = xmlDoc.CreateElement("ContractStartT");
xesub9.InnerText = ContractStartT;//設置文本節點
el.AppendChild(xesub9);
XmlElement xesub10 = xmlDoc.CreateElement("ContractEndT");
xesub10.InnerText = ContractEndT;//設置文本節點
el.AppendChild(xesub10);
XmlElement xesub11 = xmlDoc.CreateElement("ContractRemarks");
xesub11.InnerText = ContractRemarks;//設置文本節點
el.AppendChild(xesub11);
XmlElement xesub12 = xmlDoc.CreateElement("ContractId");
xesub12.InnerText = ContractId;//設置文本節點
el.AppendChild(xesub12);
xmldocSelect.AppendChild(el);
xmlDoc.Save(Server.MapPath("/WebTest/DocumentManage/User.xml")); //保存xml文件
}
}
User.xml最初文件
<?xml version="1.0" encoding="utf-8"?>
<User></User>