📄 form_lj.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace bizdb
{
/// <summary>
/// Form_lj 的摘要说明。
/// </summary>
public class Form_lj : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lbl_fwq;
private System.Windows.Forms.Label lbl_sjk;
private System.Windows.Forms.Label lbl_yhm;
private System.Windows.Forms.Label lbl_mm;
private System.Windows.Forms.TextBox txt_fwq;
private System.Windows.Forms.TextBox txt_sjk;
private System.Windows.Forms.TextBox txt_yhm;
private System.Windows.Forms.TextBox txt_mm;
private System.Windows.Forms.Button btn_qd;
private System.Windows.Forms.Button btn_lk;
private dbAccess db = new dbAccess();
private common c = new common();
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form_lj()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lbl_fwq = new System.Windows.Forms.Label();
this.lbl_sjk = new System.Windows.Forms.Label();
this.lbl_yhm = new System.Windows.Forms.Label();
this.lbl_mm = new System.Windows.Forms.Label();
this.txt_fwq = new System.Windows.Forms.TextBox();
this.txt_sjk = new System.Windows.Forms.TextBox();
this.txt_yhm = new System.Windows.Forms.TextBox();
this.txt_mm = new System.Windows.Forms.TextBox();
this.btn_qd = new System.Windows.Forms.Button();
this.btn_lk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lbl_fwq
//
this.lbl_fwq.Location = new System.Drawing.Point(16, 24);
this.lbl_fwq.Name = "lbl_fwq";
this.lbl_fwq.TabIndex = 0;
this.lbl_fwq.Text = "服务器";
//
// lbl_sjk
//
this.lbl_sjk.Location = new System.Drawing.Point(16, 72);
this.lbl_sjk.Name = "lbl_sjk";
this.lbl_sjk.TabIndex = 1;
this.lbl_sjk.Text = "数据库";
//
// lbl_yhm
//
this.lbl_yhm.Location = new System.Drawing.Point(16, 120);
this.lbl_yhm.Name = "lbl_yhm";
this.lbl_yhm.TabIndex = 2;
this.lbl_yhm.Text = "用户名";
//
// lbl_mm
//
this.lbl_mm.Location = new System.Drawing.Point(16, 168);
this.lbl_mm.Name = "lbl_mm";
this.lbl_mm.TabIndex = 3;
this.lbl_mm.Text = "密码";
//
// txt_fwq
//
this.txt_fwq.Location = new System.Drawing.Point(128, 24);
this.txt_fwq.Name = "txt_fwq";
this.txt_fwq.TabIndex = 4;
this.txt_fwq.Text = "";
//
// txt_sjk
//
this.txt_sjk.Location = new System.Drawing.Point(128, 72);
this.txt_sjk.Name = "txt_sjk";
this.txt_sjk.TabIndex = 5;
this.txt_sjk.Text = "";
//
// txt_yhm
//
this.txt_yhm.Location = new System.Drawing.Point(128, 120);
this.txt_yhm.Name = "txt_yhm";
this.txt_yhm.TabIndex = 6;
this.txt_yhm.Text = "";
//
// txt_mm
//
this.txt_mm.Location = new System.Drawing.Point(128, 168);
this.txt_mm.Name = "txt_mm";
this.txt_mm.PasswordChar = '*';
this.txt_mm.TabIndex = 7;
this.txt_mm.Text = "";
//
// btn_qd
//
this.btn_qd.Location = new System.Drawing.Point(32, 208);
this.btn_qd.Name = "btn_qd";
this.btn_qd.TabIndex = 8;
this.btn_qd.Text = "确定";
this.btn_qd.Click += new System.EventHandler(this.btn_qd_Click);
//
// btn_lk
//
this.btn_lk.Location = new System.Drawing.Point(136, 208);
this.btn_lk.Name = "btn_lk";
this.btn_lk.TabIndex = 9;
this.btn_lk.Text = "离开";
this.btn_lk.Click += new System.EventHandler(this.btn_lk_Click);
//
// Form_lj
//
this.AcceptButton = this.btn_qd;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(248, 253);
this.Controls.Add(this.btn_lk);
this.Controls.Add(this.btn_qd);
this.Controls.Add(this.txt_mm);
this.Controls.Add(this.txt_yhm);
this.Controls.Add(this.txt_sjk);
this.Controls.Add(this.txt_fwq);
this.Controls.Add(this.lbl_mm);
this.Controls.Add(this.lbl_yhm);
this.Controls.Add(this.lbl_sjk);
this.Controls.Add(this.lbl_fwq);
this.Name = "Form_lj";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "请选择数据库服务器";
this.ResumeLayout(false);
}
#endregion
protected override void OnLoad(System.EventArgs e)
{
this.Activate();
}
private void btn_qd_Click(object sender, System.EventArgs e)
{
if(File.Exists("conn.ini"))
{
File.Delete("conn.ini");
StreamWriter srd;
srd = File.CreateText("conn.ini");
srd.WriteLine("server=" + txt_fwq.Text + ";database="+ txt_sjk.Text +
";uid=" + txt_yhm.Text + ";pwd=" + txt_mm.Text);
srd.Close();
}
else
{
StreamWriter srd;
srd = File.CreateText("conn.ini");
srd.WriteLine("server=" + txt_fwq.Text + ";database="+ txt_sjk.Text +
";uid=" + txt_yhm.Text + ";pwd=" + txt_mm.Text);
srd.Close();
}
db.connStr="server=" + txt_fwq.Text + ";database="+ txt_sjk.Text +
";uid=" + txt_yhm.Text + ";pwd=" + txt_mm.Text;
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = db.connStr;
try
{
myConn.Open();
}
catch
{
MessageBox.Show("数据库连接失败,请重新配置数据库连接",c.sysname+"课程体系试题库系统提示");
return;
}
string strCom = "SELECT name FROM sysobjects where xtype in ('u')";
System.Data.SqlClient.SqlCommand comm;
comm = myConn.CreateCommand();
comm.CommandText = strCom;
SqlDataAdapter mydataA= new SqlDataAdapter();
mydataA.SelectCommand = comm;
DataSet myDataSet = new DataSet ( ) ;
mydataA.Fill(myDataSet,"sysobjects");
myConn.Close ( ) ;
this.Hide();
Form_logon fr2 =new Form_logon();
fr2.Show();
}
private void btn_lk_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -