📄 cinstorequery.h
字号:
this->QueryField->FormattingEnabled = true;
this->QueryField->Items->AddRange(gcnew cli::array< System::Object^ >(4) {L"图书名称", L"作者", L"条形码", L"出版社"});
this->QueryField->Location = System::Drawing::Point(100, 23);
this->QueryField->Name = L"QueryField";
this->QueryField->Size = System::Drawing::Size(113, 20);
this->QueryField->TabIndex = 5;
this->QueryField->SelectedIndexChanged += gcnew System::EventHandler(this, &CInStoreQuery::QueryField_SelectedIndexChanged);
//
// CheckField
//
this->CheckField->AutoSize = true;
this->CheckField->Location = System::Drawing::Point(24, 25);
this->CheckField->Name = L"CheckField";
this->CheckField->Size = System::Drawing::Size(72, 16);
this->CheckField->TabIndex = 4;
this->CheckField->Text = L"查询字段";
this->CheckField->UseVisualStyleBackColor = true;
//
// DataList
//
this->DataList->AutoSizeColumnsMode = System::Windows::Forms::DataGridViewAutoSizeColumnsMode::Fill;
this->DataList->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->DataList->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(7) {this->BookName, this->Barcode,
this->BookAuthor, this->Num, this->Rebate, this->Price, this->SumMoney});
this->DataList->Location = System::Drawing::Point(12, 139);
this->DataList->Name = L"DataList";
this->DataList->RowHeadersVisible = false;
this->DataList->RowTemplate->DefaultCellStyle->SelectionBackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)),
static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(192)));
this->DataList->RowTemplate->DefaultCellStyle->SelectionForeColor = System::Drawing::Color::Red;
this->DataList->RowTemplate->Height = 20;
this->DataList->RowTemplate->ReadOnly = true;
this->DataList->SelectionMode = System::Windows::Forms::DataGridViewSelectionMode::FullRowSelect;
this->DataList->Size = System::Drawing::Size(835, 413);
this->DataList->TabIndex = 4;
//
// BookName
//
this->BookName->DataPropertyName = L"BookName";
this->BookName->HeaderText = L"图书名称";
this->BookName->Name = L"BookName";
this->BookName->ReadOnly = true;
//
// Barcode
//
this->Barcode->DataPropertyName = L"Barcode";
this->Barcode->HeaderText = L"条形码";
this->Barcode->Name = L"Barcode";
this->Barcode->ReadOnly = true;
//
// BookAuthor
//
this->BookAuthor->DataPropertyName = L"BookAuthor";
this->BookAuthor->HeaderText = L"作者";
this->BookAuthor->Name = L"BookAuthor";
this->BookAuthor->ReadOnly = true;
//
// Num
//
this->Num->DataPropertyName = L"Num";
this->Num->HeaderText = L"数量";
this->Num->Name = L"Num";
this->Num->ReadOnly = true;
//
// Rebate
//
this->Rebate->DataPropertyName = L"Rebate";
this->Rebate->HeaderText = L"折扣";
this->Rebate->Name = L"Rebate";
this->Rebate->ReadOnly = true;
//
// Price
//
this->Price->DataPropertyName = L"Price";
this->Price->HeaderText = L"价格";
this->Price->Name = L"Price";
this->Price->ReadOnly = true;
//
// SumMoney
//
this->SumMoney->DataPropertyName = L"NumMoney";
this->SumMoney->HeaderText = L"小计";
this->SumMoney->Name = L"SumMoney";
this->SumMoney->ReadOnly = true;
//
// CInStoreQuery
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(861, 564);
this->Controls->Add(this->DataList);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->label1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MaximizeBox = false;
this->Name = L"CInStoreQuery";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"图书入库查询";
this->Load += gcnew System::EventHandler(this, &CInStoreQuery::CInStoreQuery_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->DataList))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->BandDataSource))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
//查询按钮单击事件
private: System::Void ButtonQuery_Click(System::Object^ sender, System::EventArgs^ e)
{
String^ sql;
if (!CheckField->Checked && !CheckTimeQuery->Checked)
{
MessageBox::Show("请设置查询条件");
return;
}
else if (CheckField->Checked && ! CheckTimeQuery->Checked) //按字段查询
{
if (FieldName=="" || FieldValue->Text->Trim()=="")
{
MessageBox::Show("查询条件不能为空");
return;
}
sql = String::Format("select a.BookName,a.barcode,a.Bookauthor,b.Num,b.Rebate ,b.price,b.NumMoney from BookInfo a inner join InStoreDetail b on a.BookName = b.Bookname and a."+FieldName +" = '{0}'",FieldValue->Text->Trim());
}
else if (!CheckField->Checked && CheckTimeQuery->Checked) //按时间段查询
{
DateTime end_time = EndTime->Value;
end_time = end_time.AddDays(1);
sql = String::Format("select a.BookName,a.barcode,a.Bookauthor,b.Num,b.Rebate , \
b.price, b.NumMoney from BookInfo a inner join InStoreDetail b \
on a.BookName = b.Bookname and b.BookName in (select d.bookname from InStoreDetail d \
inner join InStoreMain c on d.InStoreID = c.InStoreID and \
c.InDate > = '{0}' and c.Indate < '{1}')",StartTime->Value.Date,end_time.Date);
}
else //按时间段和字段查询
{
if (FieldName=="" || FieldValue->Text->Trim()=="")
{
MessageBox::Show("查询条件不能为空");
return;
}
DateTime end_time = EndTime->Value;
end_time = end_time.AddDays(1);
sql = String::Format("select a.BookName,a.barcode,a.Bookauthor,b.Num,b.Rebate , \
b.price, b.NumMoney from BookInfo a inner join InStoreDetail b \
on a.BookName = b.Bookname and a."+FieldName +" = '{0}' \
and b.BookName in (select d.bookname from InStoreDetail d \
inner join InStoreMain c on d.InStoreID = c.InStoreID and \
c.InDate > = '{1}' and c.Indate < '{2}')",FieldValue->Text->Trim(),StartTime->Value.Date,end_time.Date);
}
SqlDataAdapter^ dataAdapter = gcnew SqlDataAdapter(sql,DataManage.Connection);
DataTable^ dataset = gcnew DataTable();
dataAdapter->Fill(dataset);
if (dataset->Rows->Count>0)
{
DataList->DataSource =dataset;
}
else
{
DataList->DataSource = nullptr;
MessageBox::Show("没有发现符合条件的数据");
}
}
private: System::Void CInStoreQuery_Load(System::Object^ sender, System::EventArgs^ e) {
DataManage.ConStr ="Data Source=.;Initial Catalog=BookManage;User ID=sa";
DataManage.ConnectDataBase();
DataList->AutoGenerateColumns = false;
}
private: System::Void QueryField_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
switch (QueryField->SelectedIndex)
{
case 0:
FieldName = "Bookname";
break;
case 1:
FieldName = "BookAuthor";
break;
case 2:
FieldName = "Barcode";
break;
case 3:
FieldName = "BookConcern";
break;
default:
FieldName = "";
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -