?? 綜合信息.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace student
{
/// <summary>
/// 綜合信息 的摘要說明。
/// </summary>
public class 綜合信息 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label8;
/// <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 Form Designer generated code
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1,
this.label2,
this.label1});
this.panel1.Location = new System.Drawing.Point(16, 16);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(368, 88);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label8,
this.button1,
this.textBox6,
this.label7,
this.textBox5,
this.label6,
this.textBox4,
this.label5,
this.textBox3,
this.label4,
this.textBox2,
this.label3});
this.panel2.Location = new System.Drawing.Point(16, 112);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(368, 184);
this.panel2.TabIndex = 1;
//
// label1
//
this.label1.Font = new System.Drawing.Font("華文行楷", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Red;
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(312, 24);
this.label1.TabIndex = 0;
this.label1.Text = "請輸入要查詢的學生的學號";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 24);
this.label2.TabIndex = 1;
this.label2.Text = "學號:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(112, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(120, 21);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 56);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 16);
this.label3.TabIndex = 1;
this.label3.Text = "姓名";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(104, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(80, 21);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 96);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 24);
this.label4.TabIndex = 3;
this.label4.Text = "學號:";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(104, 96);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(80, 21);
this.textBox3.TabIndex = 4;
this.textBox3.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 136);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 24);
this.label5.TabIndex = 5;
this.label5.Text = "性別:";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(104, 136);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(80, 21);
this.textBox4.TabIndex = 6;
this.textBox4.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(200, 56);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(56, 24);
this.label6.TabIndex = 7;
this.label6.Text = "年齡:";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(280, 56);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(80, 21);
this.textBox5.TabIndex = 8;
this.textBox5.Text = "";
//
// label7
//
this.label7.Location = new System.Drawing.Point(200, 96);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(56, 24);
this.label7.TabIndex = 9;
this.label7.Text = "所在系:";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(280, 96);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(80, 21);
this.textBox6.TabIndex = 10;
this.textBox6.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 24);
this.button1.TabIndex = 11;
this.button1.Text = "查詢";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label8
//
this.label8.Font = new System.Drawing.Font("華文行楷", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label8.ForeColor = System.Drawing.Color.Red;
this.label8.Location = new System.Drawing.Point(8, 8);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(336, 32);
this.label8.TabIndex = 12;
this.label8.Text = "輸出查詢結果如下:";
//
// 綜合信息
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.ClientSize = new System.Drawing.Size(400, 314);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel2,
this.panel1});
this.Name = "綜合信息";
this.Text = "綜合信息";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
try
{
int i=0;
string hostname=System.Net.Dns.GetHostName();
string cnStr="Integrated Security=SSPI;Persist Security Info=False;password=;"
+"Initial Catalog=學生信息管理系統;Data Source='"+hostname+"'";
SqlConnection cn=new SqlConnection(cnStr);
cn.Open();
string sqlStr="select * from xs";
SqlCommand cmd=new SqlCommand(sqlStr,cn);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
string sno1=dr["sno"].ToString();
string sname1=dr["sname"].ToString();
string sno2=sno1.Trim();
string sname2=sname1.Trim();
if(dr["sno"].ToString().Trim()==textBox1.Text)
{
textBox2.Text=dr[1].ToString();
textBox3.Text=dr[0].ToString();
textBox4.Text=dr[2].ToString();
textBox5.Text=dr[3].ToString();
textBox6.Text=dr[4].ToString();
i=1;
break;
}
}
if(i==0)
{
MessageBox.Show("輸入錯誤!");
}
dr.Close();
cn.Close();
}
catch(SqlException)
{
MessageBox.Show("輸入錯誤!");
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -