📄 frmselect.cs
字号:
this.grbTop.Controls.Add(this.txbId);
this.grbTop.Dock = System.Windows.Forms.DockStyle.Top;
this.grbTop.Location = new System.Drawing.Point(0, 0);
this.grbTop.Name = "grbTop";
this.grbTop.Size = new System.Drawing.Size(533, 59);
this.grbTop.TabIndex = 6;
this.grbTop.TabStop = false;
this.grbTop.Text = "学生信息";
//
// Label4
//
this.Label4.Location = new System.Drawing.Point(313, 10);
this.Label4.Name = "Label4";
this.Label4.Size = new System.Drawing.Size(214, 37);
this.Label4.TabIndex = 7;
this.Label4.Text = "这里输入学号后回车,正常操作是学生用自己的学号登陆到系统,只能选择自己的课程。因为系统没有制作登陆功能,所以这么处理。";
//
// Label3
//
this.Label3.Location = new System.Drawing.Point(220, 25);
this.Label3.Name = "Label3";
this.Label3.Size = new System.Drawing.Size(27, 14);
this.Label3.TabIndex = 6;
this.Label3.Text = "班级";
//
// txbGrade
//
this.txbGrade.Location = new System.Drawing.Point(253, 20);
this.txbGrade.Name = "txbGrade";
this.txbGrade.ReadOnly = true;
this.txbGrade.Size = new System.Drawing.Size(47, 20);
this.txbGrade.TabIndex = 5;
this.txbGrade.Text = "";
//
// txbName
//
this.txbName.Location = new System.Drawing.Point(160, 20);
this.txbName.Name = "txbName";
this.txbName.ReadOnly = true;
this.txbName.Size = new System.Drawing.Size(47, 20);
this.txbName.TabIndex = 4;
this.txbName.Text = "";
//
// Label2
//
this.Label2.Location = new System.Drawing.Point(133, 25);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(27, 14);
this.Label2.TabIndex = 3;
this.Label2.Text = "姓名";
//
// Label1
//
this.Label1.Location = new System.Drawing.Point(7, 25);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(26, 14);
this.Label1.TabIndex = 2;
this.Label1.Text = "学号";
//
// txbId
//
this.txbId.Location = new System.Drawing.Point(33, 20);
this.txbId.Name = "txbId";
this.txbId.Size = new System.Drawing.Size(94, 20);
this.txbId.TabIndex = 1;
this.txbId.Text = "";
this.txbId.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txbId_KeyDown);
//
// frmSelect
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(533, 301);
this.Controls.Add(this.GroupBox2);
this.Controls.Add(this.GroupBox1);
this.Controls.Add(this.grbTop);
this.Name = "frmSelect";
this.Text = "frmSelect";
this.GroupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgdSubject)).EndInit();
this.GroupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgdList)).EndInit();
this.grbTop.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
// added code
private void SetDGDSubject()
{
string strSQL = "select a.课序号,b.课程编号,b.课程名称,b.教师,";
strSQL += "b.开课系别,a.上课时间天,a.上课时间节,a.上课地点 from 课程表";
strSQL += " as a, 课程信息 as b where a.课程编号=b.课程编号";
string strFilter = "";
if ( txbPY.Text.Trim().Length != 0 )
{
strFilter += " and 拼音码 like '" + txbPY.Text.Trim() + "%'";
}
if ( txbCName.Text.Trim().Length != 0 )
{
strFilter += " and 课程名称 like '" + txbCName.Text.Trim() + "%'";
}
if ( txbCId.Text.Trim().Length != 0 )
{
strFilter += " and b.课程编号 like '" + txbCId.Text.Trim() + "%'";
}
if ( txbCNumber.Text.Trim().Length != 0 )
{
strFilter += " and 课序号 like '" + txbCNumber.Text.Trim() + "%'";
}
if ( strFilter.Trim().Length == 0 )
{
return;
}
strFilter += " order by 课序号";
// 执行SQL语句
DataBase db = new DataBase();
DataView dv = db.RunSelectSQL( strSQL + strFilter );
dv.AllowDelete = false;
dv.AllowEdit = false;
dv.AllowNew = false;
dgdSubject.AllowSorting = false;
dtSubject = dv.Table;
// 设置数据源
dgdSubject.DataSource = dtSubject;
db.Dispose();
}
private void txbId_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter && txbId.Text.Trim().Length != 0 )
{
DataBase db = new DataBase();
string strSQL = "select 姓名, 班级名称, 学籍编号 from 学生信息 as a,";
strSQL += " 班级信息 as b where a.班级编号=b.班级编号 ";
strSQL += "and 学号='" + txbId.Text.Trim() + "'";
DataView dv = db.RunSelectSQL( strSQL );
if ( dv.Count == 0 )
{
MessageBox.Show( "不是在籍学生" );
txbId.Text = "";
}
else
{
txbName.Text = dv[ 0 ][ 0 ].ToString().Trim();
txbGrade.Text = dv[ 0 ][ 1 ].ToString().Trim();
}
strSQL = "select c.学号,a.课序号,b.课程名称,b.教师,b.开课系别,";
strSQL += "a.上课时间天,a.上课时间节,a.上课地点 from 选课表 ";
strSQL += "as c, 课程表 as a, 课程信息 as b where a.课程编号 ";
strSQL += "=b.课程编号 and c.课序号=a.课序号 and 学号='";
strSQL += txbId.Text.Trim() + "' order by a.课序号";
dv = db.RunSelectSQL(strSQL);
if ( dv.Count == 0 )
{
MessageBox.Show( "不是在籍学生" );
txbId.Text = "";
}
else
{
dv.AllowDelete = false;
dv.AllowEdit = false;
dv.AllowNew = false;
dtData = dv.Table;
dgdList.DataSource = dtData;
}
db.Dispose();
}
}
private void txbPY_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
{
SetDGDSubject();
}
}
private void txbCName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
{
SetDGDSubject();
}
}
private void txbCId_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
{
SetDGDSubject();
}
}
private void txbCNumber_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyCode == Keys.Enter )
{
SetDGDSubject();
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
SetDGDSubject();
}
private void btnSelect_Click(object sender, System.EventArgs e)
{
if ( dgdList.CurrentCell.RowNumber == -1 || dgdSubject.CurrentCell.RowNumber == -1 )
return;
DataBase db = new DataBase();
DataView dv;
string strSQL = "";
string strTmp = dtSubject.Rows[ dgdSubject.CurrentCell.RowNumber ][ 1 ].ToString().Trim();
strSQL = "select * from 选课表 where 学号='" + txbId.Text.Trim();
strSQL += "' and 课序号 in(select 课序号 from 课程表 where 课程编号='";
strSQL += strTmp + "')";
dv = db.RunSelectSQL( strSQL );
if ( dv.Count != 0 )
{
MessageBox.Show( "该课程已经选定" );
db.Dispose();
return;
}
string strCId = dtSubject.Rows[ dgdSubject.CurrentCell.RowNumber ][ 0 ].ToString().Trim();
strSQL = "select * from 选课表 as a, 课程表 as b ";
strSQL += "where a.课序号=b.课序号 and a.学号='";
strSQL += txbId.Text.Trim() + "' and 100*b.上课时间天+";
strSQL += "b.上课时间节 in (select 100*上课时间天+上课时间节";
strSQL += " from 课程表 where 课序号='" + strCId + "')";
dv = db.RunSelectSQL(strSQL);
if ( dv.Count == 0 )
{
MessageBox.Show( "该课序号时间和已经选择的课程冲突!" );
return;
}
else
{
strSQL = "insert into 选课表(学号,课序号) values('";
strSQL += txbId.Text.Trim() + "','" + strCId + " ')";
db.RunDelOrInsSQL(strSQL);
strSQL = "select c.学号,a.课序号,b.课程名称,b.教师,b.开课系别,";
strSQL += "a.上课时间天,a.上课时间节,a.上课地点 from 选课表 ";
strSQL += "as c, 课程表 as a, 课程信息 as b where ";
strSQL += "a.课程编号=b.课程编号 and c.课序号=a.课序号 and 学号='";
strSQL += txbId.Text.Trim() + "' order by a.课序号";
dv = db.RunSelectSQL( strSQL );
dv.AllowDelete = false;
dv.AllowEdit = false;
dv.AllowNew = false;
dtData = dv.Table;
dgdList.DataSource = dtData;
}
db.Dispose();
}
private void btnDel_Click(object sender, System.EventArgs e)
{
if ( dgdList.CurrentCell.RowNumber == -1 )
{
return;
}
DialogResult dlgResult = MessageBox.Show( "确定删除指定的已选课程吗?", "提示",
MessageBoxButtons.YesNo );
if ( dlgResult == DialogResult.Yes )
{
string strCId = dtData.Rows[ dgdList.CurrentCell.RowNumber ][ 1 ].ToString().Trim();
string strSQL = "delete from 选课表 where 学号='";
strSQL += txbId.Text.Trim();
strSQL += "' and 课序号 = '" + strCId + "'";
DataBase db = new DataBase();
db.RunDelOrInsSQL( strSQL );
DataView dv;
strSQL = "select c.学号,a.课序号,b.课程名称,b.教师,b.开课系别,";
strSQL += "a.上课时间天,a.上课时间节,a.上课地点 from 选课表 ";
strSQL += "as c, 课程表 as a, 课程信息 as b where ";
strSQL += "a.课程编号=b.课程编号 and c.课序号=a.课序号 ";
strSQL += "and 学号='" + txbId.Text.Trim() + "' order by a.课序号";
dv = db.RunSelectSQL( strSQL );
dv.AllowDelete = false;
dv.AllowEdit = false;
dv.AllowNew = false;
dtData = dv.Table;
dgdList.DataSource = dtData;
db.Dispose();
}
}
private void btnDisplay_Click(object sender, System.EventArgs e)
{
frmCourse dlgChild = new frmCourse();
dlgChild.Show();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -