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

📄 cbookinfomanage.h

📁 MFC程序开发参考大全 【明日科技】宋坤 刘锐宁 李伟明 【丛 书 名】 软件工程师典藏 【出 版 社】 人民邮电出版社 本书详细介绍了MFC框架中所有常用类及控件的应用
💻 H
📖 第 1 页 / 共 3 页
字号:
			// 
			// Column6
			// 
			this->Column6->HeaderText = L"书号";
			this->Column6->Name = L"Column6";
			this->Column6->ReadOnly = true;
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->ButtonQuery);
			this->groupBox1->Controls->Add(this->QueryValue);
			this->groupBox1->Controls->Add(this->label8);
			this->groupBox1->Controls->Add(this->QueryCondition);
			this->groupBox1->Controls->Add(this->label7);
			this->groupBox1->Location = System::Drawing::Point(16, 10);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(464, 50);
			this->groupBox1->TabIndex = 0;
			this->groupBox1->TabStop = false;
			// 
			// ButtonQuery
			// 
			this->ButtonQuery->Location = System::Drawing::Point(396, 15);
			this->ButtonQuery->Name = L"ButtonQuery";
			this->ButtonQuery->Size = System::Drawing::Size(56, 22);
			this->ButtonQuery->TabIndex = 4;
			this->ButtonQuery->Text = L"查询";
			this->ButtonQuery->UseVisualStyleBackColor = true;
			this->ButtonQuery->Click += gcnew System::EventHandler(this, &CBookInfoManage::ButtonQuery_Click);
			// 
			// QueryValue
			// 
			this->QueryValue->Location = System::Drawing::Point(217, 15);
			this->QueryValue->Name = L"QueryValue";
			this->QueryValue->Size = System::Drawing::Size(170, 21);
			this->QueryValue->TabIndex = 3;
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(201, 20);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(11, 12);
			this->label8->TabIndex = 2;
			this->label8->Text = L"=";
			// 
			// QueryCondition
			// 
			this->QueryCondition->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->QueryCondition->FormattingEnabled = true;
			this->QueryCondition->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"图书名称", L"作者", L"条形码"});
			this->QueryCondition->Location = System::Drawing::Point(73, 15);
			this->QueryCondition->Name = L"QueryCondition";
			this->QueryCondition->Size = System::Drawing::Size(121, 20);
			this->QueryCondition->TabIndex = 1;
			this->QueryCondition->SelectedIndexChanged += gcnew System::EventHandler(this, &CBookInfoManage::QueryCondition_SelectedIndexChanged);
			this->QueryCondition->SelectedValueChanged += gcnew System::EventHandler(this, &CBookInfoManage::QueryCondition_SelectedValueChanged);
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(14, 20);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(53, 12);
			this->label7->TabIndex = 0;
			this->label7->Text = L"查询条件";
			// 
			// CBookInfoManage
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(547, 340);
			this->Controls->Add(this->tabControl1);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
			this->KeyPreview = true;
			this->MaximizeBox = false;
			this->Name = L"CBookInfoManage";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"图书信息管理";
			this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &CBookInfoManage::CBookInfoManage_KeyDown);
			this->Load += gcnew System::EventHandler(this, &CBookInfoManage::CBookInfoManage_Load);
			this->tabControl1->ResumeLayout(false);
			this->BookAdd->ResumeLayout(false);
			this->Panel1->ResumeLayout(false);
			this->Panel1->PerformLayout();
			this->BookUpdate->ResumeLayout(false);
			this->panel2->ResumeLayout(false);
			this->panel2->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->BookList))->EndInit();
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion

	private: System::Void label4_Click(System::Object^  sender, System::EventArgs^  e) {
			 }

		 //保存按钮单击事件代码
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			
			 if (BookInfoIsNull(CTag::tg_Add))
			 {
				 MessageBox::Show("图书基础信息不能为空.");
				return;
			 }
			 
			 String ^ sql = String::Format("Insert into BookInfo values ( '{0}','{1}','{2}',{3},'{4}','{5}')",
			    BookName->Text->Trim(),Author->Text->Trim(),Barcode->Text->Trim(), Convert::ToDecimal(BookPrice->Text),BookConcern->Text->Trim(),ISBN->Text->Trim());
			 DataManage.Command->CommandText = sql;

			 try
			 {
				 DataManage.Command->ExecuteNonQuery();
				 ClearText(CTag::tg_Add);
				 MessageBox::Show("操作成功.","提示");
			 }
			 catch(DbException^ exp)
			 {
				 MessageBox::Show("操作失败,错误信息为:"+exp->Message,"提示");
			 
			 }
		 }

		 //取消按钮单击事件
