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

📄 frmplatfstutree.cs

📁 Oracle源码:Oracle 数据库管理与应用系统开发代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms; 
using System.Data;
using System.Data.OracleClient;
using System.Threading;
using GlobleUtility;



namespace PlatF
{
	/// <summary>
	/// 学校地址的查询界面。
	/// </summary>
	public class CfrmPlatFStuTree : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListView lvStuTree;//ListView控件,显示TreeView控件中所选定班级的学生信息
		private System.Windows.Forms.ImageList imageListtbr;
		private System.Windows.Forms.ToolBar tbrStuTree;//工具栏
		private System.Windows.Forms.ToolBarButton toolBarButton8;
		private System.Windows.Forms.ToolBarButton tbrButtonDel;//工具栏上“删除”按钮
		private System.Windows.Forms.ToolBarButton tbrButtonExit;//工具栏上“退出”按钮
		private System.Windows.Forms.Label labview;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.TreeView trvDept;//TreeView控件,以树形结构显示部门及班级列表
		private System.Windows.Forms.ImageList imgDeptList;
		private System.Windows.Forms.ToolBarButton tbrButtonAdd;//工具栏上“新增”按钮 
		
		
		//private bool blocalmodified;
		
		//动态数组,保存从查询窗口传回的两条数据,第一条是查询窗口生成的sql查询语句,第二条是查询的内容显示
		//private ArrayList arrayPipe;  
		//private CfrmProgressStatus status; //查询操作时弹出的进度条
		
		
		
