FormParameter.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //======================================================================
  2. //
  3. // 成都同飞科技地下管网GIS系统
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: Tofly.AutoUpdateSystem.Win
  7. // 类 名: FormParameter
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2017/1/17 14:00:00
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Configuration;
  18. using System.Data;
  19. using System.Drawing;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. using System.Windows.Forms;
  25. namespace Tofly.AutoUpdateSystem.Win
  26. {
  27. public partial class FormParameter : Form
  28. {
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. private Configuration _config;
  33. public FormParameter()
  34. {
  35. InitializeComponent();
  36. }
  37. private void FormParameter_Shown(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. this._config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //ConfigurationUserLevel.None //Application.ExecutablePath
  42. this.txtShareFolder.Text = ConfigurationManager.AppSettings["ShareFoder"];
  43. this.txtNetUser.Text = ConfigurationManager.AppSettings["NetUser"];
  44. this.txtPassword.Text = ConfigurationManager.AppSettings["Password"];
  45. this.txtSystemFolder.Text = ConfigurationManager.AppSettings["DestinationFolder"];
  46. }
  47. catch (System.Exception ex)
  48. {
  49. MessageBox.Show("初始化失败: " + ex.Message, "初始化");
  50. }
  51. }
  52. private void btnOpen_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. FolderBrowserDialog __fbDialog = new FolderBrowserDialog()
  57. {
  58. Description = "打开系统目录",
  59. ShowNewFolderButton = false
  60. };
  61. if (__fbDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
  62. {
  63. string __strTestFile = string.Format(@"{0}\{1}", __fbDialog.SelectedPath, ConfigurationManager.AppSettings["ExcuteEXE"]);
  64. if (File.Exists(__strTestFile) == true)
  65. {
  66. this.txtSystemFolder.Text = __fbDialog.SelectedPath;
  67. }
  68. else
  69. {
  70. MessageBox.Show("测试发现此目录不是有效的系统目录,请重新选择.", "浏览系统目录", MessageBoxButtons.OK, MessageBoxIcon.Information);
  71. }
  72. }
  73. __fbDialog.Dispose();
  74. __fbDialog = null;
  75. }
  76. catch (System.Exception ex)
  77. {
  78. MessageBox.Show("打开失败: " + ex.Message, "浏览系统目录");
  79. }
  80. }
  81. private void btmConfirm_Click(object sender, EventArgs e)
  82. {
  83. try
  84. {
  85. //if (this._config.AppSettings.Settings.AllKeys.Contains("ShareFoder"))
  86. //{
  87. //}
  88. this._config.AppSettings.Settings["ShareFoder"].Value = this.txtShareFolder.Text.Trim();
  89. this._config.AppSettings.Settings["NetUser"].Value = this.txtNetUser.Text.Trim();
  90. this._config.AppSettings.Settings["Password"].Value = this.txtPassword.Text.Trim();
  91. this._config.AppSettings.Settings["DestinationFolder"].Value = this.txtSystemFolder.Text.Trim();
  92. this._config.Save(ConfigurationSaveMode.Modified);
  93. ConfigurationManager.RefreshSection("appSettings"); //刷新缓存数据
  94. MessageBox.Show("成功保存参数设置.", "保存参数设置");
  95. this.Close();
  96. }
  97. catch (System.Exception ex)
  98. {
  99. MessageBox.Show("保存失败: " + ex.Message, "保存参数设置");
  100. }
  101. }
  102. private void btnCancel_Click(object sender, EventArgs e)
  103. {
  104. this.Close();
  105. }
  106. }
  107. }