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

📄 classinfo.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 2 页
字号:
			this->dgrdClass->Dock = System::Windows::Forms::DockStyle::Fill;
			this->dgrdClass->HeaderForeColor = System::Drawing::SystemColors::ControlText;
			this->dgrdClass->Location = System::Drawing::Point(0, 120);
			this->dgrdClass->Name = S"dgrdClass";
			this->dgrdClass->Size = System::Drawing::Size(776, 165);
			this->dgrdClass->TabIndex = 2;
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->tBoxClassShortName);
			this->groupBox2->Controls->Add(this->label12);
			this->groupBox2->Controls->Add(this->tBoxStudents);
			this->groupBox2->Controls->Add(this->label26);
			this->groupBox2->Controls->Add(this->label8);
			this->groupBox2->Controls->Add(this->tBoxClassManager);
			this->groupBox2->Controls->Add(this->tBoxGradeShow);
			this->groupBox2->Controls->Add(this->label9);
			this->groupBox2->Controls->Add(this->tBoxClassNameShow);
			this->groupBox2->Controls->Add(this->label10);
			this->groupBox2->Controls->Add(this->tBoxClassIDShow);
			this->groupBox2->Controls->Add(this->label5);
			this->groupBox2->Dock = System::Windows::Forms::DockStyle::Bottom;
			this->groupBox2->Location = System::Drawing::Point(0, 285);
			this->groupBox2->Name = S"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(776, 136);
			this->groupBox2->TabIndex = 3;
			this->groupBox2->TabStop = false;
			// 
			// tBoxClassShortName
			// 
			this->tBoxClassShortName->Location = System::Drawing::Point(104, 88);
			this->tBoxClassShortName->Name = S"tBoxClassShortName";
			this->tBoxClassShortName->Size = System::Drawing::Size(176, 21);
			this->tBoxClassShortName->TabIndex = 59;
			this->tBoxClassShortName->Text = S"";
			// 
			// label12
			// 
			this->label12->Location = System::Drawing::Point(104, 72);
			this->label12->Name = S"label12";
			this->label12->Size = System::Drawing::Size(56, 11);
			this->label12->TabIndex = 58;
			this->label12->Text = S"班级简称";
			// 
			// tBoxStudents
			// 
			this->tBoxStudents->Location = System::Drawing::Point(288, 88);
			this->tBoxStudents->Name = S"tBoxStudents";
			this->tBoxStudents->Size = System::Drawing::Size(168, 21);
			this->tBoxStudents->TabIndex = 49;
			this->tBoxStudents->Text = S"";
			// 
			// label26
			// 
			this->label26->Location = System::Drawing::Point(288, 72);
			this->label26->Name = S"label26";
			this->label26->Size = System::Drawing::Size(120, 11);
			this->label26->TabIndex = 48;
			this->label26->Text = S"人数";
			// 
			// label8
			// 
			this->label8->Location = System::Drawing::Point(464, 72);
			this->label8->Name = S"label8";
			this->label8->Size = System::Drawing::Size(80, 11);
			this->label8->TabIndex = 16;
			this->label8->Text = S"班主任";
			// 
			// tBoxClassManager
			// 
			this->tBoxClassManager->Location = System::Drawing::Point(464, 88);
			this->tBoxClassManager->Name = S"tBoxClassManager";
			this->tBoxClassManager->Size = System::Drawing::Size(176, 21);
			this->tBoxClassManager->TabIndex = 12;
			this->tBoxClassManager->Text = S"";
			// 
			// tBoxGradeShow
			// 
			this->tBoxGradeShow->Location = System::Drawing::Point(288, 40);
			this->tBoxGradeShow->Name = S"tBoxGradeShow";
			this->tBoxGradeShow->Size = System::Drawing::Size(168, 21);
			this->tBoxGradeShow->TabIndex = 10;
			this->tBoxGradeShow->Text = S"";
			// 
			// label9
			// 
			this->label9->Location = System::Drawing::Point(288, 24);
			this->label9->Name = S"label9";
			this->label9->Size = System::Drawing::Size(56, 11);
			this->label9->TabIndex = 9;
			this->label9->Text = S"年级";
			// 
			// tBoxClassNameShow
			// 
			this->tBoxClassNameShow->Location = System::Drawing::Point(464, 40);
			this->tBoxClassNameShow->Name = S"tBoxClassNameShow";
			this->tBoxClassNameShow->Size = System::Drawing::Size(176, 21);
			this->tBoxClassNameShow->TabIndex = 14;
			this->tBoxClassNameShow->Text = S"";
			// 
			// label10
			// 
			this->label10->Location = System::Drawing::Point(464, 24);
			this->label10->Name = S"label10";
			this->label10->Size = System::Drawing::Size(56, 11);
			this->label10->TabIndex = 13;
			this->label10->Text = S"班级名称";
			// 
			// tBoxClassIDShow
			// 
			this->tBoxClassIDShow->Location = System::Drawing::Point(104, 40);
			this->tBoxClassIDShow->Name = S"tBoxClassIDShow";
			this->tBoxClassIDShow->Size = System::Drawing::Size(176, 21);
			this->tBoxClassIDShow->TabIndex = 2;
			this->tBoxClassIDShow->Text = S"";
			this->tBoxClassIDShow->Leave += new System::EventHandler(this, tBoxClassIDShow_Leave);
			// 
			// label5
			// 
			this->label5->Location = System::Drawing::Point(104, 24);
			this->label5->Name = S"label5";
			this->label5->Size = System::Drawing::Size(56, 11);
			this->label5->TabIndex = 1;
			this->label5->Text = S"班级编号";
			// 
			// ClassInfo
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(776, 421);
			this->Controls->Add(this->dgrdClass);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->toolBar1);
			this->Name = S"ClassInfo";
			this->Text = S"班级管理";
			this->groupBox1->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdClass))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->ResumeLayout(false);

		}		
	private:
		//----------------设置控件ReadOnly属性------------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxClassIDShow->ReadOnly = !isModifiable;
			this->tBoxGradeShow->ReadOnly = !isModifiable;
			this->tBoxClassNameShow->ReadOnly = !isModifiable;
			this->tBoxClassShortName->ReadOnly = !isModifiable;
			this->tBoxStudents->ReadOnly = !isModifiable;
			this->tBoxClassManager->ReadOnly = !isModifiable;

			this->btnSearch->Enabled = !isModifiable;

			this->dgrdClass->ReadOnly = !isModifiable;
		}
		//---------------------设置控件的数据邦定--------------------------
		void SetDataBindings()
		{
			this->tBoxClassIDShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"班级信息"],S"班级编号");
			this->tBoxGradeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"班级信息"],S"年级");
			this->tBoxClassNameShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"班级信息"],S"班级名称");
			this->tBoxClassShortName->DataBindings->Add(S"Text",this->ds->Tables->Item[S"班级信息"],S"班级简称");
			this->tBoxStudents->DataBindings->Add(S"Text",this->ds->Tables->Item[S"班级信息"],S"人数");
			this->tBoxClassManager->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"";
				ts->GridColumnStyles->Add(aTextColumn);
			}

			this->dgrdClass->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->dgrdClass->UnSelect(this->cmClass->Position);
				 this->cmClass->Position = 0;
				 this->dgrdClass->Select(this->cmClass->Position);
				 this->dgrdClass->CurrentRowIndex = this->cmClass->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmClass->Position > 0)
				 {
					 this->dgrdClass->UnSelect(this->cmClass->Position);
					 this->cmClass->Position--;
					 this->dgrdClass->Select(this->cmClass->Position);
					 this->dgrdClass->CurrentRowIndex = this->cmClass->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmClass->Position < this->cmClass->Count)
				 {
					 this->dgrdClass->UnSelect(this->cmClass->Position);
					 this->cmClass->Position++;
					 this->dgrdClass->Select(this->cmClass->Position);
					 this->dgrdClass->CurrentRowIndex = this->cmClass->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdClass->UnSelect(this->cmClass->Position);
				 this->cmClass->Position = this->cmClass->Count;
				 this->dgrdClass->Select(this->cmClass->Position);
				 this->dgrdClass->CurrentRowIndex = this->cmClass->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->cmClass->AddNew();				 
				 this->SetModify(true);

				 this->dgrdClass->UnSelect(this->cmClass->Position);
				 this->cmClass->Position = this->cmClass->Count;
				 this->dgrdClass->Select(this->cmClass->Position);
				 this->dgrdClass->CurrentRowIndex = this->cmClass->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->cmClass->Count > 0)
						 this->cmClass->RemoveAt(this->cmClass->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmClass->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->ClassAdapter,this->ds,S"班级信息");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmClass->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* strClassID = this->tBoxClassID->Text->Trim();
			 String* strGrade = this->tBoxGrade->Text->Trim();
			 String* strClassName = this->tBoxClassName->Text->Trim();
			 String* Filter = S"";
			 if(String::Compare(strClassID,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (班级编号 LIKE '%{1}%')",Filter,strClassID);
			 }
			 if(String::Compare(strGrade,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (年级 LIKE '%{1}%')",Filter,strGrade);
			 }
			 if(String::Compare(strClassName,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (班级名称 LIKE '%{1}%')",Filter,strClassName);
			 }

			 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->ClassAdapter,this->ds,this->strSQL,this->strTableName);           
			 }
			 else
			 {
				 //查询班级信息
				 this->strSQL = S"Select * from 班级信息";
				 this->strTableName = S"班级信息";
				 this->MyDataBase->SelectDataBase(this->ClassAdapter,this->ds,this->strSQL,this->strTableName);            
			 }
		 }

		 
		 //编号不能为空
private: System::Void tBoxClassIDShow_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxClassIDShow->Text,String::Empty) == 0)
				 {
					 MessageBox::Show(S"班级编号不能为空",S"提示");
					 this->tBoxClassIDShow->Focus();
				 }
		 }

};
}

⌨️ 快捷键说明

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