Click here to Skip to main content
15,878,945 members
Articles / Desktop Programming / Windows Forms

Most Recently Used (MRU) Component

Rate me:
Please Sign up or sign in to vote.
4.38/5 (4 votes)
5 Nov 20045 min read 110.6K   656   52  
A Most Recently Used component written in C#.
//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by a tool.
//     Runtime Version: 1.0.3705.288
//
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

namespace MostRecentlyUsedHandler {
    using System;
    using System.Data;
    using System.Xml;
    using System.Runtime.Serialization;
    
    
    [Serializable()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Diagnostics.DebuggerStepThrough()]
    [System.ComponentModel.ToolboxItem(true)]
    internal class MRUListFile : DataSet {
        
        private MRUListDataTable tableMRUList;
        
        public MRUListFile() {
            this.InitClass();
            System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
            this.Tables.CollectionChanged += schemaChangedHandler;
            this.Relations.CollectionChanged += schemaChangedHandler;
        }
        
        protected MRUListFile(SerializationInfo info, StreamingContext context) {
            string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string))));
            if ((strSchema != null)) {
                DataSet ds = new DataSet();
                ds.ReadXmlSchema(new XmlTextReader(new System.IO.StringReader(strSchema)));
                if ((ds.Tables["MRUList"] != null)) {
                    this.Tables.Add(new MRUListDataTable(ds.Tables["MRUList"]));
                }
                this.DataSetName = ds.DataSetName;
                this.Prefix = ds.Prefix;
                this.Namespace = ds.Namespace;
                this.Locale = ds.Locale;
                this.CaseSensitive = ds.CaseSensitive;
                this.EnforceConstraints = ds.EnforceConstraints;
                this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
                this.InitVars();
            }
            else {
                this.InitClass();
            }
            this.GetSerializationData(info, context);
            System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
            this.Tables.CollectionChanged += schemaChangedHandler;
            this.Relations.CollectionChanged += schemaChangedHandler;
        }
        
        [System.ComponentModel.Browsable(false)]
        [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
        public MRUListDataTable MRUList {
            get {
                return this.tableMRUList;
            }
        }
        
        public override DataSet Clone() {
            MRUListFile cln = ((MRUListFile)(base.Clone()));
            cln.InitVars();
            return cln;
        }
        
        protected override bool ShouldSerializeTables() {
            return false;
        }
        
        protected override bool ShouldSerializeRelations() {
            return false;
        }
        
        protected override void ReadXmlSerializable(XmlReader reader) {
            this.Reset();
            DataSet ds = new DataSet();
            ds.ReadXml(reader);
            if ((ds.Tables["MRUList"] != null)) {
                this.Tables.Add(new MRUListDataTable(ds.Tables["MRUList"]));
            }
            this.DataSetName = ds.DataSetName;
            this.Prefix = ds.Prefix;
            this.Namespace = ds.Namespace;
            this.Locale = ds.Locale;
            this.CaseSensitive = ds.CaseSensitive;
            this.EnforceConstraints = ds.EnforceConstraints;
            this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
            this.InitVars();
        }
        
        protected override System.Xml.Schema.XmlSchema GetSchemaSerializable() {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            this.WriteXmlSchema(new XmlTextWriter(stream, null));
            stream.Position = 0;
            return System.Xml.Schema.XmlSchema.Read(new XmlTextReader(stream), null);
        }
        
        internal void InitVars() {
            this.tableMRUList = ((MRUListDataTable)(this.Tables["MRUList"]));
            if ((this.tableMRUList != null)) {
                this.tableMRUList.InitVars();
            }
        }
        
        private void InitClass() {
            this.DataSetName = "MRUListFile";
            this.Prefix = "";
            this.Namespace = "http://mruhandler/MRUListFile.xsd";
            this.Locale = new System.Globalization.CultureInfo("en-US");
            this.CaseSensitive = false;
            this.EnforceConstraints = true;
            this.tableMRUList = new MRUListDataTable();
            this.Tables.Add(this.tableMRUList);
        }
        
        private bool ShouldSerializeMRUList() {
            return false;
        }
        
        private void SchemaChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) {
            if ((e.Action == System.ComponentModel.CollectionChangeAction.Remove)) {
                this.InitVars();
            }
        }
        
        public delegate void MRUListRowChangeEventHandler(object sender, MRUListRowChangeEvent e);
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class MRUListDataTable : DataTable, System.Collections.IEnumerable {
            
            private DataColumn columnmruentry;
            
            internal MRUListDataTable() : 
                    base("MRUList") {
                this.InitClass();
            }
            
            internal MRUListDataTable(DataTable table) : 
                    base(table.TableName) {
                if ((table.CaseSensitive != table.DataSet.CaseSensitive)) {
                    this.CaseSensitive = table.CaseSensitive;
                }
                if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) {
                    this.Locale = table.Locale;
                }
                if ((table.Namespace != table.DataSet.Namespace)) {
                    this.Namespace = table.Namespace;
                }
                this.Prefix = table.Prefix;
                this.MinimumCapacity = table.MinimumCapacity;
                this.DisplayExpression = table.DisplayExpression;
            }
            
            [System.ComponentModel.Browsable(false)]
            public int Count {
                get {
                    return this.Rows.Count;
                }
            }
            
            internal DataColumn mruentryColumn {
                get {
                    return this.columnmruentry;
                }
            }
            
            public MRUListRow this[int index] {
                get {
                    return ((MRUListRow)(this.Rows[index]));
                }
            }
            
            public event MRUListRowChangeEventHandler MRUListRowChanged;
            
            public event MRUListRowChangeEventHandler MRUListRowChanging;
            
            public event MRUListRowChangeEventHandler MRUListRowDeleted;
            
            public event MRUListRowChangeEventHandler MRUListRowDeleting;
            
            public void AddMRUListRow(MRUListRow row) {
                this.Rows.Add(row);
            }
            
            public MRUListRow AddMRUListRow(string mruentry) {
                MRUListRow rowMRUListRow = ((MRUListRow)(this.NewRow()));
                rowMRUListRow.ItemArray = new object[] {
                        mruentry};
                this.Rows.Add(rowMRUListRow);
                return rowMRUListRow;
            }
            
            public System.Collections.IEnumerator GetEnumerator() {
                return this.Rows.GetEnumerator();
            }
            
            public override DataTable Clone() {
                MRUListDataTable cln = ((MRUListDataTable)(base.Clone()));
                cln.InitVars();
                return cln;
            }
            
            protected override DataTable CreateInstance() {
                return new MRUListDataTable();
            }
            
            internal void InitVars() {
                this.columnmruentry = this.Columns["mruentry"];
            }
            
            private void InitClass() {
                this.columnmruentry = new DataColumn("mruentry", typeof(string), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnmruentry);
            }
            
            public MRUListRow NewMRUListRow() {
                return ((MRUListRow)(this.NewRow()));
            }
            
            protected override DataRow NewRowFromBuilder(DataRowBuilder builder) {
                return new MRUListRow(builder);
            }
            
            protected override System.Type GetRowType() {
                return typeof(MRUListRow);
            }
            
            protected override void OnRowChanged(DataRowChangeEventArgs e) {
                base.OnRowChanged(e);
                if ((this.MRUListRowChanged != null)) {
                    this.MRUListRowChanged(this, new MRUListRowChangeEvent(((MRUListRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowChanging(DataRowChangeEventArgs e) {
                base.OnRowChanging(e);
                if ((this.MRUListRowChanging != null)) {
                    this.MRUListRowChanging(this, new MRUListRowChangeEvent(((MRUListRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleted(DataRowChangeEventArgs e) {
                base.OnRowDeleted(e);
                if ((this.MRUListRowDeleted != null)) {
                    this.MRUListRowDeleted(this, new MRUListRowChangeEvent(((MRUListRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleting(DataRowChangeEventArgs e) {
                base.OnRowDeleting(e);
                if ((this.MRUListRowDeleting != null)) {
                    this.MRUListRowDeleting(this, new MRUListRowChangeEvent(((MRUListRow)(e.Row)), e.Action));
                }
            }
            
            public void RemoveMRUListRow(MRUListRow row) {
                this.Rows.Remove(row);
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class MRUListRow : DataRow {
            
            private MRUListDataTable tableMRUList;
            
            internal MRUListRow(DataRowBuilder rb) : 
                    base(rb) {
                this.tableMRUList = ((MRUListDataTable)(this.Table));
            }
            
            public string mruentry {
                get {
                    try {
                        return ((string)(this[this.tableMRUList.mruentryColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tableMRUList.mruentryColumn] = value;
                }
            }
            
            public bool IsmruentryNull() {
                return this.IsNull(this.tableMRUList.mruentryColumn);
            }
            
            public void SetmruentryNull() {
                this[this.tableMRUList.mruentryColumn] = System.Convert.DBNull;
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class MRUListRowChangeEvent : EventArgs {
            
            private MRUListRow eventRow;
            
            private DataRowAction eventAction;
            
            public MRUListRowChangeEvent(MRUListRow row, DataRowAction action) {
                this.eventRow = row;
                this.eventAction = action;
            }
            
            public MRUListRow Row {
                get {
                    return this.eventRow;
                }
            }
            
            public DataRowAction Action {
                get {
                    return this.eventAction;
                }
            }
        }
    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions