📄 memberform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace KTMIS
{
/// <summary>
/// Member 的摘要说明。
/// </summary>
public class Member : System.Windows.Forms.Form
{
private System.Windows.Forms.Button returnBtn;
private System.Windows.Forms.Label colegelabel;
private System.Windows.Forms.TextBox colegetextBox;
private System.Windows.Forms.Button selectBtn;
private System.Windows.Forms.Button deleteBtn;
private System.Windows.Forms.Button updateBtn;
private System.Windows.Forms.Button addBtn;
private System.Windows.Forms.DataGrid MemberdataGrid;
private SqlConnection MemberConnection = null;
private SqlCommand MemberSelectCommand = null;
private SqlCommand MemberDeleteCommand = null;
private SqlDataAdapter MemberDataAdapter = null;
private DataSet ds = null;
private string sqlString = null;
private int Row = -1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox MemberNacomboBox;
private System.Windows.Forms.ComboBox CollegeCocomboBox;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Member()
{
//
// 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.returnBtn = new System.Windows.Forms.Button();
this.colegelabel = new System.Windows.Forms.Label();
this.colegetextBox = new System.Windows.Forms.TextBox();
this.selectBtn = new System.Windows.Forms.Button();
this.deleteBtn = new System.Windows.Forms.Button();
this.updateBtn = new System.Windows.Forms.Button();
this.addBtn = new System.Windows.Forms.Button();
this.MemberdataGrid = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
this.MemberNacomboBox = new System.Windows.Forms.ComboBox();
this.CollegeCocomboBox = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.MemberdataGrid)).BeginInit();
this.SuspendLayout();
//
// returnBtn
//
this.returnBtn.Location = new System.Drawing.Point(536, 24);
this.returnBtn.Name = "returnBtn";
this.returnBtn.Size = new System.Drawing.Size(120, 32);
this.returnBtn.TabIndex = 31;
this.returnBtn.Text = "返回";
this.returnBtn.Click += new System.EventHandler(this.returnBtn_Click);
//
// colegelabel
//
this.colegelabel.Location = new System.Drawing.Point(16, 72);
this.colegelabel.Name = "colegelabel";
this.colegelabel.Size = new System.Drawing.Size(280, 24);
this.colegelabel.TabIndex = 32;
this.colegelabel.Text = "请输入所要查询的成员名称:";
//
// colegetextBox
//
this.colegetextBox.Location = new System.Drawing.Point(304, 72);
this.colegetextBox.Name = "colegetextBox";
this.colegetextBox.Size = new System.Drawing.Size(192, 30);
this.colegetextBox.TabIndex = 33;
this.colegetextBox.Text = "";
//
// selectBtn
//
this.selectBtn.Location = new System.Drawing.Point(536, 72);
this.selectBtn.Name = "selectBtn";
this.selectBtn.Size = new System.Drawing.Size(120, 32);
this.selectBtn.TabIndex = 29;
this.selectBtn.Text = "查询";
this.selectBtn.Click += new System.EventHandler(this.selectBtn_Click);
//
// deleteBtn
//
this.deleteBtn.Location = new System.Drawing.Point(360, 24);
this.deleteBtn.Name = "deleteBtn";
this.deleteBtn.Size = new System.Drawing.Size(120, 32);
this.deleteBtn.TabIndex = 28;
this.deleteBtn.Text = "删除";
this.deleteBtn.Click += new System.EventHandler(this.deleteBtn_Click);
//
// updateBtn
//
this.updateBtn.Location = new System.Drawing.Point(192, 24);
this.updateBtn.Name = "updateBtn";
this.updateBtn.Size = new System.Drawing.Size(120, 32);
this.updateBtn.TabIndex = 27;
this.updateBtn.Text = "修改";
this.updateBtn.Click += new System.EventHandler(this.updateBtn_Click);
//
// addBtn
//
this.addBtn.Location = new System.Drawing.Point(24, 24);
this.addBtn.Name = "addBtn";
this.addBtn.Size = new System.Drawing.Size(120, 32);
this.addBtn.TabIndex = 26;
this.addBtn.Text = "添加";
this.addBtn.Click += new System.EventHandler(this.addBtn_Click);
//
// MemberdataGrid
//
this.MemberdataGrid.DataMember = "";
this.MemberdataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.MemberdataGrid.Location = new System.Drawing.Point(8, 160);
this.MemberdataGrid.Name = "MemberdataGrid";
this.MemberdataGrid.ReadOnly = true;
this.MemberdataGrid.Size = new System.Drawing.Size(664, 288);
this.MemberdataGrid.TabIndex = 34;
this.MemberdataGrid.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MemberdataGrid_MouseDown);
this.MemberdataGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MemberdataGrid_MouseUp);
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 120);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(280, 24);
this.label1.TabIndex = 35;
this.label1.Text = "请选择所要查询的学院名称:";
//
// MemberNacomboBox
//
this.MemberNacomboBox.Location = new System.Drawing.Point(304, 120);
this.MemberNacomboBox.Name = "MemberNacomboBox";
this.MemberNacomboBox.Size = new System.Drawing.Size(200, 28);
this.MemberNacomboBox.TabIndex = 36;
this.MemberNacomboBox.Text = "--请选择--";
this.MemberNacomboBox.SelectedIndexChanged += new System.EventHandler(this.MemberNacomboBox_SelectedIndexChanged);
//
// CollegeCocomboBox
//
this.CollegeCocomboBox.Location = new System.Drawing.Point(512, 120);
this.CollegeCocomboBox.Name = "CollegeCocomboBox";
this.CollegeCocomboBox.Size = new System.Drawing.Size(128, 28);
this.CollegeCocomboBox.TabIndex = 37;
this.CollegeCocomboBox.Visible = false;
//
// Member
//
this.AutoScaleBaseSize = new System.Drawing.Size(11, 23);
this.ClientSize = new System.Drawing.Size(688, 462);
this.Controls.Add(this.CollegeCocomboBox);
this.Controls.Add(this.MemberNacomboBox);
this.Controls.Add(this.label1);
this.Controls.Add(this.MemberdataGrid);
this.Controls.Add(this.returnBtn);
this.Controls.Add(this.colegelabel);
this.Controls.Add(this.colegetextBox);
this.Controls.Add(this.selectBtn);
this.Controls.Add(this.deleteBtn);
this.Controls.Add(this.updateBtn);
this.Controls.Add(this.addBtn);
this.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "Member";
this.Text = "Member";
this.Load += new System.EventHandler(this.Member_Load);
((System.ComponentModel.ISupportInitialize)(this.MemberdataGrid)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void Member_Load(object sender, System.EventArgs e)
{
//string connString = "user id=sa;data source=\".\";initial catalog=KTMIS";
//MemberConnection = new SqlConnection(connString);
MemberSelectCommand = new SqlCommand("",MemberConnection);
MemberDeleteCommand = new SqlCommand("DeleteMember",MemberConnection);
sqlString = "select MemberNa as 成员性名,CollegeNa as 所属院系 from Member,College where Member.CollegeCo=College.CollegeCo";
ds = new DataSet();
try
{
MemberDataAdapter = new SqlDataAdapter(sqlString,MemberConnection);
MemberDataAdapter.Fill(ds,"Member");
}
catch(Exception ex)
{
MessageBox.Show("载入错误!原因是"+ex.ToString(),"系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
MemberdataGrid.SetDataBinding(ds,"Member");
string sqlStr = "select CollegeCo,CollegeNa from College";
SqlCommand CollegeCommand = new SqlCommand(sqlStr,MemberConnection);
try
{
MemberConnection.Open();
SqlDataReader dr = CollegeCommand.ExecuteReader();
while(dr.Read())
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -