⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curriculumschedule.h

📁 Visual C++.net数据库开发经典案例
💻 H
字号:
#pragma once
#pragma once
#include "LinkDataBase.h"
#include "DataGridNoActiveCellColumn.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;


namespace My
{
	/// <summary> 
	/// CurriculumSchedule 摘要
	///
	/// 警告: 如果您更改该类的名称,则将需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	/// </summary>
	public __gc class CurriculumSchedule : public System::Windows::Forms::Form
	{
		//--------------------成员声明------------------------
	private:
		LinkDataBase* MyDataBase;	//数据库连接类
		SqlDataAdapter* CourseAdapter;
		DataSet* ds;
		String* strTableName;
		String* strSQL;
		DataView* CourseView;
		DataTable* CurriculumTable;
	public:
		String* strStudentID;
		//-------------------成员声明结束-----------------------
	public: 
		CurriculumSchedule(String* ID)
		{
			InitializeComponent();
			//初始化
			this->MyDataBase = new LinkDataBase();
			this->ds = new DataSet();
			this->CourseAdapter = new SqlDataAdapter();
			
			//课程表格
			this->CurriculumTable = new DataTable();
			this->CurriculumTable->Columns->Add(S"星期一",System::Type::GetType(S"System.String"));
			this->CurriculumTable->Columns->Add(S"星期二",System::Type::GetType(S"System.String"));
			this->CurriculumTable->Columns->Add(S"星期三",System::Type::GetType(S"System.String"));
			this->CurriculumTable->Columns->Add(S"星期四",System::Type::GetType(S"System.String"));
			this->CurriculumTable->Columns->Add(S"星期五",System::Type::GetType(S"System.String"));
			
			//设置表格
			this->dgrdCourseSelected->DataSource = this->CurriculumTable;
			this->DataGridStateControl();
			//如果从选课窗口调用
			if(ID != NULL)
			{
				this->tBoxStudentID->Text = ID;
				this->strStudentID = ID;
				this->tBoxStudentID->Enabled = false;
				this->tBoxStudentID->ReadOnly = true;
				this->CurriculumInfo();
			}
		}
        
	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: System::Windows::Forms::DataGrid *  dgrdCourseSelected;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container* components;

		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->dgrdCourseSelected = new System::Windows::Forms::DataGrid();
			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();
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdCourseSelected))->BeginInit();
			this->groupBox1->SuspendLayout();
			this->SuspendLayout();
			// 
			// dgrdCourseSelected
			// 
			this->dgrdCourseSelected->DataMember = S"";
			this->dgrdCourseSelected->Dock = System::Windows::Forms::DockStyle::Fill;
			this->dgrdCourseSelected->HeaderForeColor = System::Drawing::SystemColors::ControlText;
			this->dgrdCourseSelected->Location = System::Drawing::Point(0, 64);
			this->dgrdCourseSelected->Name = S"dgrdCourseSelected";
			this->dgrdCourseSelected->Size = System::Drawing::Size(696, 309);
			this->dgrdCourseSelected->TabIndex = 3;
			// 
			// 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(696, 64);
			this->groupBox1->TabIndex = 4;
			this->groupBox1->TabStop = false;
			// 
			// tBoxName
			// 
			this->tBoxName->Location = System::Drawing::Point(344, 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(280, 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(144, 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(80, 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(561, 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(495, 32);
			this->label4->Name = S"label4";
			this->label4->Size = System::Drawing::Size(56, 11);
			this->label4->TabIndex = 11;
			this->label4->Text = S"班级";
			// 
			// CurriculumSchedule
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(696, 373);
			this->Controls->Add(this->dgrdCourseSelected);
			this->Controls->Add(this->groupBox1);
			this->Name = S"CurriculumSchedule";
			this->Text = S"课程表";
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdCourseSelected))->EndInit();
			this->groupBox1->ResumeLayout(false);
			this->ResumeLayout(false);

		}		
				//-----------------------设置表格各列的属性-----------------------
		void DataGridStateControl()
		{

			DataGridTableStyle* ts = new DataGridTableStyle();			
			ts->MappingName = this->CurriculumTable->TableName;
			
			DataGridTextBoxColumn* aTextColumn;
			ts->AllowSorting = false;
			ts->AlternatingBackColor = Color::LightGray;

			int numCols = this->CurriculumTable->Columns->Count;
			for(int i = 0;i < numCols;i++)
			{
				aTextColumn = new DataGridTextBoxColumn();
				aTextColumn->get_TextBox()->Enabled = false;
				aTextColumn->MappingName = this->CurriculumTable->Columns->Item[i]->ColumnName;
				aTextColumn->HeaderText = this->CurriculumTable->Columns->Item[i]->ColumnName;
				aTextColumn->NullText = S"";
				aTextColumn->Format = S"D";
				ts->GridColumnStyles->Add(aTextColumn);
			}

			this->dgrdCourseSelected->TableStyles->Add(ts);
  		 }	
		 void CurriculumInfo()
		 {
			 int Day;
			 int Time;
			 //查询学生信息
			 String* tempSQL = String::Format(S"SELECT 学生信息.姓名, 班级信息.班级名称, 学生信息.学籍编号 FROM 班级信息 INNER JOIN 学生信息 ON 班级信息.班级编号 = 学生信息.班级编号 Where 学生信息.学号 = '{0}'",this->strStudentID);
			 SqlDataReader* reader = this->MyDataBase->SQLRead(tempSQL);
             
			 reader->Read();
			 //未找到学生资料则返回
			 if(!(reader->HasRows))
			 {
				 MessageBox::Show(S"没有这个学号,请重新填写");
				 reader->Close();
				 return;
			 }

			 //如果是非在籍学生则返回
			 if(String::Compare(reader->Item[S"学籍编号"]->ToString(),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();

			 //查询选课信息
			 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);

			 if(this->CurriculumTable->Rows->Count > 0)
				 this->CurriculumTable->Clear();
			 //向表中添加7行,即每天7节课
			 for(int i = 0;i < 8;i++)
			 {
				 this->CurriculumTable->Rows->Add(this->CurriculumTable->NewRow());
			 }

			 int Count = this->ds->Tables->Item[S"课程表"]->Rows->Count;
			 for(int l = 0;l < Count;l++)
			 {
				 Day = System::Convert::ToInt32(this->ds->Tables->Item[S"课程表"]->Rows->Item[l]->Item[S"上课时间天"]->ToString());
				 Time = System::Convert::ToInt32(this->ds->Tables->Item[S"课程表"]->Rows->Item[l]->Item[S"上课时间节"]->ToString());
				 this->CurriculumTable->Rows->Item[Time - 1]->Item[Day - 1] = this->ds->Tables->Item[S"课程表"]->Rows->Item[l]->Item[S"课程名称"]->ToString();
			 }
             			 
		 }
	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;
			 this->strStudentID = this->tBoxStudentID->Text;
			 this->CurriculumInfo();
			 
		}


};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -