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

📄 popedommanage.h

📁 Visual C++.net数据库开发经典案例
💻 H
字号:
#pragma once
#include "LinkDataBase.h"
#include "DataGridComboboxColumn.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> 
	/// PopedomManage 摘要
	///
	/// 警告: 如果您更改该类的名称,则将需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	/// </summary>
	public __gc class PopedomManage : public System::Windows::Forms::Form
	{
		//--------------------成员声明------------------------
		LinkDataBase* MyDataBase;
		DataSet* ds;
		DataTable* PopedomDataTable;
		SqlDataAdapter* PriorityAdapter;
		String* SelectedUserID;
		bool blInitial;
		//------------------成员声明结束----------------------
	public: 
		PopedomManage(void)
		{
			InitializeComponent();

			this->MyDataBase = new LinkDataBase();
			this->PopedomDataTable = new DataTable();
			this->blInitial = true;
			//查询所有用户
			String* tempSQL = new String("Select * from 用户清单 where 姓名 <> 'sys'");			
			String* tempTableName = new String("用户清单");
			this->ds = this->MyDataBase->SelectDataBase(tempSQL,tempTableName);
			//查询所有用户的权限
			this->PriorityAdapter = new SqlDataAdapter();
			tempSQL = S"Select * from 权限清单";
			tempTableName = S"权限清单";
			this->MyDataBase->SelectDataBase(this->PriorityAdapter,this->ds,tempSQL,tempTableName);
			//设置DataGrid
			this->dgrdPeopedom->DataSource = this->ds->Tables->Item[S"用户清单"];
			this->DataGridStateControl();
			//窗体显示时选中第一行
			this->dgrdPeopedom->Select(0);
			//查询用户的权限,默认选中第一个用户
			this->SelectedUserID = this->ds->Tables->Item[S"用户清单"]->Rows->Item[0]->Item[0]->ToString();
			String* Filter = String::Format(S"用户编号 = '{0}'",this->SelectedUserID);
			DataRow* foundrows[] = this->ds->Tables->Item[S"权限清单"]->Select(Filter);
			if(foundrows->Length > 0)
			{
				for(int i = 0;i < foundrows->Length;i++)
				{
					String* Priority = foundrows[i]->Item[3]->ToString()->Trim();
					for(int j = 0;j < this->chklstPriority->Items->Count;j++)
					{
						if(String::Compare(Priority,this->chklstPriority->Items->Item[j]->ToString()->Trim()) == 0)
							this->chklstPriority->SetItemChecked(j,true);
						else
							this->chklstPriority->SetItemChecked(j,false);
					}
		
				}
			}
			this->blInitial = false;
		}
        
	protected: 
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}

	private: System::Windows::Forms::DataGrid *  dgrdPeopedom;
	private: System::Windows::Forms::Label *  label1;
	private: System::Windows::Forms::Label *  label2;
	private: System::Windows::Forms::CheckedListBox *  chklstPriority;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container* components;

		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->chklstPriority = new System::Windows::Forms::CheckedListBox();
			this->dgrdPeopedom = new System::Windows::Forms::DataGrid();
			this->label1 = new System::Windows::Forms::Label();
			this->label2 = new System::Windows::Forms::Label();
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdPeopedom))->BeginInit();
			this->SuspendLayout();
			// 
			// chklstPriority
			// 
			System::Object* __mcTemp__1[] = new System::Object*[7];
			__mcTemp__1[0] = S"商品资料维护";
			__mcTemp__1[1] = S"供货商资料维护";
			__mcTemp__1[2] = S"客户资料维护";
			__mcTemp__1[3] = S"进货单";
			__mcTemp__1[4] = S"销售单";
			__mcTemp__1[5] = S"库存查询";
			__mcTemp__1[6] = S"权限管理";
			this->chklstPriority->Items->AddRange(__mcTemp__1);
			this->chklstPriority->Location = System::Drawing::Point(352, 40);
			this->chklstPriority->Name = S"chklstPriority";
			this->chklstPriority->Size = System::Drawing::Size(208, 244);
			this->chklstPriority->TabIndex = 0;
			this->chklstPriority->ItemCheck += new System::Windows::Forms::ItemCheckEventHandler(this, chklstPriority_ItemCheck);
			// 
			// dgrdPeopedom
			// 
			this->dgrdPeopedom->DataMember = S"";
			this->dgrdPeopedom->HeaderForeColor = System::Drawing::SystemColors::ControlText;
			this->dgrdPeopedom->Location = System::Drawing::Point(8, 40);
			this->dgrdPeopedom->Name = S"dgrdPeopedom";
			this->dgrdPeopedom->ReadOnly = true;
			this->dgrdPeopedom->Size = System::Drawing::Size(328, 248);
			this->dgrdPeopedom->TabIndex = 1;
			this->dgrdPeopedom->MouseDown += new System::Windows::Forms::MouseEventHandler(this, dgrdPeopedom_MouseUp);
			this->dgrdPeopedom->MouseUp += new System::Windows::Forms::MouseEventHandler(this, dgrdPeopedom_MouseUp);
			// 
			// label1
			// 
			this->label1->Location = System::Drawing::Point(8, 16);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(88, 16);
			this->label1->TabIndex = 2;
			this->label1->Text = S"用户:";
			// 
			// label2
			// 
			this->label2->Location = System::Drawing::Point(352, 16);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(88, 16);
			this->label2->TabIndex = 3;
			this->label2->Text = S"权限:";
			// 
			// PopedomManage
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(568, 326);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->dgrdPeopedom);
			this->Controls->Add(this->chklstPriority);
			this->Name = S"PopedomManage";
			this->Text = S"权限管理";
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdPeopedom))->EndInit();
			this->ResumeLayout(false);

		}		
			//--------------------成员方法------------------------
	private:
		//------------------设置表格样式----------------------
		void DataGridStateControl()
		{
			DataGridTableStyle* ts = new DataGridTableStyle();
			DataGridNoActiveCellColumn* aTextColumn;
			ts->AlternatingBackColor = Color::LightGray;
			ts->MappingName = this->ds->Tables->Item[S"用户清单"]->TableName;

			int numCols = this->ds->Tables->Item[S"用户清单"]->Columns->Count;
			for(int i = 0;i < numCols;i++)
			{
				aTextColumn = new DataGridNoActiveCellColumn();
				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 = S"";
				aTextColumn->Format = S"D";
				ts->GridColumnStyles->Add(aTextColumn);
			}
			this->dgrdPeopedom->TableStyles->Add(ts);
		}
		//------------------改变用户权限----------------------------
	private: 
		System::Void chklstPriority_ItemCheck(System::Object *  sender, System::Windows::Forms::ItemCheckEventArgs *  e)
		{	
			if(!blInitial)
			{
				if(e->CurrentValue == CheckState::Unchecked)
				{
					DataRow* row = this->ds->Tables->Item[S"权限清单"]->NewRow();
					row->Item[S"用户编号"] = this->dgrdPeopedom->get_Item(this->dgrdPeopedom->CurrentCell.RowNumber,0);
					row->Item[S"权限名称"] = this->chklstPriority->SelectedItem->ToString();
					this->ds->Tables->Item[S"权限清单"]->Rows->Add(row);
					//更新权限信息
					this->MyDataBase->UpdateDataBase(this->PriorityAdapter,this->ds,S"权限清单");
				}
				else
				{
					//更新数据表
					this->SelectedUserID = this->dgrdPeopedom->get_Item(this->dgrdPeopedom->CurrentCell.RowNumber,0)->ToString();
					String* Priority = this->chklstPriority->SelectedItem->ToString();
					String* Filter = String::Format(S"用户编号 = '{0}' and 权限名称 = '{1}'",this->SelectedUserID,Priority);
					DataRow* foundrows[] = this->ds->Tables->Item[S"权限清单"]->Select(Filter);
					if(foundrows->Length <= 0)
						return;
					foundrows[0]->Delete();
					this->ds->AcceptChanges();
					//更新数据库
					String* tempSQL = String::Format(S"delete from 权限清单 where (用户编号 = '{0}' and 权限名称 = '{1}')",this->SelectedUserID,Priority);
					this->MyDataBase->SQLOperate(tempSQL);
				}
				
			}
		}

