⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportcommonrepairform.h

📁 小区物业管理系统
💻 H
字号:
//文件名:ReportCommonRepairForm.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 Microsoft::Office::Interop::Excel;
using namespace System::Reflection;
using namespace System::Data::SqlClient;
namespace MyCommunity {

	/// <summary>
	/// ReportCommonRepairForm 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class ReportCommonRepairForm : public System::Windows::Forms::Form
	{
	public:
		ReportCommonRepairForm(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~ReportCommonRepairForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  故障现象TextBox;
	protected: 
	private: System::Windows::Forms::TextBox^  开始日期TextBox;
	private: System::Windows::Forms::TextBox^  结束日期TextBox;
	private: System::Windows::Forms::DataGridView^  公共维修报表DataGridView;
	private: System::Windows::Forms::Button^  打印Button;
	private: System::Windows::Forms::Label^  故障现象Label;
	private: System::Windows::Forms::Label^  开始日期Label;
	private: System::Windows::Forms::Button^  查询Button;
	private: System::Windows::Forms::Label^  结束日期Label;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			System::Windows::Forms::DataGridViewCellStyle^  dataGridViewCellStyle1 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
			System::Windows::Forms::DataGridViewCellStyle^  dataGridViewCellStyle2 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
			System::Windows::Forms::DataGridViewCellStyle^  dataGridViewCellStyle3 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(ReportCommonRepairForm::typeid));
			this->故障现象TextBox = (gcnew System::Windows::Forms::TextBox());
			this->开始日期TextBox = (gcnew System::Windows::Forms::TextBox());
			this->结束日期TextBox = (gcnew System::Windows::Forms::TextBox());
			this->公共维修报表DataGridView = (gcnew System::Windows::Forms::DataGridView());
			this->打印Button = (gcnew System::Windows::Forms::Button());
			this->故障现象Label = (gcnew System::Windows::Forms::Label());
			this->开始日期Label = (gcnew System::Windows::Forms::Label());
			this->查询Button = (gcnew System::Windows::Forms::Button());
			this->结束日期Label = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->公共维修报表DataGridView))->BeginInit();
			this->SuspendLayout();
			// 
			// 故障现象TextBox
			// 
			this->故障现象TextBox->Location = System::Drawing::Point(74, 34);
			this->故障现象TextBox->Name = L"故障现象TextBox";
			this->故障现象TextBox->Size = System::Drawing::Size(458, 21);
			this->故障现象TextBox->TabIndex = 94;
			// 
			// 开始日期TextBox
			// 
			this->开始日期TextBox->Location = System::Drawing::Point(71, 7);
			this->开始日期TextBox->Name = L"开始日期TextBox";
			this->开始日期TextBox->Size = System::Drawing::Size(103, 21);
			this->开始日期TextBox->TabIndex = 93;
			this->开始日期TextBox->Text = L"2006-1-1";
			// 
			// 结束日期TextBox
			// 
			this->结束日期TextBox->Location = System::Drawing::Point(243, 7);
			this->结束日期TextBox->Name = L"结束日期TextBox";
			this->结束日期TextBox->Size = System::Drawing::Size(114, 21);
			this->结束日期TextBox->TabIndex = 92;
			this->结束日期TextBox->Text = L"2010-12-31";
			// 
			// 公共维修报表DataGridView
			// 
			this->公共维修报表DataGridView->AllowUserToAddRows = false;
			this->公共维修报表DataGridView->AllowUserToDeleteRows = false;
			this->公共维修报表DataGridView->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
				| System::Windows::Forms::AnchorStyles::Left) 
				| System::Windows::Forms::AnchorStyles::Right));
			this->公共维修报表DataGridView->BackgroundColor = System::Drawing::Color::LightGray;
			this->公共维修报表DataGridView->ColumnHeadersBorderStyle = System::Windows::Forms::DataGridViewHeaderBorderStyle::Sunken;
			dataGridViewCellStyle1->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleCenter;
			dataGridViewCellStyle1->BackColor = System::Drawing::SystemColors::ActiveCaption;
			dataGridViewCellStyle1->Font = (gcnew System::Drawing::Font(L"宋体", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			dataGridViewCellStyle1->ForeColor = System::Drawing::SystemColors::WindowText;
			dataGridViewCellStyle1->SelectionBackColor = System::Drawing::SystemColors::Highlight;
			dataGridViewCellStyle1->SelectionForeColor = System::Drawing::SystemColors::GradientActiveCaption;
			dataGridViewCellStyle1->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
			this->公共维修报表DataGridView->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
			this->公共维修报表DataGridView->Location = System::Drawing::Point(9, 61);
			this->公共维修报表DataGridView->MultiSelect = false;
			this->公共维修报表DataGridView->Name = L"公共维修报表DataGridView";
			this->公共维修报表DataGridView->ReadOnly = true;
			dataGridViewCellStyle2->Alignment = System::Windows::Forms::DataGridViewContentAlignment::TopCenter;
			dataGridViewCellStyle2->BackColor = System::Drawing::SystemColors::Control;
			dataGridViewCellStyle2->Font = (gcnew System::Drawing::Font(L"宋体", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			dataGridViewCellStyle2->ForeColor = System::Drawing::SystemColors::WindowText;
			dataGridViewCellStyle2->SelectionBackColor = System::Drawing::SystemColors::Highlight;
			dataGridViewCellStyle2->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
			dataGridViewCellStyle2->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
			this->公共维修报表DataGridView->RowHeadersDefaultCellStyle = dataGridViewCellStyle2;
			this->公共维修报表DataGridView->RowHeadersVisible = false;
			dataGridViewCellStyle3->SelectionBackColor = System::Drawing::Color::Green;
			this->公共维修报表DataGridView->RowsDefaultCellStyle = dataGridViewCellStyle3;
			this->公共维修报表DataGridView->RowTemplate->Height = 23;
			this->公共维修报表DataGridView->SelectionMode = System::Windows::Forms::DataGridViewSelectionMode::FullRowSelect;
			this->公共维修报表DataGridView->Size = System::Drawing::Size(523, 345);
			this->公共维修报表DataGridView->TabIndex = 91;
			// 
			// 打印Button
			// 
			this->打印Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"打印Button.Image")));
			this->打印Button->Location = System::Drawing::Point(449, 5);
			this->打印Button->Name = L"打印Button";
			this->打印Button->Size = System::Drawing::Size(80, 23);
			this->打印Button->TabIndex = 90;
			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, &ReportCommonRepairForm::打印Button_Click);
			// 
			// 故障现象Label
			// 
			this->故障现象Label->AutoSize = true;
			this->故障现象Label->Location = System::Drawing::Point(8, 39);
			this->故障现象Label->Name = L"故障现象Label";
			this->故障现象Label->Size = System::Drawing::Size(65, 12);
			this->故障现象Label->TabIndex = 89;
			this->故障现象Label->Text = L"故障现象:";
			// 
			// 开始日期Label
			// 
			this->开始日期Label->AutoSize = true;
			this->开始日期Label->Location = System::Drawing::Point(7, 13);
			this->开始日期Label->Name = L"开始日期Label";
			this->开始日期Label->Size = System::Drawing::Size(65, 12);
			this->开始日期Label->TabIndex = 88;
			this->开始日期Label->Text = L"开始日期:";
			// 
			// 查询Button
			// 
			this->查询Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"查询Button.Image")));
			this->查询Button->Location = System::Drawing::Point(363, 5);
			this->查询Button->Name = L"查询Button";
			this->查询Button->Size = System::Drawing::Size(80, 23);
			this->查询Button->TabIndex = 87;
			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, &ReportCommonRepairForm::查询Button_Click);
			// 
			// 结束日期Label
			// 
			this->结束日期Label->AutoSize = true;
			this->结束日期Label->Location = System::Drawing::Point(180, 13);
			this->结束日期Label->Name = L"结束日期Label";
			this->结束日期Label->Size = System::Drawing::Size(65, 12);
			this->结束日期Label->TabIndex = 86;
			this->结束日期Label->Text = L"结束日期:";
			// 
			// ReportCommonRepairForm
			// 
			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->故障现象Label);
			this->Controls->Add(this->开始日期Label);
			this->Controls->Add(this->查询Button);
			this->Controls->Add(this->结束日期Label);
			this->Name = L"ReportCommonRepairForm";
			this->ShowInTaskbar = false;
			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^ MyCommunity;
	public:String^ MySQLConnectionString;	
	private: System::Data::DataTable^ MyTable;  
	private: System::Void 查询Button_Click(System::Object^  sender, System::EventArgs^  e) 
	{//查询公共维修信息
      MyTable=gcnew System::Data::DataTable();
      String^ MySQL = "Select * FROM 公共维修 WHERE (报修日期 BETWEEN '" + this->开始日期TextBox->Text + "' AND '" + this->结束日期TextBox->Text + "') AND (故障现象 LIKE '%" + this->故障现象TextBox->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==3)
		  {
			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 + -