📄 printregisterform.h
字号:
//文件名:PrintRegisterForm.h
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Data::SqlClient;
using namespace Microsoft::Office::Interop::Excel;
using namespace System::Reflection;
namespace 宾馆酒店管理系统 {
/// <summary>
/// PrintRegisterForm 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class PrintRegisterForm : public System::Windows::Forms::Form
{
public:
PrintRegisterForm(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~PrintRegisterForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ 打印Button;
protected:
private: System::Windows::Forms::Button^ 查询Button;
private: System::Windows::Forms::DataGridView^ 客房入住DataGridView;
private: System::Windows::Forms::DateTimePicker^ 开始日期DateTimePicker;
private: System::Windows::Forms::DateTimePicker^ 结束日期DateTimePicker;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(PrintRegisterForm::typeid));
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle1 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::Label^ 开始日期Label;
System::Windows::Forms::Label^ 结束日期Label;
this->打印Button = (gcnew System::Windows::Forms::Button());
this->查询Button = (gcnew System::Windows::Forms::Button());
this->客房入住DataGridView = (gcnew System::Windows::Forms::DataGridView());
this->开始日期DateTimePicker = (gcnew System::Windows::Forms::DateTimePicker());
this->结束日期DateTimePicker = (gcnew System::Windows::Forms::DateTimePicker());
开始日期Label = (gcnew System::Windows::Forms::Label());
结束日期Label = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->客房入住DataGridView))->BeginInit();
this->SuspendLayout();
//
// 打印Button
//
this->打印Button->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"打印Button.Image")));
this->打印Button->Location = System::Drawing::Point(459, 3);
this->打印Button->Name = L"打印Button";
this->打印Button->Size = System::Drawing::Size(80, 25);
this->打印Button->TabIndex = 80;
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, &PrintRegisterForm::打印Button_Click);
//
// 查询Button
//
this->查询Button->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"查询Button.Image")));
this->查询Button->Location = System::Drawing::Point(373, 3);
this->查询Button->Name = L"查询Button";
this->查询Button->Size = System::Drawing::Size(80, 25);
this->查询Button->TabIndex = 79;
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, &PrintRegisterForm::查询Button_Click);
//
// 客房入住DataGridView
//
this->客房入住DataGridView->BackgroundColor = System::Drawing::SystemColors::MenuHighlight;
this->客房入住DataGridView->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->客房入住DataGridView->Location = System::Drawing::Point(3, 31);
this->客房入住DataGridView->Name = L"客房入住DataGridView";
this->客房入住DataGridView->ReadOnly = true;
this->客房入住DataGridView->RowHeadersVisible = false;
dataGridViewCellStyle1->BackColor = System::Drawing::Color::Green;
dataGridViewCellStyle1->ForeColor = System::Drawing::Color::Yellow;
this->客房入住DataGridView->RowsDefaultCellStyle = dataGridViewCellStyle1;
this->客房入住DataGridView->RowTemplate->Height = 23;
this->客房入住DataGridView->SelectionMode = System::Windows::Forms::DataGridViewSelectionMode::FullRowSelect;
this->客房入住DataGridView->Size = System::Drawing::Size(535, 379);
this->客房入住DataGridView->TabIndex = 78;
//
// 开始日期Label
//
开始日期Label->AutoSize = true;
开始日期Label->Location = System::Drawing::Point(4, 10);
开始日期Label->Name = L"开始日期Label";
开始日期Label->Size = System::Drawing::Size(59, 12);
开始日期Label->TabIndex = 74;
开始日期Label->Text = L"开始日期:";
//
// 开始日期DateTimePicker
//
this->开始日期DateTimePicker->Location = System::Drawing::Point(66, 5);
this->开始日期DateTimePicker->Name = L"开始日期DateTimePicker";
this->开始日期DateTimePicker->Size = System::Drawing::Size(118, 21);
this->开始日期DateTimePicker->TabIndex = 75;
this->开始日期DateTimePicker->Value = System::DateTime(2006, 2, 16, 19, 14, 0, 0);
//
// 结束日期Label
//
结束日期Label->AutoSize = true;
结束日期Label->Location = System::Drawing::Point(187, 10);
结束日期Label->Name = L"结束日期Label";
结束日期Label->Size = System::Drawing::Size(59, 12);
结束日期Label->TabIndex = 76;
结束日期Label->Text = L"结束日期:";
//
// 结束日期DateTimePicker
//
this->结束日期DateTimePicker->Location = System::Drawing::Point(250, 5);
this->结束日期DateTimePicker->Name = L"结束日期DateTimePicker";
this->结束日期DateTimePicker->Size = System::Drawing::Size(117, 21);
this->结束日期DateTimePicker->TabIndex = 77;
//
// PrintRegisterForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(0)), static_cast<System::Int32>(static_cast<System::Byte>(192)),
static_cast<System::Int32>(static_cast<System::Byte>(192)));
this->ClientSize = System::Drawing::Size(540, 414);
this->Controls->Add(this->打印Button);
this->Controls->Add(this->查询Button);
this->Controls->Add(this->客房入住DataGridView);
this->Controls->Add(开始日期Label);
this->Controls->Add(this->开始日期DateTimePicker);
this->Controls->Add(结束日期Label);
this->Controls->Add(this->结束日期DateTimePicker);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D;
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"PrintRegisterForm";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
this->Text = L"打印入住旅客登记信息";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->客房入住DataGridView))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
public: String^ MyOperator;
public: String^ MyCompany;
public: System::Data::DataTable^ MyPrintTable;
private: static String^ MyHotelConnectionString= L"Data Source=.;Initial Catalog=MyHotel;Integrated Security=True;Pooling=False";
private: System::Void 查询Button_Click(System::Object^ sender, System::EventArgs^ e) {
String^ MySQLConnectionString =MyHotelConnectionString;
SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
MyConnection->Open();
MyPrintTable = gcnew System::Data::DataTable();
String^ MySQL = "Select * From 客房入住报表视图 Where 客房入住报表视图.入住日期 Between '" + this->开始日期DateTimePicker->Value + "' AND '" + this->结束日期DateTimePicker->Value + "'";
SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
MyAdapter->Fill(MyPrintTable);
this->客房入住DataGridView->DataSource = this->MyPrintTable;
if (MyConnection->State == ConnectionState::Open)
{
MyConnection->Close();
}
}
private: System::Void 打印Button_Click(System::Object^ sender, System::EventArgs^ e) {
if (MyPrintTable->Rows->Count < 1)
{
return;
}
//导出Excel表格数据文件
ApplicationClass^ MyExcel;
Workbooks^ MyWorkBooks;
Workbook^ MyWorkBook;
Worksheet^ MyWorkSheet;
char MyColumns;
Range^ MyRange;
array<System::Object^,2>^ MyData=gcnew array<System::Object^,2>(5000,30);
int Count, i, j;
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];
switch(MyPrintTable->Columns->Count + 64)
{
case 64:
MyRange=MyWorkSheet->Range["A5","A5"];
break;
case 65:
MyRange=MyWorkSheet->Range["A5","B5"];
break;
case 66:
MyRange=MyWorkSheet->Range["A5","C5"];
break;
case 67:
MyRange=MyWorkSheet->Range["A5","D5"];
break;
case 68:
MyRange=MyWorkSheet->Range["A5","E5"];
break;
case 69:
MyRange=MyWorkSheet->Range["A5","F5"];
break;
case 70:
MyRange=MyWorkSheet->Range["A5","G5"];
break;
case 71:
MyRange=MyWorkSheet->Range["A5","H5"];
break;
case 72:
MyRange=MyWorkSheet->Range["A5","I5"];
break;
case 73:
MyRange=MyWorkSheet->Range["A5","J5"];
break;
case 74:
MyRange=MyWorkSheet->Range["A5","K5"];
break;
case 75:
MyRange=MyWorkSheet->Range["A5","L5"];
break;
case 76:
MyRange=MyWorkSheet->Range["A5","M5"];
break;
case 77:
MyRange=MyWorkSheet->Range["A5","N5"];
break;
case 78:
MyRange=MyWorkSheet->Range["A5","O5"];
break;
case 79:
MyRange=MyWorkSheet->Range["A5","P5"];
break;
case 80:
MyRange=MyWorkSheet->Range["A5","Q5"];
break;
case 81:
MyRange=MyWorkSheet->Range["A5","R5"];
break;
case 82:
MyRange=MyWorkSheet->Range["A5","S5"];
break;
case 83:
MyRange=MyWorkSheet->Range["A5","T5"];
break;
case 84:
MyRange=MyWorkSheet->Range["A5","U5"];
break;
case 85:
MyRange=MyWorkSheet->Range["A5","V5"];
break;
case 86:
MyRange=MyWorkSheet->Range["A5","W5"];
break;
case 87:
MyRange=MyWorkSheet->Range["A5","X5"];
break;
case 88:
MyRange=MyWorkSheet->Range["A5","Y5"];
break;
case 89:
MyRange=MyWorkSheet->Range["A5","Z5"];
break;
}
Count = 0;
for each (DataColumn^ MyNewColumn in MyPrintTable->Columns)
{
MyData[0, Count] = MyNewColumn->ColumnName;
Count = Count + 1;
}
j = 1;
//输出数据库记录
for each (DataRow^ MyRow in MyPrintTable->Rows)
{
for (i = 0; i < MyPrintTable->Columns->Count; i++)
{
MyData[j, i] = MyRow[i]->ToString();
}
j++;
}
MyRange = MyRange->Resize[MyPrintTable->Rows->Count + 1, MyPrintTable->Columns->Count];
MyRange->Value2 = MyData;
MyRange->EntireColumn->AutoFit();
MyWorkSheet->Cells[1, 2] = this->MyCompany + "入住旅客登记信息表";
MyWorkSheet->Cells[2, 1] = "操作员:" + this->MyOperator;
MyWorkSheet->Cells[3, 1] = "开始日期:" + this->开始日期DateTimePicker->Value.ToLongDateString();
MyWorkSheet->Cells[4, 1] = "结束日期:" + this->结束日期DateTimePicker->Value.ToLongDateString();
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -