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

📄 studentinfo.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 3 页
字号:
			this->label9->Location = System::Drawing::Point(120, 16);
			this->label9->Name = S"label9";
			this->label9->Size = System::Drawing::Size(56, 11);
			this->label9->TabIndex = 9;
			this->label9->Text = S"姓名";
			// 
			// tBoxGradeShow
			// 
			this->tBoxGradeShow->Location = System::Drawing::Point(368, 32);
			this->tBoxGradeShow->Name = S"tBoxGradeShow";
			this->tBoxGradeShow->Size = System::Drawing::Size(112, 21);
			this->tBoxGradeShow->TabIndex = 14;
			this->tBoxGradeShow->Text = S"";
			// 
			// label10
			// 
			this->label10->Location = System::Drawing::Point(368, 16);
			this->label10->Name = S"label10";
			this->label10->Size = System::Drawing::Size(56, 11);
			this->label10->TabIndex = 13;
			this->label10->Text = S"年级";
			// 
			// tBoxStudentIDShow
			// 
			this->tBoxStudentIDShow->Location = System::Drawing::Point(8, 32);
			this->tBoxStudentIDShow->Name = S"tBoxStudentIDShow";
			this->tBoxStudentIDShow->Size = System::Drawing::Size(104, 21);
			this->tBoxStudentIDShow->TabIndex = 2;
			this->tBoxStudentIDShow->Text = S"";
			this->tBoxStudentIDShow->Leave += new System::EventHandler(this, tBoxStudentIDShow_Leave);
			// 
			// label5
			// 
			this->label5->Location = System::Drawing::Point(8, 16);
			this->label5->Name = S"label5";
			this->label5->Size = System::Drawing::Size(56, 11);
			this->label5->TabIndex = 1;
			this->label5->Text = S"学号";
			// 
			// StudentInfo
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(760, 421);
			this->Controls->Add(this->dgrdStudent);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->toolBar1);
			this->Name = S"StudentInfo";
			this->Text = S"学生信息管理";
			this->groupBox1->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdStudent))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->ResumeLayout(false);

		}		
	private:
		//----------------设置控件ReadOnly属性------------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxGradeShow->ReadOnly = !isModifiable;
			this->tBoxNameShow->ReadOnly = !isModifiable;
			this->tBoxStudentIDShow->ReadOnly = !isModifiable;
			this->tBoxPersonalID->ReadOnly = !isModifiable;
			this->cmbClass->Enabled = isModifiable;
			this->cmbHomeTown->Enabled = isModifiable;
			this->cmbPolicy->Enabled = isModifiable;
			this->cmbRate->Enabled = isModifiable;
			this->cmbSchool->Enabled = isModifiable;
			this->cmbSex->Enabled = isModifiable;

			this->btnSearch->Enabled = !isModifiable;

			this->dgrdStudent->ReadOnly = !isModifiable;
		}
		//---------------------设置控件的数据邦定--------------------------
		void SetDataBindings()
		{
			this->tBoxGradeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"学生信息"],S"年级");
			this->tBoxNameShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"学生信息"],S"姓名");
			this->tBoxStudentIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"学生信息"],S"学号");
			this->tBoxPersonalID->DataBindings->Add(S"Text",this->ds->Tables->Item[S"学生信息"],S"身份证号");
			this->cmbClass->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"学生信息"],S"班级编号");
			this->cmbHomeTown->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"学生信息"],S"籍贯编号");
			this->cmbPolicy->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"学生信息"],S"政治面貌编号");
			this->cmbRate->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"学生信息"],S"民族编号");
			this->cmbSchool->DataBindings->Add(S"SelectedValue",this->ds->Tables->Item[S"学生信息"],S"学籍编号");
			this->cmbSex->DataBindings->Add(S"Text",this->ds->Tables->Item[S"学生信息"],S"性别");										
		}
		//-----------------------设置表格各列的属性-----------------------
		void DataGridStateControl()
		{

			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->dgrdStudent->TableStyles->Add(ts);
  		 }
		//-----------------------工具栏按钮-----------------------
	private:System::Void toolBar1_ButtonClick(System::Object *  sender, System::Windows::Forms::ToolBarButtonClickEventArgs *  e)
		 {
			 //设置控件属性
			 this->SetModify(false);

			 if(String::Compare(e->Button->ToolTipText,S"首记录") == 0)
			 {
				 this->dgrdStudent->UnSelect(this->cmStudent->Position);
				 this->cmStudent->Position = 0;
				 this->dgrdStudent->Select(this->cmStudent->Position);
				 this->dgrdStudent->CurrentRowIndex = this->cmStudent->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmStudent->Position > 0)
				 {
					 this->dgrdStudent->UnSelect(this->cmStudent->Position);
					 this->cmStudent->Position--;
					 this->dgrdStudent->Select(this->cmStudent->Position);
					 this->dgrdStudent->CurrentRowIndex = this->cmStudent->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmStudent->Position < this->cmStudent->Count)
				 {
					 this->dgrdStudent->UnSelect(this->cmStudent->Position);
					 this->cmStudent->Position++;
					 this->dgrdStudent->Select(this->cmStudent->Position);
					 this->dgrdStudent->CurrentRowIndex = this->cmStudent->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdStudent->UnSelect(this->cmStudent->Position);
				 this->cmStudent->Position = this->cmStudent->Count;
				 this->dgrdStudent->Select(this->cmStudent->Position);
				 this->dgrdStudent->CurrentRowIndex = this->cmStudent->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->cmStudent->AddNew();				 
				 this->SetModify(true);

				 this->dgrdStudent->UnSelect(this->cmStudent->Position);
				 this->cmStudent->Position = this->cmStudent->Count;
				 this->dgrdStudent->Select(this->cmStudent->Position);
				 this->dgrdStudent->CurrentRowIndex = this->cmStudent->Position;			 		 
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"修改") == 0)
			 {
				 this->SetModify(true);
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"删除") == 0)
			 {
				 System::Windows::Forms::DialogResult r = MessageBox::Show(S"确定删除?",S"删除数据",MessageBoxButtons::OKCancel);
				 if(r == DialogResult::OK)
				 {
					 if(this->cmStudent->Count > 0)
						 this->cmStudent->RemoveAt(this->cmStudent->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmStudent->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->StudentAdapter,this->ds,S"学生信息");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmStudent->CancelCurrentEdit();
				 }
				 catch(Exception* e)
				 {
					 MessageBox::Show(e->Message,S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"退出") == 0)
			 {
				 this->Close();
			 }
		 }
		 //按条件查询
