📄 reportownerform.h
字号:
//
// 查询Button
//
this->查询Button->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"查询Button.Image")));
this->查询Button->Location = System::Drawing::Point(467, 6);
this->查询Button->Name = L"查询Button";
this->查询Button->Size = System::Drawing::Size(67, 23);
this->查询Button->TabIndex = 58;
this->查询Button->Text = L"查询";
this->查询Button->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
this->查询Button->TextImageRelation = System::Windows::Forms::TextImageRelation::ImageBeforeText;
this->查询Button->UseVisualStyleBackColor = true;
this->查询Button->Click += gcnew System::EventHandler(this, &ReportOwnerForm::查询Button_Click);
//
// 房屋性质ComboBox
//
this->房屋性质ComboBox->FormattingEnabled = true;
this->房屋性质ComboBox->Location = System::Drawing::Point(380, 8);
this->房屋性质ComboBox->Name = L"房屋性质ComboBox";
this->房屋性质ComboBox->Size = System::Drawing::Size(81, 20);
this->房屋性质ComboBox->TabIndex = 57;
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 = 56;
this->费用类型Label->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 = 55;
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 = 54;
this->楼栋名称ComboBox->Text = L"全部";
//
// 楼栋名称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 = 53;
this->楼栋名称Label->Text = L"楼栋名称:";
//
// ReportOwnerForm
//
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->常住人员TextBox);
this->Controls->Add(this->房屋类型TextBox);
this->Controls->Add(this->单元名称TextBox);
this->Controls->Add(this->业主报表DataGridView);
this->Controls->Add(this->打印Button);
this->Controls->Add(this->当前状态ComboBox);
this->Controls->Add(this->当前状态Label);
this->Controls->Add(this->常住人员Label);
this->Controls->Add(this->房屋类型Label);
this->Controls->Add(this->查询Button);
this->Controls->Add(this->房屋性质ComboBox);
this->Controls->Add(this->费用类型Label);
this->Controls->Add(this->单元名称Label);
this->Controls->Add(this->楼栋名称ComboBox);
this->Controls->Add(this->楼栋名称Label);
this->Name = L"ReportOwnerForm";
this->ShowInTaskbar = false;
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
this->Text = L"报表管理[业主统计报表]";
this->Load += gcnew System::EventHandler(this, &ReportOwnerForm::ReportOwnerForm_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 ReportOwnerForm_Load(System::Object^ sender, System::EventArgs^ e)
{
MyTable = gcnew System::Data::DataTable();
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 (业主编号 NOT IN (Select 业主编号 FROM 迁出信息)) ";
if (this->楼栋名称ComboBox->Text == "全部")
MySQL += "";
else
MySQL += " AND (楼栋名称='" + this->楼栋名称ComboBox->Text + "')";
MySQL += " AND (单元名称 LIKE '%" + this->单元名称TextBox->Text + "%')";
if (this->房屋性质ComboBox->Text == "全部")
MySQL += "";
else
MySQL += " AND (房屋性质='" + this->房屋性质ComboBox->Text + "')";
MySQL += " AND (房屋类型 LIKE '%" + this->房屋类型TextBox->Text + "%')";
MySQL += " AND (常住人员 LIKE '%" + this->常住人员TextBox->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++)
{
if(i==12)
{
MyData[j, i] =DateTime::Parse( MyRow[i]->ToString()).ToShortDateString();
}
else
{
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();
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -