Files
2026-07-10 15:25:05 +08:00

79 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 System.Data.SqlClient;
using CommonLib;
using CommonLib.data;
using DevExpress.XtraEditors;
namespace Lskj.Main.sub
{
public partial class FrmConfig : XtraForm {
public FrmConfig() {
InitializeComponent();
DevExpress.Skins.SkinManager.EnableFormSkins();
}
private void btnTestConnect_Click(object sender, EventArgs e) {
TestConfig(false);
}
private void btnSave_Click(object sender, EventArgs e) {
TestConfig(true);
}
private void TestConfig(bool bSave) {
if (txtServerName.Text.Trim() == string.Empty) {
MessageBox.Show("请输入服务器名称或IP");
return;
}
if (txtDBName.Text.Trim() == string.Empty) {
MessageBox.Show("请输入数据库名称!");
return;
}
DBConfig.Instance.ServerName = txtServerName.Text.Trim();
DBConfig.Instance.datastr = txtDBName.Text.Trim();
Cursor = Cursors.Hand;
try {
string connectionStr = DBConfig.Instance.GetConStr();
using (SqlConnection conn = new SqlConnection(connectionStr)) {
conn.Open();
conn.Close();
conn.Dispose();
}
if (bSave) {
MessageBox.Show("保存成功,系统需要重启.");
DBConfig.Instance.WriteConfig();
DialogResult = DialogResult.OK;
Close();
}
else {
MessageBox.Show("连接正确.");
}
}
catch (Exception ex) {
MessageBox.Show("连接失败,请确认配置是否正确!");
}
finally {
Cursor = Cursors.Default;
}
}
private void btnQuit_Click(object sender, EventArgs e) {
Close();
}
private void FrmConfig_Load(object sender, EventArgs e) {
txtServerName.Text = DBConfig.Instance.ServerName;
txtDBName.Text = DBConfig.Instance.datastr;
}
}
}