📄 viewscore.h
字号:
#pragma once
#include "LinkDataBase.h"
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace CrystalDecisions::CrystalReports::Engine;
using namespace CrystalDecisions::Windows::Forms;
namespace My
{
/// <summary>
/// ViewScore 摘要
///
/// 警告: 如果您更改该类的名称,则将需要更改
/// 与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。 否则,
/// 设计器将不能与此窗体关联的
/// 本地化资源正确交互。
/// </summary>
public __gc class ViewScore : public System::Windows::Forms::Form
{
//--------------------成员声明------------------------
private:
LinkDataBase* MyDataBase; //数据库连接类
private: My::ScoreDataSet * scoreDataSet1;
public:
String* strStudentID;
//-------------------成员声明结束-----------------------
public:
ViewScore()
{
InitializeComponent();
//初始化
this->MyDataBase = new LinkDataBase();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::GroupBox * groupBox1;
private: System::Windows::Forms::TextBox * tBoxName;
private: System::Windows::Forms::Label * label2;
private: System::Windows::Forms::TextBox * tBoxStudentID;
private: System::Windows::Forms::Label * label1;
private: System::Windows::Forms::TextBox * tBoxClass;
private: System::Windows::Forms::Label * label4;
private: CrystalDecisions::Windows::Forms::CrystalReportViewer * crystalReportViewer1;
private: System::Data::SqlClient::SqlCommand * sqlSelectCommand1;
private: System::Data::SqlClient::SqlConnection * sqlConnection1;
private: System::Data::SqlClient::SqlDataAdapter * ScoreAdapter;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container* components;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->groupBox1 = new System::Windows::Forms::GroupBox();
this->tBoxName = new System::Windows::Forms::TextBox();
this->label2 = new System::Windows::Forms::Label();
this->tBoxStudentID = new System::Windows::Forms::TextBox();
this->label1 = new System::Windows::Forms::Label();
this->tBoxClass = new System::Windows::Forms::TextBox();
this->label4 = new System::Windows::Forms::Label();
this->crystalReportViewer1 = new CrystalDecisions::Windows::Forms::CrystalReportViewer();
this->ScoreAdapter = new System::Data::SqlClient::SqlDataAdapter();
this->sqlSelectCommand1 = new System::Data::SqlClient::SqlCommand();
this->sqlConnection1 = new System::Data::SqlClient::SqlConnection();
this->scoreDataSet1 = new My::ScoreDataSet();
this->groupBox1->SuspendLayout();
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->scoreDataSet1))->BeginInit();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->Controls->Add(this->tBoxName);
this->groupBox1->Controls->Add(this->label2);
this->groupBox1->Controls->Add(this->tBoxStudentID);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Controls->Add(this->tBoxClass);
this->groupBox1->Controls->Add(this->label4);
this->groupBox1->Dock = System::Windows::Forms::DockStyle::Top;
this->groupBox1->Location = System::Drawing::Point(0, 0);
this->groupBox1->Name = S"groupBox1";
this->groupBox1->Size = System::Drawing::Size(624, 64);
this->groupBox1->TabIndex = 4;
this->groupBox1->TabStop = false;
//
// tBoxName
//
this->tBoxName->Location = System::Drawing::Point(280, 28);
this->tBoxName->Name = S"tBoxName";
this->tBoxName->ReadOnly = true;
this->tBoxName->Size = System::Drawing::Size(120, 21);
this->tBoxName->TabIndex = 10;
this->tBoxName->Text = S"";
//
// label2
//
this->label2->Location = System::Drawing::Point(216, 33);
this->label2->Name = S"label2";
this->label2->Size = System::Drawing::Size(56, 11);
this->label2->TabIndex = 9;
this->label2->Text = S"姓名";
//
// tBoxStudentID
//
this->tBoxStudentID->Location = System::Drawing::Point(80, 29);
this->tBoxStudentID->Name = S"tBoxStudentID";
this->tBoxStudentID->Size = System::Drawing::Size(120, 21);
this->tBoxStudentID->TabIndex = 8;
this->tBoxStudentID->Text = S"";
this->tBoxStudentID->KeyPress += new System::Windows::Forms::KeyPressEventHandler(this, tBoxStudentID_KeyPress);
//
// label1
//
this->label1->Location = System::Drawing::Point(16, 34);
this->label1->Name = S"label1";
this->label1->Size = System::Drawing::Size(56, 11);
this->label1->TabIndex = 7;
this->label1->Text = S"学号";
//
// tBoxClass
//
this->tBoxClass->Location = System::Drawing::Point(496, 29);
this->tBoxClass->Name = S"tBoxClass";
this->tBoxClass->ReadOnly = true;
this->tBoxClass->Size = System::Drawing::Size(120, 21);
this->tBoxClass->TabIndex = 12;
this->tBoxClass->Text = S"";
//
// label4
//
this->label4->Location = System::Drawing::Point(432, 32);
this->label4->Name = S"label4";
this->label4->Size = System::Drawing::Size(56, 11);
this->label4->TabIndex = 11;
this->label4->Text = S"班级";
//
// crystalReportViewer1
//
this->crystalReportViewer1->ActiveViewIndex = -1;
this->crystalReportViewer1->DisplayGroupTree = false;
this->crystalReportViewer1->Dock = System::Windows::Forms::DockStyle::Fill;
this->crystalReportViewer1->Location = System::Drawing::Point(0, 64);
this->crystalReportViewer1->Name = S"crystalReportViewer1";
this->crystalReportViewer1->ReportSource = 0;
this->crystalReportViewer1->Size = System::Drawing::Size(624, 357);
this->crystalReportViewer1->TabIndex = 6;
//
// ScoreAdapter
//
this->ScoreAdapter->SelectCommand = this->sqlSelectCommand1;
System::Data::Common::DataTableMapping* __mcTemp__1[] = new System::Data::Common::DataTableMapping*[1];
System::Data::Common::DataColumnMapping* __mcTemp__2[] = new System::Data::Common::DataColumnMapping*[9];
__mcTemp__2[0] = new System::Data::Common::DataColumnMapping(S"学号", S"StudentID");
__mcTemp__2[1] = new System::Data::Common::DataColumnMapping(S"姓名", S"StudentName");
__mcTemp__2[2] = new System::Data::Common::DataColumnMapping(S"课程名称", S"CourseName");
__mcTemp__2[3] = new System::Data::Common::DataColumnMapping(S"开课系别", S"Department");
__mcTemp__2[4] = new System::Data::Common::DataColumnMapping(S"教师", S"Teacher");
__mcTemp__2[5] = new System::Data::Common::DataColumnMapping(S"成绩", S"Mark");
__mcTemp__2[6] = new System::Data::Common::DataColumnMapping(S"Expr1", S"Expr1");
__mcTemp__2[7] = new System::Data::Common::DataColumnMapping(S"编号", S"Number");
__mcTemp__2[8] = new System::Data::Common::DataColumnMapping(S"课程编号", S"CourseID");
__mcTemp__1[0] = new System::Data::Common::DataTableMapping(S"Table", S"MarkTable", __mcTemp__2);
this->ScoreAdapter->TableMappings->AddRange(__mcTemp__1);
//
// sqlSelectCommand1
//
this->sqlSelectCommand1->CommandText = S"SELECT 成绩表.学号, 学生信息.姓名, 课程信息.课程名称, 课程信息.开课系别, 课程信息.教师, 成绩表.成绩, 学生信息.学号 AS Expr1, "
S"成绩表.编号, 课程信息.课程编号 FROM 成绩表 INNER JOIN 学生信息 ON 成绩表.学号 = 学生信息.学号 INNER JOIN 课程信息 O"
S"N 成绩表.课程编号 = 课程信息.课程编号 WHERE (成绩表.学号 = @学号)";
this->sqlSelectCommand1->Connection = this->sqlConnection1;
this->sqlSelectCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@学号", System::Data::SqlDbType::VarChar, 14, S"学号"));
//
// sqlConnection1
//
this->sqlConnection1->ConnectionString = S"workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo"
S"g=eisbook;persist security info=False";
//
// scoreDataSet1
//
this->scoreDataSet1->DataSetName = S"ScoreDataSet";
this->scoreDataSet1->Locale = new System::Globalization::CultureInfo(S"zh-CN");
//
// ViewScore
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(624, 421);
this->Controls->Add(this->crystalReportViewer1);
this->Controls->Add(this->groupBox1);
this->Name = S"ViewScore";
this->Text = S"成绩单打印";
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->scoreDataSet1))->EndInit();
this->ResumeLayout(false);
}
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;
strStudentID = this->tBoxStudentID->Text;
//查询学生信息
String* tempSQL = String::Format(S"SELECT 学生信息.姓名, 班级信息.班级名称, 学生信息.学籍编号 FROM 班级信息 INNER JOIN 学生信息 ON 班级信息.班级编号 = 学生信息.班级编号 Where 学生信息.学号 = '{0}'",strStudentID);
SqlDataReader* reader = this->MyDataBase->SQLRead(tempSQL);
reader->Read();
//未找到学生资料则返回
if(!(reader->HasRows))
{
MessageBox::Show(S"没有这个学号,请重新填写");
reader->Close();
return;
}
//显示学生信息
this->tBoxName->Text = reader->Item[S"姓名"]->ToString();
this->tBoxClass->Text = reader->Item[S"班级名称"]->ToString();
reader->Close();
//查询成绩单
this->ScoreAdapter->SelectCommand->Parameters->Item[S"@学号"]->Value = strStudentID;
this->ScoreAdapter->Fill(this->scoreDataSet1);
//设置报表数据源
ReportDocument* oRpt = new ReportDocument();
oRpt->Load(".\\MarkTable.rpt");
oRpt->SetDataSource(this->scoreDataSet1->Tables->Item[0]);
crystalReportViewer1->ReportSource = oRpt;
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -