| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_SYS_0102.cs
- * 2.功能描述:系统配置主界面
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 张国印 2014/08/27 1.00 新建
- *******************************************************************************/
- using System;
- using System.IO;
- using System.Reflection;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.Public
- {
- /// <summary>
- /// 系统配置页面,配置WCF服务地址和端口
- /// </summary>
- public partial class F_SYS_0102 : FormBase
- {
- #region 成员变量
- //配置文件路径
- private string _iniFilePath = LocalPath.RootPath + Constant.INI_FILE_NAME;
- private F_SYS_0104 _key = new F_SYS_0104();
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_SYS_0102()
- {
- InitializeComponent();
- this.SetFromTitleInfo();
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_SYS_0102_Load(object sender, EventArgs e)
- {
- try
- {
- // 存在该文件,直接读取该文件,否则不读取
- if (File.Exists(_iniFilePath))
- {
- this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
- Constant.INI_KEY_IP, this._iniFilePath);
- this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET,
- Constant.INI_KEY_PORT, this._iniFilePath);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// WCF服务测试按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnTest_Click(object sender, EventArgs e)
- {
- try
- {
- ProxySettings.ResetRemoteAddress(this.txtIP.Text, this.txtPort.Text);
- bool isSuccess = (bool)DoAsync(new BaseAsyncMethod(() =>
- {
- return DKIBOSSPRDProxy.Service.GetServiceState();
- }));
- if (isSuccess)
- {
- MessageBox.Show(Messages.MSG_SYS_I001,
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- }
- }
- catch (Exception ex)
- {
- // 写错误日志
- OutputLog.Trace(LogPriority.Error, this.ToString(),
- MethodBase.GetCurrentMethod().Name, ex.ToString());
- MessageBox.Show(Messages.MSG_SYS_W003,
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning,
- MessageBoxDefaultButton.Button1);
- }
- }
- /// <summary>
- /// 保存按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (!this.IsCheckInfo())
- {
- return;
- }
- // 文件夹不存在的情况下创建文件夹
- if (!Directory.Exists(LocalPath.RootPath))
- {
- Directory.CreateDirectory(LocalPath.RootPath);
- }
- // 存在该文件,更改文件
- if (!File.Exists(this._iniFilePath))
- {
- File.Create(this._iniFilePath).Close();
- }
- // 保存业务系统配置
- Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP,
- this.txtIP.Text.Trim(), this._iniFilePath);
- Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT,
- this.txtPort.Text.Trim(), this._iniFilePath);
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.Close();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 点击取消按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.Close();
- }
- #endregion
- #region 方法私有
- /// <summary>
- /// 设置窗体按钮的文本信息
- /// </summary>
- private void SetFromTitleInfo()
- {
- // 设置标题
- this.Text = FormTitles.F_SYS_0102;
- // 按钮文本赋值
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CANCEL;
- this.btnTest.Text = ButtonText.BTN_TEST;
- }
- /// <summary>
- /// 保存数据的验证处理
- /// </summary>
- private bool IsCheckInfo()
- {
- string wcfIp = this.txtIP.Text.Trim();
- if (!string.IsNullOrEmpty(wcfIp))
- {
- Regex regEdpIP = new Regex(Constant.REGEX_IP_STRING, RegexOptions.None);
- if (!regEdpIP.IsMatch(wcfIp))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器地址", "255.255.255.255"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning,
- MessageBoxDefaultButton.Button1);
- this.txtIP.Focus();
- return false;
- }
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器地址"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning,
- MessageBoxDefaultButton.Button1);
- this.txtIP.Focus();
- return false;
- }
- string wcfPort = this.txtPort.Text.Trim();
- if (!string.IsNullOrEmpty(wcfPort))
- {
- Regex regEdpPort = new Regex(Constant.REGEX_PORT_STRING, RegexOptions.None);
- if (!regEdpPort.IsMatch(wcfPort))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W004, "服务器端口", "99999"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning,
- MessageBoxDefaultButton.Button1);
- this.txtPort.Focus();
- return false;
- }
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "服务器端口"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning,
- MessageBoxDefaultButton.Button1);
- this.txtPort.Focus();
- return false;
- }
- return true;
- }
- #endregion
- private void btnKey1_Click(object sender, EventArgs e)
- {
- this._key.Hide();
- this.txtIP.Focus();
- //this.txtIP.SelectionLength = 0;
- this._key.SetLocation(this.txtIP);
- this._key.Show();
- }
- private void btnKey2_Click(object sender, EventArgs e)
- {
- this._key.Hide();
- this.txtPort.Focus();
- //this.txtPort.SelectionLength = 0;
- this._key.SetLocation(this.txtPort);
- this._key.Show();
- }
- }
- }
|