using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using System.Xml; using DSWeb.EntityDA; using DSWeb.Models; using JsonHelper; namespace DSWeb.Accounts { public partial class SendMailXML : System.Web.UI.Page { public string strGIDS;// public string strBSNO;// public string strUserID;//登录用户GID public string strCompanyID;//公司GID public string strShowName;//用户显示名 public string strDeptName;//部门名称 protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString(); } else { Server.Transfer("~/Error/FriendError.aspx"); return; } if (Session["SHOWNAME"] != null) { strShowName = Session["SHOWNAME"].ToString(); } if (Session["COMPANYID"] != null) { strCompanyID = Session["COMPANYID"].ToString(); } if (Session["DEPTNAME"] != null) { strDeptName = Session["DEPTNAME"].ToString(); } // if (this.hdExport.Value != "") { setXML(); tbPASSWORD.Attributes.Add("value", this.hdPASSWORD.Value.Trim()); return; } // if (!IsPostBack) { getXML(); } } protected void getXML() { string OppPath = "xml"; string xmlPath = Server.MapPath(OppPath); string xmlName = "SendMail.xml"; // if (File.Exists(xmlPath + "//" + xmlName)) //判断文件是否寸在 { //存在的情况下 XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlPath + "//" + xmlName); //更新文件 XmlNode roots = xmldoc.SelectSingleNode("Data");//获取Data节点的所有子节点 foreach (XmlNode root in roots)//遍历所有子节点 { XmlElement xe = (XmlElement)root;//将子节点类型转换为XmlElement类型 if (xe.GetAttribute("companyid").ToString().Trim() == strCompanyID.Trim())//如果id属性值为“strCompanyID” { XmlNodeList bakss = xe.ChildNodes;//继续获取xe子节点的所有子节点 foreach (XmlNode baks in bakss)//遍历 { XmlElement bak = (XmlElement)baks;//转换类型 if (bak.Name == "MAILSERVE")//如果找到 { tbMAILSERVE.Text = bak.InnerText.Trim();//发件人邮箱服务器地址 } else if (bak.Name == "SENDER")//如果找到 { tbSENDER.Text = bak.InnerText.Trim();//发件人地址 } else if (bak.Name == "PASSWORD")//发件人密码 { //tbPASSWORD.Text = bak.InnerText.Trim(); tbPASSWORD.Attributes.Add("value", bak.InnerText.Trim()); } else if (bak.Name == "TITLE")//邮件的主题 { tbTITLE.Text = bak.InnerText.Trim(); } else if (bak.Name == "REMARK")//备注信息 { tbREMARK.Text = bak.InnerText.Trim(); } else if (bak.Name == "TITLEAUDIT")//邮件的主题 { tbTITLEAUDIT.Text = bak.InnerText.Trim(); } else if (bak.Name == "REMARKAUDIT")//内容信息 { tbREMARKAUDIT.Text = bak.InnerText.Trim(); } } break; } // } } } protected void setXML() { string OppPath = "xml"; string xmlPath = Server.MapPath(OppPath); string xmlName = "SendMail.xml"; // if (File.Exists(xmlPath + "//" + xmlName)) //判断文件是否寸在 { //更新文件 updateXML(xmlPath, xmlName); } else { //创建文件 createXML(xmlPath, xmlName); } this.hdExport.Value = ""; return; } protected void updateXML(string xmlPath, string xmlName) { int bz = 0; //插入 //存在的情况下 XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlPath + "//" + xmlName); //更新文件 XmlNode roots = xmldoc.SelectSingleNode("Data");//获取Data节点的所有子节点 foreach (XmlNode root in roots)//遍历所有子节点 { XmlElement xe = (XmlElement)root;//将子节点类型转换为XmlElement类型 if (xe.GetAttribute("companyid").ToString().Trim() == strCompanyID.Trim())//如果id属性值为“strCompanyID.Trim()” { bz = 1; XmlNodeList bakss = xe.ChildNodes;//继续获取xe子节点的所有子节点 foreach (XmlNode baks in bakss)//遍历 { XmlElement bak = (XmlElement)baks;//转换类型 if (bak.Name == "MAILSERVE")//如果找到 { bak.InnerText = tbMAILSERVE.Text.Trim();//发件人邮箱服务器地址 } else if (bak.Name == "SENDER")//如果找到 { bak.InnerText = tbSENDER.Text.Trim();//发件人地址 } else if (bak.Name == "PASSWORD")//发件人密码 { bak.InnerText = tbPASSWORD.Text.Trim(); } else if (bak.Name == "TITLE")//邮件的主题 { bak.InnerText = tbTITLE.Text.Trim(); } else if (bak.Name == "REMARK")//备注信息 { bak.InnerText = tbREMARK.Text.Trim(); } else if (bak.Name == "TITLEAUDIT")//邮件的主题 { bak.InnerText = tbTITLEAUDIT.Text.Trim(); } else if (bak.Name == "REMARKAUDIT")//内容信息 { bak.InnerText = tbREMARKAUDIT.Text.Trim(); } } break; } } // if (bz == 0) { insertXML(xmlPath, xmlName); } else { xmldoc.Save(xmlPath + "//" + xmlName); } } protected void createXML(string xmlPath, string xmlName) { Directory.CreateDirectory(xmlPath);//创建该文件 XmlDocument xmldoc = new XmlDocument(); XmlNode xmlnode = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null); xmldoc.AppendChild(xmlnode); XmlElement root = xmldoc.CreateElement("Data"); xmldoc.AppendChild(root); XmlElement bak = xmldoc.CreateElement("Bak"); bak.SetAttribute("companyid", strCompanyID.Trim()); root.AppendChild(bak); XmlElement MAILSERVE = xmldoc.CreateElement("MAILSERVE"); MAILSERVE.InnerText = tbMAILSERVE.Text.Trim(); bak.AppendChild(MAILSERVE); // XmlElement SENDER = xmldoc.CreateElement("SENDER"); SENDER.InnerText = tbSENDER.Text.Trim(); bak.AppendChild(SENDER); // XmlElement PASSWORD = xmldoc.CreateElement("PASSWORD"); PASSWORD.InnerText = tbPASSWORD.Text.Trim(); bak.AppendChild(PASSWORD); // XmlElement TITLE = xmldoc.CreateElement("TITLE"); TITLE.InnerText = tbTITLE.Text.Trim(); bak.AppendChild(TITLE); // XmlElement REMARK = xmldoc.CreateElement("REMARK"); REMARK.InnerText = tbREMARK.Text.Trim(); bak.AppendChild(REMARK); // XmlElement TITLEAUDIT = xmldoc.CreateElement("TITLEAUDIT"); TITLEAUDIT.InnerText = tbTITLEAUDIT.Text.Trim(); bak.AppendChild(TITLEAUDIT); // XmlElement REMARKAUDIT = xmldoc.CreateElement("REMARKAUDIT"); REMARKAUDIT.InnerText = tbREMARKAUDIT.Text.Trim(); bak.AppendChild(REMARKAUDIT); // xmldoc.Save(xmlPath + "//" + xmlName); } protected void insertXML(string xmlPath, string xmlName) { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlPath + "\\" + xmlName); //存在文件 XmlNode root = xmldoc.SelectSingleNode("Data"); XmlElement bak = xmldoc.CreateElement("Bak"); bak.SetAttribute("companyid", strCompanyID.Trim()); root.AppendChild(bak); XmlElement MAILSERVE = xmldoc.CreateElement("MAILSERVE"); MAILSERVE.InnerText = tbMAILSERVE.Text.Trim(); bak.AppendChild(MAILSERVE); // XmlElement SENDER = xmldoc.CreateElement("SENDER"); SENDER.InnerText = tbSENDER.Text.Trim(); bak.AppendChild(SENDER); // XmlElement PASSWORD = xmldoc.CreateElement("PASSWORD"); PASSWORD.InnerText = tbPASSWORD.Text.Trim(); bak.AppendChild(PASSWORD); // XmlElement TITLE = xmldoc.CreateElement("TITLE"); TITLE.InnerText = tbTITLE.Text.Trim(); bak.AppendChild(TITLE); // XmlElement REMARK = xmldoc.CreateElement("REMARK"); REMARK.InnerText = tbREMARK.Text.Trim(); bak.AppendChild(REMARK); // XmlElement TITLEAUDIT = xmldoc.CreateElement("TITLEAUDIT"); TITLEAUDIT.InnerText = tbTITLEAUDIT.Text.Trim(); bak.AppendChild(TITLEAUDIT); // XmlElement REMARKAUDIT = xmldoc.CreateElement("REMARKAUDIT"); REMARKAUDIT.InnerText = tbREMARKAUDIT.Text.Trim(); bak.AppendChild(REMARKAUDIT); // xmldoc.Save(xmlPath + "//" + xmlName); } // } }