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

📄 runreportselectfrm.cs

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

namespace TreeReportApp
{
	/// <summary>
	/// TreeReportSelectFrm 的摘要说明。
	/// </summary>
	public class TreeReportSelectFrm : System.Windows.Forms.Form
	{
		public string _selectreportid;
		public string _selectreportdescript;
		public string _wherestr="";

		public ArrayList _idlist;
		public ArrayList _desclist;

		private System.Windows.Forms.TreeView treeView_report;
		private System.Windows.Forms.ImageList imageList_view;
		private System.ComponentModel.IContainer components;

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

			_selectreportid="";
			_selectreportdescript="";
			_wherestr="";
		}

		/// <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(TreeReportSelectFrm));
			this.treeView_report = new System.Windows.Forms.TreeView();
			this.imageList_view = new System.Windows.Forms.ImageList(this.components);
			this.SuspendLayout();
			// 
			// treeView_report
			// 
			this.treeView_report.Dock = System.Windows.Forms.DockStyle.Fill;
			this.treeView_report.ImageList = this.imageList_view;
			this.treeView_report.Location = new System.Drawing.Point(0, 0);
			this.treeView_report.Name = "treeView_report";
			this.treeView_report.Size = new System.Drawing.Size(320, 245);
			this.treeView_report.TabIndex = 0;
			this.treeView_report.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.treeView_report_KeyPress);
			this.treeView_report.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_report_AfterSelect);
			this.treeView_report.MouseLeave += new System.EventHandler(this.treeView_report_MouseLeave);
			// 
			// imageList_view
			// 
			this.imageList_view.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList_view.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList_view.ImageStream")));
			this.imageList_view.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// TreeReportSelectFrm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.Info;
			this.ClientSize = new System.Drawing.Size(320, 245);
			this.ControlBox = false;
			this.Controls.Add(this.treeView_report);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Name = "TreeReportSelectFrm";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.Text = "TreeReportSelectFrm";
			this.Load += new System.EventHandler(this.TreeReportSelectFrm_Load);
			this.Deactivate += new System.EventHandler(this.TreeReportSelectFrm_Deactivate);
			this.ResumeLayout(false);

		}
		#endregion

		private void treeView_report_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if ("@catalog@".Equals(treeView_report.SelectedNode.Tag.ToString()))
				return;
            
			//设置所选择的内容
			_selectreportid = treeView_report.SelectedNode.Tag.ToString();
			_selectreportdescript = treeView_report.SelectedNode.Text;
			
			//关闭此列表窗体
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void TreeReportSelectFrm_Deactivate(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void TreeReportSelectFrm_Load(object sender, System.EventArgs e)
		{
			if (_idlist==null || _idlist.Count==0)
			{
				OleDbConnection conn =  new OleDbConnection();
				//连接据库,这段程序用一个公共连接类代替
				conn.ConnectionString = TreeConnection.connstr;
				conn.Open();

				//没有指明列表中的内容时,从数据库中按条件取报表的信息
				try
				{

					//判断是否有条件
					_wherestr = (""+_wherestr).Trim();
					_wherestr =(_wherestr.Length>0 && !_wherestr.ToLower().StartsWith("where"))?(" where "+ _wherestr):_wherestr;

					System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("select * from ReportsManage " + _wherestr ,conn);
					System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();


					TreeNode catalognode = null;
					string catalogstr = "";

					while(rd.Read())
					{   
						if (!catalogstr.Equals(""+rd["ManageCategory"]))
						{
							catalogstr = ""+rd["ManageCategory"];
							catalognode = new TreeNode(catalogstr,0,0);
							catalognode.Tag = "@catalog@";

							treeView_report.Nodes.Add(catalognode);
						}

						string multilangname = "CReportName";//多种语言的设置

						TreeNode newnode = new TreeNode(""+rd["ReportID"]+" ["+rd[multilangname]+"]",1,1);
						newnode.Tag = rd["ReportID"].ToString();

						catalognode.Nodes.Add(newnode);
					}
			
					rd.Close();
				}
				catch
				{}

				if( conn.State == System.Data.ConnectionState.Open)
					conn.Close();
			}
			else
			{
				//指明了列表中的内容时,直接生成listview
				for(int i =0; i<_idlist.Count;i++)
				{
					TreeNode newnode = new TreeNode(""+_idlist[i]+" ["+_desclist[i]+"]",1,1);
					newnode.Tag = _idlist[i].ToString();

					treeView_report.Nodes.Add(newnode);
				}
			}
		}

		private void treeView_report_MouseLeave(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void treeView_report_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		
		}
	}
}

⌨️ 快捷键说明

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