F_SYS_0102.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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.Public
  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 F_SYS_0104 _key = new F_SYS_0104();
  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(_iniFilePath))
  54. {
  55. this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  56. Constant.INI_KEY_IP, this._iniFilePath);
  57. this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
  58. Constant.INI_KEY_PORT, this._iniFilePath);
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. // 对异常进行共通处理
  64. ExceptionManager.HandleEventException(this.ToString(),
  65. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  66. }
  67. }
  68. /// <summary>
  69. /// WCF服务测试按钮
  70. /// </summary>
  71. /// <param name="sender"></param>
  72. /// <param name="e"></param>
  73. private void btnTest_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. ProxySettings.ResetRemoteAddress(this.txtIP.Text, this.txtPort.Text);
  78. bool isSuccess = (bool)DoAsync(new BaseAsyncMethod(() =>
  79. {
  80. return DKIBOSSPRDProxy.Service.GetServiceState();
  81. }));
  82. if (isSuccess)
  83. {
  84. MessageBox.Show(Messages.MSG_SYS_I001,
  85. this.Text,
  86. MessageBoxButtons.OK,
  87. MessageBoxIcon.Information,
  88. MessageBoxDefaultButton.Button1);
  89. }
  90. }
  91. catch (Exception ex)
  92. {
  93. // 写错误日志
  94. OutputLog.Trace(LogPriority.Error, this.ToString(),
  95. MethodBase.GetCurrentMethod().Name, ex.ToString());
  96. MessageBox.Show(Messages.MSG_SYS_W003,
  97. this.Text,
  98. MessageBoxButtons.OK,
  99. MessageBoxIcon.Warning,
  100. MessageBoxDefaultButton.Button1);
  101. }
  102. }
  103. /// <summary>
  104. /// 保存按钮
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. private void btnSave_Click(object sender, EventArgs e)
  109. {
  110. try
  111. {
  112. if (!this.IsCheckInfo())
  113. {
  114. return;
  115. }
  116. // 文件夹不存在的情况下创建文件夹
  117. if (!Directory.Exists(LocalPath.RootPath))
  118. {
  119. Directory.CreateDirectory(LocalPath.RootPath);
  120. }
  121. // 存在该文件,更改文件
  122. if (!File.Exists(this._iniFilePath))
  123. {
  124. File.Create(this._iniFilePath).Close();
  125. }
  126. // 保存业务系统配置
  127. Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP,
  128. this.txtIP.Text.Trim(), this._iniFilePath);
  129. Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT,
  130. this.txtPort.Text.Trim(), this._iniFilePath);
  131. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  132. this.Close();
  133. }
  134. catch (Exception ex)
  135. {
  136. // 对异常进行共通处理
  137. ExceptionManager.HandleEventException(this.ToString(),
  138. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  139. }
  140. }
  141. /// <summary>
  142. /// 点击取消按钮
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void btnCancel_Click(object sender, EventArgs e)
  147. {
  148. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  149. this.Close();
  150. }
  151. #endregion
  152. #region 方法私有
  153. /// <summary>
  154. /// 设置窗体按钮的文本信息
  155. /// </summary>
  156. private void SetFromTitleInfo()
  157. {
  158. // 设置标题
  159. this.Text = FormTitles.F_SYS_0102;
  160. // 按钮文本赋值
  161. this.btnSave.Text = ButtonText.BTN_SAVE;
  162. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  163. this.btnTest.Text = ButtonText.BTN_TEST;
  164. }
  165. /// <summary>
  166. /// 保存数据的验证处理
  167. /// </summary>
  168. private bool IsCheckInfo()
  169. {
  170. string wcfIp = this.txtIP.Text.Trim();
  171. if (!string.IsNullOrEmpty(wcfIp))
  172. {
  173. Regex regEdpIP = new Regex(Constant.REGEX_IP_STRING, RegexOptions.None);
  174. if (!regEdpIP.IsMatch(wcfIp))
  175. {
  176. MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器地址", "255.255.255.255"),
  177. this.Text,
  178. MessageBoxButtons.OK,
  179. MessageBoxIcon.Warning,
  180. MessageBoxDefaultButton.Button1);
  181. this.txtIP.Focus();
  182. return false;
  183. }
  184. }
  185. else
  186. {
  187. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器地址"),
  188. this.Text,
  189. MessageBoxButtons.OK,
  190. MessageBoxIcon.Warning,
  191. MessageBoxDefaultButton.Button1);
  192. this.txtIP.Focus();
  193. return false;
  194. }
  195. string wcfPort = this.txtPort.Text.Trim();
  196. if (!string.IsNullOrEmpty(wcfPort))
  197. {
  198. Regex regEdpPort = new Regex(Constant.REGEX_PORT_STRING, RegexOptions.None);
  199. if (!regEdpPort.IsMatch(wcfPort))
  200. {
  201. MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器端口", "99999"),
  202. this.Text,
  203. MessageBoxButtons.OK,
  204. MessageBoxIcon.Warning,
  205. MessageBoxDefaultButton.Button1);
  206. this.txtPort.Focus();
  207. return false;
  208. }
  209. }
  210. else
  211. {
  212. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器端口"),
  213. this.Text,
  214. MessageBoxButtons.OK,
  215. MessageBoxIcon.Warning,
  216. MessageBoxDefaultButton.Button1);
  217. this.txtPort.Focus();
  218. return false;
  219. }
  220. return true;
  221. }
  222. #endregion
  223. private void btnKey1_Click(object sender, EventArgs e)
  224. {
  225. this._key.Hide();
  226. this.txtIP.Focus();
  227. //this.txtIP.SelectionLength = 0;
  228. this._key.SetLocation(this.txtIP);
  229. this._key.Show();
  230. }
  231. private void btnKey2_Click(object sender, EventArgs e)
  232. {
  233. this._key.Hide();
  234. this.txtPort.Focus();
  235. //this.txtPort.SelectionLength = 0;
  236. this._key.SetLocation(this.txtPort);
  237. this._key.Show();
  238. }
  239. }
  240. }