📄 数据库配置.cs
字号:
namespace 毕业设计
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace 软件系统
{
/// <summary>
/// 数据库配置 的摘要说明。
/// </summary>
public class 数据库配置 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtUserID;
private System.Windows.Forms.TextBox txtPassWd;
private System.Windows.Forms.TextBox txtHost;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnConfirm;
private System.Windows.Forms.Button btnTestConnect;
private System.Windows.Forms.CheckBox chkHost;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public 数据库配置()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtUserID = new System.Windows.Forms.TextBox();
this.txtPassWd = new System.Windows.Forms.TextBox();
this.chkHost = new System.Windows.Forms.CheckBox();
this.txtHost = new System.Windows.Forms.TextBox();
this.btnCancel = new System.Windows.Forms.Button();
this.btnConfirm = new System.Windows.Forms.Button();
this.btnTestConnect = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 72);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "密码";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 32);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "用户名";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtUserID
//
this.txtUserID.Location = new System.Drawing.Point(128, 32);
this.txtUserID.Name = "txtUserID";
this.txtUserID.TabIndex = 2;
this.txtUserID.Text = "sa";
//
// txtPassWd
//
this.txtPassWd.Location = new System.Drawing.Point(128, 72);
this.txtPassWd.Name = "txtPassWd";
this.txtPassWd.TabIndex = 3;
this.txtPassWd.Text = "";
//
// chkHost
//
this.chkHost.Location = new System.Drawing.Point(32, 112);
this.chkHost.Name = "chkHost";
this.chkHost.Size = new System.Drawing.Size(64, 24);
this.chkHost.TabIndex = 5;
this.chkHost.Text = "主机";
this.chkHost.CheckedChanged += new System.EventHandler(this.chkHost_CheckedChanged);
//
// txtHost
//
this.txtHost.Enabled = false;
this.txtHost.Location = new System.Drawing.Point(128, 112);
this.txtHost.Name = "txtHost";
this.txtHost.TabIndex = 6;
this.txtHost.Text = "(local)";
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(200, 160);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 7;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnConfirm
//
this.btnConfirm.Enabled = false;
this.btnConfirm.Location = new System.Drawing.Point(108, 160);
this.btnConfirm.Name = "btnConfirm";
this.btnConfirm.TabIndex = 8;
this.btnConfirm.Text = "确定";
this.btnConfirm.Click += new System.EventHandler(this.btnConfirm_Click);
//
// btnTestConnect
//
this.btnTestConnect.Location = new System.Drawing.Point(16, 160);
this.btnTestConnect.Name = "btnTestConnect";
this.btnTestConnect.TabIndex = 9;
this.btnTestConnect.Text = "测试连接";
this.btnTestConnect.Click += new System.EventHandler(this.btnTestConnect_Click);
//
// 数据库配置
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 190);
this.Controls.Add(this.btnTestConnect);
this.Controls.Add(this.btnConfirm);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.txtHost);
this.Controls.Add(this.chkHost);
this.Controls.Add(this.txtPassWd);
this.Controls.Add(this.txtUserID);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "数据库配置";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "数据库配置";
this.Load += new System.EventHandler(this.数据库配置_Load);
this.ResumeLayout(false);
}
#endregion
private void 数据库配置_Load(object sender, System.EventArgs e)
{
System.Data.DataSet o=new System.Data.DataSet();
try
{
o.ReadXml("DataBase.Config");
this.txtUserID.Text=o.Tables[0].Rows[0][0].ToString();
this.txtPassWd.Text=o.Tables[0].Rows[0][1].ToString();
this.txtHost.Text=o.Tables[0].Rows[0][2].ToString();
}
catch
{
MessageBox.Show("配置文件丢失,请配置程序!");
}
}
private void btnTestConnect_Click(object sender, System.EventArgs e)
{
string Constring="user id="+this.txtUserID.Text+";data source=\""+this.txtHost.Text+"\";initial catalog=master;password="+this.txtPassWd.Text;
毕业设计.射频卡.初始化状态 o=new 毕业设计.射频卡.初始化状态();
毕业设计.数据处理.数据处理 连接测试=new 毕业设计.数据处理.数据处理();
if(连接测试.TestConnect(Constring))
{
o.lbStatus.Text="测试连接成功!";
o.ShowDialog(this);
this.btnConfirm.Enabled=true;
}
else
{
o.lbStatus.Text="测试连接失败!";
o.ShowDialog(this);
this.btnConfirm.Enabled=false;
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Dispose(true);
}
private void chkHost_CheckedChanged(object sender, System.EventArgs e)
{
if(this.chkHost.Checked)
this.txtHost.Enabled=true;
else
this.txtHost.Enabled=false;
}
private void btnConfirm_Click(object sender, System.EventArgs e)
{
System.Data.DataSet o=new System.Data.DataSet();
System.Data.DataTable tb=new System.Data.DataTable();
tb.Columns.Add("SA",System.Type.GetType("System.String"));
tb.Columns.Add("PASSWORD",System.Type.GetType("System.String"));
tb.Columns.Add("HOST",System.Type.GetType("System.String"));
o.Tables.Add(tb);
System.Data.DataRow dr=o.Tables[0].NewRow();
dr[0]=this.txtUserID.Text;
dr[1]=this.txtPassWd.Text;
dr[2]=this.txtHost.Text;
o.Tables[0].Rows.Add(dr);
o.WriteXml("DataBase.Config",System.Data.XmlWriteMode.WriteSchema);
this.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -