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

📄 favoriteform.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.DALFactory;
using CallCenter.IDAL;
using CallCenter.Modules;
using CallCenter.OracleDAL;
using System.Data;


namespace  CallCenter.BusinessInterfaces.MainForms
{
	/// <summary>
	/// FavoriteForm 的摘要说明。
	/// </summary>
	public class FavoriteForm : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.Panel panel1;
		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 System.Data.DataSet ds;
		private KnowledgeTypeBLL bll = new KnowledgeTypeBLL();
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.DataGrid dgFavor;
		private DataSet dsf=null;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private int i=0;
		
		private string node;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FavoriteForm()
		{
			//
			// 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.panel1 = new System.Windows.Forms.Panel();
			this.treeList1 = new DevExpress.XtraTreeList.TreeList();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.dgFavor = new System.Windows.Forms.DataGrid();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.treeList1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dgFavor)).BeginInit();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.treeList1);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(208, 541);
			this.panel1.TabIndex = 0;
			// 
			// treeList1
			// 
			this.treeList1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.treeList1.Location = new System.Drawing.Point(0, 0);
			this.treeList1.Name = "treeList1";
			this.treeList1.Size = new System.Drawing.Size(208, 541);
			this.treeList1.TabIndex = 0;
			// 
			// splitter1
			// 
			this.splitter1.Location = new System.Drawing.Point(208, 0);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 541);
			this.splitter1.TabIndex = 1;
			this.splitter1.TabStop = false;
			// 
			// dgFavor
			// 
			this.dgFavor.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.dgFavor.CaptionText = "收藏夹列表";
			this.dgFavor.ContextMenu = this.contextMenu1;
			this.dgFavor.DataMember = "";
			this.dgFavor.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgFavor.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgFavor.Location = new System.Drawing.Point(211, 0);
			this.dgFavor.Name = "dgFavor";
			this.dgFavor.ReadOnly = true;
			this.dgFavor.Size = new System.Drawing.Size(533, 541);
			this.dgFavor.TabIndex = 2;
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItem1,
																						 this.menuItem2});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "取消收藏";
			this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "查看详细";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// FavoriteForm
			// 
			this.AutoScroll = true;
			this.Controls.Add(this.dgFavor);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.panel1);
			this.Name = "FavoriteForm";
			this.Size = new System.Drawing.Size(744, 541);
			this.Load += new System.EventHandler(this.FavoriteForm_Load);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dgFavor)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void FavoriteForm_Load(object sender, System.EventArgs e)
		{
			ds = bll.getKnowledgeType("KNOWLEDGETYPE");
			initTreeList();
			paintTreeList();
			getFavor();
		}

		private void getFavor()
		{
			KnowledgeBLL kbll=new KnowledgeBLL();
			dsf=new DataSet();
			dsf=kbll.getFavoriteByCId_DataSet(ShareClass.Operator,"favor");
			this.dgFavor.DataSource=dsf.Tables["favor"].DefaultView;

			this.dgFavor.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = dsf.Tables["favor"].TableName;

			DataGridColumnStyle gs0 = new DataGridTextBoxColumn();
			gs0.MappingName = "id";
			gs0.HeaderText = "编号";
			gs0.ReadOnly=true;
			gs0.Width=0;
			gs0.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(gs0);

			DataGridColumnStyle gs1 = new DataGridTextBoxColumn();
			gs1.MappingName = "ktitle";
			gs1.HeaderText = "标题";
			gs1.ReadOnly=true;
			gs1.Width=360;
			gs1.Alignment = HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(gs1);

			DataGridColumnStyle gs2 = new DataGridTextBoxColumn();
			gs2.MappingName = "kkeywords";
			gs2.HeaderText = "关键字";
			gs2.ReadOnly=true;
			gs2.Width=200;
			gs2.Alignment = HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(gs2);


			this.dgFavor.TableStyles.Add(ts);
		}
		private void initTreeList()
		{
			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();
			// 
			// treeList1
			// 
			this.treeList1.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] {
																									 this.colTNAME,
																									 this.colOAMARK,
																									 this.colID,
																									 this.colPARENTID});
			this.treeList1.Location = new System.Drawing.Point(16, 48);
			this.treeList1.Name = "treeList1";
			this.treeList1.Size = new System.Drawing.Size(280, 464);
			this.treeList1.TabIndex = 0;
			this.treeList1.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(this.treeList1_FocusedNodeChanged);
			// 
			// colTNAME
			// 
			this.colTNAME.Caption = "分类名称";
			this.colTNAME.FieldName = "TNAME";
			this.colTNAME.Name = "colTNAME";
			this.colTNAME.OptionsColumn.AllowEdit = false;
			this.colTNAME.OptionsColumn.FixedWidth = true;
			this.colTNAME.VisibleIndex = 0;
			this.colTNAME.Width = 160;
			// 
			// colOAMARK
			// 
			this.colOAMARK.FieldName = "OAMARK";
			this.colOAMARK.Name = "colOAMARK";
			this.colOAMARK.OptionsColumn.AllowEdit = false;
			this.colOAMARK.Width = 20;
			// 
			// colID
			// 
			this.colID.Caption = "ID";
			this.colID.FieldName = "ID";
			this.colID.Name = "colID";
			this.colID.OptionsColumn.AllowEdit = false;
			// 
			// colPARENTID
			// 
			this.colPARENTID.Caption = "PARENTID";
			this.colPARENTID.FieldName = "PARENTID";
			this.colPARENTID.Name = "colPARENTID";
			this.colPARENTID.OptionsColumn.AllowEdit = false;
		}

		private void treeList1_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
		{
			if(i==0)
			{
				i++;
			}
			else
			{
				node=e.Node.GetDisplayText(2);
				DataView dv=new DataView(dsf.Tables["favor"],"ktype like '%,"+e.Node.GetDisplayText(2)+",%'","camount",DataViewRowState.CurrentRows);
				this.dgFavor.DataSource=dv;//
			}
			
		}

		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);
				}

			}			
		}

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
//		static void Main() 
//		{
//			Application.Run(new FavoriteForm());
//		}

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(this.dgFavor[this.dgFavor.CurrentCell.RowNumber,0].ToString()=="")
				{
					MessageBox.Show(this,"此行数据不存在,请重新选择!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					return;
				}
				KnowledgeBLL kbll=new KnowledgeBLL();
				kbll.delFavorite(ShareClass.Operator,Convert.ToInt32(this.dgFavor[this.dgFavor.CurrentCell.RowNumber,0]));
			


				dsf=new DataSet();
				dsf=kbll.getFavoriteByCId_DataSet(ShareClass.Operator,"favor");

				if(i==1)
				{
					this.dgFavor.DataSource=dsf.Tables["favor"].DefaultView;
				}
				else
				{
					DataView dv=new DataView(dsf.Tables["favor"],"ktype like '%,"+node+",%'","camount",DataViewRowState.CurrentRows);
					this.dgFavor.DataSource=dv;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(this.dgFavor[this.dgFavor.CurrentCell.RowNumber,0].ToString()=="")
				{
					MessageBox.Show(this,"此行数据不存在,请重新选择!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					return;
				}
				KnowledgeBLL kbll=new KnowledgeBLL();
				KnowledgeInfo kinfo=new KnowledgeInfo();
				kinfo=kbll.getKnowledgeById(Convert.ToInt32(this.dgFavor[this.dgFavor.CurrentCell.RowNumber,0]));
//				KnowledgeManage_Dialog km=new KnowledgeManage_Dialog(kinfo);
				CallCenter.BusinessInterfaces.BaseForms.KnowledgeDetailForm km = new CallCenter.BusinessInterfaces.BaseForms.KnowledgeDetailForm(kinfo);
				km.ShowDialog();
//				km.ShowDialog();

			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
	}
}

⌨️ 快捷键说明

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