📄 coutstorequery.h
字号:
this->ButtonQuery->Name = L"ButtonQuery";
this->ButtonQuery->Size = System::Drawing::Size(71, 21);
this->ButtonQuery->TabIndex = 11;
this->ButtonQuery->Text = L"查询";
this->ButtonQuery->UseVisualStyleBackColor = true;
this->ButtonQuery->Click += gcnew System::EventHandler(this, &COutStoreQuery::ButtonQuery_Click);
//
// EndTime
//
this->EndTime->Location = System::Drawing::Point(635, 21);
this->EndTime->Name = L"EndTime";
this->EndTime->Size = System::Drawing::Size(107, 21);
this->EndTime->TabIndex = 10;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(612, 27);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(17, 12);
this->label2->TabIndex = 9;
this->label2->Text = L"到";
//
// StartTime
//
this->StartTime->Location = System::Drawing::Point(499, 22);
this->StartTime->Name = L"StartTime";
this->StartTime->Size = System::Drawing::Size(107, 21);
this->StartTime->TabIndex = 8;
//
// FieldValue
//
this->FieldValue->Location = System::Drawing::Point(229, 24);
this->FieldValue->Name = L"FieldValue";
this->FieldValue->Size = System::Drawing::Size(163, 21);
this->FieldValue->TabIndex = 7;
//
// CheckTimeQuery
//
this->CheckTimeQuery->AutoSize = true;
this->CheckTimeQuery->Location = System::Drawing::Point(412, 26);
this->CheckTimeQuery->Name = L"CheckTimeQuery";
this->CheckTimeQuery->Size = System::Drawing::Size(84, 16);
this->CheckTimeQuery->TabIndex = 6;
this->CheckTimeQuery->Text = L"时间段查询";
this->CheckTimeQuery->UseVisualStyleBackColor = true;
//
// QueryField
//
this->QueryField->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->QueryField->FormattingEnabled = true;
this->QueryField->Items->AddRange(gcnew cli::array< System::Object^ >(4) {L"图书名称", L"作者", L"条形码", L"出版社"});
this->QueryField->Location = System::Drawing::Point(106, 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, &COutStoreQuery::QueryField_SelectedIndexChanged);
//
// CheckField
//
this->CheckField->AutoSize = true;
this->CheckField->Location = System::Drawing::Point(30, 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;
//
// label1
//
this->label1->AutoSize = true;
this->label1->BackColor = System::Drawing::Color::Transparent;
this->label1->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
this->label1->Font = (gcnew System::Drawing::Font(L"隶书", 21.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(134)));
this->label1->ForeColor = System::Drawing::Color::Red;
this->label1->Location = System::Drawing::Point(316, 18);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(199, 29);
this->label1->TabIndex = 5;
this->label1->Text = L"图书出库查询";
//
// COutStoreQuery
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(888, 570);
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"COutStoreQuery";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"图书出库查询";
this->Load += gcnew System::EventHandler(this, &COutStoreQuery::COutStoreQuery_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->DataList))->EndInit();
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->BandDataSource))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void COutStoreQuery_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 = "";
}
}
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 OutStoreDetail 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 OutStoreDetail b \
on a.BookName = b.Bookname and b.BookName in (select d.bookname from OutStoreDetail d \
inner join OutStoreMain c on d.OutID = c.OutID and \
c.OutDate > = '{0}' and c.Outdate < '{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 OutStoreDetail b \
on a.BookName = b.Bookname and a."+FieldName +" = '{0}' \
and b.BookName in (select d.bookname from OutStoreDetail d \
inner join OutStoreMain c on d.OutID = c.OutID and \
c.OutDate > = '{1}' and c.OutDate < '{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("没有发现符合条件的数据");
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -