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

📄 ktypemanage.cs

📁 c#编写的汽车销售公司erp进销存系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.labTitle);
			this.Name = "KTypeManage";
			this.Size = new System.Drawing.Size(656, 565);
			this.Load += new System.EventHandler(this.KTypeManage_Load);
			((System.ComponentModel.ISupportInitialize)(this.panel2)).EndInit();
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.repositoryItemTextEdit1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.repositoryItemCheckEdit1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
			//		static void Main() 
			//		{
			//			Application.Run(new KTypeManage());
			//		}
		private void KTypeManage_Load(object sender, System.EventArgs e)
		{
			ds = bll.getKnowledgeType("KNOWLEDGETYPE");
			paintTreeList();
			
		}

	
		private void paintTreeList()
		{
			TreeListNode node;
			string strexp="id="+1;
			DataRow[] funrow= ds.Tables[0].Select(strexp,"");
			DataRow dr = funrow[0];	
			node = this.treeList1.AppendNode(new Object[]{dr["TNAME"],dr["OAMARK"],dr["ID"],dr["PARENTID"]},null);

			string strsel = "parentid="+dr["ID"];
			DataRow[] chdr = ds.Tables[0].Select(strsel);
			if(chdr.Length>0)
			{
				digui(node,chdr);
			}
			this.treeList1.ExpandAll();
		}

		private void digui(TreeListNode pnode,DataRow[] chdr)
		{						
			TreeListNode node;
			for(int i=0;i<chdr.Length;i++)
			{
				node = this.treeList1.AppendNode(new Object[]{chdr[i]["TNAME"],chdr[i]["OAMARK"],chdr[i]["ID"],chdr[i]["PARENTID"]},pnode);
				string strsel = "parentid="+chdr[i]["ID"];
				DataRow[] dgdr = ds.Tables[0].Select(strsel);
				if(dgdr.Length>0)
				{
					digui(node,dgdr);
				}

			}			
		}
	

		private void treeList1_DragOver(object sender, DragEventArgs e)
		{
			TreeListHitInfo hi = treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y)));
			overNode = GetDragNode(e.Data);
			//			MessageBox.Show(overNode.GetDisplayText(0));
		}

		private void treeList1_DragDrop(object sender, DragEventArgs e)
		{
			TreeListHitInfo hi = treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y)));

			TreeListNode node = hi.Node;
			if(node != null) 
			{
				overNode.SetValue(this.colPARENTID,node.GetValue(this.colID));
				KnowledgeTypeInfo info = new KnowledgeTypeInfo();
				info.id = Convert.ToInt32(overNode.GetDisplayText(2));
				info.oamark = Convert.ToInt32(overNode.GetDisplayText(1));
				info.pid = Convert.ToInt32(overNode.GetDisplayText(3));
				info.tname = overNode.GetDisplayText(0);
				bll.updateKnowledgeType(info);
			}
		}

		private TreeListNode GetDragNode(IDataObject data) 
		{
			return data.GetData(typeof(TreeListNode)) as TreeListNode;
		}
		
		/// <summary>
		/// 修改分类
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void treeList1_CellValueChanged(object sender, CellValueChangedEventArgs e)
		{			
//			//			string tempTname = e.Node.GetDisplayText(0);
			if(!flag)
			{
				flag = !flag;
				return;
			}
			else
			{
				flag = !flag;
			}
			if(e.Node.GetDisplayText(0).Length>30)
			{
				MessageBox.Show(this,"分类名称不可超过30个字符!","警告",MessageBoxButtons.OK);
				e.Node.SetValue(this.colTNAME,"请输入正确的分类名称");
				this.treeList1.SetFocusedNode(e.Node);
				return;
			}
			KnowledgeTypeInfo info = new KnowledgeTypeInfo();
			info.tname = e.Node.GetDisplayText(0);
			info.oamark = Convert.ToInt32(e.Node.GetDisplayText(1));
			info.id = Convert.ToInt32(e.Node.GetDisplayText(2));			
			info.pid = Convert.ToInt32(e.Node.GetDisplayText(3));
			//			MessageBox.Show(info.id+" ; "+info.tname);
			this.saveKType(info);
		}

		private void saveKType(KnowledgeTypeInfo info)
		{			
			bll.updateKnowledgeType(info);
			
		}

		/// <summary>
		/// 增加新分类
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuItem3_Click(object sender, EventArgs e)
		{
			TreeListNode parentNode = this.treeList1.FocusedNode;
			if(parentNode == null)
			{
				MessageBox.Show(this,"请先选择父分类!","警告",MessageBoxButtons.OK);
				return;
			}
			KnowledgeTypeInfo info = new KnowledgeTypeInfo();
			info.pid = Convert.ToInt32(parentNode.GetDisplayText(2));
			info.oamark = 0;
			info.tname = "请输入分类名称";
			info.id = bll.addKnowledgeType(info);
			TreeListNode newNode = this.treeList1.AppendNode(new Object[]{info.tname,info.oamark,info.id,info.pid},parentNode);

			flag = !flag;
		}

		/// <summary>
		/// 删除分类
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuItem2_Click(object sender, EventArgs e)
		{
			TreeListNode currNode = this.treeList1.FocusedNode;
			int id = Convert.ToInt32(currNode.GetDisplayText(2));
			if(currNode == null)
			{
				MessageBox.Show(this,"请先选择要删除的分离!","警告",MessageBoxButtons.OK);
				return;
			}
			if(1 == id)
			{
				MessageBox.Show(this,"该分类不允许删除!","警告",MessageBoxButtons.OK);
				return ;
			}
			if(DialogResult.Yes== MessageBox.Show(this,"确定要删除"+currNode.GetDisplayText(0)+"分类吗?","提示",MessageBoxButtons.YesNo))
			{				
				int flag = bll.delKnowledgeType(id);
				if(-1 == flag)
				{
					MessageBox.Show(this,"该分类下存在知识,不允许删除!","警告",MessageBoxButtons.OK);
					return ;
				}
				else if(0 == flag)
				{
					MessageBox.Show(this,"该分类下有子分类,不允许删除!","警告",MessageBoxButtons.OK);
					return ;
				}				
			}
			else
			{
				return;
			}
			this.treeList1.Nodes.Remove(currNode);										
		}

	

		private void treeList1_MouseDown(object sender, MouseEventArgs e)
		{
			
			if(e.Button == MouseButtons.Right)
			{
				//				MessageBox.Show(this,"111");
				TreeListHitInfo hi = this.treeList1.CalcHitInfo(new Point(e.X, e.Y));
				//				TreeListHitInfo hi = treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y)));
				TreeListNode node = hi.Node;
				//				MessageBox.Show(this,node.GetDisplayText(0));
				if(null != node)
				{
					this.treeList1.SetFocusedNode(node);
					this.contextMenu1.Show(this,new Point(e.X,e.Y));
				}
			}
		}
	}
}

⌨️ 快捷键说明

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