📄 bookborrow.h
字号:
//
this->label3->Location = System::Drawing::Point(472, 16);
this->label3->Name = S"label3";
this->label3->Size = System::Drawing::Size(168, 11);
this->label3->TabIndex = 48;
this->label3->Text = S"本次借书";
//
// groupBox3
//
this->groupBox3->Controls->Add(this->cmbBook);
this->groupBox3->Controls->Add(this->tBoxSelectBook);
this->groupBox3->Controls->Add(this->label19);
this->groupBox3->Controls->Add(this->tBoxBookName);
this->groupBox3->Controls->Add(this->label17);
this->groupBox3->Dock = System::Windows::Forms::DockStyle::Top;
this->groupBox3->Location = System::Drawing::Point(0, 120);
this->groupBox3->Name = S"groupBox3";
this->groupBox3->Size = System::Drawing::Size(760, 88);
this->groupBox3->TabIndex = 4;
this->groupBox3->TabStop = false;
//
// cmbBook
//
System::Object* __mcTemp__3[] = new System::Object*[2];
__mcTemp__3[0] = S"编号";
__mcTemp__3[1] = S"条形码";
this->cmbBook->Items->AddRange(__mcTemp__3);
this->cmbBook->Location = System::Drawing::Point(152, 48);
this->cmbBook->Name = S"cmbBook";
this->cmbBook->Size = System::Drawing::Size(88, 20);
this->cmbBook->TabIndex = 10;
this->cmbBook->Text = S"请选择查询";
//
// tBoxSelectBook
//
this->tBoxSelectBook->Location = System::Drawing::Point(24, 48);
this->tBoxSelectBook->Name = S"tBoxSelectBook";
this->tBoxSelectBook->Size = System::Drawing::Size(120, 21);
this->tBoxSelectBook->TabIndex = 9;
this->tBoxSelectBook->Text = S"";
this->tBoxSelectBook->KeyUp += new System::Windows::Forms::KeyEventHandler(this, tBoxSelectBook_KeyUp);
//
// label19
//
this->label19->Location = System::Drawing::Point(24, 24);
this->label19->Name = S"label19";
this->label19->Size = System::Drawing::Size(120, 11);
this->label19->TabIndex = 8;
this->label19->Text = S"输入后回车选择图书";
//
// tBoxBookName
//
this->tBoxBookName->Location = System::Drawing::Point(248, 48);
this->tBoxBookName->Name = S"tBoxBookName";
this->tBoxBookName->ReadOnly = true;
this->tBoxBookName->Size = System::Drawing::Size(120, 21);
this->tBoxBookName->TabIndex = 6;
this->tBoxBookName->Text = S"";
//
// label17
//
this->label17->Location = System::Drawing::Point(248, 24);
this->label17->Name = S"label17";
this->label17->Size = System::Drawing::Size(56, 11);
this->label17->TabIndex = 5;
this->label17->Text = S"书名";
//
// BookBorrowAdapter
//
this->BookBorrowAdapter->DeleteCommand = this->DeleteSqlCmd;
this->BookBorrowAdapter->InsertCommand = this->InsertSqlCmd;
this->BookBorrowAdapter->SelectCommand = this->sqlSelectCommand1;
System::Data::Common::DataTableMapping* __mcTemp__4[] = new System::Data::Common::DataTableMapping*[1];
System::Data::Common::DataColumnMapping* __mcTemp__5[] = new System::Data::Common::DataColumnMapping*[7];
__mcTemp__5[0] = new System::Data::Common::DataColumnMapping(S"图书编号", S"图书编号");
__mcTemp__5[1] = new System::Data::Common::DataColumnMapping(S"书名", S"书名");
__mcTemp__5[2] = new System::Data::Common::DataColumnMapping(S"出版社", S"出版社");
__mcTemp__5[3] = new System::Data::Common::DataColumnMapping(S"价格", S"价格");
__mcTemp__5[4] = new System::Data::Common::DataColumnMapping(S"借阅时间", S"借阅时间");
__mcTemp__5[5] = new System::Data::Common::DataColumnMapping(S"应还时间", S"应还时间");
__mcTemp__5[6] = new System::Data::Common::DataColumnMapping(S"状态", S"状态");
__mcTemp__4[0] = new System::Data::Common::DataTableMapping(S"Table", S"图书借阅", __mcTemp__5);
this->BookBorrowAdapter->TableMappings->AddRange(__mcTemp__4);
this->BookBorrowAdapter->RowUpdating += new System::Data::SqlClient::SqlRowUpdatingEventHandler(this, BookBorrowAdapter_RowUpdating);
//
// DeleteSqlCmd
//
this->DeleteSqlCmd->CommandText = S"DELETE FROM 图书借阅 WHERE (图书编号 = @图书编号) AND (读者编号 = @读者编号)";
this->DeleteSqlCmd->Connection = this->sqlConnection1;
this->DeleteSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@图书编号", System::Data::SqlDbType::VarChar, 50, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"图书编号", System::Data::DataRowVersion::Original, 0));
this->DeleteSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@读者编号", System::Data::SqlDbType::VarChar, 40, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"读者编号", System::Data::DataRowVersion::Original, 0));
//
// sqlConnection1
//
this->sqlConnection1->ConnectionString = S"workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo"
S"g=libbook;persist security info=False";
//
// InsertSqlCmd
//
this->InsertSqlCmd->CommandText = S"INSERT INTO 图书借阅 (图书编号, 读者编号, 借阅时间, 应还时间, 状态) VALUES (@图书编号, @读者编号, @借阅时间, @应还时间,"
S" @状态)";
this->InsertSqlCmd->Connection = this->sqlConnection1;
this->InsertSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@图书编号", System::Data::SqlDbType::VarChar, 50, S"图书编号"));
this->InsertSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@读者编号", System::Data::SqlDbType::VarChar, 40, S"读者编号"));
this->InsertSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@借阅时间", System::Data::SqlDbType::DateTime, 4, S"借阅时间"));
this->InsertSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@应还时间", System::Data::SqlDbType::DateTime, 4, S"应还时间"));
this->InsertSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@状态", System::Data::SqlDbType::VarChar, 10, S"状态"));
//
// sqlSelectCommand1
//
this->sqlSelectCommand1->CommandText = S"SELECT 图书借阅.图书编号, 图书信息.书名, 图书信息.出版社, 图书信息.价格, 图书借阅.借阅时间, 图书借阅.应还时间, 图书借阅.状态 FROM "
S"图书借阅 INNER JOIN 图书信息 ON 图书借阅.图书编号 = 图书信息.编号 WHERE (图书借阅.状态 = \'未还\') AND (图书借阅.读者编"
S"号 = @读者编号)";
this->sqlSelectCommand1->Connection = this->sqlConnection1;
this->sqlSelectCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@读者编号", System::Data::SqlDbType::VarChar, 40, S"读者编号"));
//
// BookBorrow
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(760, 429);
this->Controls->Add(this->dgrdBooks);
this->Controls->Add(this->groupBox3);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->toolBar1);
this->Name = S"BookBorrow";
this->Text = S"图书借阅";
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdBooks))->EndInit();
this->groupBox2->ResumeLayout(false);
this->groupBox3->ResumeLayout(false);
this->ResumeLayout(false);
}
//-----------------------设置表格各列的属性-----------------------
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)
{
if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
{
this->BookBorrowAdapter->Update(this->ds->GetChanges(),S"图书借阅");
//this->BookAdapter->Update(this->ds->GetChanges(),S"图书信息");
this->ds->AcceptChanges();
String* tempSQL = S"exec sf_图书借阅";
this->MyDataBase->SQLOperate(tempSQL);
if(this->ds->Tables->Count == 3)
{
this->ds->Tables->Item[S"图书借阅"]->Clear();
this->BookBorrowAdapter->Fill(this->ds,S"图书借阅");
}
}
else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
{
try
{
this->ds->Tables->Item[S"图书借阅"]->RejectChanges();
}
catch(Exception* e)
{
MessageBox::Show(e->Message,S"提示");
}
}
else if(String::Compare(e->Button->ToolTipText,S"退出") == 0)
{
this->Close();
}
}
//---------设定读者信息-------------
private: System::Void tBoxSelectReader_KeyUp(System::Object * sender, System::Windows::Forms::KeyEventArgs * e)
{
String* Filter;
//如果弹起的不是回车键则返回
if(e->KeyCode != System::Windows::Forms::Keys::Enter)
return;
this->ReaderID = S"";
//查询读者信息
if(this->cmbReader->SelectedIndex != -1)
{
//设置过滤器
Filter = String::Format("{0} = '{1}'",this->cmbReader->Text,this->tBoxSelectReader->Text);
}
else
{
Filter = String::Format("{0} = '{1}'",S"编号",this->tBoxSelectReader->Text);
}
DataRow* rows[] = this->ds->Tables->Item[S"读者信息"]->Select(Filter);
//如果查询不到读者则返回
if(rows->Length <= 0)
return;
//显示读者信息
this->tBoxReaderName->Text = rows[0]->Item[S"姓名"]->ToString()->Trim();
this->tBoxReaderClass->Text = rows[0]->Item[S"类型"]->ToString()->Trim();
this->tBoxBooksCanBorrow->Text = rows[0]->Item[S"图书册书"]->ToString()->Trim();
//查询借阅记录
this->ReaderID = rows[0]->Item[S"编号"]->ToString()->Trim();
this->BookBorrowAdapter->SelectCommand->Parameters->Item[S"@读者编号"]->Value = rows[0]->Item[S"编号"]->ToString()->Trim();
if(this->ds->Tables->Count == 2)
{
//如果数据集中只有“图书信息”和“读者信息”两个表则填入“图书借阅”表
this->BookBorrowAdapter->Fill(this->ds,S"图书借阅");
//设置DataGrid
this->dgrdBooks->DataSource = this->ds->Tables->Item[S"图书借阅"];
this->DataGridStateControl();
}
else
{
//如果数据集中存在“图书借阅”表,则将其刷新
this->ds->Tables->Item[S"图书借阅"]->Clear();
this->BookBorrowAdapter->Fill(this->ds,S"图书借阅");
}
//开始选择图书
this->tBoxSelectBook->Focus();
//设定总借阅数
this->TotalBorrow = this->ds->Tables->Item[S"图书借阅"]->Rows->Count;
this->label26->Text = String::Format(S"已借书:{0}",this->TotalBorrow.ToString());
this->label3->Text = String::Format(S"本次借书:{0}",this->ThisBorrow.ToString());
}
private: System::Void tBoxSelectBook_KeyUp(System::Object * sender, System::Windows::Forms::KeyEventArgs * e)
{
String* Filter;
//如果弹起的不是回车键则返回
if(e->KeyCode != System::Windows::Forms::Keys::Enter)
return;
//如果没有指定读者则不能选择图书
if(String::Compare(this->tBoxReaderName->Text,String::Empty) == 0)
return;
//如果弹起的不是回车键则返回
if(e->KeyCode != System::Windows::Forms::Keys::Enter)
return;
//如果所借图书册数超过允许最大数,则不允许再借
if(this->ds->Tables->Item[S"图书借阅"]->Rows->Count >= System::Convert::ToInt32(this->tBoxBooksCanBorrow->Text->Trim()))
{
MessageBox::Show("已经达到最大借书数量,请先归还图书后再借阅");
return;
}
//如果读者已经结果此书,则不能再借
Filter = String::Format("{0} = '{1}'",S"图书编号",this->tBoxSelectBook->Text);
DataRow* ExsistBook[] = this->ds->Tables->Item[S"图书借阅"]->Select(Filter);
if(ExsistBook->Length > 0)
{
MessageBox::Show("读者已借此书");
return;
}
//查询图书信息
if(this->cmbReader->SelectedIndex != -1)
{
//设置过滤器
Filter = String::Format("{0} = '{1}'",this->cmbBook->Text,this->tBoxSelectBook->Text);
}
else
{
Filter = String::Format("{0} = '{1}'",S"编号",this->tBoxSelectBook->Text);
}
DataRow* rows[] = this->ds->Tables->Item[S"图书信息"]->Select(Filter);
//如果查询不到图书则返回
if(rows->Length <= 0)
return;
//新建借阅记录
DataRow* row = this->ds->Tables->Item[S"图书借阅"]->NewRow();
row->Item[S"图书编号"] = rows[0]->Item[S"编号"];
row->Item[S"书名"] = rows[0]->Item[S"书名"];
row->Item[S"出版社"] = rows[0]->Item[S"出版社"];
row->Item[S"价格"] = rows[0]->Item[S"价格"];
row->Item[S"状态"] = S"等待借出";
row->Item[S"借阅时间"] = System::DateTime::Now.ToString()->Trim();
row->Item[S"应还时间"] = System::DateTime::Now.AddDays(System::Convert::ToDouble(rows[0]->Item[S"可借天数"])).ToString();
this->ds->Tables->Item[S"图书借阅"]->Rows->Add(row);
//更新借出次数
rows[0]->Item[S"借出次数"] = __box(System::Convert::ToInt32(rows[0]->Item[S"借出次数"]) + 1);
//增加借阅计数
this->TotalBorrow++;
this->ThisBorrow++;
this->label26->Text = String::Format(S"已借书:{0}",this->TotalBorrow.ToString());
this->label3->Text = String::Format(S"本次借书:{0}",this->ThisBorrow.ToString());
}
private: System::Void BookBorrowAdapter_RowUpdating(System::Object * sender, System::Data::SqlClient::SqlRowUpdatingEventArgs * e)
{
if(e->StatementType == StatementType::Insert)
{
e->Command->Parameters->Item[S"@读者编号"]->Value = this->tBoxSelectReader->Text;
e->Command->Parameters->Item[S"@状态"]->Value = S"新借";
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -