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

📄 querydepartmentform.h

📁 这是一个用VC++编写的人事工资管理系统,开发平台为VS2005,是开发企业管理程序的程序员的很好参考!
💻 H
字号:
//文件名:QueryDepartmentForm.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>
	/// QueryDepartmentForm 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class QueryDepartmentForm : public System::Windows::Forms::Form
	{
	public:
		QueryDepartmentForm(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~QueryDepartmentForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ToolStripButton^  查询部门员工人事档案ToolStripButton;
	protected: 
	private: System::Windows::Forms::ToolStripButton^  打印部门员工人事档案ToolStripButton;
	private: System::Windows::Forms::DataGridView^  基本档案DataGridView;
	private: System::Windows::Forms::ToolStrip^  toolStrip1;
	private: System::Windows::Forms::ToolStripLabel^  toolStripLabel1;
	private: System::Windows::Forms::ToolStripComboBox^  部门ToolStripComboBox;

	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(QueryDepartmentForm::typeid));
			System::Windows::Forms::DataGridViewCellStyle^  dataGridViewCellStyle1 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
			this->查询部门员工人事档案ToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->打印部门员工人事档案ToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->基本档案DataGridView = (gcnew System::Windows::Forms::DataGridView());
			this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
			this->toolStripLabel1 = (gcnew System::Windows::Forms::ToolStripLabel());
			this->部门ToolStripComboBox = (gcnew System::Windows::Forms::ToolStripComboBox());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->基本档案DataGridView))->BeginInit();
			this->toolStrip1->SuspendLayout();
			this->SuspendLayout();
			// 
			// 查询部门员工人事档案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(145, 22);
			this->查询部门员工人事档案ToolStripButton->Text = L"查询部门员工人事档案";
			this->查询部门员工人事档案ToolStripButton->Click += gcnew System::EventHandler(this, &QueryDepartmentForm::查询部门员工人事档案ToolStripButton_Click);
			// 
			// 打印部门员工人事档案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(145, 22);
			this->打印部门员工人事档案ToolStripButton->Text = L"打印部门员工人事档案";
			this->打印部门员工人事档案ToolStripButton->Click += gcnew System::EventHandler(this, &QueryDepartmentForm::打印部门员工人事档案ToolStripButton_Click);
			// 
			// 基本档案DataGridView
			// 
			this->基本档案DataGridView->AllowUserToAddRows = false;
			this->基本档案DataGridView->AllowUserToDeleteRows = false;
			this->基本档案DataGridView->AllowUserToResizeRows = false;
			this->基本档案DataGridView->BackgroundColor = System::Drawing::SystemColors::ActiveCaption;
			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;
			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(542, 391);
			this->基本档案DataGridView->TabIndex = 30;
			// 
			// toolStrip1
			// 
			this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(4) {this->toolStripLabel1, 
				this->部门ToolStripComboBox, this->查询部门员工人事档案ToolStripButton, this->打印部门员工人事档案ToolStripButton});
			this->toolStrip1->Location = System::Drawing::Point(0, 0);
			this->toolStrip1->Name = L"toolStrip1";
			this->toolStrip1->Size = System::Drawing::Size(542, 25);
			this->toolStrip1->TabIndex = 29;
			this->toolStrip1->Text = L"toolStrip1";
			// 
			// toolStripLabel1
			// 
			this->toolStripLabel1->Name = L"toolStripLabel1";
			this->toolStripLabel1->Size = System::Drawing::Size(77, 22);
			this->toolStripLabel1->Text = L"请选择部门:";
			// 
			// 部门ToolStripComboBox
			// 
			this->部门ToolStripComboBox->Name = L"部门ToolStripComboBox";
			this->部门ToolStripComboBox->Size = System::Drawing::Size(121, 25);
			// 
			// QueryDepartmentForm
			// 
			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(542, 416);
			this->Controls->Add(this->基本档案DataGridView);
			this->Controls->Add(this->toolStrip1);
			this->Name = L"QueryDepartmentForm";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"查询部门员工人事档案";
			this->Load += gcnew System::EventHandler(this, &QueryDepartmentForm::QueryDepartmentForm_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->基本档案DataGridView))->EndInit();
			this->toolStrip1->ResumeLayout(false);
			this->toolStrip1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
		private: static String^ MyPersonnelConnectionString= L"Data Source=.;Initial Catalog=MyPersonnel;Integrated Security=True;Pooling=False";
		public: String^ MyCompany;
		private: System::Data::DataTable^ MyQueryTable;
		private: System::Void QueryDepartmentForm_Load(System::Object^  sender, System::EventArgs^  e) {
			//获取公司的部门信息            
            String^ MySQLConnectionString = MyPersonnelConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
            System::Data::DataTable^ MyDepartmentTable = gcnew System::Data::DataTable();
            String^ MySQL = "Select 部门名称 From 公司部门";
            SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
            MyAdapter->Fill(MyDepartmentTable);
            for each (DataRow^ MyRow in MyDepartmentTable->Rows)
            {
                this->部门ToolStripComboBox->Items->Add(MyRow[0]->ToString());
            }
            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }
		}
		private: System::Void 查询部门员工人事档案ToolStripButton_Click(System::Object^  sender, System::EventArgs^  e) {
			String^ MySQLConnectionString = MyPersonnelConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
            MyQueryTable = gcnew System::Data::DataTable();
            String^ MySQL = "Select 员工编号, 姓名, 性别, 出生年月, 身份证号码, 民族, 政治面貌, 婚姻状况, 文化程度, 专业, 毕业院校, 职称, 职务, 进入本单位时间, 合同服务年限, 基本工资, 银行帐号, 养老保险帐号, 医疗保险帐号, 住房基金帐号, 联系电话, 手机号码, 电子信箱, 家庭住址, 邮政编码, 籍贯  From 基本档案 WHERE (部门='" + this->部门ToolStripComboBox->Text + " ' AND 员工编号 NOT IN (SELECT 员工编号 FROM 离职管理))";
            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 (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];			
			MyRange=MyWorkSheet->Range["A5","AF5"];
            Count = 0;
            for each (DataColumn^ MyNewColumn in MyQueryTable->Columns)
            {
                MyData[0, Count] = MyNewColumn->ColumnName;
                Count = Count + 1;
            }
            j = 1;
            //输出数据库记录
            for each (DataRow^ MyRow in MyQueryTable->Rows)
            {
                for (i = 0; i < MyQueryTable->Columns->Count; i++)
                {
                    MyData[j, i] = MyRow[i]->ToString();
                    if (i == 3 || i==13)
                    {
                        MyData[j, i] = ((DateTime)MyRow[i]).ToShortDateString();
                    }
                }
                j++;
            }
            MyRange = MyRange->Resize[MyQueryTable->Rows->Count + 1, MyQueryTable->Columns->Count];
            MyRange->Value2 = MyData;
            MyRange->EntireColumn->AutoFit();
            MyWorkSheet->Cells[1, 2] = this->MyCompany +this->部门ToolStripComboBox->Text+ "员工人事档案";
			MyWorkSheet->Cells[4, 1] = "制表日期:" + DateTime::Now.ToShortDateString();            
		 }
	};
}

⌨️ 快捷键说明

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