private: System::Void ButtonCancel_Click(System::Object^  sender, System::EventArgs^  e) {

			 for (int i = 0; i< Panel1->Controls->Count;i++)
			 {
				 if (Panel1->Controls[i]->GetType()->Name=="TextBox")
					 Panel1->Controls[i]->Text = "";
			 }
		 }

private: System::Void CBookInfoManage_Load(System::Object^  sender, System::EventArgs^  e) {

			DataManage.ConStr ="Data Source=.;Initial Catalog=BookManage;User ID=sa";
			DataManage.ConnectDataBase();
		 }

private: System::Void CBookInfoManage_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {

			 if (e->KeyValue==13)
			 {
				 if (ActiveControl->GetType()->Name=="TextBox")
				 {
					 Control^ temp = GetNextControl(ActiveControl,true);
					 temp->Focus();
				 } 
			 }
		 }
private: System::Void ButtonExit_Click(System::Object^  sender, System::EventArgs^  e) {
			 Close();
		 }

		 //查询数据
private: System::Void ButtonQuery_Click(System::Object^  sender, System::EventArgs^  e) {

			 if (QueryCondition->Text->Trim() != "" && QueryValue->Text->Trim() != "")
			 {
				 String ^ sql = String::Format("select * from BookInfo where "+QueryField +" = '{0}'",QueryValue->Text->Trim());
				 
				 DataManage.Command->CommandText = sql;
				 try
				 {
					 SqlDataAdapter^ dataAdapter = gcnew SqlDataAdapter(sql,DataManage.Connection);
					 
					 DataSet^ dataset = gcnew DataSet();
					 dataAdapter->Fill(dataset);
					 dataset->Tables[0]->Rows->Count;
									
					 int currow = 0;
					 if (dataset->Tables[0]->Rows->Count>0)
					 {
						 BookList->RowCount =dataset->Tables[0]->Rows->Count;
						 for (int row = 0; row<dataset->Tables[0]->Rows->Count; row++)
						 {
							 for (int col = 0; col < dataset->Tables[0]->Columns->Count; col++)
							 {
								 BookList->Rows[currow]->Cells[col]->Value = dataset->Tables[0]->Rows[row]->ItemArray[col]->ToString();
							 }
							 currow+=1;

						 }
					 }
					 else
					 {
                         ClearList();
						 MessageBox::Show("没有符合条件的数据");
					 }
				 }
				 catch(DbException^ exp)
				 {
					 MessageBox::Show("操作失败,错误信息为:"+exp->Message,"提示");
				 }
			 }
			 else
				 MessageBox::Show("查询条件不完整.","提示");
		 }
private: System::Void QueryCondition_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {


		 }
private: System::Void QueryCondition_SelectedValueChanged(System::Object^  sender, System::EventArgs^  e) {

			 String ^ temp = ((ComboBox^)sender)->Text->Trim(); 
			 if ( temp !="" )
			 {
				if (temp=="图书名称")
					QueryField = "Bookname";
				else if (temp =="条形码")
					QueryField ="Barcode";
				else if (temp=="作者")
					QueryField = "BookAuthor";
			 }
		 }
private: System::Void BookList_CellClick(System::Object^  sender, System::Windows::Forms::DataGridViewCellEventArgs^  e) {

			 if (BookList->SelectedCells->Count>0)
			 {
				 CurSelRow = BookList->SelectedCells[0]->RowIndex;
				 BookName2->Text = Convert::ToString(BookList->Rows[CurSelRow]->Cells[0]->Value);
				 Author2->Text = Convert::ToString(BookList->Rows[CurSelRow ]->Cells[1]->Value);
				 Barcode2->Text = Convert::ToString(BookList->Rows[CurSelRow ]->Cells[2]->Value);
				 BookPrice2->Text = Convert::ToString(BookList->Rows[CurSelRow]->Cells[3]->Value);
				 BookConcern2->Text = Convert::ToString( BookList->Rows[CurSelRow ]->Cells[4]->Value);
				 ISBN2->Text = Convert::ToString(BookList->Rows[CurSelRow]->Cells[5]->Value);
			 }
		 }
