F_SYS_0102.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_SYS_0102.cs
  5. * 2.功能描述:系统配置主界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/08/27 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.IO;
  12. using System.Reflection;
  13. using System.Text.RegularExpressions;
  14. using System.Windows.Forms;
  15. using System.Diagnostics;
  16. using Dongke.IBOSS.PRD.Basics.BaseControls;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Dongke.IBOSS.PRD.Basics.Library;
  19. using Dongke.IBOSS.PRD.Client.CommonModule;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. namespace Dongke.IBOSS.PRD.Client
  22. {
  23. /// <summary>
  24. /// 系统配置页面,配置WCF服务地址和端口
  25. /// </summary>
  26. public partial class F_SYS_0102 : FormBase
  27. {
  28. #region 成员变量
  29. //配置文件路径
  30. private string _iniFilePath = LocalPath.RootPath + Constant.INI_FILE_NAME;
  31. private string _localiniFilePath = AppDomain.CurrentDomain.BaseDirectory + Constant.INI_FILE_NAME;
  32. #endregion
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. public F_SYS_0102()
  38. {
  39. InitializeComponent();
  40. this.SetFromTitleInfo();
  41. }
  42. #endregion
  43. #region 事件
  44. /// <summary>
  45. /// 窗体加载事件
  46. /// </summary>
  47. /// <param name="sender"></param>
  48. /// <param name="e"></param>
  49. private void F_SYS_0102_Load(object sender, EventArgs e)
  50. {
  51. try
  52. {
  53. // 存在该文件,直接读取该文件,否则不读取
  54. if (File.Exists(_localiniFilePath))
  55. {
  56. this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  57. Constant.INI_KEY_IP, this._localiniFilePath);
  58. this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  59. Constant.INI_KEY_PORT, this._localiniFilePath);
  60. }
  61. else if (File.Exists(_iniFilePath))
  62. {
  63. //this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  64. // Constant.INI_KEY_IP, this._iniFilePath);
  65. //this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  66. // Constant.INI_KEY_PORT, this._iniFilePath);
  67. File.Copy(this._iniFilePath, _localiniFilePath);
  68. this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  69. Constant.INI_KEY_IP, this._localiniFilePath);
  70. this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  71. Constant.INI_KEY_PORT, this._localiniFilePath);
  72. }
  73. }
  74. catch (Exception ex)
  75. {
  76. // 对异常进行共通处理
  77. ExceptionManager.HandleEventException(this.ToString(),
  78. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  79. }
  80. }
  81. /// <summary>
  82. /// WCF服务测试按钮
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private void btnTest_Click(object sender, EventArgs e)
  87. {
  88. try
  89. {
  90. ProxySettings.ResetRemoteAddress(this.txtIP.Text, this.txtPort.Text);
  91. bool isSuccess = (bool)DoAsync(new BaseAsyncMethod(() =>
  92. {
  93. return DKIBOSSPRDProxy.Service.GetServiceState();
  94. }));
  95. if (isSuccess)
  96. {
  97. MessageBox.Show(Messages.MSG_SYS_I001,
  98. this.Text,
  99. MessageBoxButtons.OK,
  100. MessageBoxIcon.Information,
  101. MessageBoxDefaultButton.Button1);
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. // 写错误日志
  107. OutputLog.Trace(LogPriority.Error, this.ToString(),
  108. MethodBase.GetCurrentMethod().Name, ex.ToString());
  109. MessageBox.Show(Messages.MSG_SYS_W003,
  110. this.Text,
  111. MessageBoxButtons.OK,
  112. MessageBoxIcon.Warning,
  113. MessageBoxDefaultButton.Button1);
  114. }
  115. }
  116. /// <summary>
  117. /// 保存按钮
  118. /// </summary>
  119. /// <param name="sender"></param>
  120. /// <param name="e"></param>
  121. private void btnSave_Click(object sender, EventArgs e)
  122. {
  123. try
  124. {
  125. if (!this.IsCheckInfo())
  126. {
  127. return;
  128. }
  129. if (!File.Exists(_localiniFilePath))
  130. {
  131. File.Create(this._localiniFilePath).Close();
  132. }
  133. Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP,
  134. this.txtIP.Text.Trim(), this._localiniFilePath);
  135. Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT,
  136. this.txtPort.Text.Trim(), this._localiniFilePath);
  137. //{
  138. // // 文件夹不存在的情况下创建文件夹
  139. // if (!Directory.Exists(LocalPath.RootPath))
  140. // {
  141. // Directory.CreateDirectory(LocalPath.RootPath);
  142. // }
  143. // // 存在该文件,更改文件
  144. // if (!File.Exists(this._iniFilePath))
  145. // {
  146. // File.Create(this._iniFilePath).Close();
  147. // }
  148. // // 保存业务系统配置
  149. // Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP,
  150. // this.txtIP.Text.Trim(), this._iniFilePath);
  151. // Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT,
  152. // this.txtPort.Text.Trim(), this._iniFilePath);
  153. //}
  154. this.Close();
  155. }
  156. catch (Exception ex)
  157. {
  158. // 对异常进行共通处理
  159. ExceptionManager.HandleEventException(this.ToString(),
  160. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  161. }
  162. }
  163. /// <summary>
  164. /// 点击取消按钮
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void btnCancel_Click(object sender, EventArgs e)
  169. {
  170. this.Close();
  171. }
  172. /// <summary>
  173. /// 手动升级功能
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. private void btnUpdate_Click(object sender, EventArgs e)
  178. {
  179. try
  180. {
  181. DialogResult dres = MessageBox.Show("是否进行手动升级操作?",
  182. Text,
  183. MessageBoxButtons.YesNo,
  184. MessageBoxIcon.Question,
  185. MessageBoxDefaultButton.Button1);
  186. if (dres.Equals(DialogResult.Yes))
  187. {
  188. Application.Exit();
  189. Process.Start(AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRD.exe ");
  190. }
  191. }
  192. catch (Exception ex)
  193. {
  194. // 对异常进行共通处理
  195. ExceptionManager.HandleEventException(this.ToString(),
  196. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  197. }
  198. }
  199. #endregion
  200. #region 方法私有
  201. /// <summary>
  202. /// 设置窗体按钮的文本信息
  203. /// </summary>
  204. private void SetFromTitleInfo()
  205. {
  206. // 设置标题
  207. this.Text = FormTitles.F_SYS_0102;
  208. // 按钮文本赋值
  209. this.btnSave.Text = ButtonText.BTN_SAVE;
  210. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  211. this.btnTest.Text = ButtonText.BTN_TEST;
  212. }
  213. /// <summary>
  214. /// 保存数据的验证处理
  215. /// </summary>
  216. private bool IsCheckInfo()
  217. {
  218. string wcfIp = this.txtIP.Text.Trim();
  219. if (!string.IsNullOrEmpty(wcfIp))
  220. {
  221. //Regex regEdpIP = new Regex(Constant.REGEX_IP_STRING, RegexOptions.None);
  222. //if (!regEdpIP.IsMatch(wcfIp))
  223. //{
  224. // MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器地址", "255.255.255.255"),
  225. // this.Text,
  226. // MessageBoxButtons.OK,
  227. // MessageBoxIcon.Warning,
  228. // MessageBoxDefaultButton.Button1);
  229. // this.txtIP.Focus();
  230. // return false;
  231. //}
  232. }
  233. else
  234. {
  235. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器地址"),
  236. this.Text,
  237. MessageBoxButtons.OK,
  238. MessageBoxIcon.Warning,
  239. MessageBoxDefaultButton.Button1);
  240. this.txtIP.Focus();
  241. return false;
  242. }
  243. string wcfPort = this.txtPort.Text.Trim();
  244. if (!string.IsNullOrEmpty(wcfPort))
  245. {
  246. Regex regEdpPort = new Regex(Constant.REGEX_PORT_STRING, RegexOptions.None);
  247. if (!regEdpPort.IsMatch(wcfPort))
  248. {
  249. MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器端口", "99999"),
  250. this.Text,
  251. MessageBoxButtons.OK,
  252. MessageBoxIcon.Warning,
  253. MessageBoxDefaultButton.Button1);
  254. this.txtPort.Focus();
  255. return false;
  256. }
  257. }
  258. else
  259. {
  260. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器端口"),
  261. this.Text,
  262. MessageBoxButtons.OK,
  263. MessageBoxIcon.Warning,
  264. MessageBoxDefaultButton.Button1);
  265. this.txtPort.Focus();
  266. return false;
  267. }
  268. return true;
  269. }
  270. #endregion
  271. }
  272. }