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

📄 bookclassify.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 2 页
字号:
			this->tBoxBookType->Location = System::Drawing::Point(448, 40);
			this->tBoxBookType->Name = S"tBoxBookType";
			this->tBoxBookType->Size = System::Drawing::Size(120, 21);
			this->tBoxBookType->TabIndex = 2;
			this->tBoxBookType->Text = S"";
			// 
			// dgrdBooks
			// 
			this->dgrdBooks->DataMember = S"";
			this->dgrdBooks->Dock = System::Windows::Forms::DockStyle::Fill;
			this->dgrdBooks->HeaderForeColor = System::Drawing::SystemColors::ControlText;
			this->dgrdBooks->Location = System::Drawing::Point(0, 120);
			this->dgrdBooks->Name = S"dgrdBooks";
			this->dgrdBooks->Size = System::Drawing::Size(584, 309);
			this->dgrdBooks->TabIndex = 2;
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->tBoxMaxBorrowDays);
			this->groupBox2->Controls->Add(this->tBoxBookTypeCodeShow);
			this->groupBox2->Controls->Add(this->label5);
			this->groupBox2->Controls->Add(this->tBoxBookTypeShow);
			this->groupBox2->Controls->Add(this->label6);
			this->groupBox2->Controls->Add(this->label7);
			this->groupBox2->Dock = System::Windows::Forms::DockStyle::Right;
			this->groupBox2->Location = System::Drawing::Point(584, 120);
			this->groupBox2->Name = S"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(176, 309);
			this->groupBox2->TabIndex = 3;
			this->groupBox2->TabStop = false;
			// 
			// tBoxMaxBorrowDays
			// 
			this->tBoxMaxBorrowDays->Location = System::Drawing::Point(40, 128);
			this->tBoxMaxBorrowDays->Name = S"tBoxMaxBorrowDays";
			this->tBoxMaxBorrowDays->ReadOnly = true;
			this->tBoxMaxBorrowDays->Size = System::Drawing::Size(112, 21);
			this->tBoxMaxBorrowDays->TabIndex = 4;
			this->tBoxMaxBorrowDays->Text = S"";
			// 
			// tBoxBookTypeCodeShow
			// 
			this->tBoxBookTypeCodeShow->Location = System::Drawing::Point(40, 80);
			this->tBoxBookTypeCodeShow->Name = S"tBoxBookTypeCodeShow";
			this->tBoxBookTypeCodeShow->ReadOnly = true;
			this->tBoxBookTypeCodeShow->Size = System::Drawing::Size(112, 21);
			this->tBoxBookTypeCodeShow->TabIndex = 2;
			this->tBoxBookTypeCodeShow->Text = S"";
			this->tBoxBookTypeCodeShow->Leave += new System::EventHandler(this, tBoxBookTypeCodeShow_Leave);
			// 
			// label5
			// 
			this->label5->Location = System::Drawing::Point(40, 64);
			this->label5->Name = S"label5";
			this->label5->Size = System::Drawing::Size(56, 11);
			this->label5->TabIndex = 1;
			this->label5->Text = S"类型编号";
			// 
			// tBoxBookTypeShow
			// 
			this->tBoxBookTypeShow->Location = System::Drawing::Point(40, 176);
			this->tBoxBookTypeShow->Name = S"tBoxBookTypeShow";
			this->tBoxBookTypeShow->ReadOnly = true;
			this->tBoxBookTypeShow->Size = System::Drawing::Size(120, 21);
			this->tBoxBookTypeShow->TabIndex = 6;
			this->tBoxBookTypeShow->Text = S"";
			// 
			// label6
			// 
			this->label6->Location = System::Drawing::Point(40, 160);
			this->label6->Name = S"label6";
			this->label6->Size = System::Drawing::Size(80, 11);
			this->label6->TabIndex = 5;
			this->label6->Text = S"类型名称";
			// 
			// label7
			// 
			this->label7->Location = System::Drawing::Point(40, 112);
			this->label7->Name = S"label7";
			this->label7->Size = System::Drawing::Size(80, 11);
			this->label7->TabIndex = 3;
			this->label7->Text = S"可借天数";
			// 
			// BookClassify
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(760, 429);
			this->Controls->Add(this->dgrdBooks);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->toolBar1);
			this->Name = S"BookClassify";
			this->Text = S"图书类别设置";
			this->groupBox1->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdBooks))->EndInit();
			this->groupBox2->ResumeLayout(false);
			this->ResumeLayout(false);

		}		
	private:
		//----------------设置控件ReadOnly属性------------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxBookTypeCodeShow->ReadOnly = !isModifiable;
			this->tBoxBookTypeShow->ReadOnly = !isModifiable;
			this->tBoxMaxBorrowDays->ReadOnly = !isModifiable;			

			this->btnSearch->Enabled = !isModifiable;
			this->dgrdBooks->ReadOnly = !isModifiable;
		}
		//---------------------设置控件的数据邦定--------------------------
		void SetDataBindings()
		{
			this->tBoxBookTypeCodeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书类型"],S"类型编号");
			this->tBoxBookTypeShow->DataBindings->Add(S"Text",this->ds->Tables->Item[S"图书类型"],S"类型名称");
			this->tBoxMaxBorrowDays->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->dgrdBooks->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->dgrdBooks->UnSelect(this->cmBook->Position);
				 this->cmBook->Position = 0;
				 this->dgrdBooks->Select(this->cmBook->Position);
				 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmBook->Position > 0)
				 {
					 this->dgrdBooks->UnSelect(this->cmBook->Position);
					 this->cmBook->Position--;
					 this->dgrdBooks->Select(this->cmBook->Position);
					 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmBook->Position < this->cmBook->Count)
				 {
					 this->dgrdBooks->UnSelect(this->cmBook->Position);
					 this->cmBook->Position++;
					 this->dgrdBooks->Select(this->cmBook->Position);
					 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdBooks->UnSelect(this->cmBook->Position);
				 this->cmBook->Position = this->cmBook->Count;
				 this->dgrdBooks->Select(this->cmBook->Position);
				 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->cmBook->AddNew();
				 //设置控件属性
				 this->SetModify(true);
				 //移动到新增的行
				 this->dgrdBooks->UnSelect(this->cmBook->Position);
				 this->cmBook->Position = this->cmBook->Count;
				 this->dgrdBooks->Select(this->cmBook->Position);
				 this->dgrdBooks->CurrentRowIndex = this->cmBook->Position;

				 //设置默认值
				 //设置编号
				 String* tempSQL = S"Select max(类型编号) 最大编号 from 图书类型";
				 SqlCommand* sqlCmd = new SqlCommand(tempSQL,this->MyDataBase->myConnection);
				 int MaxID = 1;
				 Object* r = sqlCmd->ExecuteScalar();
				 if(r != System::DBNull::Value)
					 MaxID = System::Convert::ToInt32(r) + 1;
				 this->tBoxBookTypeCodeShow->Text = MaxID.ToString()->Trim();
								 
			 }
			 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->cmBook->Count > 0)
						 this->cmBook->RemoveAt(this->cmBook->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmBook->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->BookAdapter,this->ds,S"图书类型");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmBook->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* strBookTypeCode = this->tBoxBookTypeCode->Text->Trim();
			 String* strBookType = this->tBoxBookType->Text->Trim();			 
			 String* Filter = S"";
			 if(String::Compare(strBookTypeCode,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (类型编号 LIKE '%{1}%')",Filter,strBookTypeCode);
			 }
			 if(String::Compare(strBookType,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (类型名称 LIKE '%{1}%')",Filter,strBookType);
			 }			 

			 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->BookAdapter,this->ds,this->strSQL,this->strTableName);           
			 }
			 else
			 {
				 //查询图书类型
				 this->strSQL = S"Select * from 图书类型";
				 this->strTableName = S"图书类型";
				 this->MyDataBase->SelectDataBase(this->BookAdapter,this->ds,this->strSQL,this->strTableName);            
			 }    			
		 }

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

};
}

⌨️ 快捷键说明

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