241 lines
8.3 KiB
C#
241 lines
8.3 KiB
C#
/******************************
|
|
* 说明:数据库配置界面
|
|
* 创建人:龚宇超
|
|
* 创建日期:2017-08-09
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using Lskj.Core;
|
|
using Lskj.Control;
|
|
using Lskj.Data;
|
|
using Lskj.Main.Model;
|
|
using Lskj.Business.Impl;
|
|
using System.IO;
|
|
using Lskj.Business;
|
|
using Lskj.Control.Model;
|
|
using System.Net;
|
|
using DevExpress.Utils.OAuth.Provider;
|
|
using Lskj.Util;
|
|
|
|
namespace Lskj.Main
|
|
{
|
|
/// <summary>
|
|
/// 数据库配置界面
|
|
/// </summary>
|
|
public partial class FrmConfig : XtraForm
|
|
{
|
|
/// <summary>
|
|
/// 默认下载地址
|
|
/// </summary>
|
|
public string filePath = string.Empty;
|
|
/// <summary>
|
|
/// 返回地址值
|
|
/// </summary>
|
|
public string outText = string.Empty;
|
|
|
|
public FrmConfig()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:窗口加载</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void FrmConfig_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DBConfig.Instance.ReadConfig(true);
|
|
serverType.Items.Add("SqlServer");
|
|
serverType.Items.Add("达梦数据库");
|
|
serverType.Text = DBConfig.Instance.ServerType;
|
|
this.txtServerName.Text = DBConfig.Instance.ServerName;
|
|
this.txtServerNameInternal.Text = DBConfig.Instance.InternalNetworkAddress;
|
|
this.txtDBName.Text = DBConfig.Instance.DataBase;
|
|
|
|
if (DBConfig.Instance.IsInternalNetwork)
|
|
{
|
|
this.radioWithin.Checked = true;
|
|
if (DBConfig.Instance.ServerName.Equals(DBConfig.Instance.InternalNetworkAddress)) this.txtServerName.Text = DBConfig.Instance.ExternalNetworkAddress;
|
|
}
|
|
else
|
|
{
|
|
this.radioOutside.Checked = true;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:测试数据库连接</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnConnect_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ConnectServer();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:保存配置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ConnectServer(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:退出配置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:连接服务器</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="isSave">if set to <c>true</c> [is save].</param>
|
|
private void ConnectServer(bool isSave = false)
|
|
{
|
|
|
|
string dbName = this.txtDBName.Text.Trim();
|
|
string internalNetworkAddress = this.txtServerNameInternal.Text.Trim();
|
|
string externalNetworkAddress = this.txtServerName.Text.Trim();
|
|
bool internalNetwork = radioWithin.Checked;
|
|
string serverTypeValue = serverType.Text + "";
|
|
string serverName = internalNetwork ? internalNetworkAddress : externalNetworkAddress;
|
|
|
|
if (string.IsNullOrWhiteSpace(serverName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ServerNameIsNull);
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(dbName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ServerDBIsNull);
|
|
return;
|
|
}
|
|
DBConfig.Instance.ServerName = serverName;
|
|
DBConfig.Instance.DataBase = dbName;
|
|
DBConfig.Instance.InternalNetworkAddress = internalNetworkAddress;
|
|
DBConfig.Instance.IsInternalNetwork = internalNetwork;
|
|
DBConfig.Instance.ExternalNetworkAddress = externalNetworkAddress;
|
|
DBConfig.Instance.ServerType = serverTypeValue;
|
|
DBConfig.Instance.Connection = "";
|
|
DBConfig.Instance.dephiConnection = "";
|
|
|
|
// 测试数据库连接
|
|
try
|
|
{
|
|
if (DBConfig.Instance.CreateConnection())
|
|
{
|
|
if (!DBConfig.Instance.ServerType.Equals("达梦数据库"))
|
|
{
|
|
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection())) == 0)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (isSave)
|
|
{
|
|
DBConfig.Instance.WriteConfig();
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectSuccess);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
//IniHelper.Write("SystemResources.ini", "FrmConfigFlag", "0");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
}
|
|
}
|
|
}
|