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

📄 mrphistory.h

📁 Visual C++.net数据库开发经典案例
💻 H
字号:
#pragma once

#include "LinkDataBase.h"
#include "DataGridNoActiveCellColumn.h"

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace My
{
	/// <summary> 
	/// MRPHistory 摘要
	///
	/// 警告: 如果您更改该类的名称,则将需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	/// </summary>
	public __gc class MRPHistory : public System::Windows::Forms::Form
	{
	//--------------------成员声明------------------------
	private:
		LinkDataBase* MyDataBase;	//数据库连接类
		DataSet* ds;
		String* strTableName;
		String* strSQL;
	private: System::Windows::Forms::ImageList *  imageList1;
			 DataView* DemandView;
	//-------------------成员声明结束-----------------------
	public: 
		MRPHistory(void)
		{
			InitializeComponent();
			//初始化
			this->MyDataBase = new LinkDataBase();
			this->ds = new DataSet();			
			this->DemandAdapter->SelectCommand->Connection = this->MyDataBase->myConnection;			
			//查询物料需求历史
			this->strSQL = this->DemandAdapter->SelectCommand->CommandText;
			this->strTableName = S"物料需求历史";
			this->MyDataBase->SelectDataBase(this->DemandAdapter,this->ds,this->strSQL,this->strTableName);
			//设置DataGrid	
			this->DemandView = new DataView(this->ds->Tables->Item[S"物料需求历史"]);
			this->dgrdMRPHistory->DataSource = this->DemandView;
			this->DataGridStateDemand();
		}
        
	protected: 
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
	private: System::Windows::Forms::GroupBox *  groupBox1;

	private: System::Windows::Forms::Label *  label2;
	private: System::Windows::Forms::TextBox *  tBoxMaterialID;
	private: System::Windows::Forms::Label *  label1;
	private: System::Windows::Forms::Button *  btnSearch;

	private: System::Windows::Forms::Label *  label4;
	private: System::Windows::Forms::DataGrid *  dgrdMRPHistory;
	private: System::Windows::Forms::TextBox *  tBoxYear;
	private: System::Windows::Forms::TextBox *  tBoxPlanDate;
	private: System::Data::SqlClient::SqlDataAdapter *  DemandAdapter;
	private: System::Data::SqlClient::SqlCommand *  sqlSelectCommand1;
	private: System::ComponentModel::IContainer *  components;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>


		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = new System::ComponentModel::Container();
			System::Resources::ResourceManager *  resources = new System::Resources::ResourceManager(__typeof(My::MRPHistory));
			this->groupBox1 = new System::Windows::Forms::GroupBox();
			this->tBoxYear = new System::Windows::Forms::TextBox();
			this->label2 = new System::Windows::Forms::Label();
			this->tBoxMaterialID = new System::Windows::Forms::TextBox();
			this->label1 = new System::Windows::Forms::Label();
			this->btnSearch = new System::Windows::Forms::Button();
			this->imageList1 = new System::Windows::Forms::ImageList(this->components);
			this->tBoxPlanDate = new System::Windows::Forms::TextBox();
			this->label4 = new System::Windows::Forms::Label();
			this->dgrdMRPHistory = new System::Windows::Forms::DataGrid();
			this->DemandAdapter = new System::Data::SqlClient::SqlDataAdapter();
			this->sqlSelectCommand1 = new System::Data::SqlClient::SqlCommand();
			this->groupBox1->SuspendLayout();
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdMRPHistory))->BeginInit();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->tBoxYear);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->tBoxMaterialID);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Controls->Add(this->btnSearch);
			this->groupBox1->Controls->Add(this->tBoxPlanDate);
			this->groupBox1->Controls->Add(this->label4);
			this->groupBox1->Dock = System::Windows::Forms::DockStyle::Top;
			this->groupBox1->Location = System::Drawing::Point(0, 0);
			this->groupBox1->Name = S"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(744, 79);
			this->groupBox1->TabIndex = 2;
			this->groupBox1->TabStop = false;
			// 
			// tBoxYear
			// 
			this->tBoxYear->Location = System::Drawing::Point(408, 39);
			this->tBoxYear->Name = S"tBoxYear";
			this->tBoxYear->Size = System::Drawing::Size(120, 21);
			this->tBoxYear->TabIndex = 4;
			this->tBoxYear->Text = S"";
			// 
			// label2
			// 
			this->label2->Location = System::Drawing::Point(344, 44);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(56, 11);
			this->label2->TabIndex = 3;
			this->label2->Text = S"年份";
			// 
			// tBoxMaterialID
			// 
			this->tBoxMaterialID->Location = System::Drawing::Point(208, 40);
			this->tBoxMaterialID->Name = S"tBoxMaterialID";
			this->tBoxMaterialID->Size = System::Drawing::Size(120, 21);
			this->tBoxMaterialID->TabIndex = 2;
			this->tBoxMaterialID->Text = S"";
			// 
			// label1
			// 
			this->label1->Location = System::Drawing::Point(144, 45);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(56, 11);
			this->label1->TabIndex = 1;
			this->label1->Text = S"物料编号";
			// 
			// btnSearch
			// 
			this->btnSearch->ImageAlign = System::Drawing::ContentAlignment::MiddleLeft;
			this->btnSearch->ImageIndex = 6;
			this->btnSearch->ImageList = this->imageList1;
			this->btnSearch->Location = System::Drawing::Point(32, 40);
			this->btnSearch->Name = S"btnSearch";
			this->btnSearch->Size = System::Drawing::Size(72, 24);
			this->btnSearch->TabIndex = 0;
			this->btnSearch->Text = S"搜索";
			this->btnSearch->Click += new System::EventHandler(this, btnSearch_Click);
			// 
			// imageList1
			// 
			this->imageList1->ImageSize = System::Drawing::Size(16, 16);
			this->imageList1->ImageStream = (__try_cast<System::Windows::Forms::ImageListStreamer *  >(resources->GetObject(S"imageList1.ImageStream")));
			this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
			// 
			// tBoxPlanDate
			// 
			this->tBoxPlanDate->Location = System::Drawing::Point(625, 40);
			this->tBoxPlanDate->Name = S"tBoxPlanDate";
			this->tBoxPlanDate->Size = System::Drawing::Size(120, 21);
			this->tBoxPlanDate->TabIndex = 6;
			this->tBoxPlanDate->Text = S"";
			// 
			// label4
			// 
			this->label4->Location = System::Drawing::Point(559, 43);
			this->label4->Name = S"label4";
			this->label4->Size = System::Drawing::Size(56, 11);
			this->label4->TabIndex = 5;
			this->label4->Text = S"计划期";
			// 
			// dgrdMRPHistory
			// 
			this->dgrdMRPHistory->DataMember = S"";
			this->dgrdMRPHistory->Dock = System::Windows::Forms::DockStyle::Fill;
			this->dgrdMRPHistory->HeaderForeColor = System::Drawing::SystemColors::ControlText;
			this->dgrdMRPHistory->Location = System::Drawing::Point(0, 79);
			this->dgrdMRPHistory->Name = S"dgrdMRPHistory";
			this->dgrdMRPHistory->Size = System::Drawing::Size(744, 358);
			this->dgrdMRPHistory->TabIndex = 3;
			// 
			// DemandAdapter
			// 
			this->DemandAdapter->SelectCommand = this->sqlSelectCommand1;
			System::Data::Common::DataTableMapping* __mcTemp__1[] = new System::Data::Common::DataTableMapping*[1];
			System::Data::Common::DataColumnMapping* __mcTemp__2[] = new System::Data::Common::DataColumnMapping*[14];
			__mcTemp__2[0] = new System::Data::Common::DataColumnMapping(S"物料名称", S"物料名称");
			__mcTemp__2[1] = new System::Data::Common::DataColumnMapping(S"发布编号", S"发布编号");
			__mcTemp__2[2] = new System::Data::Common::DataColumnMapping(S"发布时间", S"发布时间");
			__mcTemp__2[3] = new System::Data::Common::DataColumnMapping(S"物料编号", S"物料编号");
			__mcTemp__2[4] = new System::Data::Common::DataColumnMapping(S"年份", S"年份");
			__mcTemp__2[5] = new System::Data::Common::DataColumnMapping(S"计划期", S"计划期");
			__mcTemp__2[6] = new System::Data::Common::DataColumnMapping(S"期初库存", S"期初库存");
			__mcTemp__2[7] = new System::Data::Common::DataColumnMapping(S"毛需求", S"毛需求");
			__mcTemp__2[8] = new System::Data::Common::DataColumnMapping(S"预计入库", S"预计入库");
			__mcTemp__2[9] = new System::Data::Common::DataColumnMapping(S"预计出库", S"预计出库");
			__mcTemp__2[10] = new System::Data::Common::DataColumnMapping(S"预计库存", S"预计库存");
			__mcTemp__2[11] = new System::Data::Common::DataColumnMapping(S"净需求", S"净需求");
			__mcTemp__2[12] = new System::Data::Common::DataColumnMapping(S"计划产出", S"计划产出");
			__mcTemp__2[13] = new System::Data::Common::DataColumnMapping(S"计划投入", S"计划投入");
			__mcTemp__1[0] = new System::Data::Common::DataTableMapping(S"Table", S"mrp物料需求历史", __mcTemp__2);
			this->DemandAdapter->TableMappings->AddRange(__mcTemp__1);
			// 
			// sqlSelectCommand1
			// 
			this->sqlSelectCommand1->CommandText = S"SELECT 物料主文件.物料名称, mrp物料需求历史.发布编号, mrp物料需求历史.发布时间, mrp物料需求历史.物料编号, mrp物料需求历史.年份, " 
				S"mrp物料需求历史.计划期, mrp物料需求历史.期初库存, mrp物料需求历史.毛需求, mrp物料需求历史.预计入库, mrp物料需求历史.预计出库, mr" 
				S"p物料需求历史.预计库存, mrp物料需求历史.净需求, mrp物料需求历史.计划产出, mrp物料需求历史.计划投入 FROM mrp物料需求历史 INNER" 
				S" JOIN 物料主文件 ON mrp物料需求历史.物料编号 = 物料主文件.物料编号";
			// 
			// MRPHistory
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(744, 437);
			this->Controls->Add(this->dgrdMRPHistory);
			this->Controls->Add(this->groupBox1);
			this->Name = S"MRPHistory";
			this->Text = S"MRP历史";
			this->groupBox1->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdMRPHistory))->EndInit();
			this->ResumeLayout(false);

		}		
		//-----------------------设置表格各列的属性-----------------------
		void DataGridStateDemand()
		{

			DataGridTableStyle* ts = new DataGridTableStyle();			
			ts->MappingName = this->ds->Tables->Item[S"物料需求历史"]->TableName;
			
			DataGridTextBoxColumn* aTextColumn;
			ts->AllowSorting = false;
			ts->AlternatingBackColor = Color::LightGray;
			int numCols = this->ds->Tables->Item[S"物料需求历史"]->Columns->Count;
			for(int i = 0;i < numCols;i++)
			{				
				aTextColumn = new DataGridNoActiveCellColumn();				
				aTextColumn->ReadOnly = true;
				aTextColumn->get_TextBox()->Enabled = false;
				aTextColumn->MappingName = this->ds->Tables->Item[S"物料需求历史"]->Columns->Item[i]->ColumnName;
				aTextColumn->HeaderText =  this->ds->Tables->Item[S"物料需求历史"]->Columns->Item[i]->ColumnName;
				aTextColumn->NullText = String::Empty;									
				ts->GridColumnStyles->Add(aTextColumn);				
			}
			this->dgrdMRPHistory->TableStyles->Add(ts);
		}
private: System::Void btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 String* strMaterialID = this->tBoxMaterialID->Text->Trim();
			 String* strYear = this->tBoxYear->Text->Trim();
			 String* strPlandate = this->tBoxPlanDate->Text->Trim();
			 String* Filter = S"";
			 if(String::Compare(strMaterialID,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (物料编号 LIKE '%{1}%')",Filter,strMaterialID);
			 }
			 if(String::Compare(strYear,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (年份 = {1})",Filter,strYear);
			 }
			 if(String::Compare(strPlandate,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (计划期 = {1})",Filter,strPlandate);
			 }			
			 if(String::Compare(Filter,String::Empty) != 0)
			 {
				 Filter = Filter->Substring(5,Filter->Length - 5);
				 this->DemandView->RowFilter = Filter;
			 }
		 }

};
}

⌨️ 快捷键说明

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