		public CfrmPlatFStuTree()
		{
		
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			//blocalmodified = false;
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CfrmPlatFStuTree));
			this.lvStuTree = new System.Windows.Forms.ListView();
			this.imageListtbr = new System.Windows.Forms.ImageList(this.components);
			this.tbrStuTree = new System.Windows.Forms.ToolBar();
			this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
			this.tbrButtonDel = new System.Windows.Forms.ToolBarButton();
			this.tbrButtonExit = new System.Windows.Forms.ToolBarButton();
			this.labview = new System.Windows.Forms.Label();
			this.trvDept = new System.Windows.Forms.TreeView();
			this.imgDeptList = new System.Windows.Forms.ImageList(this.components);
			this.tbrButtonAdd = new System.Windows.Forms.ToolBarButton();
			this.SuspendLayout();
			// 
			// lvStuTree
			// 
			this.lvStuTree.BackColor = System.Drawing.SystemColors.Info;
			this.lvStuTree.Location = new System.Drawing.Point(232, 104);
			this.lvStuTree.Name = "lvStuTree";
			this.lvStuTree.Size = new System.Drawing.Size(552, 376);
			this.lvStuTree.TabIndex = 0;
			//this.lvStuTree.DoubleClick += new System.EventHandler(this.lvStuTree_DoubleClick);
			this.lvStuTree.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvStuTree_ColumnClick);
			// 
			// imageListtbr
			// 
			this.imageListtbr.ImageSize = new System.Drawing.Size(32, 32);
			this.imageListtbr.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListtbr.ImageStream")));
			this.imageListtbr.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tbrStuTree
			// 
			this.tbrStuTree.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						  this.toolBarButton8,
																						  this.tbrButtonAdd,
																						  this.tbrButtonDel,
																						  this.tbrButtonExit});
			this.tbrStuTree.ButtonSize = new System.Drawing.Size(52, 52);
			this.tbrStuTree.DropDownArrows = true;
			this.tbrStuTree.ImageList = this.imageListtbr;
			this.tbrStuTree.Location = new System.Drawing.Point(0, 0);
			this.tbrStuTree.Name = "tbrStuTree";
			this.tbrStuTree.ShowToolTips = true;
			this.tbrStuTree.Size = new System.Drawing.Size(792, 58);
			this.tbrStuTree.TabIndex = 8;
			this.tbrStuTree.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbrStuTree_ButtonClick);
			// 
			// toolBarButton8
			// 
			this.toolBarButton8.Enabled = false;
			this.toolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbrButtonDel
			// 
			this.tbrButtonDel.ImageIndex = 3;
			this.tbrButtonDel.Text = "删除";
			this.tbrButtonDel.ToolTipText = "删除";
			// 
			// tbrButtonExit
			// 
			this.tbrButtonExit.ImageIndex = 6;
			this.tbrButtonExit.Text = "退出";
			this.tbrButtonExit.ToolTipText = "退出";
			// 
			// labview
			// 
			this.labview.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.labview.Location = new System.Drawing.Point(8, 64);
			this.labview.Name = "labview";
			this.labview.Size = new System.Drawing.Size(696, 32);
			this.labview.TabIndex = 9;
			this.labview.Text = "学生信息:";
			// 
			// trvDept
			// 
			this.trvDept.HideSelection = false;
			this.trvDept.ImageList = this.imgDeptList;
			this.trvDept.Location = new System.Drawing.Point(0, 104);
			this.trvDept.Name = "trvDept";
			this.trvDept.Size = new System.Drawing.Size(224, 376);
			this.trvDept.TabIndex = 10;
			this.trvDept.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.trvDept_AfterSelect);
			// 
			// imgDeptList
			// 
			this.imgDeptList.ImageSize = new System.Drawing.Size(16, 16);
			this.imgDeptList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgDeptList.ImageStream")));
			this.imgDeptList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tbrButtonAdd
			// 
			this.tbrButtonAdd.ImageIndex = 0;
			this.tbrButtonAdd.Text = "新增";
			// 
			// CfrmPlatFStuTree
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(792, 501);
			this.Controls.Add(this.trvDept);
			this.Controls.Add(this.labview);
			this.Controls.Add(this.tbrStuTree);
			this.Controls.Add(this.lvStuTree);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "CfrmPlatFStuTree";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "学生信息维护";
			this.Load += new System.EventHandler(this.CfrmPlatFStuTree_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void CfrmPlatFStuTree_Load(object sender, System.EventArgs e)
		{
			//窗体初始化
			//StuTreeview();
			lvStuTree.FullRowSelect =true;  //整行选择
			lvStuTree.HideSelection = false; //当listview没有焦点时,选定项是否仍然突出显示
			lvStuTree.View=View.Details;  
			lvStuTree.GridLines=true; 
			lvStuTree.Clear();
			string[] UserFieldInfo = {"姓名","性别","学号","类别","专业","入学时间"};
			for (int i = 0; i <= 5; i++)
			{
				lvStuTree.Columns.Add(UserFieldInfo[i], 80, HorizontalAlignment.Center);
			}			
			//初始化pnlDept部门显示控件
			//数据库查询操作,listview中按照名称顺序显示记录
			System.Data.OracleClient.OracleConnection Org_myConn = Connection.DBConnection;
			if (Org_myConn == null)
			{
				return;	
			}
			//如无学校则退出
			string Org_mySql = "SELECT OrgName FROM charge_school_Info";
			OracleCommand selCommand = new OracleCommand(Org_mySql,Org_myConn);
			
			OracleDataReader trvDataReader = null;
			try
			{
				trvDataReader = selCommand.ExecuteReader();
			}
			catch(Exception ee)
			{
				MessageBox.Show("数据库查询出错,消息如下:\r\n"+ee.Message,"消息:",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return;
			}
			if (!trvDataReader.HasRows)
			{
				

				MessageBox.Show("必须先建立学校信息!");
				this.Close();
				return;
			}
			//初始化TreeView控件,将学校设为其根节点
			trvTagTemp TagTemp= new trvTagTemp();//为结构trvTagTemp分配内存
			TreeNode rootNode = new TreeNode();
			while (trvDataReader.Read ())
			{
				
				rootNode =trvDept.Nodes.Add(trvDataReader.GetValue(0).ToString().Trim());
				rootNode.ImageIndex = 2;
				rootNode.SelectedImageIndex = 2;
				TagTemp.temp_id = "0";   //在部门部门关系表中将一级部门的上级部门ID设为0
				TagTemp.temp_isexpand = 2; //表示根节点已展开过

				//该值为0代表此节点是最高节点,该值为1代表此节点是部门类型,该值为2代表此节点是班级类型,该值为3代表此节点是专业类型
				TagTemp.temp_type = 0; 
				rootNode.Tag = TagTemp;

			}	
			GetDepttree(rootNode);//获得所有一级部门列表
			GetClasstree(rootNode);//获得学校直属班级列表
			trvDept.CollapseAll(); //折叠所有树节点

		}

		/****************************************************************************
			Function Description:
				获得下属部门列表
			Arguments:
				Type_ID		查找类别	1—查下属有学生的部门
										2—查下属有老师

	的部门
										3—查所有部门
				Node		当前点击的树结点,即当前部门
			Return Value:
				NONE
			History:
				Modified on 07/23/2004 by may-fly@tom.com
				Modified on 08/02/2004 by may-fly@tom.com
				Modified on 08/14/2004 by cellz
		
		

	*****************************************************************************/
		private void GetDepttree(TreeNode Node)//ok
		{
			string strDtName = "dtDept";
			DataSet dsDept = new DataSet();

			//存储过程的名称
			string strProcedureName = "";

			//输出参数(两个)
			OracleParameter[] outParam = {new OracleParameter(), new OracleParameter()};
			outParam[0].ParameterName = "p_Result";
			outParam[0].OracleType = OracleType.Number;
			outParam[0].Direction = ParameterDirection.Output;
			outParam[1].ParameterName = "Re_CURSOR";
			outParam[1].OracleType = OracleType.Cursor;
			outParam[1].Direction = ParameterDirection.Output;

			//输入参数(两个)
			OracleParameter[] inParam = {new OracleParameter(), new	OracleParameter()};			

			
			//Node.tag里保存的是节点的类别
			

			//实例化结构trvTagTemp,用来取得选定treenode的tag属性中保存的Deptid
			trvTagTemp selectedTag = (trvTagTemp)Node.Tag ;
			//int nTag = selectedTag.temp_type;
	
			//显示学生部门类型
		
			strProcedureName = "SP_charge_GETDEPTBYID";
			inParam[0].ParameterName = "p_DeptID";
			inParam[0].OracleType = OracleType.Int32;
			inParam[0].Value = selectedTag.temp_id;
			inParam[1].ParameterName = "p_Type";
			inParam[1].OracleType = OracleType.Int32;
			inParam[1].Value = 1;
				

			//存储过程的调用,更新dtDept,dsDept
			
			GlobleHelper.ExecStoredProc(strProcedureName, inParam, ref outParam, ref dsDept);
			if (Convert.ToInt32(outParam[0].Value) == 0)
			{
				trvTagTemp TagTemp= new trvTagTemp();//为结构trvTagTemp分配内存
			
				foreach(DataTable dtTable in dsDept.Tables)
				{
					dtTable.TableName = strDtName;
									

					TreeNode NewNode;

					if (dtTable.Rows.Count > 0)
					{						

	
						foreach (DataRow myRow in dtTable.Rows)
						{
							//在treeview中显示数据
							NewNode = new TreeNode(Node.Index.ToString() + myRow[0].ToString());//保证node唯一性
							Node.Nodes.Add(NewNode);
							NewNode.Text = myRow["DeptName"].ToString();	//DeptName或ClassName
							TagTemp.temp_id = myRow[0].ToString();   //部门ID
							TagTemp.temp_isexpand = 1; //表示根节点未展开过
							TagTemp.temp_type = 1; //该节点是部门类型
							NewNode.Tag = TagTemp;
							NewNode.ImageIndex = 0;
							NewNode.SelectedImageIndex = 1;
							
						}

					}
					Node.Expand();
					selectedTag.temp_isexpand = 2;
					Node.Tag = selectedTag;				

		
				}
			}
			else
			{
				

				MessageBox.Show("未知数据库操作错误,请重新打开窗体!");
			}
			

		}
		/****************************************************************************
		Function Description:
			获得下属班级列表
		Arguments:
			Node		当前点击的树结点,即当前部门
		Return Value:
			NONE
		History:
			Modified on 07/23/2004 by may-fly@tom.com
		*****************************************************************************/
		private void GetClasstree(TreeNode Node)
		{
			if(Node == null)
			{
				return;
			}
			string strDtName = "dtClass";
			DataSet dsClass = new DataSet();
            //实例化结构trvTagTemp,用来取得选定treenode的tag属性中保存的Deptid
			if(Node.Tag == null)
			{
				return;
			}
			trvTagTemp selectedTag = (trvTagTemp)Node.Tag ;
            //存储过程的名称
			string strProcedureName = "SP_charge_GETCLASSBYDEPTID";
			//输出参数(两个)
			OracleParameter[] outParam = {new OracleParameter(), new OracleParameter()};

			outParam[0].ParameterName = "p_Result";
			outParam[0].OracleType = OracleType.Number;
			outParam[0].Direction = ParameterDirection.Output;

			outParam[1].ParameterName = "Re_CURSOR";
			outParam[1].OracleType = OracleType.Cursor;
			outParam[1].Direction = ParameterDirection.Output;

			//输入参数(两个)
			OracleParameter[] inParam = {new OracleParameter()};
			inParam[0].Direction = ParameterDirection.Input;
			inParam[0].ParameterName = "p_DeptID";
			inParam[0].Value = selectedTag.temp_id;

			//调用CStoreProc的RunProcedure方法,更新dtDept,dsClass
			
			GlobleHelper.ExecStoredProc(strProcedureName, inParam, ref outParam, ref dsClass);
		
			if( Convert.ToInt32(outParam[0].Value)==0)
			{
				trvTagTemp TagTemp= new trvTagTemp();//为结构trvTagTemp分配内存
				
				foreach(DataTable dtTable in dsClass.Tables)
				{
					dtTable.TableName = strDtName;						
					TreeNode NewNode;
					if (dtTable.Rows.Count > 0)
					{
							
						foreach (DataRow myRow in dtTable.Rows)
						{
							//在treeview中显示数据
							NewNode = new TreeNode(Node.Index.ToString() + myRow[0].ToString());//保证node唯一性
							Node.Nodes.Add(NewNode);
							NewNode.Text = myRow["ClassName"].ToString();	//ClassName
							TagTemp.temp_id = myRow[0].ToString();   //部门ID
							TagTemp.temp_isexpand = 2; //表示根节点已展开,因为是叶子节点,所以默认展开
							TagTemp.temp_type = 2; //该节点是班级类型
							NewNode.Tag = TagTemp;

⌨️ 快捷键说明

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