private: System::Void ButtionSave2_Click(System::Object^  sender, System::EventArgs^  e) {

			 if (BookInfoIsNull(CTag::tg_Update))
			 {
				 MessageBox::Show("图书信息不能为空");
				return;
			 }
			 String ^ str = Convert::ToString( BookList->Rows[CurSelRow]->Cells[0]->Value);
			 if (str=="")
			 {
				 MessageBox::Show("请在表格中选择需要修改的数据");
				 return;
			 }
			 if (MessageBox::Show("确实要修改图书名称为"+str+"的数据吗?","提示",MessageBoxButtons::YesNo)==::DialogResult::Yes)
			 {
				
				 String^ sql = String::Format("update BookInfo set BookName = '{0}',BookAuthor = '{1}',Barcode = '{2}',BookPrice = {3},BookConcern = '{4}',ISBN = '{5}' where Bookname = '{6}'",
				 BookName2->Text->Trim(),Author2->Text->Trim(),Barcode2->Text->Trim(), Convert::ToString(BookPrice2->Text->Trim()),BookConcern2->Text->Trim(),ISBN2->Text->Trim(),str);
				 
				 DataManage.Command->CommandText =sql;
				 try
				 {
					 DataManage.Command->ExecuteNonQuery();
					 ClearText(CTag::tg_Update);
					 CurSelRow = 0;
					 ClearList();
					 MessageBox::Show("修改成功.","提示");
				 }
				 catch(DbException^ exp)
				 {
					 MessageBox::Show("操作失败,错误信息为"+exp->Message,"提示");
				 }			 		 
			 }			 
		 }
private: System::Void ButtionCancel2_Click(System::Object^  sender, System::EventArgs^  e) {

			 ClearText(CTag::tg_Update);
			 ClearList();
			 CurSelRow = 0;
		 }
		 
private: System::Void BookPrice_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			


		 }
		 //防止在价格编辑框中输入非法数据
private: System::Void BookPrice_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {

			 if (e->KeyChar<8||e->KeyChar>8 && e->KeyChar<46 || e->KeyChar>46 && e->KeyChar<48 || e->KeyChar>57 )
				 e->KeyChar = 0;
		 }

		 //删除图书信息
private: System::Void ButtonDelete_Click(System::Object^  sender, System::EventArgs^  e) {

			 String ^ str = Convert::ToString( BookList->Rows[CurSelRow]->Cells[0]->Value);
			 if (str=="")
			 {
				 MessageBox::Show("请在表格中选择需要删除的数据");
				 return;
			 }
			 if (MessageBox::Show("确实要删除图书名称为"+str+"的数据吗?","提示",MessageBoxButtons::YesNo)==::DialogResult::Yes)
			 {
				
				 String^ sql = String::Format("delete BookInfo where BookName = '{0}'",str);
				 DataManage.Command->CommandText =sql;
				 try
				 {
					 DataManage.Command->ExecuteNonQuery();
					 ClearText(CTag::tg_Update);
					 CurSelRow = 0;
					 ClearList();
					 MessageBox::Show("删除成功.","提示");
				 }
				 catch(DbException^ exp)
				 {
					 MessageBox::Show("操作失败,错误信息为"+exp->Message,"提示");
				 }			 		 
			 }			 
		 }
private: System::Void tabControl1_Selected(System::Object^  sender, System::Windows::Forms::TabControlEventArgs^  e) {

			 if (tabControl1->SelectedIndex == 0)
			 {
				 tabControl1->Size = System::Drawing::Size(tabControl1->Width,270);
				 Size = System::Drawing::Size(Width,360);
			 }
			 else
			 {
				tabControl1->Size = System::Drawing::Size(tabControl1->Width,470);
				Size = System::Drawing::Size(Width,548);
			 }
		 }
private: System::Void tabControl1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {


		 }
private: System::Void BookName_Layout(System::Object^  sender, System::Windows::Forms::LayoutEventArgs^  e) {

		
		 }
};
}

⌨️ 快捷键说明

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