/******************************************************************************* * 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 System.Diagnostics; 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 { /// /// 系统配置页面,配置WCF服务地址和端口 /// public partial class F_SYS_0102 : FormBase { #region 成员变量 //配置文件路径 private string _iniFilePath = LocalPath.RootPath + Constant.INI_FILE_NAME; private string _localiniFilePath = AppDomain.CurrentDomain.BaseDirectory + Constant.INI_FILE_NAME; #endregion #region 构造函数 /// /// 构造函数 /// public F_SYS_0102() { InitializeComponent(); this.SetFromTitleInfo(); } #endregion #region 事件 /// /// 窗体加载事件 /// /// /// private void F_SYS_0102_Load(object sender, EventArgs e) { try { // 存在该文件,直接读取该文件,否则不读取 if (File.Exists(_localiniFilePath)) { this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP, this._localiniFilePath); this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT, this._localiniFilePath); } else 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); File.Copy(this._iniFilePath, _localiniFilePath); this.txtIP.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP, this._localiniFilePath); this.txtPort.Text = Utility.ReadIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT, this._localiniFilePath); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// WCF服务测试按钮 /// /// /// 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); } } /// /// 保存按钮 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { if (!this.IsCheckInfo()) { return; } if (!File.Exists(_localiniFilePath)) { File.Create(this._localiniFilePath).Close(); } Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_IP, this.txtIP.Text.Trim(), this._localiniFilePath); Utility.WriteIniFile(Constant.INI_SECTION_NET, Constant.INI_KEY_PORT, this.txtPort.Text.Trim(), this._localiniFilePath); //{ // // 文件夹不存在的情况下创建文件夹 // 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.Close(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 点击取消按钮 /// /// /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } /// /// 手动升级功能 /// /// /// private void btnUpdate_Click(object sender, EventArgs e) { try { DialogResult dres = MessageBox.Show("是否进行手动升级操作?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dres.Equals(DialogResult.Yes)) { Application.Exit(); Process.Start(AppDomain.CurrentDomain.BaseDirectory + "AutoUpgrade.exe", "IBOSSPRD.exe "); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } #endregion #region 方法私有 /// /// 设置窗体按钮的文本信息 /// 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; } /// /// 保存数据的验证处理 /// 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 } }