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

📄 designreportselectdata.cs

📁 树形逻辑报表程序源码,能根居元数据定义拖拉开发新的报表.
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;

namespace TreeReportApp
{
	/// <summary>
	/// TreeReportSelectData 的摘要说明。
	/// </summary>
	public class TreeReportSelectData : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Splitter splitter2;
		private System.Windows.Forms.TreeView treeView_diction;
		private System.Windows.Forms.ListView listView_dictionitem;
		private System.Windows.Forms.Button button_select;
		private System.Windows.Forms.Button button_cancel;
		private System.Windows.Forms.ImageList imageList_TreeListView;
		private System.Data.OleDb.OleDbConnection conn;
		private System.ComponentModel.IContainer components;

		private string currenttreenodetext = "";
		public string selecteddiction = "";

		public TreeReportSelectData()
		{
			//
			// 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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TreeReportSelectData));
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.panel1 = new System.Windows.Forms.Panel();
			this.button_select = new System.Windows.Forms.Button();
			this.button_cancel = new System.Windows.Forms.Button();
			this.treeView_diction = new System.Windows.Forms.TreeView();
			this.splitter2 = new System.Windows.Forms.Splitter();
			this.listView_dictionitem = new System.Windows.Forms.ListView();
			this.imageList_TreeListView = new System.Windows.Forms.ImageList(this.components);
			this.conn = new System.Data.OleDb.OleDbConnection();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// splitter1
			// 
			this.splitter1.Location = new System.Drawing.Point(0, 0);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 349);
			this.splitter1.TabIndex = 1;
			this.splitter1.TabStop = false;
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.button_select);
			this.panel1.Controls.Add(this.button_cancel);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel1.Location = new System.Drawing.Point(3, 309);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(509, 40);
			this.panel1.TabIndex = 2;
			// 
			// button_select
			// 
			this.button_select.Location = new System.Drawing.Point(104, 8);
			this.button_select.Name = "button_select";
			this.button_select.Size = new System.Drawing.Size(88, 24);
			this.button_select.TabIndex = 0;
			this.button_select.Text = "选  择";
			this.button_select.Click += new System.EventHandler(this.button_select_Click);
			// 
			// button_cancel
			// 
			this.button_cancel.Location = new System.Drawing.Point(312, 8);
			this.button_cancel.Name = "button_cancel";
			this.button_cancel.Size = new System.Drawing.Size(88, 24);
			this.button_cancel.TabIndex = 0;
			this.button_cancel.Text = "取  消";
			this.button_cancel.Click += new System.EventHandler(this.button_cancel_Click);
			// 
			// treeView_diction
			// 
			this.treeView_diction.Dock = System.Windows.Forms.DockStyle.Left;
			this.treeView_diction.ImageIndex = -1;
			this.treeView_diction.Location = new System.Drawing.Point(3, 0);
			this.treeView_diction.Name = "treeView_diction";
			this.treeView_diction.SelectedImageIndex = -1;
			this.treeView_diction.Size = new System.Drawing.Size(125, 309);
			this.treeView_diction.TabIndex = 3;
			this.treeView_diction.DoubleClick += new System.EventHandler(this.treeView_diction_DoubleClick);
			this.treeView_diction.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_diction_AfterSelect);
			// 
			// splitter2
			// 
			this.splitter2.Location = new System.Drawing.Point(128, 0);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(3, 309);
			this.splitter2.TabIndex = 4;
			this.splitter2.TabStop = false;
			// 
			// listView_dictionitem
			// 
			this.listView_dictionitem.Dock = System.Windows.Forms.DockStyle.Fill;
			this.listView_dictionitem.Location = new System.Drawing.Point(131, 0);
			this.listView_dictionitem.MultiSelect = false;
			this.listView_dictionitem.Name = "listView_dictionitem";
			this.listView_dictionitem.Size = new System.Drawing.Size(381, 309);
			this.listView_dictionitem.TabIndex = 5;
			this.listView_dictionitem.DoubleClick += new System.EventHandler(this.listView_dictionitem_DoubleClick);
			// 
			// imageList_TreeListView
			// 
			this.imageList_TreeListView.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList_TreeListView.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList_TreeListView.ImageStream")));
			this.imageList_TreeListView.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// TreeReportSelectData
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(512, 349);
			this.Controls.Add(this.listView_dictionitem);
			this.Controls.Add(this.splitter2);
			this.Controls.Add(this.treeView_diction);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.splitter1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MaximumSize = new System.Drawing.Size(520, 376);
			this.MinimizeBox = false;
			this.MinimumSize = new System.Drawing.Size(520, 376);
			this.Name = "TreeReportSelectData";
			this.Text = "选择报表数据源(业务数据字典)";
			this.Load += new System.EventHandler(this.TreeReportSelectData_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// TreeReportSelectData_Load - 初始化树形视图
		/// </summary>
		private void TreeReportSelectData_Load(object sender, System.EventArgs e)
		{
			//连接据库,这段程序用一个公共连接类代替
			conn.ConnectionString = TreeConnection.connstr;

			listView_dictionitem.Clear();
			treeView_diction.Nodes.Clear();

			if (conn.State == System.Data.ConnectionState.Closed)
				conn.Open();

			System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("select ObjectName,CatalogName,ObjectType,EDescription,CDescription,HDescription from TreeDbObjectInfos where upper(IsBussinessDict)='Y' order by CatalogName",conn);
			System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();

			string belongto = "@@@`~";
			TreeNode belongtonode=null;
			TreeNode selectednode=null;
			while(rd.Read())
			{   
				if (!belongto.Equals(rd.GetString(1)))//CatalogName
				{
					belongto = rd.GetString(1);
					belongtonode = new TreeNode( belongto,1,1);
					belongtonode.Tag = "@catalog@";//字典分类项标志
					treeView_diction.Nodes.Add(belongtonode);
				}

				string dictionname = rd.GetString(rd.GetOrdinal("ObjectName"));
				int i = rd.GetOrdinal("CDescription");
				string dictiondescript = dictionname+"["+(rd.IsDBNull(i)?"":rd.GetString(i))+"]";
				TreeNode objectnode = new TreeNode( dictiondescript,2,3);
				objectnode.Tag = dictionname;//字典项
				belongtonode.Nodes.Add(objectnode);


				//记住当前使用的数据字典
				if(selecteddiction.Equals(dictionname))
					selectednode = objectnode;
			}

			rd.Close();
			conn.Close();

			listView_dictionitem.View = View.Details;
			//标明当前数据字典为被选
			treeView_diction.SelectedNode = selectednode;			
		}

		/// <summary>
		/// treeView_diction_AfterSelect - 更新右边的列表视图
		/// </summary>
		private void treeView_diction_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if (currenttreenodetext.Equals(e.Node.Text))
				return;

			currenttreenodetext = e.Node.Text;

			listView_dictionitem.Clear();

			if (conn.State == System.Data.ConnectionState.Closed)
				conn.Open();

			if(e.Node.Tag.ToString().Equals("@catalog@"))
			{
				listView_dictionitem.Columns.Add("数据对象",100,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("类型",80,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add( "英文描述",120,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("简体中文描述",120,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("繁体中文描述",120,HorizontalAlignment.Left);

				System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("select ObjectName,ObjectType,EDescription,CDescription,HDescription from TreeDbObjectInfos where upper(IsBussinessDict)='Y' and CatalogName='" + e.Node.Text + "'" ,conn);
				System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();
				while(rd.Read())
				{
					ListViewItem item = new ListViewItem(rd.GetString(0),2);
					item.Tag = "diction";
					
					item.SubItems.Add(rd.IsDBNull(1)?"":rd.GetString(1));
					item.SubItems.Add(rd.IsDBNull(2)?"":rd.GetString(2));
					item.SubItems.Add(rd.IsDBNull(3)?"":rd.GetString(3));
					item.SubItems.Add(rd.IsDBNull(4)?"":rd.GetString(4));
					listView_dictionitem.Items.Add(item);
				}
				rd.Close();

			}
			else
			{
				listView_dictionitem.Columns.Add("数据项",100,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("类型",60,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add( "长度",40,HorizontalAlignment.Center);
				listView_dictionitem.Columns.Add("简体中文描述",120,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("繁体中文描述",120,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add( "英文描述",120,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("有效位",70,HorizontalAlignment.Center);
				listView_dictionitem.Columns.Add("约束",100,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("数据检查",100,HorizontalAlignment.Left);
				listView_dictionitem.Columns.Add("外键引用",100,HorizontalAlignment.Left);

				System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("select itemname,TypeOfData,LengthOfData,EItemDescription,CItemDescription,HItemDescription,PrecisionOfData,ConstrainExp,CheckExp,ForeignExp from TreeDbObjectInfos_items where ObjectName='" + e.Node.Tag + "'" ,conn);
				System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();
				while(rd.Read())
				{
					ListViewItem item = new ListViewItem(rd.GetString(0));
					item.ImageIndex = 4;
					item.Tag = "item";

					item.SubItems.Add(rd.GetString(1));
					item.SubItems.Add(rd.IsDBNull(2)?"":rd.GetInt32(2).ToString());
					item.SubItems.Add(rd.IsDBNull(4)?"":rd.GetString(4));
					item.SubItems.Add(rd.IsDBNull(5)?"":rd.GetString(5));
					item.SubItems.Add(rd.IsDBNull(3)?"":rd.GetString(3));
					item.SubItems.Add(rd.IsDBNull(6)?"":rd.GetInt32(6).ToString());
					item.SubItems.Add(rd.IsDBNull(7)?"":rd.GetString(7));
					item.SubItems.Add(rd.IsDBNull(8)?"":rd.GetString(8));
					item.SubItems.Add(rd.IsDBNull(9)?"":rd.GetString(9));
					listView_dictionitem.Items.Add(item);
				}
				rd.Close();
			}

			conn.Close();

		}

		/// <summary>
		/// treeView_diction_DoubleClick - 双击树形视图中的项,选择数据字典
		/// </summary>
		private void treeView_diction_DoubleClick(object sender, System.EventArgs e)
		{
			if (treeView_diction.SelectedNode.Tag.ToString().Equals("@catalog@"))
				return;//不是数据字典项

			selecteddiction = treeView_diction.SelectedNode.Tag.ToString();

			DialogResult = DialogResult.OK;
			this.Close();
		}


		/// <summary>
		/// button_select_Click - 单击按钮选择数据字典
		/// </summary>
		private void button_select_Click(object sender, System.EventArgs e)
		{
			if ( treeView_diction.SelectedNode==null || treeView_diction.SelectedNode.Tag.ToString().Equals("@catalog@"))
			{
				MessageBox.Show(this,"请在左边数据字典树中选择报表数据!");
				return;//不是数据字典项
			}

			selecteddiction = treeView_diction.SelectedNode.Tag.ToString();
			DialogResult = DialogResult.OK;
			this.Close();
		}

		/// <summary>
		/// listView_dictionitem_DoubleClick - 双击列表视图中的项,选择数据字典
		/// </summary>
		private void listView_dictionitem_DoubleClick(object sender, System.EventArgs e)
		{
			if (listView_dictionitem.SelectedItems.Count==0)
				return;//没有选上
				
			if(!listView_dictionitem.SelectedItems[0].Tag.ToString().Equals("diction"))
				return;//不是数据字典项

			selecteddiction = listView_dictionitem.SelectedItems[0].Text;

			DialogResult = DialogResult.OK;
			this.Close();
		}

		
		/// <summary>
		/// button_cancel_Click - 选择退出按钮
		/// </summary>
		private void button_cancel_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			this.Close();
		}

	}
}

⌨️ 快捷键说明

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