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

📄 printreturnform.h

📁 vc++开发环境SQL数据库固定资产管理系统
💻 H
字号:
//文件名:PrintReturnForm.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>
	/// PrintReturnForm 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class PrintReturnForm : public System::Windows::Forms::Form
	{
	public:
		PrintReturnForm(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~PrintReturnForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::DataGridView^  完修固定资产DataGridView;
	protected: 
	private: System::Windows::Forms::Button^  打印Button;
	private: System::Windows::Forms::Button^  查询Button;
	private: System::Windows::Forms::DateTimePicker^  结束日期DateTimePicker;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::DateTimePicker^  开始日期DateTimePicker;
	private: System::Windows::Forms::Label^  label1;

	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(PrintReturnForm::typeid));
			this->完修固定资产DataGridView = (gcnew System::Windows::Forms::DataGridView());
			this->打印Button = (gcnew System::Windows::Forms::Button());
			this->查询Button = (gcnew System::Windows::Forms::Button());
			this->结束日期DateTimePicker = (gcnew System::Windows::Forms::DateTimePicker());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->开始日期DateTimePicker = (gcnew System::Windows::Forms::DateTimePicker());
			this->label1 = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->完修固定资产DataGridView))->BeginInit();
			this->SuspendLayout();
			// 
			// 完修固定资产DataGridView
			// 
			this->完修固定资产DataGridView->AllowUserToAddRows = false;
			this->完修固定资产DataGridView->AllowUserToDeleteRows = false;
			this->完修固定资产DataGridView->AllowUserToResizeRows = 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->Location = System::Drawing::Point(6, 36);
			this->完修固定资产DataGridView->MultiSelect = false;
			this->完修固定资产DataGridView->Name = L"完修固定资产DataGridView";
			this->完修固定资产DataGridView->ReadOnly = true;
			this->完修固定资产DataGridView->RowHeadersVisible = false;
			this->完修固定资产DataGridView->RowTemplate->Height = 23;
			this->完修固定资产DataGridView->SelectionMode = System::Windows::Forms::DataGridViewSelectionMode::FullRowSelect;
			this->完修固定资产DataGridView->Size = System::Drawing::Size(530, 372);
			this->完修固定资产DataGridView->TabIndex = 34;
			// 
			// 打印Button
			// 
			this->打印Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"打印Button.Image")));
			this->打印Button->Location = System::Drawing::Point(456, 7);
			this->打印Button->Name = L"打印Button";
			this->打印Button->Size = System::Drawing::Size(80, 23);
			this->打印Button->TabIndex = 33;
			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, &PrintReturnForm::打印Button_Click);
			// 
			// 查询Button
			// 
			this->查询Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"查询Button.Image")));
			this->查询Button->Location = System::Drawing::Point(370, 7);
			this->查询Button->Name = L"查询Button";
			this->查询Button->Size = System::Drawing::Size(80, 23);
			this->查询Button->TabIndex = 32;
			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, &PrintReturnForm::查询Button_Click);
			// 
			// 结束日期DateTimePicker
			// 
			this->结束日期DateTimePicker->Location = System::Drawing::Point(257, 9);
			this->结束日期DateTimePicker->Name = L"结束日期DateTimePicker";
			this->结束日期DateTimePicker->Size = System::Drawing::Size(106, 21);
			this->结束日期DateTimePicker->TabIndex = 31;
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(185, 13);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(65, 12);
			this->label2->TabIndex = 30;
			this->label2->Text = L"结束日期:";
			// 
			// 开始日期DateTimePicker
			// 
			this->开始日期DateTimePicker->Location = System::Drawing::Point(66, 9);
			this->开始日期DateTimePicker->Name = L"开始日期DateTimePicker";
			this->开始日期DateTimePicker->Size = System::Drawing::Size(113, 21);
			this->开始日期DateTimePicker->TabIndex = 29;
			this->开始日期DateTimePicker->Value = System::DateTime(2006, 3, 30, 17, 7, 0, 0);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(5, 13);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(65, 12);
			this->label1->TabIndex = 28;
			this->label1->Text = L"开始日期:";
			// 
			// PrintReturnForm
			// 
			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->查询Button);
			this->Controls->Add(this->结束日期DateTimePicker);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->开始日期DateTimePicker);
			this->Controls->Add(this->label1);
			this->Name = L"PrintReturnForm";
			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^ MyCompany;
		private: System::Data::DataTable^ MyQueryTable;
		private: static String^ MyAssetsConnectionString= L"Data Source=.;Initial Catalog=MyAssets;Integrated Security=True;Pooling=False";
		private: System::Void 查询Button_Click(System::Object^  sender, System::EventArgs^  e) {
            String^ MySQLConnectionString = MyAssetsConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
			MyQueryTable = gcnew System::Data::DataTable();
            String^ MySQL = "SELECT dbo.固定资产明细.使用部门, dbo.固定资产租借记录.资产编号,dbo.固定资产租借记录.名称, dbo.固定资产租借记录.数量,dbo.固定资产租借记录.单位, dbo.固定资产租借记录.租借公司,dbo.固定资产租借记录.租借日期, dbo.固定资产租借记录.归还日期,dbo.固定资产租借记录.实际收益, dbo.固定资产租借记录.经办人,dbo.固定资产租借记录.说明 FROM dbo.固定资产租借记录 INNER JOIN dbo.固定资产明细 ON dbo.固定资产租借记录.资产编号 = dbo.固定资产明细.资产编号 WHERE 归还日期 BETWEEN '" + this->开始日期DateTimePicker->Value + "' AND '" + this->结束日期DateTimePicker->Value + "'";
            SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
            MyAdapter->Fill(MyQueryTable);
            this->完修固定资产DataGridView->DataSource = MyQueryTable;
			if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
		 }
		private: System::Void 打印Button_Click(System::Object^  sender, System::EventArgs^  e) {
            if (this->MyQueryTable->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(this->MyQueryTable->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 this->MyQueryTable->Columns)
            {
                MyData[0, Count] = MyNewColumn->ColumnName;
                Count = Count + 1;
            }
            j = 1;
            //输出数据库记录
            for each (DataRow^ MyRow in this->MyQueryTable->Rows)
            {
                for (i = 0; i < this->MyQueryTable->Columns->Count; i++)
                {
                    MyData[j, i] = MyRow[i]->ToString();
                }
                j++;
            }
            MyRange = MyRange->Resize[this->MyQueryTable->Rows->Count + 1, this->MyQueryTable->Columns->Count];
            MyRange->Value2 = MyData;
            MyRange->EntireColumn->AutoFit();
            MyWorkSheet->Cells[2, 2] = this->MyCompany + "借出已归还的固定资产统计表";
            MyWorkSheet->Cells[4, 1] = "开始日期:" + this->开始日期DateTimePicker->Value.ToShortDateString() + "        结束日期:" + this->结束日期DateTimePicker->Value.ToShortDateString();           
  		 }
	};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -