F_SYS_0102.cs 8.9 KB

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