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

📄 sumdepreciationform.h

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

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~SumDepreciationForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ToolStripButton^  查询ToolStripButton;
	protected: 
	private: System::Windows::Forms::ToolStripComboBox^  折旧月份ToolStripComboBox;
	private: System::Windows::Forms::DataGridView^  汇总累计折旧DataGridView;
	private: System::Windows::Forms::ToolStripButton^  打印ToolStripButton;
	private: System::Windows::Forms::ToolStripLabel^  折旧年份ToolStripLabel;
	private: System::Windows::Forms::ToolStrip^  fillToolStrip;
	private: System::Windows::Forms::ToolStripComboBox^  折旧年份ToolStripComboBox;
	private: System::Windows::Forms::ToolStripLabel^  折旧月份ToolStripLabel;

	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(SumDepreciationForm::typeid));
			this->查询ToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->折旧月份ToolStripComboBox = (gcnew System::Windows::Forms::ToolStripComboBox());
			this->汇总累计折旧DataGridView = (gcnew System::Windows::Forms::DataGridView());
			this->打印ToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->折旧年份ToolStripLabel = (gcnew System::Windows::Forms::ToolStripLabel());
			this->fillToolStrip = (gcnew System::Windows::Forms::ToolStrip());
			this->折旧年份ToolStripComboBox = (gcnew System::Windows::Forms::ToolStripComboBox());
			this->折旧月份ToolStripLabel = (gcnew System::Windows::Forms::ToolStripLabel());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->汇总累计折旧DataGridView))->BeginInit();
			this->fillToolStrip->SuspendLayout();
			this->SuspendLayout();
			// 
			// 查询ToolStripButton
			// 
			this->查询ToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"查询ToolStripButton.Image")));
			this->查询ToolStripButton->Name = L"查询ToolStripButton";
			this->查询ToolStripButton->Size = System::Drawing::Size(49, 22);
			this->查询ToolStripButton->Text = L"查询";
			this->查询ToolStripButton->Click += gcnew System::EventHandler(this, &SumDepreciationForm::查询ToolStripButton_Click);
			// 
			// 折旧月份ToolStripComboBox
			// 
			this->折旧月份ToolStripComboBox->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->折旧月份ToolStripComboBox->Name = L"折旧月份ToolStripComboBox";
			this->折旧月份ToolStripComboBox->Size = System::Drawing::Size(75, 25);
			// 
			// 汇总累计折旧DataGridView
			// 
			this->汇总累计折旧DataGridView->AllowUserToAddRows = false;
			this->汇总累计折旧DataGridView->AllowUserToDeleteRows = false;
			this->汇总累计折旧DataGridView->AllowUserToResizeRows = false;
			this->汇总累计折旧DataGridView->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->汇总累计折旧DataGridView->Dock = System::Windows::Forms::DockStyle::Fill;
			this->汇总累计折旧DataGridView->Location = System::Drawing::Point(0, 25);
			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(542, 391);
			this->汇总累计折旧DataGridView->TabIndex = 5;
			// 
			// 打印ToolStripButton
			// 
			this->打印ToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"打印ToolStripButton.Image")));
			this->打印ToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->打印ToolStripButton->Name = L"打印ToolStripButton";
			this->打印ToolStripButton->Size = System::Drawing::Size(49, 22);
			this->打印ToolStripButton->Text = L"打印";
			this->打印ToolStripButton->Click += gcnew System::EventHandler(this, &SumDepreciationForm::打印ToolStripButton_Click);
			// 
			// 折旧年份ToolStripLabel
			// 
			this->折旧年份ToolStripLabel->Name = L"折旧年份ToolStripLabel";
			this->折旧年份ToolStripLabel->Size = System::Drawing::Size(59, 22);
			this->折旧年份ToolStripLabel->Text = L"折旧年份:";
			// 
			// fillToolStrip
			// 
			this->fillToolStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(6) {this->折旧年份ToolStripLabel, 
				this->折旧年份ToolStripComboBox, this->折旧月份ToolStripLabel, this->折旧月份ToolStripComboBox, this->查询ToolStripButton, this->打印ToolStripButton});
			this->fillToolStrip->Location = System::Drawing::Point(0, 0);
			this->fillToolStrip->Name = L"fillToolStrip";
			this->fillToolStrip->Size = System::Drawing::Size(542, 25);
			this->fillToolStrip->TabIndex = 4;
			this->fillToolStrip->Text = L"fillToolStrip";
			// 
			// 折旧年份ToolStripComboBox
			// 
			this->折旧年份ToolStripComboBox->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->折旧年份ToolStripComboBox->Name = L"折旧年份ToolStripComboBox";
			this->折旧年份ToolStripComboBox->Size = System::Drawing::Size(75, 25);
			// 
			// 折旧月份ToolStripLabel
			// 
			this->折旧月份ToolStripLabel->Name = L"折旧月份ToolStripLabel";
			this->折旧月份ToolStripLabel->Size = System::Drawing::Size(59, 22);
			this->折旧月份ToolStripLabel->Text = L"折旧月份:";
			// 
			// SumDepreciationForm
			// 
			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->fillToolStrip);
			this->Name = L"SumDepreciationForm";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"汇总月度计提的固定资产折旧";
			this->Load += gcnew System::EventHandler(this, &SumDepreciationForm::SumDepreciationForm_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->汇总累计折旧DataGridView))->EndInit();
			this->fillToolStrip->ResumeLayout(false);
			this->fillToolStrip->PerformLayout();
			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 SumDepreciationForm_Load(System::Object^  sender, System::EventArgs^  e) {
			for (int i = 2006; i < 2100; i++)
            {
                this->折旧年份ToolStripComboBox->Items->Add(i.ToString());
            }
            for (int i = 1; i < 13; i++)
            {
                this->折旧月份ToolStripComboBox->Items->Add(i.ToString());
            }
		 }
		private: System::Void 查询ToolStripButton_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.固定资产明细.使用部门 AS 部门, SUM(dbo.固定资产明细.资产原值) AS 资产原值, SUM(dbo.固定资产明细.累计折旧) AS 累计折旧, SUM(dbo.计提累计折旧.月度折旧额) AS 月度折旧额 FROM dbo.固定资产明细 INNER JOIN dbo.计提累计折旧 ON dbo.固定资产明细.资产编号 = dbo.计提累计折旧.资产编号  WHERE (折旧年份 ="+this->折旧年份ToolStripComboBox->Text+") AND (折旧月份="+this->折旧月份ToolStripComboBox->Text+") GROUP BY dbo.固定资产明细.使用部门";
            SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
            MyAdapter->Fill(MyQueryTable);
            this->汇总累计折旧DataGridView->DataSource = MyQueryTable;
            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
		 }
		private: System::Void 打印ToolStripButton_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->折旧年份ToolStripComboBox->Text + "年" + this->折旧月份ToolStripComboBox->Text + "月";  
		 }
	};
}

⌨️ 快捷键说明

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