ab56a9bcf7
SVN-Revision: r240
275 lines
12 KiB
C#
275 lines
12 KiB
C#
using DevExpress.XtraEditors;
|
|
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 Lskj.Core;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Data;
|
|
using Lskj.Util;
|
|
using System.IO;
|
|
using System.Net;
|
|
|
|
namespace Lskj.Main3
|
|
{
|
|
public partial class FrmConfigLocal : XtraForm
|
|
{/// <summary>
|
|
/// 默认下载地址
|
|
/// </summary>
|
|
public string filePath = string.Empty;
|
|
/// <summary>
|
|
/// 返回地址值
|
|
/// </summary>
|
|
public string outText = string.Empty;
|
|
/// <summary>
|
|
/// 账套数据
|
|
/// </summary>
|
|
public DataTable sourceTab = new DataTable();
|
|
public FrmConfigLocal()
|
|
{
|
|
InitializeComponent();
|
|
this.txtIP.KeyUp += OnTxtEdit_KeyUp;
|
|
this.txtPort.KeyUp += OnTxtEdit_KeyUp;
|
|
this.txtZT.EditValueChanged += OnTxtZT_EditValueChanged;
|
|
}
|
|
|
|
private void OnTxtZT_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DataRow focusRow = (this.txtZT.GetSelectedDataRow() as DataRowView).Row;
|
|
this.txtIP.Text = (focusRow["dm"] + "").Split(':')[0];
|
|
this.txtPort.Text = (focusRow["dm"] + "").Split(':')[1];
|
|
this.txtZTName.Text = focusRow["mc"] + "";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void OnTxtEdit_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
string IPProt = string.Format("{0}:{1}", this.txtIP.Text, this.txtPort.Text);
|
|
DataRow[] rows = sourceTab.Select(string.Format("dm='{0}'", IPProt));
|
|
if (rows != null && rows.Count() > 0)
|
|
{
|
|
this.txtZT.EditValue = IPProt;
|
|
}
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
sourceTab.Columns.Add("dm");
|
|
sourceTab.Columns.Add("mc");
|
|
try
|
|
{
|
|
Dictionary<string, string> sourceDic = IniHelper.GetSectionKeys("SystemResources.ini", "SystemResources");
|
|
foreach (string key in sourceDic.Keys)
|
|
{
|
|
if (key.Contains("DownloadAESStr_"))
|
|
{
|
|
DataRow row = sourceTab.NewRow();
|
|
string[] keyArgs = key.Split('_');
|
|
if (keyArgs.Length == 2)
|
|
{
|
|
row["dm"] = keyArgs[1];//ip+port
|
|
row["mc"] = sourceDic[key].Split('^')[0];//账套名
|
|
sourceTab.Rows.Add(row);
|
|
}
|
|
else
|
|
continue;
|
|
}
|
|
}
|
|
this.txtZT.Properties.View.Columns.AddVisible("dm", "地址");
|
|
this.txtZT.Properties.View.Columns.AddVisible("mc", "账套名称");
|
|
this.txtZT.Properties.DataSource = sourceTab; //数据源
|
|
this.txtZT.Properties.ValueMember = "dm";
|
|
this.txtZT.Properties.DisplayMember = "mc";
|
|
this.txtZT.Properties.View.BestFitColumns();
|
|
this.txtZT.Properties.View.Columns["dm"].Visible = false;
|
|
|
|
this.txtZT.EditValue = string.Format("{0}:{1}", IniHelper.Read("SystemResources.ini", "LocalLastIP"), IniHelper.Read("SystemResources.ini", "LocalLastPort"));
|
|
//this.txtIP.Text = IniHelper.Read("SystemResources.ini", "LocalLastIP");
|
|
//this.txtPort.Text = IniHelper.Read("SystemResources.ini", "LocalLastPort");
|
|
//this.txtZTName.Text = IniHelper.Read("SystemResources.ini", "LocalLastPortName");
|
|
}
|
|
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 serverName = DBConfig.Instance.ServerName;
|
|
string dbName = DBConfig.Instance.DataBase;
|
|
// 测试数据库连接
|
|
try
|
|
{
|
|
string ip = this.txtIP.Text;
|
|
string defaultPort = ":" + this.txtPort.Text;
|
|
//服务器下载
|
|
string newServerName = !serverName.StartsWith("http") ? "http://" + ip + defaultPort : ip + defaultPort;
|
|
newServerName = !newServerName.EndsWith("/") ? newServerName + "/" : newServerName;
|
|
string newfilePath = Path.Combine(newServerName, "SystemResources.txt");
|
|
//string name = WebRequest.Create(filePath).GetResponse().GetResponseStream().ToString();
|
|
string fileName = "SystemResources.txt";//客户端保存的文件名
|
|
WebClient webClient = new WebClient();
|
|
webClient.Encoding = Encoding.UTF8;
|
|
//这里使用DownloadString方法,如果是不需要对文件的文本内容做处理,直接保存,那么可以直接使用功能DownloadFile(url,savepath)直接进行文件保存。
|
|
string newoutText = newfilePath != filePath ? webClient.DownloadString(newfilePath) : outText;
|
|
outText = newoutText.Trim();
|
|
filePath = newfilePath;
|
|
//File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemResources.txt"), outText);
|
|
string args = AESUtil.Decrypt(outText);
|
|
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;
|
|
DBConfig.Instance.Connection = Connection;
|
|
if (DBConfig.Instance.CreateConnection(Connection))
|
|
{
|
|
if (isSave)
|
|
{
|
|
if (!string.IsNullOrEmpty(this.txtZTName.Text))
|
|
{
|
|
string IPPort = string.Format("{0}:{1}", this.txtIP.Text, this.txtPort.Text);
|
|
string writeText = string.Format("{0}^{1}", this.txtZTName.Text, outText);
|
|
IniHelper.Write("SystemResources.ini", string.Format("DownloadAESStr_{0}", IPPort), writeText);
|
|
IniHelper.Write("SystemResources.ini", "LocalLastIP", this.txtIP.Text);
|
|
IniHelper.Write("SystemResources.ini", "LocalLastPort", this.txtPort.Text);
|
|
IniHelper.Write("SystemResources.ini", "LocalLastPortName", this.txtZTName.Text);
|
|
DBConfig.Instance.WriteConfig("LocalLastIP", this.txtIP.Text);
|
|
DBConfig.Instance.WriteConfig("LocalLastPort", this.txtPort.Text);
|
|
DBConfig.Instance.WriteConfig("LocalLastPortName", this.txtZTName.Text);
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("请设置账套名!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectSuccess);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
//IniHelper.Write("SystemResources.ini", "FrmConfigFlag", "1");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ConnectFault);
|
|
}
|
|
}
|
|
}
|
|
}
|