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

📄 overduebook.h

📁 Visual C++.net数据库开发经典案例
💻 H
字号:
#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> 
	/// OverDueBook 摘要
	///
	/// 警告: 如果您更改该类的名称,则将需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	/// </summary>
	public __gc class OverDueBook : public System::Windows::Forms::Form
	{
		//--------------------成员声明------------------------
	private:
		LinkDataBase* MyDataBase;	//数据库连接类
		DataSet* ds;
		String* strTableName;


	private: System::Windows::Forms::ImageList *  imageList1;
			 String* strSQL;
		//-------------------成员声明结束-----------------------
	public: 
		OverDueBook(void)
		{
			InitializeComponent();
			//初始化
			this->MyDataBase = new LinkDataBase();
			this->ds = new DataSet();		

			//查询图书借阅
			
			 this->BookReturnAdapter->SelectCommand->Parameters->Item[S"@图书编号"]->Value = S"%%";
			 this->BookReturnAdapter->SelectCommand->Parameters->Item[S"@读者编号"]->Value = S"%%";
			 this->BookReturnAdapter->SelectCommand->Parameters->Item[S"@读者姓名"]->Value = S"%%";
			
			 this->BookReturnAdapter->Fill(this->ds,S"图书借阅");			
			//设置DataGrid
			this->dgrdBooks->DataSource = this->ds->Tables->Item[S"图书借阅"];
			this->DataGridStateControl();			
		}
        
	protected: 
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
	private: System::Windows::Forms::GroupBox *  groupBox1;
	private: System::Windows::Forms::Button *  btnSearch;
	private: System::Windows::Forms::Label *  label1;
	private: System::Windows::Forms::Label *  label2;
	private: System::Windows::Forms::Label *  label4;
	private: System::Windows::Forms::TextBox *  tBoxBookID;
	private: System::Windows::Forms::TextBox *  tBoxReaderID;
	private: System::Windows::Forms::DataGrid *  dgrdBooks;
    private: System::Windows::Forms::TextBox *  tBoxReaderName;
	private: System::Data::SqlClient::SqlDataAdapter *  BookReturnAdapter;
	private: System::Data::SqlClient::SqlCommand *  sqlSelectCommand1;
	private: System::Data::SqlClient::SqlConnection *  sqlConnection1;

	private: System::ComponentModel::IContainer *  components;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>


		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = new System::ComponentModel::Container();
			System::Resources::ResourceManager *  resources = new System::Resources::ResourceManager(__typeof(My::OverDueBook));
			this->groupBox1 = new System::Windows::Forms::GroupBox();
			this->tBoxBookID = new System::Windows::Forms::TextBox();
			this->label2 = new System::Windows::Forms::Label();
			this->tBoxReaderName = new System::Windows::Forms::TextBox();
			this->label1 = new System::Windows::Forms::Label();
			this->btnSearch = new System::Windows::Forms::Button();
			this->imageList1 = new System::Windows::Forms::ImageList(this->components);
			this->tBoxReaderID = new System::Windows::Forms::TextBox();
			this->label4 = new System::Windows::Forms::Label();
			this->dgrdBooks = new System::Windows::Forms::DataGrid();
			this->BookReturnAdapter = new System::Data::SqlClient::SqlDataAdapter();
			this->sqlSelectCommand1 = new System::Data::SqlClient::SqlCommand();
			this->sqlConnection1 = new System::Data::SqlClient::SqlConnection();
			this->groupBox1->SuspendLayout();
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdBooks))->BeginInit();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->tBoxBookID);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->tBoxReaderName);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Controls->Add(this->btnSearch);
			this->groupBox1->Controls->Add(this->tBoxReaderID);
			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(760, 79);
			this->groupBox1->TabIndex = 1;
			this->groupBox1->TabStop = false;
			// 
			// tBoxBookID
			// 
			this->tBoxBookID->Location = System::Drawing::Point(408, 40);
			this->tBoxBookID->Name = S"tBoxBookID";
			this->tBoxBookID->Size = System::Drawing::Size(120, 21);
			this->tBoxBookID->TabIndex = 4;
			this->tBoxBookID->Text = S"";
			// 
			// label2
			// 
			this->label2->Location = System::Drawing::Point(536, 48);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(56, 11);
			this->label2->TabIndex = 3;
			this->label2->Text = S"读者姓名";
			// 
			// tBoxReaderName
			// 
			this->tBoxReaderName->Location = System::Drawing::Point(592, 40);
			this->tBoxReaderName->Name = S"tBoxReaderName";
			this->tBoxReaderName->Size = System::Drawing::Size(120, 21);
			this->tBoxReaderName->TabIndex = 2;
			this->tBoxReaderName->Text = S"";
			// 
			// label1
			// 
			this->label1->Location = System::Drawing::Point(144, 45);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(56, 11);
			this->label1->TabIndex = 1;
			this->label1->Text = S"读者编号";
			// 
			// btnSearch
			// 
			this->btnSearch->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->btnSearch->ImageIndex = 6;
			this->btnSearch->ImageList = this->imageList1;
			this->btnSearch->Location = System::Drawing::Point(64, 40);
			this->btnSearch->Name = S"btnSearch";
			this->btnSearch->Size = System::Drawing::Size(56, 24);
			this->btnSearch->TabIndex = 0;
			this->btnSearch->Text = S"搜索";
			this->btnSearch->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			this->btnSearch->Click += new System::EventHandler(this, btnSearch_Click);
			// 
			// imageList1
			// 
			this->imageList1->ImageSize = System::Drawing::Size(16, 16);
			this->imageList1->ImageStream = (__try_cast<System::Windows::Forms::ImageListStreamer *  >(resources->GetObject(S"imageList1.ImageStream")));
			this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
			// 
			// tBoxReaderID
			// 
			this->tBoxReaderID->Location = System::Drawing::Point(208, 40);
			this->tBoxReaderID->Name = S"tBoxReaderID";
			this->tBoxReaderID->Size = System::Drawing::Size(120, 21);
			this->tBoxReaderID->TabIndex = 6;
			this->tBoxReaderID->Text = S"";
			// 
			// label4
			// 
			this->label4->Location = System::Drawing::Point(344, 45);
			this->label4->Name = S"label4";
			this->label4->Size = System::Drawing::Size(56, 11);
			this->label4->TabIndex = 5;
			this->label4->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, 79);
			this->dgrdBooks->Name = S"dgrdBooks";
			this->dgrdBooks->Size = System::Drawing::Size(760, 350);
			this->dgrdBooks->TabIndex = 2;
			// 
			// BookReturnAdapter
			// 
			this->BookReturnAdapter->SelectCommand = this->sqlSelectCommand1;
			System::Data::Common::DataTableMapping* __mcTemp__1[] = new System::Data::Common::DataTableMapping*[1];
			System::Data::Common::DataColumnMapping* __mcTemp__2[] = new System::Data::Common::DataColumnMapping*[10];
			__mcTemp__2[0] = new System::Data::Common::DataColumnMapping(S"借阅编号", S"借阅编号");
			__mcTemp__2[1] = new System::Data::Common::DataColumnMapping(S"姓名", S"姓名");
			__mcTemp__2[2] = new System::Data::Common::DataColumnMapping(S"读者编号", S"读者编号");
			__mcTemp__2[3] = new System::Data::Common::DataColumnMapping(S"书名", S"书名");
			__mcTemp__2[4] = new System::Data::Common::DataColumnMapping(S"图书编号", S"图书编号");
			__mcTemp__2[5] = new System::Data::Common::DataColumnMapping(S"借阅时间", S"借阅时间");
			__mcTemp__2[6] = new System::Data::Common::DataColumnMapping(S"应还时间", S"应还时间");
			__mcTemp__2[7] = new System::Data::Common::DataColumnMapping(S"续借次数", S"续借次数");
			__mcTemp__2[8] = new System::Data::Common::DataColumnMapping(S"操作员", S"操作员");
			__mcTemp__2[9] = new System::Data::Common::DataColumnMapping(S"状态", S"状态");
			__mcTemp__1[0] = new System::Data::Common::DataTableMapping(S"Table", S"图书借阅", __mcTemp__2);
			this->BookReturnAdapter->TableMappings->AddRange(__mcTemp__1);
			// 
			// sqlSelectCommand1
			// 
			this->sqlSelectCommand1->CommandText = S"SELECT 图书借阅.借阅编号, 读者信息.姓名, 图书借阅.读者编号, 图书信息.书名, 图书借阅.图书编号, 图书借阅.借阅时间, 图书借阅.应还时间, 图" 
				S"书借阅.续借次数, 图书借阅.操作员, 图书借阅.状态 FROM libbook.dbo.图书借阅 INNER JOIN libbook.dbo.图书信息 ON" 
				S" 图书借阅.图书编号 = 图书信息.编号 INNER JOIN libbook.dbo.读者信息 ON 图书借阅.读者编号 = 读者信息.编号 WHERE (图" 
				S"书借阅.读者编号 LIKE @读者编号) AND (图书借阅.图书编号 LIKE @图书编号) AND (读者信息.姓名 LIKE @读者姓名) AND (图书" 
				S"借阅.状态 = \'未还\') AND (图书借阅.应还时间 < GETDATE())";
			this->sqlSelectCommand1->Connection = this->sqlConnection1;
			this->sqlSelectCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@读者编号", System::Data::SqlDbType::VarChar, 40, S"读者编号"));
			this->sqlSelectCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@图书编号", System::Data::SqlDbType::VarChar, 50, S"图书编号"));
			this->sqlSelectCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@读者姓名", System::Data::SqlDbType::VarChar, 20, S"姓名"));
			// 
			// sqlConnection1
			// 
			this->sqlConnection1->ConnectionString = S"workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" 
				S"g=libbook;persist security info=False";
			// 
			// OverDueBook
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(760, 429);
			this->Controls->Add(this->dgrdBooks);
			this->Controls->Add(this->groupBox1);
			this->Name = S"OverDueBook";
			this->Text = S"逾期清单";
			this->groupBox1->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdBooks))->EndInit();
			this->ResumeLayout(false);

		}		
	private:		
		//-----------------------设置表格各列的属性-----------------------
		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 btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 String* strBookID = this->tBoxBookID->Text->Trim();
			 String* strReaderID = this->tBoxReaderID->Text->Trim();
			 String* strReaderName = this->tBoxReaderName->Text->Trim();
			 //填写参数
			 this->BookReturnAdapter->SelectCommand->Parameters->Item[S"@图书编号"]->Value = String::Format(S"%{0}%",strBookID);
			 this->BookReturnAdapter->SelectCommand->Parameters->Item[S"@读者编号"]->Value = String::Format(S"%{0}%",strReaderID);
			 this->BookReturnAdapter->SelectCommand->Parameters->Item[S"@读者姓名"]->Value = String::Format(S"%{0}%",strReaderName);
			 //更新数据集
			 this->ds->Tables->Item[S"图书借阅"]->Clear();
			 this->BookReturnAdapter->Fill(this->ds,S"图书借阅");
		 }	
};
}

⌨️ 快捷键说明

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