123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
-
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Tofly.AutoUpdateSystem.Win
- {
- public partial class FormParameter : Form
- {
-
-
-
- private Configuration _config;
- public FormParameter()
- {
- InitializeComponent();
- }
- private void FormParameter_Shown(object sender, EventArgs e)
- {
- try
- {
- this._config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- this.txtShareFolder.Text = ConfigurationManager.AppSettings["ShareFoder"];
- this.txtNetUser.Text = ConfigurationManager.AppSettings["NetUser"];
- this.txtPassword.Text = ConfigurationManager.AppSettings["Password"];
- this.txtSystemFolder.Text = ConfigurationManager.AppSettings["DestinationFolder"];
- }
- catch (System.Exception ex)
- {
- MessageBox.Show("初始化失败: " + ex.Message, "初始化");
- }
- }
- private void btnOpen_Click(object sender, EventArgs e)
- {
- try
- {
- FolderBrowserDialog __fbDialog = new FolderBrowserDialog()
- {
- Description = "打开系统目录",
- ShowNewFolderButton = false
- };
- if (__fbDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
- {
- string __strTestFile = string.Format(@"{0}\{1}", __fbDialog.SelectedPath, ConfigurationManager.AppSettings["ExcuteEXE"]);
- if (File.Exists(__strTestFile) == true)
- {
- this.txtSystemFolder.Text = __fbDialog.SelectedPath;
- }
- else
- {
- MessageBox.Show("测试发现此目录不是有效的系统目录,请重新选择.", "浏览系统目录", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- __fbDialog.Dispose();
- __fbDialog = null;
- }
- catch (System.Exception ex)
- {
- MessageBox.Show("打开失败: " + ex.Message, "浏览系统目录");
- }
- }
- private void btmConfirm_Click(object sender, EventArgs e)
- {
- try
- {
-
-
-
- this._config.AppSettings.Settings["ShareFoder"].Value = this.txtShareFolder.Text.Trim();
- this._config.AppSettings.Settings["NetUser"].Value = this.txtNetUser.Text.Trim();
- this._config.AppSettings.Settings["Password"].Value = this.txtPassword.Text.Trim();
- this._config.AppSettings.Settings["DestinationFolder"].Value = this.txtSystemFolder.Text.Trim();
- this._config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");
- MessageBox.Show("成功保存参数设置.", "保存参数设置");
- this.Close();
- }
- catch (System.Exception ex)
- {
- MessageBox.Show("保存失败: " + ex.Message, "保存参数设置");
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
|