F_SYS_0102.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 string _localiniFilePath = AppDomain.CurrentDomain.BaseDirectory + Constant.INI_FILE_NAME;
  31. private F_SYS_0104 _key = new F_SYS_0104();
  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. // 存在该文件,更改文件
  130. if (!File.Exists(this._localiniFilePath))
  131. {
  132. File.Create(this._localiniFilePath).Close();
  133. }
  134. // 保存业务系统配置
  135. Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP,
  136. this.txtIP.Text.Trim(), this._localiniFilePath);
  137. Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT,
  138. this.txtPort.Text.Trim(), this._localiniFilePath);
  139. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  140. this.Close();
  141. }
  142. catch (Exception ex)
  143. {
  144. // 对异常进行共通处理
  145. ExceptionManager.HandleEventException(this.ToString(),
  146. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  147. }
  148. }
  149. /// <summary>
  150. /// 点击取消按钮
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. private void btnCancel_Click(object sender, EventArgs e)
  155. {
  156. this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  157. this.Close();
  158. }
  159. #endregion
  160. #region 方法私有
  161. /// <summary>
  162. /// 设置窗体按钮的文本信息
  163. /// </summary>
  164. private void SetFromTitleInfo()
  165. {
  166. // 设置标题
  167. this.Text = FormTitles.F_SYS_0102;
  168. // 按钮文本赋值
  169. this.btnSave.Text = ButtonText.BTN_SAVE;
  170. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  171. this.btnTest.Text = ButtonText.BTN_TEST;
  172. }
  173. /// <summary>
  174. /// 保存数据的验证处理
  175. /// </summary>
  176. private bool IsCheckInfo()
  177. {
  178. string wcfIp = this.txtIP.Text.Trim();
  179. if (!string.IsNullOrEmpty(wcfIp))
  180. {
  181. Regex regEdpIP = new Regex(Constant.REGEX_IP_STRING, RegexOptions.None);
  182. if (!regEdpIP.IsMatch(wcfIp))
  183. {
  184. MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器地址", "255.255.255.255"),
  185. this.Text,
  186. MessageBoxButtons.OK,
  187. MessageBoxIcon.Warning,
  188. MessageBoxDefaultButton.Button1);
  189. this.txtIP.Focus();
  190. return false;
  191. }
  192. }
  193. else
  194. {
  195. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器地址"),
  196. this.Text,
  197. MessageBoxButtons.OK,
  198. MessageBoxIcon.Warning,
  199. MessageBoxDefaultButton.Button1);
  200. this.txtIP.Focus();
  201. return false;
  202. }
  203. string wcfPort = this.txtPort.Text.Trim();
  204. if (!string.IsNullOrEmpty(wcfPort))
  205. {
  206. Regex regEdpPort = new Regex(Constant.REGEX_PORT_STRING, RegexOptions.None);
  207. if (!regEdpPort.IsMatch(wcfPort))
  208. {
  209. MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器端口", "99999"),
  210. this.Text,
  211. MessageBoxButtons.OK,
  212. MessageBoxIcon.Warning,
  213. MessageBoxDefaultButton.Button1);
  214. this.txtPort.Focus();
  215. return false;
  216. }
  217. }
  218. else
  219. {
  220. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器端口"),
  221. this.Text,
  222. MessageBoxButtons.OK,
  223. MessageBoxIcon.Warning,
  224. MessageBoxDefaultButton.Button1);
  225. this.txtPort.Focus();
  226. return false;
  227. }
  228. return true;
  229. }
  230. #endregion
  231. private void btnKey1_Click(object sender, EventArgs e)
  232. {
  233. this._key.Hide();
  234. this.txtIP.Focus();
  235. //this.txtIP.SelectionLength = 0;
  236. this._key.SetLocation(this.txtIP);
  237. this._key.Show();
  238. }
  239. private void btnKey2_Click(object sender, EventArgs e)
  240. {
  241. this._key.Hide();
  242. this.txtPort.Focus();
  243. //this.txtPort.SelectionLength = 0;
  244. this._key.SetLocation(this.txtPort);
  245. this._key.Show();
  246. }
  247. }
  248. }