Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#

EasiReports

Rate me:
Please Sign up or sign in to vote.
4.87/5 (64 votes)
13 Feb 2006CPOL6 min read 480.1K   9.7K   219  
A library to add reports to your application.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Text;

using Fusion.Native;

namespace EasiReports
{
	/// <summary>
	/// Summary description for DlgAlgorithmReferencesSelect.
	/// </summary>
	internal class CDlgAlgorithmReferencesSelect : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox listReferences;
		private System.Windows.Forms.Button buttonBrowse;
		private System.Windows.Forms.TextBox textReference;
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.Button buttonCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private string m_sReference = null;
		public string sReference { get { return m_sReference; } }

		public CDlgAlgorithmReferencesSelect( string sReference )
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			IAssemblyCache ac;
			FusionApi.CreateAssemblyCache( out ac, 0 );
			
			IAssemblyEnum ae;
			FusionApi.CreateAssemblyEnum( out ae, IntPtr.Zero, null, ASM_CACHE_FLAGS.ASM_CACHE_GAC, IntPtr.Zero );

			IAssemblyName an;
			while ( ae.GetNextAssembly( IntPtr.Zero, out an, 0 ) == 0 ) 
			{
				string sName;
				if ( true )
				{
					uint nChars = 0;
					an.GetName( ref nChars, null );

					StringBuilder sb;
					sb = new StringBuilder( (int)nChars );

					an.GetName( ref nChars, sb );

					sName = sb.ToString();
				}

				string sPath;
				if ( true )
				{
					ASSEMBLY_INFO ai = new ASSEMBLY_INFO();
					ac.QueryAssemblyInfo( 0, sName, ref ai );

					ai.pszCurrentAssemblyPathBuf = new string( '\0', (int)ai.cchBuf );
					ac.QueryAssemblyInfo( 0, sName, ref ai );

					sPath = ai.pszCurrentAssemblyPathBuf;
				}

				listReferences.Items.Add( Path.GetFileName( sPath ) );
			}

			if ( sReference != null )
			{
				m_sReference = sReference;
				textReference.Text = sReference;
				listReferences.SelectedItem = sReference;
			}
		}

		/// <summary>Clean up any resources being used.</summary>
		/// <param name="disposing"><b>true</b> to release both managed and unmanaged resources; <b>false</b> to release only unmanaged resources.</param>
		/// <remarks>Releases the unmanaged resources and optionally releases the managed resources.</remarks>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CDlgAlgorithmReferencesSelect));
			this.listReferences = new System.Windows.Forms.ListBox();
			this.buttonBrowse = new System.Windows.Forms.Button();
			this.textReference = new System.Windows.Forms.TextBox();
			this.buttonOK = new System.Windows.Forms.Button();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// listReferences
			// 
			this.listReferences.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.listReferences.Location = new System.Drawing.Point(8, 8);
			this.listReferences.Name = "listReferences";
			this.listReferences.Size = new System.Drawing.Size(232, 186);
			this.listReferences.TabIndex = 0;
			this.listReferences.DoubleClick += new System.EventHandler(this.listReferences_DoubleClick);
			this.listReferences.SelectedIndexChanged += new System.EventHandler(this.listReferences_SelectedIndexChanged);
			// 
			// buttonBrowse
			// 
			this.buttonBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.buttonBrowse.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.buttonBrowse.Location = new System.Drawing.Point(8, 224);
			this.buttonBrowse.Name = "buttonBrowse";
			this.buttonBrowse.TabIndex = 1;
			this.buttonBrowse.Text = "Browse...";
			this.buttonBrowse.Click += new System.EventHandler(this.buttonBrowse_Click);
			// 
			// textReference
			// 
			this.textReference.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textReference.Location = new System.Drawing.Point(8, 200);
			this.textReference.Name = "textReference";
			this.textReference.Size = new System.Drawing.Size(232, 20);
			this.textReference.TabIndex = 2;
			this.textReference.Text = "";
			// 
			// buttonOK
			// 
			this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.buttonOK.Location = new System.Drawing.Point(88, 224);
			this.buttonOK.Name = "buttonOK";
			this.buttonOK.TabIndex = 3;
			this.buttonOK.Text = "OK";
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
			// 
			// buttonCancel
			// 
			this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.buttonCancel.Location = new System.Drawing.Point(168, 224);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.TabIndex = 4;
			this.buttonCancel.Text = "Cancel";
			// 
			// CDlgAlgorithmReferencesSelect
			// 
			this.AcceptButton = this.buttonOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.buttonCancel;
			this.ClientSize = new System.Drawing.Size(248, 254);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.buttonOK);
			this.Controls.Add(this.textReference);
			this.Controls.Add(this.buttonBrowse);
			this.Controls.Add(this.listReferences);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "CDlgAlgorithmReferencesSelect";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Select Reference";
			this.ResumeLayout(false);

		}
		#endregion

		private void listReferences_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			textReference.Text = listReferences.SelectedItem.ToString();
		}

		private void buttonBrowse_Click(object sender, System.EventArgs e)
		{
			FileDialog dlg = new OpenFileDialog();
			dlg.CheckFileExists = true;
			dlg.Filter = "Component Files (*.dll;*.tlb;*.olb;*.ocx;*.exe)|*.dll;*.tlb;*.olb;*.ocx;*.exe|All Files (*.*)|*.*";
			dlg.Title = "Select Component File";
			if ( dlg.ShowDialog( this ) != DialogResult.OK ) return;

			textReference.Text = dlg.FileName;
		}

		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			m_sReference = textReference.Text;
		}

		private void listReferences_DoubleClick(object sender, System.EventArgs e)
		{
			m_sReference = textReference.Text;
			DialogResult = DialogResult.OK;
			Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
I discovered C# and .NET 1.0 Beta 1 in late 2000 and loved them immediately.
I have been writing software professionally in C# ever since

In real life, I have spent 3 years travelling abroad,
I have held a UK Private Pilots Licence for 20 years,
and I am a PADI Divemaster.

I now live near idyllic Bournemouth in England.

I can work 'virtually' anywhere!

Comments and Discussions