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

📄 ktypemanage.cs

📁 c#编写的汽车销售公司erp进销存系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;
using CallCenter.BusinessLayer;
using CallCenter.Modules;
using System.Data;

namespace CallCenter.BusinessInterfaces.MainForms
{
	/// <summary>
	/// KTypeManage 的摘要说明。
	/// </summary>
	public class KTypeManage : System.Windows.Forms.UserControl
	{
		private DevExpress.XtraTreeList.TreeList treeList1;
		private DevExpress.XtraTreeList.Columns.TreeListColumn colTNAME;
		private DevExpress.XtraTreeList.Columns.TreeListColumn colOAMARK;
		private DevExpress.XtraTreeList.Columns.TreeListColumn colID;
		private DevExpress.XtraTreeList.Columns.TreeListColumn colPARENTID;
		private DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repositoryItemCheckEdit1;
		private System.Data.DataSet ds;
		private bool flag = true;

		
		/// <summary>
		/// 知识分类数据操作类
		/// </summary>
		private KnowledgeTypeBLL bll = new KnowledgeTypeBLL();
		private System.Windows.Forms.Label labTitle;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private TreeListNode overNode;
		private System.Windows.Forms.Button btnClose;
	
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public KTypeManage()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// 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.treeList1 = new DevExpress.XtraTreeList.TreeList();
			this.colTNAME = new DevExpress.XtraTreeList.Columns.TreeListColumn();
			this.colOAMARK = new DevExpress.XtraTreeList.Columns.TreeListColumn();
			this.colID = new DevExpress.XtraTreeList.Columns.TreeListColumn();
			this.colPARENTID = new DevExpress.XtraTreeList.Columns.TreeListColumn();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.labTitle = new System.Windows.Forms.Label();
			this.panel2 = new System.Windows.Forms.Panel();
			this.btnClose = new System.Windows.Forms.Button();
			this.repositoryItemCheckEdit1 = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
			((System.ComponentModel.ISupportInitialize)(this.treeList1)).BeginInit();
			this.panel2.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.repositoryItemCheckEdit1)).BeginInit();
			this.SuspendLayout();
			// 
			// treeList1
			// 
			this.treeList1.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] {
																									 this.colTNAME,
																									 this.colOAMARK,
																									 this.colID,
																									 this.colPARENTID});
//			this.treeList1.ContextMenu = this.contextMenu1;
			this.treeList1.Location = new System.Drawing.Point(16, 48);
			this.treeList1.Name = "treeList1";
			this.treeList1.OptionsBehavior.AutoFocusNewNode = true;
			this.treeList1.OptionsBehavior.AutoMoveRowFocus = true;
			this.treeList1.OptionsBehavior.DragNodes = true;
			this.treeList1.OptionsBehavior.ShowEditorOnMouseUp = true;
			this.treeList1.Size = new System.Drawing.Size(380, 464);
			this.treeList1.TabIndex = 4;
			this.treeList1.CellValueChanged += new DevExpress.XtraTreeList.CellValueChangedEventHandler(this.treeList1_CellValueChanged);
			this.treeList1.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeList1_DragDrop);
			this.treeList1.DragOver += new System.Windows.Forms.DragEventHandler(this.treeList1_DragOver);
			this.treeList1.MouseDown += new MouseEventHandler(treeList1_MouseDown);
			// 
			// colTNAME
			// 
			this.colTNAME.Caption = "分类名称";
			this.colTNAME.FieldName = "TNAME";
			this.colTNAME.Name = "colTNAME";
			this.colTNAME.OptionsColumn.FixedWidth = true;
			this.colTNAME.VisibleIndex = 0;
			this.colTNAME.Width = 160;
			// 
			// colOAMARK
			// 
			this.colOAMARK.Caption = "OAMARK";
			this.colOAMARK.FieldName = "OAMARK";
			this.colOAMARK.Name = "colOAMARK";
			this.colOAMARK.VisibleIndex = -1;
			// 
			// colID
			// 
			this.colID.Caption = "ID";
			this.colID.FieldName = "ID";
			this.colID.Name = "colID";
			this.colID.VisibleIndex = -2;
			// 
			// colPARENTID
			// 
			this.colPARENTID.Caption = "PARENTID";
			this.colPARENTID.FieldName = "PARENTID";
			this.colPARENTID.Name = "colPARENTID";
			this.colPARENTID.VisibleIndex = -3;
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItem3,
																						 this.menuItem2});
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 0;
			this.menuItem3.Text = "添加";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "删除";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// labTitle
			// 
			this.labTitle.Location = new System.Drawing.Point(16, 16);
			this.labTitle.Name = "labTitle";
			this.labTitle.Size = new System.Drawing.Size(136, 16);
			this.labTitle.TabIndex = 3;
			this.labTitle.Text = "知识分类列表";
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.labTitle);
			this.panel2.Controls.Add(this.treeList1);
			this.panel2.Location = new System.Drawing.Point(16, 8);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(440, 520);
			this.panel2.TabIndex = 11;
			// 
			// btnClose
			// 
			this.btnClose.Location = new System.Drawing.Point(512, 504);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(80, 32);
			this.btnClose.TabIndex = 12;
			this.btnClose.Text = "关闭";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click_1);
			// 
			// repositoryItemCheckEdit1
			// 
			this.repositoryItemCheckEdit1.AllowFocused = false;
			this.repositoryItemCheckEdit1.AutoHeight = false;
			this.repositoryItemCheckEdit1.Name = "repositoryItemCheckEdit1";
			// 
			// KTypeManage
			// 
//			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(656, 565);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.panel2);
			this.Name = "KTypeManage";
			this.Text = "KTypeManage";
			this.Load += new System.EventHandler(this.KTypeManage_Load);
			((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit();
			this.panel2.ResumeLayout(false);
			((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);
		}

		/// <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 btnClose_Click_1(object sender, System.EventArgs e)
		{
//			this.Close();
		}

		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 + -