private: System::Void dgrdPeopedom_MouseUp(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
		 {		
			 //如果所选用户超出范围则返回
			if(this->dgrdPeopedom->CurrentCell.RowNumber >= this->ds->Tables->Item[S"用户清单"]->Rows->Count)
			{
				return;
			}
			blInitial = true;
			int intRowNumber = this->dgrdPeopedom->CurrentCell.RowNumber;
			this->SelectedUserID = this->ds->Tables->Item[S"用户清单"]->Rows->Item[intRowNumber]->Item[0]->ToString();
			String* Filter = String::Format(S"用户编号 = '{0}'",this->SelectedUserID);
			DataRow* foundrows[] = this->ds->Tables->Item[S"权限清单"]->Select(Filter);

			for(int j = 0;j < this->chklstPriority->Items->Count;j++)
			{
				this->chklstPriority->SetItemChecked(j,false);
			}		
			if(foundrows->Length > 0)
			{
				for(int i = 0;i < foundrows->Length;i++)
				{
					String* Priority = foundrows[i]->Item[3]->ToString()->Trim();
					for(int j = 0;j < this->chklstPriority->Items->Count;j++)
					{
						String* tempPriority = this->chklstPriority->Items->Item[j]->ToString()->Trim();
						if(String::Compare(Priority,tempPriority) == 0)
							this->chklstPriority->SetItemChecked(j,true);
					}		
				}
			}
			blInitial = false;
		 }



};
}

⌨️ 快捷键说明

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