8a41c8f764
SVN-Revision: r1002
146 lines
6.4 KiB
C#
146 lines
6.4 KiB
C#
using DevExpress.XtraEditors;
|
|
using Lskj.Control;
|
|
using Lskj.Core;
|
|
using Lskj.Data;
|
|
using Lskj.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.Main
|
|
{
|
|
public partial class FrmConfigSet : XtraForm
|
|
{
|
|
public FrmConfigSet()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void FrmConfigSet_Load(object sender, EventArgs e)
|
|
{
|
|
string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemResources.ini");
|
|
if (!File.Exists(file))
|
|
{
|
|
FileStream fileStream = new FileStream(file, FileMode.CreateNew);
|
|
fileStream.Close();
|
|
this.frmConfigBtn.Checked = true;
|
|
}
|
|
else
|
|
{
|
|
string configFlag = IniHelper.Read("SystemResources.ini", "FrmConfigFlag");
|
|
if (configFlag.Equals("1"))
|
|
this.frmConfigLocalBtn.Checked = true;
|
|
else
|
|
this.frmConfigBtn.Checked = true;
|
|
}
|
|
this.btnSettings.Click += new EventHandler(OnBtnSettings_Click);
|
|
this.btnChange.Click += new EventHandler(OnBtnChange_Click);
|
|
}
|
|
|
|
private void OnBtnChange_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.frmConfigLocalBtn.Checked)
|
|
{
|
|
try
|
|
{
|
|
string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemResources.ini");
|
|
if (File.Exists(file))
|
|
{
|
|
string lastIPPort = string.Format("{0}:{1}", IniHelper.Read("SystemResources.ini", "LocalLastIP"), IniHelper.Read("SystemResources.ini", "LocalLastPort"));
|
|
string downloadAESStrKey = string.Format("DownloadAESStr_{0}", lastIPPort);
|
|
string[] downloadAESStrValue = IniHelper.Read("SystemResources.ini", downloadAESStrKey).Split('^');
|
|
string downloadAESStr = downloadAESStrValue.Length == 2 ? downloadAESStrValue[1] : "";
|
|
if (!string.IsNullOrEmpty(downloadAESStr))
|
|
{
|
|
string args = AESUtil.Decrypt(downloadAESStr);
|
|
string[] controlAfgs = args.Split('^');
|
|
if (controlAfgs != null && controlAfgs.Length == 5)
|
|
{
|
|
DBConfig.Instance.ServerName = controlAfgs[0];
|
|
DBConfig.Instance.DataBase = controlAfgs[1];
|
|
string Connection = "Server={0};Database={1};Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5;MultipleActiveResultSets=true";
|
|
string dephistr = "Provider=SQLOLEDB.1;Server={0};Database={1};Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5";
|
|
Connection = AESUtil.Encrypt(Connection);
|
|
dephistr = AESUtil.Encrypt(dephistr);
|
|
DBConfig.Instance.dephiConnection = dephistr;
|
|
if (DBConfig.Instance.CreateConnection(Connection))
|
|
{
|
|
DBConfig.Instance.Connection = Connection;
|
|
this.DialogResult = DialogResult.OK;
|
|
IniHelper.Write("SystemResources.ini", "FrmConfigFlag", "1");
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("未检测到配置数据,切换失败!\r\n请进行手动设置!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("配置文件不存在,请手动设置!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
}
|
|
else if (this.frmConfigBtn.Checked)
|
|
{
|
|
DBConfig.Instance.ReadConfig(true);
|
|
string serverName = DBConfig.Instance.ServerName;
|
|
string dbName = DBConfig.Instance.DataBase;
|
|
if (string.IsNullOrWhiteSpace(serverName))
|
|
{
|
|
MessageUtil.Show("数据库地址为空,切换失败");
|
|
return;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(dbName))
|
|
{
|
|
MessageUtil.Show("数据库名称为空,切换失败");
|
|
return;
|
|
}
|
|
DBConfig.Instance.ServerName = serverName;
|
|
DBConfig.Instance.DataBase = dbName;
|
|
try
|
|
{
|
|
if (DBConfig.Instance.CreateConnection())
|
|
{
|
|
DBConfig.Instance.Connection = "";
|
|
|
|
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection())) == 0)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
|
|
return;
|
|
}
|
|
DBConfig.Instance.dephiConnection = "";
|
|
DBConfig.Instance.WriteConfig();
|
|
this.DialogResult = DialogResult.OK;
|
|
IniHelper.Write("SystemResources.ini", "FrmConfigFlag", "0");
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
}
|
|
}
|
|
private void OnBtnSettings_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult dialogResult;
|
|
if (this.frmConfigBtn.Checked)
|
|
{
|
|
this.Hide();
|
|
|