📄 gasqueryform.h
字号:
this->费用类型ComboBox->Size = System::Drawing::Size(81, 20);
this->费用类型ComboBox->TabIndex = 40;
this->费用类型ComboBox->Text = L"全部";
//
// 费用类型Label
//
this->费用类型Label->AutoSize = true;
this->费用类型Label->Location = System::Drawing::Point(312, 13);
this->费用类型Label->Name = L"费用类型Label";
this->费用类型Label->Size = System::Drawing::Size(65, 12);
this->费用类型Label->TabIndex = 39;
this->费用类型Label->Text = L"费用类型:";
//
// 计费月份ComboBox
//
this->计费月份ComboBox->FormattingEnabled = true;
this->计费月份ComboBox->Location = System::Drawing::Point(231, 8);
this->计费月份ComboBox->Name = L"计费月份ComboBox";
this->计费月份ComboBox->Size = System::Drawing::Size(75, 20);
this->计费月份ComboBox->TabIndex = 38;
this->计费月份ComboBox->Text = L"全年";
//
// 计费月份Label
//
this->计费月份Label->AutoSize = true;
this->计费月份Label->Location = System::Drawing::Point(163, 13);
this->计费月份Label->Name = L"计费月份Label";
this->计费月份Label->Size = System::Drawing::Size(65, 12);
this->计费月份Label->TabIndex = 37;
this->计费月份Label->Text = L"计费月份:";
//
// 计费年份ComboBox
//
this->计费年份ComboBox->FormattingEnabled = true;
this->计费年份ComboBox->Location = System::Drawing::Point(74, 8);
this->计费年份ComboBox->Name = L"计费年份ComboBox";
this->计费年份ComboBox->Size = System::Drawing::Size(81, 20);
this->计费年份ComboBox->TabIndex = 36;
this->计费年份ComboBox->Text = L"2006";
//
// 计费年份Label
//
this->计费年份Label->AutoSize = true;
this->计费年份Label->Location = System::Drawing::Point(9, 13);
this->计费年份Label->Name = L"计费年份Label";
this->计费年份Label->Size = System::Drawing::Size(65, 12);
this->计费年份Label->TabIndex = 35;
this->计费年份Label->Text = L"计费年份:";
//
// GasQueryForm
//
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->水电气费DataGridView);
this->Controls->Add(this->打印Button);
this->Controls->Add(this->费用状态ComboBox);
this->Controls->Add(this->费用状态Label);
this->Controls->Add(this->业主姓名ComboBox);
this->Controls->Add(this->业主姓名Label);
this->Controls->Add(this->楼栋名称ComboBox);
this->Controls->Add(this->楼栋名称Label);
this->Controls->Add(this->查询Button);
this->Controls->Add(this->费用类型ComboBox);
this->Controls->Add(this->费用类型Label);
this->Controls->Add(this->计费月份ComboBox);
this->Controls->Add(this->计费月份Label);
this->Controls->Add(this->计费年份ComboBox);
this->Controls->Add(this->计费年份Label);
this->Name = L"GasQueryForm";
this->ShowInTaskbar = false;
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
this->Text = L"费用管理[水电气费查询]";
this->Load += gcnew System::EventHandler(this, &GasQueryForm::GasQueryForm_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->水电气费DataGridView))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
public: String^ MyCommunity;
public:String^ MySQLConnectionString;
private: System::Data::DataTable^ MyTable;
private: System::Void GasQueryForm_Load(System::Object^ sender, System::EventArgs^ e)
{
for (int i = 2006; i <= 2030; i++)
{
this->计费年份ComboBox->Items->Add(i.ToString());
}
this->计费月份ComboBox->Items->Add("全年");
for (int i = 1; i <= 12; i++)
{
this->计费月份ComboBox->Items->Add(i.ToString());
}
this->费用类型ComboBox->Items->Add("全部");
this->费用类型ComboBox->Items->Add("水费");
this->费用类型ComboBox->Items->Add("电费");
this->费用类型ComboBox->Items->Add("气费");
this->楼栋名称ComboBox->Items->Add("全部");
String^ MySQL = "SELECT * FROM [楼栋信息]";
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
System::Data::DataTable^ ItemTable = gcnew System::Data::DataTable();
SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
MyAdapter->Fill(ItemTable);
for each (System::Data::DataRow^ MyRow in ItemTable->Rows)
{
this->楼栋名称ComboBox->Items->Add(MyRow["楼栋名称"]->ToString());
}
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
this->业主姓名ComboBox->Items->Add("全部");
this->费用状态ComboBox->Items->Add("全部");
this->费用状态ComboBox->Items->Add("已交费");
this->费用状态ComboBox->Items->Add("未交费");
}
private: System::Void 查询Button_Click(System::Object^ sender, System::EventArgs^ e)
{//查询水电气信息
MyTable = gcnew System::Data::DataTable();
String^ MySQL = "Select * FROM 水电气费 WHERE (登记标志='完成登记') AND (计费年份= " + this->计费年份ComboBox->Text + ")";
if (this->计费月份ComboBox->Text == "全年")
MySQL += "";
else
MySQL += " AND (计费月份=" + this->计费月份ComboBox->Text + ")";
if (this->费用类型ComboBox->Text == "全部")
MySQL += "";
else
MySQL += " AND (费用类型='" + this->费用类型ComboBox->Text + "')";
if (this->楼栋名称ComboBox->Text == "全部")
MySQL += "";
else
MySQL += " AND (楼栋名称='" + this->楼栋名称ComboBox->Text + "')";
if (this->业主姓名ComboBox->Text == "全部")
MySQL += "";
else
MySQL += " AND (业主姓名='" + this->业主姓名ComboBox->Text + "')";
if (this->费用状态ComboBox->Text == "全部")
MySQL += "";
else
MySQL += " AND (费用状态='" + this->费用状态ComboBox->Text + "')";
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
SqlDataAdapter^ MyAdatper = gcnew SqlDataAdapter(MySQL, MyConnection);
MyAdatper->Fill(MyTable);
this->水电气费DataGridView->DataSource = MyTable;
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
}
private: System::Void 打印Button_Click(System::Object^ sender, System::EventArgs^ e)
{//打印水电气信息
ApplicationClass^ MyExcel;
Workbooks^ MyWorkBooks;
Workbook^ MyWorkBook;
Worksheet^ MyWorkSheet;
char MyColumns;
int Count,i,j;
Range^ MyRange;
array<System::Object^,2>^ MyData=gcnew array<System::Object^,2>(5000,30);
MyExcel = gcnew ApplicationClass();
MyExcel->Visible = true;
if (MyExcel == nullptr)
{
MessageBox::Show("Excel程序无法启动!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
return;
}
MyWorkBooks = MyExcel->Workbooks;
MyWorkBook = MyWorkBooks->Add(Missing::Value);
MyWorkSheet = (Worksheet^)MyWorkBook->Worksheets[1];
MyColumns = (char)(MyTable->Columns->Count + 64);
array<System::Byte>^ MyBytes =gcnew array<System::Byte> {MyColumns};
System::Text::UTF8Encoding^ MyEncoding=gcnew System::Text::UTF8Encoding();
MyRange = MyWorkSheet->Range["A5", MyEncoding->GetString(MyBytes) + "5"];
Count = 0;
for each (DataColumn^ MyNewColumn in MyTable->Columns)
{
MyData[0, Count] = MyNewColumn->ColumnName;
Count = Count + 1;
}
j = 1;
//输出数据库记录
for each (DataRow^ MyRow in MyTable->Rows)
{
for (i = 0; i < MyTable->Columns->Count; i++)
{
MyData[j, i] = MyRow[i]->ToString();
}
j++;
}
MyRange = MyRange->Resize[MyTable->Rows->Count + 1, MyTable->Columns->Count];
MyRange->Value2 = MyData;
MyRange->EntireColumn->AutoFit();
MyWorkSheet->Cells[2, 2] = this->MyCommunity+ "水电气费信息表";
Range^ MyRange22 = MyWorkSheet->Range["B2", "B2"];
MyRange22->Font->Bold = true;
MyRange22->Font->Size = "20";
MyWorkSheet->Cells[4, 1] = "打印日期:" + DateTime::Now.ToShortDateString();
}
private: System::Void 楼栋名称ComboBox_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
this->业主姓名ComboBox->Items->Clear();
this->业主姓名ComboBox->Items->Add("全部");
String^ MySQL = "SELECT * FROM [业主信息] WHERE ([楼栋名称] ='" + this->楼栋名称ComboBox->Text+ "')";
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
System::Data::DataTable^ ItemTable = gcnew System::Data::DataTable();
SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
MyAdapter->Fill(ItemTable);
for each (System::Data::DataRow^ MyRow in ItemTable->Rows)
{
this->业主姓名ComboBox->Items->Add(MyRow["业主姓名"]->ToString());
}
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -