📄 bookreturn.h
字号:
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 图书借阅 INNER JOIN 图书信息 ON 图书借阅.图书编号 = 图书信息.编号 INN"
S"ER JOIN 读者信息 ON 图书借阅.读者编号 = 读者信息.编号 WHERE (图书借阅.读者编号 LIKE @读者编号) AND (图书借阅.图书编号 "
S"LIKE @图书编号) AND (读者信息.姓名 LIKE @读者姓名) AND (图书借阅.状态 = \'未还\')";
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";
//
// groupBox2
//
this->groupBox2->Controls->Add(this->btnReturn);
this->groupBox2->Dock = System::Windows::Forms::DockStyle::Bottom;
this->groupBox2->Location = System::Drawing::Point(0, 365);
this->groupBox2->Name = S"groupBox2";
this->groupBox2->Size = System::Drawing::Size(760, 64);
this->groupBox2->TabIndex = 3;
this->groupBox2->TabStop = false;
//
// btnReturn
//
this->btnReturn->Location = System::Drawing::Point(224, 17);
this->btnReturn->Name = S"btnReturn";
this->btnReturn->Size = System::Drawing::Size(344, 40);
this->btnReturn->TabIndex = 0;
this->btnReturn->Text = S"还书";
this->btnReturn->Click += new System::EventHandler(this, btnReturn_Click);
//
// BookReturn
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(760, 429);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->dgrdBooks);
this->Controls->Add(this->groupBox1);
this->Name = S"BookReturn";
this->Text = S"图书归还";
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdBooks))->EndInit();
this->groupBox2->ResumeLayout(false);
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"图书借阅");
}
private: System::Void btnReturn_Click(System::Object * sender, System::EventArgs * e)
{
int row = this->dgrdBooks->CurrentCell.RowNumber;
String* BorrowID = this->ds->Tables->Item[S"图书借阅"]->Rows->Item[row]->Item[S"借阅编号"]->ToString();
DateTime DueTime = System::Convert::ToDateTime(this->ds->Tables->Item[S"图书借阅"]->Rows->Item[row]->Item[S"应还时间"]);
Decimal Penalty = 0;
//图书过期处理
if(DueTime < System::DateTime::Now)
{
int OverDays = 365*(System::DateTime::Now.Year - DueTime.Year) + (System::DateTime::Now.DayOfYear - DueTime.DayOfYear);
//计算罚金,本实例中过期一天罚金为0.2元
Penalty = (Decimal)(0.2 * OverDays);
//提示
String* temp = String::Format(S"借阅已过期,罚款{0}元",Penalty.ToString());
MessageBox::Show(temp);
}
//还书
String* tempSQL = String::Format(S"exec sf_图书归还 {0},{1}",BorrowID,Penalty.ToString());
this->MyDataBase->SQLOperate(tempSQL);
//更新数据集
this->ds->Tables->Item[S"图书借阅"]->Clear();
this->BookReturnAdapter->Fill(this->ds,S"图书借阅");
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -