?? ftpconfigform.cs
字號:
?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace ftpTransport
{
public partial class ftpConfigForm : Form
{
private static ftpConfigForm fcf ;
public ftpConfigForm()
{
InitializeComponent();
}
public ftpConfigForm(Form parentForm)
{
fcf = new ftpConfigForm();
fcf.MdiParent = parentForm;
fcf.Text = "FTP配置設置";
fcf.Show();
}
public static ftpConfigForm GetSingleTonInstance(Form parentForm)
{
if (fcf == null)
{
fcf = new ftpConfigForm(parentForm);
}
return fcf;
}
private void ftpConfigForm_Load(object sender, EventArgs e)
{
// 讀取 Applicationi 范圍的設置
ReadConfig();
}
private void ftpConfigForm_FormClosing(object sender, FormClosingEventArgs e)
{
//MessageBox.Show("關閉事件");
fcf = null;
}
private void btnTestLogin_Click(object sender, EventArgs e)
{
ftpClient client = new ftpClient();
string rval = client.testConnection(tbFtpIp.Text, tbFtpPort.Text, tbUserName.Text, tbPassword.Text);
MessageBox.Show(rval);
}
private void ReadConfig()
{
Properties.Settings.Default.Reload();
this.tbFtpIp.Text = Properties.Settings.Default.ftpServer;
this.tbFtpPort.Text = Properties.Settings.Default.ftpPort;
this.tbUserName.Text = Properties.Settings.Default.ftpUser;
this.tbPassword.Text = Properties.Settings.Default.ftpPassword;
this.tbFtpTimer.Text = Properties.Settings.Default.ftpFrequence;
this.tbFileType.Text = Properties.Settings.Default.FileType;
this.tbLocalDirectory.Text = Properties.Settings.Default.localFilePath;
this.tbTimer.Text = Properties.Settings.Default.Frequence;
}
private void btnSaveFtpConfig_Click(object sender, EventArgs e)
{
try
{
SaveConfig("ftpServer", tbFtpIp.Text, false);
SaveConfig("ftpPort", tbFtpPort.Text, false);
SaveConfig("ftpUser", tbUserName.Text, false);
SaveConfig("ftpPassword", tbPassword.Text, false);
SaveConfig("ftpFrequence", tbFtpTimer.Text, false);
SaveConfig("localFilePath", tbLocalDirectory.Text, false);
SaveConfig("FileType", tbFileType.Text, false);
SaveConfig("Frequence", tbTimer.Text, true);
DialogResult dr=MessageBox.Show("配置信息保存成功,請重新啟動應用程序","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1);
if (dr == DialogResult.Yes)
{
Application.ExitThread();
Restart();
}
}
catch
{
MessageBox.Show("保存配置信息失敗,請確保文件完整");
}
}
private void SaveConfig(string varient, string value, bool Reload)
{
// 保存 Applicationi 范圍的設置
string configFileName = Application.ExecutablePath + ".config";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(configFileName);
string configString = "configuration/applicationSettings/ftpTransport.Properties.Settings/setting[@name='" + varient + "']/value";
System.Xml.XmlNode configNode = doc.SelectSingleNode(configString);
if (configNode != null)
{
configNode.InnerText = value;
doc.Save(configFileName);
if (Reload)
{
// 刷新應用程序設置,這樣下次讀取時才能讀到最新的值。
Properties.Settings.Default.Reload();
}
}
}
private void Restart()
{
Thread thtmp = new Thread(new ParameterizedThreadStart(run));
object appName = Application.ExecutablePath;
Thread.Sleep(2000);
thtmp.Start(appName);
}
private void run(Object obj)
{
Process ps = new Process();
ps.StartInfo.FileName = obj.ToString();
ps.Start();
}
private void btnOpenFD_Click(object sender, EventArgs e)
{
DialogResult dr= folderBrowserDialog1.ShowDialog();
if(dr==DialogResult.OK)
{
this.tbLocalDirectory.Text = folderBrowserDialog1.SelectedPath;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -