using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Windows.Forms; using Stone.Common; namespace Stone.User { public partial class frmSqlServer : Form { public frmSqlServer() { InitializeComponent(); } private void frmSqlServer_Load(object sender, EventArgs e) { this.txtServer.Text = MyAppconfig.ReadValue("SqlServer"); this.txtUser.Text = MyAppconfig.ReadValue("SqlUser"); this.txtPassword.Text = MyStrings.DecryptStr(MyAppconfig.ReadValue("SqlPwd")); this.txtDataBase.Text = MyAppconfig.ReadValue("SqlDataBase"); this.txtTimeOut.Text = MyAppconfig.ReadValue("SqlTimeOut"); } private void btnTest_Click(object sender, EventArgs e) { SqlConnection sqlconn = new SqlConnection("uid=" + this.txtUser.Text.Trim() + ";pwd=" + this.txtPassword.Text.Trim() + ";initial catalog=" + this.txtDataBase.Text.Trim() + ";data source=" + this.txtServer.Text.Trim() + ";TimeOut=" + this.txtTimeOut.Text.Trim()); try { sqlconn.Open(); MessageBox.Show("测试成功!"); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } finally { if (sqlconn.State == ConnectionState.Open) { sqlconn.Close(); } } } private void btnOK_Click(object sender, EventArgs e) { MyAppconfig.WriteValue("SqlServer", this.txtServer.Text.Trim()); MyAppconfig.WriteValue("SqlUser", this.txtUser.Text.Trim()); MyAppconfig.WriteValue("SqlPwd", MyStrings.EncryptStr(this.txtPassword.Text.Trim())); MyAppconfig.WriteValue("SqlDataBase", this.txtDataBase.Text.Trim()); MyAppconfig.WriteValue("SqlTimeOut", this.txtTimeOut.Text.Trim()); MessageBox.Show("配置保存成功"); Application.Restart(); } private void btnCancel_Click(object sender, EventArgs e) { } } }