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

📄 bookborrowform.h

📁 vc++开发环境SQL数据库图书租借管理系统
💻 H
📖 第 1 页 / 共 2 页
字号:
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(7, 35);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(65, 12);
			this->label3->TabIndex = 22;
			this->label3->Text = L"借出日期:";
			// 
			// 读者姓名TextBox
			// 
			this->读者姓名TextBox->Location = System::Drawing::Point(233, 3);
			this->读者姓名TextBox->Name = L"读者姓名TextBox";
			this->读者姓名TextBox->ReadOnly = true;
			this->读者姓名TextBox->Size = System::Drawing::Size(79, 21);
			this->读者姓名TextBox->TabIndex = 21;
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(172, 10);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(65, 12);
			this->label2->TabIndex = 20;
			this->label2->Text = L"读者姓名:";
			// 
			// 读者编号TextBox
			// 
			this->读者编号TextBox->Location = System::Drawing::Point(68, 3);
			this->读者编号TextBox->Name = L"读者编号TextBox";
			this->读者编号TextBox->Size = System::Drawing::Size(100, 21);
			this->读者编号TextBox->TabIndex = 19;
			this->读者编号TextBox->Leave += gcnew System::EventHandler(this, &BookBorrowForm::读者编号TextBox_Leave);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(7, 10);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(65, 12);
			this->label1->TabIndex = 18;
			this->label1->Text = L"读者编号:";
			// 
			// BookBorrowForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(542, 416);
			this->Controls->Add(this->借阅图书DataGridView);
			this->Controls->Add(this->保存Button);
			this->Controls->Add(this->应还日期DateTimePicker);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->借出日期DateTimePicker);
			this->Controls->Add(this->会员等级TextBox);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->读者姓名TextBox);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->读者编号TextBox);
			this->Controls->Add(this->label1);
			this->Name = L"BookBorrowForm";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"图书借阅管理";
			this->Load += gcnew System::EventHandler(this, &BookBorrowForm::BookBorrowForm_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->借阅图书DataGridView))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->馆藏图书DataGridView))->EndInit();
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
		private: static int MyDays=0;
		private: static int MyBooks = 0;
		private: static int MyIndex = 0;
		private: static System::Data::DataTable^ MyBorrowTable = gcnew System::Data::DataTable(); 
		private: static String^ MyBooksConnectionString= L"Data Source=.;Initial Catalog=MyBooks;Integrated Security=True;Pooling=False";	
		private: System::Void 读者编号TextBox_Leave(System::Object^  sender, System::EventArgs^  e) {
		    String^ MySQLConnectionString = MyBooksConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
			System::Data::DataTable^ MyReaderTable = gcnew System::Data::DataTable();
            String^ MySQL = "Select 姓名,会员等级 From 有效读者视图 WHERE 编号= '" + this->读者编号TextBox->Text + "'";           
            SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
            MyAdapter->Fill(MyReaderTable);
            if (MyReaderTable->Rows->Count > 0)
            {
                this->读者姓名TextBox->Text = MyReaderTable->Rows[0][0]->ToString();
                this->会员等级TextBox->Text = MyReaderTable->Rows[0][1]->ToString();
				System::Data::DataTable^ MyAssociatorTable = gcnew System::Data::DataTable();
                MySQL = "Select 最长出借天数,最多借书册数 From 会员等级 WHERE 会员等级= '" + this->会员等级TextBox->Text + "'";
                MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
                MyAdapter->Fill(MyAssociatorTable);
                this->MyDays = Convert::ToInt16(MyAssociatorTable->Rows[0][0]->ToString());
                this->MyBooks = Convert::ToInt16(MyAssociatorTable->Rows[0][1]->ToString());
                //获取读者已经借出图书的数量
                MySQL = "Select COUNT(*) From 借阅管理 WHERE 应还日期 IS NOT NULL AND 归还日期 IS NULL AND 遗失图书 IS NULL AND 读者编号= '" + this->读者编号TextBox->Text + "'";
                SqlCommand^ MyCommand = gcnew SqlCommand(MySQL, MyConnection);
                String^ MyCount = MyCommand->ExecuteScalar()->ToString();
                this->MyBooks = this->MyBooks - Convert::ToInt16(MyCount);
                MyIndex = 0;
                this->MyBorrowTable->Rows->Clear();
            }
            else
            {
                this->读者姓名TextBox->Text = "";
                this->会员等级TextBox->Text = "";
            }
            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
		 }
		private: System::Void 查询Button_Click(System::Object^  sender, System::EventArgs^  e) {
            String^ MySQLConnectionString = MyBooksConnectionString;
            String^ MySQL = "Select * From 馆藏图书 WHERE 书名 LIKE '%" + this->书名TextBox->Text + "%' AND 作者 LIKE '%" + this->作者TextBox->Text + "%'AND 出版社 LIKE '%" + this->出版社TextBox->Text + "%' AND 库存数量>0";
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
            System::Data::DataTable^ MyBooksTable = gcnew System::Data::DataTable();
            SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
            MyAdapter->Fill(MyBooksTable);
            this->馆藏图书DataGridView->DataSource = MyBooksTable;
            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
		 }
		private: System::Void 馆藏图书DataGridView_DoubleClick(System::Object^  sender, System::EventArgs^  e) {
			//增加图书
            if (this->读者姓名TextBox->Text->Length < 1)
            {
                MessageBox::Show("请输入读者编号!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
                return;
            }
            if ((MyBooks - MyIndex) == 0)
            {
                MessageBox::Show("借书数量过多!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
                return;
            }
            TimeSpan MySpan = this->应还日期DateTimePicker->Value.Subtract(this->借出日期DateTimePicker->Value);
            if (MyDays < MySpan.Days)
            {
                MessageBox::Show("借书日期过长!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
                return;
            }
            if (MySpan.Days<=0)
            {
                MessageBox::Show("应还日期不正确!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
                return;
            }
            
            DataRow^ MyRow = MyBorrowTable->NewRow();
            //MyRow[0] = MyIndex;
            MyRow["读者编号"] = this->读者编号TextBox->Text;
            MyRow["读者姓名"] = this->读者姓名TextBox->Text;
            MyRow["会员等级"] = this->会员等级TextBox->Text;
            MyRow["借出日期"] = this->借出日期DateTimePicker->Value;
            MyRow["应还日期"] = this->应还日期DateTimePicker->Value;
            MyRow["图书书号"] = this->馆藏图书DataGridView->CurrentRow->Cells[0]->Value->ToString();
            MyRow["图书书名"] = this->馆藏图书DataGridView->CurrentRow->Cells[1]->Value->ToString();
            MyBorrowTable->Rows->Add(MyRow);
            MyIndex = MyIndex + 1;        
		 }
		private: System::Void 借阅图书DataGridView_DoubleClick(System::Object^  sender, System::EventArgs^  e) {
			//减少图书
            MyBorrowTable->Rows->RemoveAt(this->借阅图书DataGridView->CurrentRow->Index);
            MyIndex = MyIndex -1;
		 }
		private: System::Void BookBorrowForm_Load(System::Object^  sender, System::EventArgs^  e) {
			//创建无连接的数据表
		    array<DataColumn^>^MyKey=gcnew array<DataColumn^>(1);            
            MyBorrowTable = gcnew System::Data::DataTable("借阅管理临时表");
            DataColumn^ MyColumn = gcnew DataColumn();
			MyColumn->DataType = System::Type::GetType("System.String");
            MyColumn->ColumnName = "图书书号";
            MyBorrowTable->Columns->Add(MyColumn);
            MyKey[0] = MyColumn;
            MyBorrowTable->PrimaryKey = MyKey;
			MyBorrowTable->Columns->Add("图书书名", System::Type::GetType("System.String"));
            MyBorrowTable->Columns->Add("读者编号", System::Type::GetType("System.String"));
            MyBorrowTable->Columns->Add("读者姓名", System::Type::GetType("System.String"));
            MyBorrowTable->Columns->Add("会员等级", System::Type::GetType("System.String"));
            MyBorrowTable->Columns->Add("借出日期", System::Type::GetType("System.DateTime"));
            MyBorrowTable->Columns->Add("应还日期", System::Type::GetType("System.DateTime"));
            this->借阅图书DataGridView->DataSource = MyBorrowTable;
		 }
		private: System::Void 保存Button_Click(System::Object^  sender, System::EventArgs^  e) {
		    if (MessageBox::Show("请检查读者借阅信息是否正确,一旦保存就无法修改,是否继续?", "信息提示", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::No)
            {
                return;
            }
            String^ MySQLConnectionString =MyBooksConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
            for (int i = 0; i < MyBorrowTable->Rows->Count; i++)
            {
                String^ MySQL = "INSERT INTO 借阅管理(自编号,读者编号,读者姓名,会员等级,图书书号,图书书名,借出日期,应还日期)VALUES(@自编号,@读者编号,@读者姓名,@会员等级,@图书书号,@图书书名,@借出日期,@应还日期)";
                SqlCommand^ MyCommand = MyConnection->CreateCommand();
                MyCommand->CommandText = MySQL;
                MyCommand->Parameters->Add(gcnew SqlParameter("@自编号", SqlDbType::VarChar));
                MyCommand->Parameters->Add(gcnew SqlParameter("@读者编号", SqlDbType::VarChar));
                MyCommand->Parameters->Add(gcnew SqlParameter("@读者姓名", SqlDbType::VarChar));
                MyCommand->Parameters->Add(gcnew SqlParameter("@会员等级", SqlDbType::VarChar));
                MyCommand->Parameters->Add(gcnew SqlParameter("@图书书号", SqlDbType::VarChar));
                MyCommand->Parameters->Add(gcnew SqlParameter("@图书书名", SqlDbType::VarChar));
                MyCommand->Parameters->Add(gcnew SqlParameter("@借出日期", SqlDbType::DateTime));
                MyCommand->Parameters->Add(gcnew SqlParameter("@应还日期", SqlDbType::DateTime));
                MyCommand->Parameters["@自编号"]->Value = GetNewID();
                MyCommand->Parameters["@读者编号"]->Value = MyBorrowTable->Rows[i][2]->ToString();
                MyCommand->Parameters["@读者姓名"]->Value = MyBorrowTable->Rows[i][3]->ToString();
                MyCommand->Parameters["@会员等级"]->Value = MyBorrowTable->Rows[i][4]->ToString();
                MyCommand->Parameters["@图书书号"]->Value = MyBorrowTable->Rows[i][0]->ToString();
                MyCommand->Parameters["@图书书名"]->Value = MyBorrowTable->Rows[i][1]->ToString();
                MyCommand->Parameters["@借出日期"]->Value = MyBorrowTable->Rows[i][5]->ToString();
                MyCommand->Parameters["@应还日期"]->Value = MyBorrowTable->Rows[i][6]->ToString();
                MyCommand->ExecuteNonQuery();
                MySQL = "Update 馆藏图书 Set 出借数量=出借数量+1 WHERE 书号='" + MyBorrowTable->Rows[i][0]->ToString() + "'";
                MyCommand->CommandText = MySQL;
                MyCommand->ExecuteNonQuery();                      
            }
            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
            MyBorrowTable->Rows->Clear();
            查询Button_Click(nullptr, nullptr);
		 }
	   private:String^ GetNewID()
        {
            //自动计算自编号
            String^ MySQLConnectionString =MyBooksConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
            SqlCommand^ MyCommand = MyConnection->CreateCommand();
            MyCommand->CommandText = "Select max(自编号) 最大编号 From 借阅管理";
			System::Object^ MyResult = MyCommand->ExecuteScalar();
			System::Int64 MyID = 1;
			if (MyResult != System::DBNull::Value)
            {
                String^ MyMaxID = MyResult->ToString()->Trim();
                MyMaxID = MyMaxID->Substring(2, MyMaxID->Length - 2);
                MyID = Convert::ToInt64(MyMaxID) + 1;
            }
            int MyLength = MyID.ToString()->Length;
            String^ MyNewID = "";
            switch (MyLength)
            {
                case 1:
                    MyNewID = "JY0000000" + MyID.ToString();
                    break;
                case 2:
                    MyNewID = "JY000000" + MyID.ToString();
                    break;
                case 3:
                    MyNewID = "JY00000" + MyID.ToString();
                    break;
                case 4:
                    MyNewID = "JY0000" + MyID.ToString();
                    break;
                case 5:
                    MyNewID = "JY000" + MyID.ToString();
                    break;
                case 6:
                    MyNewID = "JY00" + MyID.ToString();
                    break;
                case 7:
                    MyNewID = "JY0" + MyID.ToString();
                    break;
            }
            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
            return MyNewID;
        }
	};
}

⌨️ 快捷键说明

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