📄 mainform.cs
字号:
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = @"SELECT CourseInfo.CourseID, CourseInfo.CourseName, CourseInfo.Credit, CourseInfo.RoomID, CourseInfo.ClassTime, CourseInfo.Capacity, CourseInfo.Teacher, ClassRoom.RoomID AS Expr1, ClassRoom.RoomName, ClassRoom.Buliding FROM ClassRoom INNER JOIN CourseInfo ON ClassRoom.RoomID = CourseInfo.RoomID";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=A85;packet size=4096;user id=sa;integrated security=SSPI;data sour" +
"ce=\".\";persist security info=False;initial catalog=selectcourse";
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand2;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "ClassRoom", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("name", "name"),
new System.Data.Common.DataColumnMapping("RoomID", "RoomID"),
new System.Data.Common.DataColumnMapping("RoomName", "RoomName"),
new System.Data.Common.DataColumnMapping("Buliding", "Buliding"),
new System.Data.Common.DataColumnMapping("CourseName", "CourseName"),
new System.Data.Common.DataColumnMapping("CourseID", "CourseID"),
new System.Data.Common.DataColumnMapping("ClassTime", "ClassTime"),
new System.Data.Common.DataColumnMapping("Teacher", "Teacher")})});
//
// sqlSelectCommand2
//
this.sqlSelectCommand2.CommandText = @"SELECT StudentInfo.name, ClassRoom.RoomID, ClassRoom.RoomName, ClassRoom.Buliding, CourseInfo.CourseName, CourseInfo.CourseID, CourseInfo.ClassTime, CourseInfo.Teacher FROM ClassRoom INNER JOIN CourseInfo ON ClassRoom.RoomID = CourseInfo.RoomID INNER JOIN CourseStudent ON CourseInfo.CourseID = CourseStudent.CourseID INNER JOIN StudentInfo ON StudentInfo.ID = CourseStudent.ID";
this.sqlSelectCommand2.Connection = this.sqlConnection1;
//
// dataView1
//
this.dataView1.Table = this.dataSet11.ClassRoom;
//
// dataSet31
//
this.dataSet31.DataSetName = "DataSet3";
this.dataSet31.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// sqlDataAdapter2
//
this.sqlDataAdapter2.SelectCommand = this.sqlSelectCommand3;
this.sqlDataAdapter2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "CourseInfo", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CourseName", "CourseName"),
new System.Data.Common.DataColumnMapping("ClassTime", "ClassTime"),
new System.Data.Common.DataColumnMapping("Teacher", "Teacher"),
new System.Data.Common.DataColumnMapping("RoomName", "RoomName"),
new System.Data.Common.DataColumnMapping("Buliding", "Buliding")})});
//
// sqlSelectCommand3
//
this.sqlSelectCommand3.CommandText = @"SELECT CourseInfo.CourseName, CourseInfo.ClassTime, CourseInfo.Teacher, ClassRoom.RoomName, ClassRoom.Buliding FROM CourseInfo INNER JOIN ClassRoom ON CourseInfo.RoomID = ClassRoom.RoomID INNER JOIN CourseStudent ON CourseInfo.CourseID = CourseStudent.CourseID";
this.sqlSelectCommand3.Connection = this.sqlConnection1;
//
// scoreadapter
//
this.scoreadapter.SelectCommand = this.sqlSelectCommand4;
this.scoreadapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "StudentInfo", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ID", "ID"),
new System.Data.Common.DataColumnMapping("name", "name"),
new System.Data.Common.DataColumnMapping("Credit", "Credit")})});
//
// sqlSelectCommand4
//
this.sqlSelectCommand4.CommandText = "SELECT s.ID, s.name, SUM(o.Credit) AS Credit FROM StudentInfo s INNER JOIN Course" +
"Student c ON s.ID = c.ID INNER JOIN CourseInfo o ON c.CourseID = o.CourseID GROU" +
"P BY s.ID, s.name ORDER BY o.Credit DESC";
this.sqlSelectCommand4.Connection = this.sqlConnection1;
//
// zongfenAdapter
//
this.zongfenAdapter.SelectCommand = this.sqlSelectCommand5;
this.zongfenAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "CourseInfo", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CourseName", "CourseName"),
new System.Data.Common.DataColumnMapping("Credit", "Credit"),
new System.Data.Common.DataColumnMapping("Capacity", "Capacity"),
new System.Data.Common.DataColumnMapping("Teacher", "Teacher"),
new System.Data.Common.DataColumnMapping("CourseID", "CourseID")})});
//
// sqlSelectCommand5
//
this.sqlSelectCommand5.CommandText = "SELECT s.CourseName, s.Credit, s.Capacity, s.Teacher, c.CourseID FROM CourseInfo " +
"s INNER JOIN CourseStudent c ON s.CourseID = c.CourseID GROUP BY c.CourseID, s.C" +
"ourseName, s.Credit, s.Teacher, s.Capacity ORDER BY COUNT(*) DESC";
this.sqlSelectCommand5.Connection = this.sqlConnection1;
//
// printAdapter
//
this.printAdapter.SelectCommand = this.sqlSelectCommand6;
this.printAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "ClassRoom", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CourseName", "CourseName"),
new System.Data.Common.DataColumnMapping("Buliding", "Buliding"),
new System.Data.Common.DataColumnMapping("RoomName", "RoomName"),
new System.Data.Common.DataColumnMapping("ClassTime", "ClassTime"),
new System.Data.Common.DataColumnMapping("Teacher", "Teacher")})});
//
// sqlSelectCommand6
//
this.sqlSelectCommand6.CommandText = @"SELECT CourseInfo.CourseName, ClassRoom.Buliding, ClassRoom.RoomName, CourseInfo.ClassTime, CourseInfo.Teacher FROM ClassRoom INNER JOIN CourseInfo ON ClassRoom.RoomID = CourseInfo.RoomID INNER JOIN CourseStudent ON CourseInfo.CourseID = CourseStudent.CourseID INNER JOIN StudentInfo ON StudentInfo.ID = CourseStudent.ID";
this.sqlSelectCommand6.Connection = this.sqlConnection1;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(434, 306);
this.Controls.Add(this.tabControl1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "MainForm";
this.Text = "学生选课系统";
this.Load += new System.EventHandler(this.MainForm_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet41)).EndInit();
this.tabPage4.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridscore)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridrenci)).EndInit();
this.tabPage5.ResumeLayout(false);
this.tabPage6.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataView2)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void MainForm_Load(object sender, System.EventArgs e)
{
//int i=0;
Form1 frm1=new Form1();
if(frm1.ShowDialog()==DialogResult.Cancel)
this.Close();
else if(!frm1.valid)
this.Close();
else
this.id=frm1.id;
//selectcourse.Form1.
try
{
this.sqlConnection1.Open();
SqlDataReader dbreader1=this.sqlSelectCommand1.ExecuteReader();
//dbreader1.Read();
while(dbreader1.Read())
{
this.listBox2.Items.Add(dbreader1["CourseName"].ToString());
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.sqlConnection1.Close();
if(this.listBox1.Items.Count<=0)
this.outlesson.Enabled=false;
else
this.outlesson.Enabled=true;
//this.sqlDataAdapter11.Fill(this.dataSet11);
}
//学生统计信息
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.dataGrid2.Visible=true;
this.dataSet21.Clear();
this.sqlDataAdapter1.Fill(this.dataSet21);
//this.sqlDataAdapter1.Fill(this.dataSet41);
SqlCommand cmd=new SqlCommand();
cmd.Connection=this.sqlConnection1;
this.sqlSelectCommand1.CommandText = "SELECT StudentInfo.name,ClassRoom.RoomID,ClassRoom.RoomName,ClassRoom.Buliding,CourseInfo.CourseName,CourseInfo.CourseID,CourseInfo.ClassTime,CourseInfo.Teacher FROM ClassRoom INNER JOIN CourseInfo ON ClassRoom.RoomID = CourseInfo.RoomID INNER JOIN CourseStudent ON CourseInfo.CourseID = CourseStudent.CourseID inner join StudentInfo on StudentInfo.ID=CourseStudent.ID";
this.sqlConnection1.Open();
SqlDataReader dtr=this.sqlSelectCommand2.ExecuteReader();
dtr.Close();
this.sqlConnection1.Close();
like();
/*try
{
if(dtr.Read())
this.textBox6.Text=
}*/
}
//**************************
private void selectlesson_Click(object sender, System.EventArgs e)
{
string temp=this.listBox2.SelectedItem.ToString();
if(test(temp))
{
this.sqlConnection1.Open();
//MessageBox.Show(this.listBox2.SelectedItem.ToString());
this.sqlSelectCommand1.CommandText = "SELECT CourseInfo.Credit,CourseInfo.CourseID, CourseInfo.Capacity, CourseInfo.ClassTime FROM CourseInfo where CourseInfo.CourseName='"+this.listBox2.SelectedItem.ToString()+"'";
SqlDataReader db;
try
{
db=this.sqlSelectCommand1.ExecuteReader();
if(db.Read())
{
score=score+Convert.ToInt32(db["Credit"].ToString());
this.courseid[index++]=Convert.ToInt32(db["CourseID"]);
this.coursecapacity[index1++]=Convert.ToInt32(db["Capacity"]);
this.time[index2++]=Convert.ToString(db["ClassTime"]);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.sqlConnection1.Close();
if(this.coursecapacitytemp>0)//如果课程容量大于0则能选则次课程否则不能
{
this.textBox9.Text=score.ToString();
this.listBox1.Items.Add(this.listBox2.SelectedItem);
}
else
MessageBox.Show("课程人数已满你不能选此课程");
if(this.listBox1.Items.Count<=0)//判断并确定退课按纽是否可用
this.outlesson.Enabled=false;
else
{
if(this.listBox1.SelectedIndex==-1)
this.outlesson.Enabled=false;
else
this.outlesson.Enabled=true;
}
}
else
MessageBox.Show("你已经添加了此课");
}
private void outlesson_Click(object sender, System.EventArgs e)
{
if(this.listBox1.SelectedIndex==-1)
return;
try
{
this.sqlConnection1.Open();
this.sqlSelectCommand1.CommandText = "SELECT CourseInfo.Credit,CourseInfo.CourseID FROM CourseInfo where CourseInfo.CourseName='"+this.listBox1.SelectedItem.ToString()+"'";
}
catch(Exception ex)
{
//MessageBox.Show(ex.Message);
}
SqlDataReader db;
db=this.sqlSelectCommand1.ExecuteReader();
if(db.Read())
{
score=score-Convert.ToInt32(db["Credit"].ToString());
/*for(int i=0;i<this.courseid.Length;i++)
{
if(this.courseid[i]==Convert.ToInt32(db["CourseID"]))
{
for(int j=0;j<courseid.Length-i;j++)
{
this.courseid[i]=this.courseid[i+1];
this.coursecapacity[i]=this.coursecapacity[i+1];//新加内容************
this.time[i]=this.time[i+1];
this.index=this.index-1;
this.index1=this.index1-1;
this.index2=this.index2-1;
}
}
} */
}
this.textBox9.Text=score.ToString();
this.sqlConnection1.Close();
this.listBox1.Items.Remove(this.listBox1.SelectedItem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -