You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Accounts/FTPXML.aspx.cs

232 lines
8.2 KiB
C#

3 years ago
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 FTPXML : 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 = "SendFTP.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("id").ToString().Trim() == "1")//如果id属性值为“strCompanyID”
{
XmlNodeList bakss = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode baks in bakss)//遍历
{
XmlElement bak = (XmlElement)baks;//转换类型
if (bak.Name == "FTPSERVE")//如果找到
{
tbFTPSERVE.Text = bak.InnerText.Trim();//用户FTP服务器地址
}
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());
}
}
break;
}
//
}
}
}
protected void setXML()
{
string OppPath = "xml";
string xmlPath = Server.MapPath(OppPath);
string xmlName = "SendFTP.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("id").ToString().Trim() == "1")//如果id属性值为“strCompanyID.Trim()”
{
bz = 1;
XmlNodeList bakss = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode baks in bakss)//遍历
{
XmlElement bak = (XmlElement)baks;//转换类型
if (bak.Name == "FTPSERVE")//如果找到
{
bak.InnerText = tbFTPSERVE.Text.Trim();//用户FTP服务器地址
}
else if (bak.Name == "SENDER")//如果找到
{
bak.InnerText = tbSENDER.Text.Trim();//用户名称
}
else if (bak.Name == "PASSWORD")//用户密码
{
bak.InnerText = tbPASSWORD.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("id", "1");
root.AppendChild(bak);
XmlElement FTPSERVE = xmldoc.CreateElement("FTPSERVE");
FTPSERVE.InnerText = tbFTPSERVE.Text.Trim();
bak.AppendChild(FTPSERVE); //
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); //
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("id", "1");
root.AppendChild(bak);
XmlElement FTPSERVE = xmldoc.CreateElement("FTPSERVE");
FTPSERVE.InnerText = tbFTPSERVE.Text.Trim();
bak.AppendChild(FTPSERVE); //
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); //
xmldoc.Save(xmlPath + "//" + xmlName);
}
//
}
}