private: System::Void btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 String* strStudentID = this->tBoxStudentID->Text->Trim();
			 String* strGrade = this->tBoxGrade->Text->Trim();
			 String* strStudentName = this->tBoxName->Text->Trim();
			 String* Filter = S"";
			 if(String::Compare(strStudentID,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (学号 LIKE '%{1}%')",Filter,strStudentID);
			 }
			 if(String::Compare(strGrade,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (年级 LIKE '%{1}%')",Filter,strGrade);
			 }
			 if(String::Compare(strStudentName,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (姓名 LIKE '%{1}%')",Filter,strStudentName);
			 }

			 this->ds->Tables->Item[S"学生信息"]->Clear();

			 if(String::Compare(Filter,String::Empty) != 0)
			 {
				 Filter = Filter->Substring(5,Filter->Length - 5);
				 //查询学生信息				 
				 this->strSQL = String::Format(S"Select * from 学生信息 where {0}",Filter);
				 this->strTableName = S"学生信息";
				 this->MyDataBase->SelectDataBase(this->StudentAdapter,this->ds,this->strSQL,this->strTableName);           
			 }
			 else
			 {
				 //查询学生信息
				 this->strSQL = S"Select * from 学生信息";
				 this->strTableName = S"学生信息";
				 this->MyDataBase->SelectDataBase(this->StudentAdapter,this->ds,this->strSQL,this->strTableName);            
			 }
		 }

		 
		 //编号不能为空
private: System::Void tBoxStudentIDShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxStudentIDShow->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"学号不能为空",S"提示");
					 this->tBoxStudentIDShow->Focus();
				 }
		 }
		 //民族不能为空
private: System::Void cmbRate_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->cmbRate->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"民族不能为空",S"提示");
					 this->cmbRate->Focus();
				 }
		 }
		 //籍贯不能为空
private: System::Void cmbHomeTown_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->cmbHomeTown->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"籍贯不能为空",S"提示");
					 this->cmbHomeTown->Focus();
				 }
		 }
		 //学籍不能为空
private: System::Void cmbSchool_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->cmbSchool->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"学籍不能为空",S"提示");
					 this->cmbSchool->Focus();
				 }
		 }

private: System::Void cmbPolicy_SelectedIndexChanged(System::Object *  sender, System::EventArgs *  e)
		 {
		 }

};
}

⌨️ 快捷键说明

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