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

📄 reportcommissaryform.h

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

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~ReportCommissaryForm()
		{
			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::ComboBox^  客户名称ComboBox;
	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(ReportCommissaryForm::typeid));
			this->客户投诉DataGridView = (gcnew System::Windows::Forms::DataGridView());
			this->打印Button = (gcnew System::Windows::Forms::Button());
			this->查询Button = (gcnew System::Windows::Forms::Button());
			this->客户名称ComboBox = (gcnew System::Windows::Forms::ComboBox());
			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->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->客户投诉DataGridView->Location = System::Drawing::Point(5, 31);
			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(535, 382);
			this->客户投诉DataGridView->TabIndex = 49;
			// 
			// 打印Button
			// 
			this->打印Button->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
			this->打印Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"打印Button.Image")));
			this->打印Button->Location = System::Drawing::Point(464, 3);
			this->打印Button->Name = L"打印Button";
			this->打印Button->Size = System::Drawing::Size(76, 23);
			this->打印Button->TabIndex = 48;
			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, &ReportCommissaryForm::打印Button_Click);
			// 
			// 查询Button
			// 
			this->查询Button->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
			this->查询Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"查询Button.Image")));
			this->查询Button->Location = System::Drawing::Point(382, 3);
			this->查询Button->Name = L"查询Button";
			this->查询Button->Size = System::Drawing::Size(76, 23);
			this->查询Button->TabIndex = 47;
			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, &ReportCommissaryForm::查询Button_Click);
			// 
			// 客户名称ComboBox
			// 
			this->客户名称ComboBox->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left) 
				| System::Windows::Forms::AnchorStyles::Right));
			this->客户名称ComboBox->FormattingEnabled = true;
			this->客户名称ComboBox->Location = System::Drawing::Point(69, 5);
			this->客户名称ComboBox->Name = L"客户名称ComboBox";
			this->客户名称ComboBox->Size = System::Drawing::Size(307, 20);
			this->客户名称ComboBox->TabIndex = 46;
			this->客户名称ComboBox->Text = L"%%";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(3, 10);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(65, 12);
			this->label1->TabIndex = 45;
			this->label1->Text = L"客户名称:";
			// 
			// ReportCommissaryForm
			// 
			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->客户名称ComboBox);
			this->Controls->Add(this->label1);
			this->Name = L"ReportCommissaryForm";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"客户业务代表报表";
			this->Load += gcnew System::EventHandler(this, &ReportCommissaryForm::ReportCommissaryForm_Load);
			(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^ MyCRMConnectionString= L"Data Source=.;Initial Catalog=MyCRM;Integrated Security=True;Pooling=False";
		private: System::Void ReportCommissaryForm_Load(System::Object^  sender, System::EventArgs^  e) {
			String^ MySQLConnectionString = MyCRMConnectionString;
            SqlConnection^ MyConnection = gcnew SqlConnection(MySQLConnectionString);
            MyConnection->Open();
            System::Data::DataTable^ MyClientTable = gcnew System::Data::DataTable();
            String^ MySQL = "SELECT 客户名称 FROM 客户资料";
            SqlDataAdapter^ MyAdapter = gcnew SqlDataAdapter(MySQL, MyConnection);
            MyAdapter->Fill(MyClientTable);
            for each (DataRow^ MyRow in MyClientTable->Rows)
            {
                this->客户名称ComboBox->Items->Add(MyRow[0]->ToString());
            }
            this->客户名称ComboBox->Items->Add("%%");

            if (MyConnection->State == ConnectionState::Open)
            {
                MyConnection->Close();
            }  
		 }
		private: System::Void 查询Button_Click(System::Object^  sender, System::EventArgs^  e) {
			MyQueryTable = gcnew System::Data::DataTable();
            SqlConnection^ MyConnection = gcnew SqlConnection();
            MyConnection->ConnectionString = MyCRMConnectionString;
            MyConnection->Open();
            String^ MySQL = "SELECT * FROM 客户代表 WHERE (客户名称 LIKE '%" + this->客户名称ComboBox->Text + "%')";
            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] = "打印日期:" + DateTime::Now.ToShortDateString();           
		 }
	};
}

⌨️ 快捷键说明

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