📄 bookreturnform.h
字号:
this->挂失Button->UseVisualStyleBackColor = true;
this->挂失Button->Click += gcnew System::EventHandler(this, &BookReturnForm::挂失Button_Click);
//
// 归还Button
//
this->归还Button->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"归还Button.Image")));
this->归还Button->Location = System::Drawing::Point(466, 34);
this->归还Button->Name = L"归还Button";
this->归还Button->Size = System::Drawing::Size(70, 23);
this->归还Button->TabIndex = 33;
this->归还Button->Text = L"归还";
this->归还Button->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
this->归还Button->TextImageRelation = System::Windows::Forms::TextImageRelation::ImageBeforeText;
this->归还Button->UseVisualStyleBackColor = true;
this->归还Button->Click += gcnew System::EventHandler(this, &BookReturnForm::归还Button_Click);
//
// 查询Button
//
this->查询Button->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"查询Button.Image")));
this->查询Button->Location = System::Drawing::Point(466, 7);
this->查询Button->Name = L"查询Button";
this->查询Button->Size = System::Drawing::Size(70, 23);
this->查询Button->TabIndex = 32;
this->查询Button->Text = L"查询";
this->查询Button->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
this->查询Button->TextImageRelation = System::Windows::Forms::TextImageRelation::ImageBeforeText;
this->查询Button->UseVisualStyleBackColor = true;
this->查询Button->Click += gcnew System::EventHandler(this, &BookReturnForm::查询Button_Click);
//
// 读者姓名TextBox
//
this->读者姓名TextBox->Location = System::Drawing::Point(70, 34);
this->读者姓名TextBox->Name = L"读者姓名TextBox";
this->读者姓名TextBox->ReadOnly = true;
this->读者姓名TextBox->Size = System::Drawing::Size(61, 21);
this->读者姓名TextBox->TabIndex = 31;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(7, 39);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(65, 12);
this->label2->TabIndex = 30;
this->label2->Text = L"读者姓名:";
//
// 读者编号TextBox
//
this->读者编号TextBox->Location = System::Drawing::Point(68, 7);
this->读者编号TextBox->Name = L"读者编号TextBox";
this->读者编号TextBox->Size = System::Drawing::Size(100, 21);
this->读者编号TextBox->TabIndex = 29;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(8, 12);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(65, 12);
this->label1->TabIndex = 28;
this->label1->Text = L"读者编号:";
//
// BookReturnForm
//
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->书号TextBox);
this->Controls->Add(this->label7);
this->Controls->Add(this->书名TextBox);
this->Controls->Add(this->label6);
this->Controls->Add(this->应还日期DateTimePicker);
this->Controls->Add(this->label4);
this->Controls->Add(this->归还日期DateTimePicker);
this->Controls->Add(this->label3);
this->Controls->Add(this->借出日期DateTimePicker);
this->Controls->Add(this->label5);
this->Controls->Add(this->借阅图书DataGridView);
this->Controls->Add(this->挂失Button);
this->Controls->Add(this->归还Button);
this->Controls->Add(this->查询Button);
this->Controls->Add(this->读者姓名TextBox);
this->Controls->Add(this->label2);
this->Controls->Add(this->读者编号TextBox);
this->Controls->Add(this->label1);
this->Name = L"BookReturnForm";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
this->Text = L"图书归还管理";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->借阅图书DataGridView))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: static System::Data::DataTable^ MyBorrowTable = gcnew System::Data::DataTable();
private: static int MyDays = 0;
private: static String^ MyBooksConnectionString= L"Data Source=.;Initial Catalog=MyBooks;Integrated Security=True;Pooling=False";
private: System::Void 查询Button_Click(System::Object^ sender, System::EventArgs^ e) {
if (this->读者编号TextBox->Text->Length < 1)
{
MessageBox::Show("请输入读者编号!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
String^ MySQLConnectionString =MyBooksConnectionString;
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
MyBorrowTable->Rows->Clear();
this->读者姓名TextBox->Text = "";
this->书号TextBox->Text = "";
this->书名TextBox->Text = "";
String^ MySQL = "Select * From 借阅管理 WHERE 应还日期 IS NOT NULL AND 归还日期 IS NULL AND 遗失图书 IS NULL AND 读者编号= '" + this->读者编号TextBox->Text + "'";
SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
MyAdapter->Fill(MyBorrowTable);
if (MyBorrowTable->Rows->Count > 0)
{
this->读者姓名TextBox->Text = MyBorrowTable->Rows[0][2]->ToString();
this->借阅图书DataGridView->DataSource = this->MyBorrowTable;
}
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
}
private: System::Void 借阅图书DataGridView_DoubleClick(System::Object^ sender, System::EventArgs^ e) {
this->书号TextBox->Text = this->借阅图书DataGridView->CurrentRow->Cells[4]->Value->ToString();
this->书名TextBox->Text = this->借阅图书DataGridView->CurrentRow->Cells[5]->Value->ToString();
this->借出日期DateTimePicker->Value = (DateTime)this->借阅图书DataGridView->CurrentRow->Cells[6]->Value;
this->应还日期DateTimePicker->Value = (DateTime)this->借阅图书DataGridView->CurrentRow->Cells[7]->Value;
}
private: System::Void 归还Button_Click(System::Object^ sender, System::EventArgs^ e) {
if (this->读者姓名TextBox->Text->Length < 1)
{
MessageBox::Show("请输入读者编号!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
if (this->书名TextBox->Text->Length < 1)
{
MessageBox::Show("请选择将要归还的图书!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
TimeSpan MySpanReturn = this->归还日期DateTimePicker->Value.Subtract(this->借出日期DateTimePicker->Value);
this->MyDays = MySpanReturn.Days;
if (MySpanReturn.Days <= 0)
{
MessageBox::Show("归还日期不正确!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
TimeSpan MySpanBorrow = this->归还日期DateTimePicker->Value.Subtract(this->应还日期DateTimePicker->Value);
if (MySpanBorrow.Days > 0)
{
String^ MyInfo="超期"+MySpanBorrow.Days.ToString()+"天归还["+this->书名TextBox->Text+"],是否继续执行本操作?";
if(MessageBox::Show(MyInfo, "信息提示", MessageBoxButtons::YesNo , MessageBoxIcon::Question)==System::Windows::Forms::DialogResult::No)
{
return;
}
}
else
{
String^ MyInfo = "是否确定归还[" + this->书名TextBox->Text + "]?";
if(MessageBox::Show(MyInfo, "信息提示", MessageBoxButtons::YesNo , MessageBoxIcon::Question)==System::Windows::Forms::DialogResult::No)
{
return;
}
}
String^ MySQLConnectionString = MyBooksConnectionString;
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
String^ MySQL = "Update 馆藏图书 Set 出借数量=出借数量-1 WHERE 书号='" + this->书号TextBox->Text+ "';";
MySQL += "Update 借阅管理 Set 归还日期='" + this->归还日期DateTimePicker->Value + "' WHERE 图书书号='" + this->书号TextBox->Text + "' AND 读者编号='" + this->读者编号TextBox->Text + "'";
SqlCommand^ MyCommand=MyConnection->CreateCommand();
MyCommand->CommandText = MySQL;
MyCommand->ExecuteNonQuery();
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
查询Button_Click(nullptr, nullptr);
}
private: System::Void 挂失Button_Click(System::Object^ sender, System::EventArgs^ e) {
if (this->读者姓名TextBox->Text->Length < 1)
{
MessageBox::Show("请输入读者编号!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
if (this->书名TextBox->Text->Length < 1)
{
MessageBox::Show("请选择将要挂失的图书!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
String^ MyInfo = "是否确定挂失[" + this->书名TextBox->Text + "]?";
if (MessageBox::Show(MyInfo, "信息提示", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::No)
{
return;
}
String^ MySQLConnectionString = MyBooksConnectionString;
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
String^ MySQL = "Update 馆藏图书 Set 出借数量=出借数量-1,遗失数量=遗失数量+1 WHERE 书号='" + this->书号TextBox->Text + "';";
MySQL += "Update 借阅管理 Set 遗失图书='是' WHERE 图书书号='" + this->书号TextBox->Text + "' AND 读者编号='" + this->读者编号TextBox->Text + "'";
SqlCommand^ MyCommand = MyConnection->CreateCommand();
MyCommand->CommandText = MySQL;
MyCommand->ExecuteNonQuery();
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
查询Button_Click(nullptr, nullptr);
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -