📄 courseselect.h
字号:
// btnSearch
//
this->btnSearch->Enabled = false;
this->btnSearch->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
this->btnSearch->ImageIndex = 6;
this->btnSearch->ImageList = this->imageList1;
this->btnSearch->Location = System::Drawing::Point(24, 168);
this->btnSearch->Name = S"btnSearch";
this->btnSearch->Size = System::Drawing::Size(64, 24);
this->btnSearch->TabIndex = 66;
this->btnSearch->Text = S"查询";
this->btnSearch->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
this->btnSearch->Click += new System::EventHandler(this, btnSearch_Click_1);
//
// tBoxPinYin
//
this->tBoxPinYin->Location = System::Drawing::Point(96, 56);
this->tBoxPinYin->Name = S"tBoxPinYin";
this->tBoxPinYin->Size = System::Drawing::Size(144, 21);
this->tBoxPinYin->TabIndex = 65;
this->tBoxPinYin->Text = S"";
//
// label13
//
this->label13->Location = System::Drawing::Point(24, 64);
this->label13->Name = S"label13";
this->label13->Size = System::Drawing::Size(48, 11);
this->label13->TabIndex = 64;
this->label13->Text = S"拼音码";
//
// tBoxCourseName
//
this->tBoxCourseName->Location = System::Drawing::Point(96, 88);
this->tBoxCourseName->Name = S"tBoxCourseName";
this->tBoxCourseName->Size = System::Drawing::Size(144, 21);
this->tBoxCourseName->TabIndex = 10;
this->tBoxCourseName->Text = S"";
//
// label9
//
this->label9->Location = System::Drawing::Point(24, 96);
this->label9->Name = S"label9";
this->label9->Size = System::Drawing::Size(56, 11);
this->label9->TabIndex = 9;
this->label9->Text = S"课程名称";
//
// tBoxSubID
//
this->tBoxSubID->Location = System::Drawing::Point(96, 120);
this->tBoxSubID->Name = S"tBoxSubID";
this->tBoxSubID->Size = System::Drawing::Size(144, 21);
this->tBoxSubID->TabIndex = 14;
this->tBoxSubID->Text = S"";
//
// label10
//
this->label10->Location = System::Drawing::Point(24, 128);
this->label10->Name = S"label10";
this->label10->Size = System::Drawing::Size(56, 11);
this->label10->TabIndex = 13;
this->label10->Text = S"课序号";
//
// tBoxCourseID
//
this->tBoxCourseID->Location = System::Drawing::Point(96, 24);
this->tBoxCourseID->Name = S"tBoxCourseID";
this->tBoxCourseID->Size = System::Drawing::Size(144, 21);
this->tBoxCourseID->TabIndex = 2;
this->tBoxCourseID->Text = S"";
//
// label5
//
this->label5->Location = System::Drawing::Point(24, 32);
this->label5->Name = S"label5";
this->label5->Size = System::Drawing::Size(56, 11);
this->label5->TabIndex = 1;
this->label5->Text = S"课程编号";
//
// dataGrid1
//
this->dataGrid1->DataMember = S"";
this->dataGrid1->Dock = System::Windows::Forms::DockStyle::Fill;
this->dataGrid1->HeaderForeColor = System::Drawing::SystemColors::ControlText;
this->dataGrid1->Location = System::Drawing::Point(0, 0);
this->dataGrid1->Name = S"dataGrid1";
this->dataGrid1->Size = System::Drawing::Size(752, 469);
this->dataGrid1->TabIndex = 2;
//
// CourseSelect
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(752, 469);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->dgrdCourseSelected);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->dataGrid1);
this->Name = S"CourseSelect";
this->Text = S"学生选课";
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdCourseSelected))->EndInit();
this->groupBox2->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdCourse))->EndInit();
this->groupBox3->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dataGrid1))->EndInit();
this->ResumeLayout(false);
}
private:
//----------------设置控件ReadOnly属性------------------------
void SetModify(bool isModifiable)
{
this->btnSearch->Enabled = isModifiable;
this->btnSelect->Enabled = isModifiable;
this->btnDeSelect->Enabled = isModifiable;
this->btnCourseTable->Enabled = isModifiable;
}
//-----------------------设置表格各列的属性-----------------------
void DataGridStateCourse()
{
DataGridTableStyle* ts = new DataGridTableStyle();
ts->MappingName = this->ds->Tables->Item[S"本学期课程"]->TableName;
DataGridNoActiveCellColumn* aTextColumn;
ts->AllowSorting = false;
ts->AlternatingBackColor = Color::LightGray;
int numCols = this->ds->Tables->Item[S"本学期课程"]->Columns->Count;
for(int i = 0;i < numCols;i++)
{
aTextColumn = new DataGridNoActiveCellColumn();
aTextColumn->get_TextBox()->Enabled = false;
aTextColumn->MappingName = this->ds->Tables->Item[S"本学期课程"]->Columns->Item[i]->ColumnName;
aTextColumn->HeaderText = this->ds->Tables->Item[S"本学期课程"]->Columns->Item[i]->ColumnName;
aTextColumn->NullText = S"";
aTextColumn->Format = S"D";
ts->GridColumnStyles->Add(aTextColumn);
}
this->dgrdCourse->TableStyles->Add(ts);
}
//-----------------------设置表格各列的属性-----------------------
void DataGridStateSelected()
{
DataGridTableStyle* ts = new DataGridTableStyle();
ts->MappingName = this->ds->Tables->Item[S"课程表"]->TableName;
DataGridNoActiveCellColumn* aTextColumn;
ts->AllowSorting = false;
ts->AlternatingBackColor = Color::LightGray;
int numCols = this->ds->Tables->Item[S"课程表"]->Columns->Count;
for(int i = 0;i < numCols;i++)
{
aTextColumn = new DataGridNoActiveCellColumn();
aTextColumn->get_TextBox()->Enabled = false;
aTextColumn->MappingName = this->ds->Tables->Item[S"课程表"]->Columns->Item[i]->ColumnName;
aTextColumn->HeaderText = this->ds->Tables->Item[S"课程表"]->Columns->Item[i]->ColumnName;
aTextColumn->NullText = S"";
aTextColumn->Format = S"D";
ts->GridColumnStyles->Add(aTextColumn);
}
this->dgrdCourseSelected->TableStyles->Add(ts);
}
//填写学号开始选课
private: System::Void tBoxStudentID_KeyPress(System::Object * sender, System::Windows::Forms::KeyPressEventArgs * e)
{
//未录入学号则返回
if(e->KeyChar != 13 || String::Compare(this->tBoxStudentID->Text,String::Empty) == 0)
return;
//查询学生信息
String* tempSQL = String::Format(S"SELECT 学生信息.姓名, 班级信息.班级名称, 学生信息.学籍编号 FROM 班级信息 INNER JOIN 学生信息 ON 班级信息.班级编号 = 学生信息.班级编号 Where 学生信息.学号 = '{0}'",this->tBoxStudentID->Text);
SqlDataReader* reader = this->MyDataBase->SQLRead(tempSQL);
reader->Read();
//未找到学生资料则返回
if(!reader->HasRows)
{
MessageBox::Show(S"没有这个学号,请重新填写");
reader->Close();
return;
}
//如果是非在籍学生则返回
if(String::Compare(reader->Item[S"学籍编号"]->ToString()->Trim(),S"1") != 0)
{
MessageBox::Show(S"非在籍学生不能选课");
reader->Close();
return;
}
//显示学生信息
this->tBoxName->Text = reader->Item[S"姓名"]->ToString();
this->tBoxClass->Text = reader->Item[S"班级名称"]->ToString();
reader->Close();
//查询选课信息
if(this->ds->Tables->Count > 1)
this->ds->Tables->Item[S"课程表"]->Clear();
this->strSQL = String::Format(S"SELECT 选课表.学号, 选课表.课序号, 课程信息.课程名称, 课程信息.教师, 课程信息.开课系别, 课程表.上课时间天, 课程表.上课时间节 FROM 课程信息 INNER JOIN 课程表 ON 课程信息.课程编号 = 课程表.课程编号 INNER JOIN 选课表 ON 课程表.课序号 = 选课表.课序号 Where 选课表.学号 = '{0}'",this->tBoxStudentID->Text);
this->strTableName = S"课程表";
this->MyDataBase->SelectDataBase(this->CourseAdapter,this->ds,this->strSQL,this->strTableName);
this->dgrdCourseSelected->DataSource = this->ds->Tables->Item[S"课程表"];
this->dgrdCourseSelected->TableStyles->Clear();
this->DataGridStateSelected();
this->SetModify(true);
}
private: System::Void btnSearch_Click_1(System::Object * sender, System::EventArgs * e)
{
String* strCourseID = this->tBoxCourseID->Text->Trim();
String* strCourseName = this->tBoxCourseName->Text->Trim();
String* strPinYin = this->tBoxPinYin->Text->Trim();
String* strSubID = this->tBoxSubID->Text->Trim();
String* Filter = S"";
if(String::Compare(strCourseID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (课程表.课程编号 = {1})",Filter,strCourseID);
}
if(String::Compare(strCourseName,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (课程信息.课程名称 LIKE '%{1}%')",Filter,strCourseName);
}
if(String::Compare(strPinYin,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (课程信息.拼音码 LIKE '%{1}%')",Filter,strPinYin);
}
if(String::Compare(strSubID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (课程表.课序号 = {1})",Filter,strSubID);
}
if(String::Compare(Filter,String::Empty) != 0)
{
Filter = Filter->Substring(5,Filter->Length - 5);
this->ds->Tables->Item[S"本学期课程"]->Clear();
//查询本学期课程
this->strSQL = String::Format(S"SELECT 课程表.课序号, 课程表.课程编号, 课程信息.课程名称, 课程信息.教师,课程信息.开课系别, 课程表.上课时间天, 课程表.上课时间节, 课程表.上课地点, 课程信息.拼音码, 课程信息.学分 FROM 课程信息 INNER JOIN 课程表 ON 课程信息.课程编号 = 课程表.课程编号 WHERE (课程信息.本学期课程 = 'Y') AND {0}",Filter);
this->strTableName = S"本学期课程";
this->MyDataBase->SelectDataBase(this->CourseAdapter,this->ds,this->strSQL,this->strTableName);
}
}
private: System::Void btnSelect_Click(System::Object * sender, System::EventArgs * e)
{
String* ID;
String* Day;
String* Time;
if(this->ds->Tables->Item[S"本学期课程"]->Rows->Count == 0)
return;
int row = this->dgrdCourse->CurrentRowIndex;
String* SelectCourseID = this->ds->Tables->Item[S"本学期课程"]->Rows->Item[row]->Item[S"课序号"]->ToString();
String* SelectCourseDay = this->ds->Tables->Item[S"本学期课程"]->Rows->Item[row]->Item[S"上课时间天"]->ToString();
String* SelectCourseTime = this->ds->Tables->Item[S"本学期课程"]->Rows->Item[row]->Item[S"上课时间节"]->ToString();
int Count = this->ds->Tables->Item[S"课程表"]->Rows->Count;
for(int i = 0;i < Count; i++)
{
ID = this->ds->Tables->Item[S"课程表"]->Rows->Item[i]->Item[S"课序号"]->ToString();
Day = this->ds->Tables->Item[S"课程表"]->Rows->Item[i]->Item[S"上课时间天"]->ToString();
Time = this->ds->Tables->Item[S"课程表"]->Rows->Item[i]->Item[S"上课时间节"]->ToString();
//如果课程已选则返回
if(String::Compare(SelectCourseID,ID) == 0)
{
MessageBox::Show(S"所选课程已经在课程表中");
return;
}
//如果课程时间与课程表中的课程冲突则返回
if(String::Compare(SelectCourseDay,Day) == 0 && String::Compare(SelectCourseTime,Time) == 0)
{
String* Msg = String::Format(S"所选课程与课程表中的课程'{0}'时间冲突",this->ds->Tables->Item[S"本学期课程"]->Rows->Item[i]->Item[S"课程名称"]->ToString());
MessageBox::Show(Msg);
return;
}
}
//选课
String* tempSQL = String::Format(S"Insert into 选课表([学号],[课序号]) Values('{0}','{1}')",this->tBoxStudentID->Text,SelectCourseID);
this->MyDataBase->SQLOperate(tempSQL);
//更新课程表
this->ds->Tables->Item[S"课程表"]->Clear();
this->strSQL = String::Format(S"SELECT 选课表.学号, 选课表.课序号, 课程信息.课程名称, 课程信息.教师, 课程信息.开课系别, 课程表.上课时间天, 课程表.上课时间节 FROM 课程信息 INNER JOIN 课程表 ON 课程信息.课程编号 = 课程表.课程编号 INNER JOIN 选课表 ON 课程表.课序号 = 选课表.课序号 Where 选课表.学号 = '{0}' AND 课程信息.本学期课程 = 'Y'",this->tBoxStudentID->Text);
this->strTableName = S"课程表";
this->MyDataBase->SelectDataBase(this->CourseAdapter,this->ds,this->strSQL,this->strTableName);
}
private: System::Void btnDeSelect_Click(System::Object * sender, System::EventArgs * e)
{
if(this->ds->Tables->Item[S"课程表"]->Rows->Count == 0)
return;
int row = this->dgrdCourseSelected->CurrentRowIndex;
String* SelectCourseID = this->ds->Tables->Item[S"课程表"]->Rows->Item[row]->Item[S"课序号"]->ToString();
//选课
String* tempSQL = String::Format(S"Delete From 选课表 Where 学号 = '{0}' And 课序号 = '{1}'",this->tBoxStudentID->Text,SelectCourseID);
this->MyDataBase->SQLOperate(tempSQL);
//更新课程表
this->ds->Tables->Item[S"课程表"]->Clear();
this->strSQL = String::Format(S"SELECT 选课表.学号, 选课表.课序号, 课程信息.课程名称, 课程信息.教师, 课程信息.开课系别, 课程表.上课时间天, 课程表.上课时间节 FROM 课程信息 INNER JOIN 课程表 ON 课程信息.课程编号 = 课程表.课程编号 INNER JOIN 选课表 ON 课程表.课序号 = 选课表.课序号 Where 选课表.学号 = '{0}' AND 课程信息.本学期课程 = 'Y'",this->tBoxStudentID->Text);
this->strTableName = S"课程表";
this->MyDataBase->SelectDataBase(this->CourseAdapter,this->ds,this->strSQL,this->strTableName);
}
private: System::Void btnCourseTable_Click(System::Object * sender, System::EventArgs * e)
{
CurriculumSchedule* newFrm = new CurriculumSchedule(this->tBoxStudentID->Text);
newFrm->ShowDialog(this);
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -