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 ERPClient { 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; } } }