//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by a tool.
//     Runtime Version: 1.1.4322.573
//
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

namespace DataSetDemo {
    using System;
    using System.Data;
    using System.Xml;
    using System.Runtime.Serialization;
    
    
    [Serializable()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Diagnostics.DebuggerStepThrough()]
    [System.ComponentModel.ToolboxItem(true)]
    public class Dataset2 : DataSet {
        
        private ClassDataTable tableClass;
        
        private PeopleDataTable tablePeople;
        
        private DataRelation relationClassPeople;
        
        public Dataset2() {
            this.InitClass();
            System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
            this.Tables.CollectionChanged += schemaChangedHandler;
            this.Relations.CollectionChanged += schemaChangedHandler;
        }
        
        protected Dataset2(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["Class"] != null)) {
                    this.Tables.Add(new ClassDataTable(ds.Tables["Class"]));
                }
                if ((ds.Tables["People"] != null)) {
                    this.Tables.Add(new PeopleDataTable(ds.Tables["People"]));
                }
                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 ClassDataTable Class {
            get {
                return this.tableClass;
            }
        }
        
        [System.ComponentModel.Browsable(false)]
        [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
        public PeopleDataTable People {
            get {
                return this.tablePeople;
            }
        }
        
        public override DataSet Clone() {
            Dataset2 cln = ((Dataset2)(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["Class"] != null)) {
                this.Tables.Add(new ClassDataTable(ds.Tables["Class"]));
            }
            if ((ds.Tables["People"] != null)) {
                this.Tables.Add(new PeopleDataTable(ds.Tables["People"]));
            }
            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.tableClass = ((ClassDataTable)(this.Tables["Class"]));
            if ((this.tableClass != null)) {
                this.tableClass.InitVars();
            }
            this.tablePeople = ((PeopleDataTable)(this.Tables["People"]));
            if ((this.tablePeople != null)) {
                this.tablePeople.InitVars();
            }
            this.relationClassPeople = this.Relations["ClassPeople"];
        }
        
        private void InitClass() {
            this.DataSetName = "Dataset2";
            this.Prefix = "";
            this.Namespace = "http://tempuri.org/Dataset2.xsd";
            this.Locale = new System.Globalization.CultureInfo("en-US");
            this.CaseSensitive = false;
            this.EnforceConstraints = true;
            this.tableClass = new ClassDataTable();
            this.Tables.Add(this.tableClass);
            this.tablePeople = new PeopleDataTable();
            this.Tables.Add(this.tablePeople);
            ForeignKeyConstraint fkc;
            fkc = new ForeignKeyConstraint("ClassPeople", new DataColumn[] {
                        this.tableClass.ClassIDColumn}, new DataColumn[] {
                        this.tablePeople.ClassIDColumn});
            this.tablePeople.Constraints.Add(fkc);
            fkc.AcceptRejectRule = System.Data.AcceptRejectRule.None;
            fkc.DeleteRule = System.Data.Rule.Cascade;
            fkc.UpdateRule = System.Data.Rule.Cascade;
            this.relationClassPeople = new DataRelation("ClassPeople", new DataColumn[] {
                        this.tableClass.ClassIDColumn}, new DataColumn[] {
                        this.tablePeople.ClassIDColumn}, false);
            this.Relations.Add(this.relationClassPeople);
        }
        
        private bool ShouldSerializeClass() {
            return false;
        }
        
        private bool ShouldSerializePeople() {
            return false;
        }
        
        private void SchemaChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) {
            if ((e.Action == System.ComponentModel.CollectionChangeAction.Remove)) {
                this.InitVars();
            }
        }
        
        public delegate void ClassRowChangeEventHandler(object sender, ClassRowChangeEvent e);
        
        public delegate void PeopleRowChangeEventHandler(object sender, PeopleRowChangeEvent e);
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class ClassDataTable : DataTable, System.Collections.IEnumerable {
            
            private DataColumn columnClassID;
            
            private DataColumn columnClassName;
            
            internal ClassDataTable() : 
                    base("Class") {
                this.InitClass();
            }
            
            internal ClassDataTable(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 ClassIDColumn {
                get {
                    return this.columnClassID;
                }
            }
            
            internal DataColumn ClassNameColumn {
                get {
                    return this.columnClassName;
                }
            }
            
            public ClassRow this[int index] {
                get {
                    return ((ClassRow)(this.Rows[index]));
                }
            }
            
            public event ClassRowChangeEventHandler ClassRowChanged;
            
            public event ClassRowChangeEventHandler ClassRowChanging;
            
            public event ClassRowChangeEventHandler ClassRowDeleted;
            
            public event ClassRowChangeEventHandler ClassRowDeleting;
            
            public void AddClassRow(ClassRow row) {
                this.Rows.Add(row);
            }
            
            public ClassRow AddClassRow(int ClassID, string ClassName) {
                ClassRow rowClassRow = ((ClassRow)(this.NewRow()));
                rowClassRow.ItemArray = new object[] {
                        ClassID,
                        ClassName};
                this.Rows.Add(rowClassRow);
                return rowClassRow;
            }
            
            public ClassRow FindByClassID(int ClassID) {
                return ((ClassRow)(this.Rows.Find(new object[] {
                            ClassID})));
            }
            
            public System.Collections.IEnumerator GetEnumerator() {
                return this.Rows.GetEnumerator();
            }
            
            public override DataTable Clone() {
                ClassDataTable cln = ((ClassDataTable)(base.Clone()));
                cln.InitVars();
                return cln;
            }
            
            protected override DataTable CreateInstance() {
                return new ClassDataTable();
            }
            
            internal void InitVars() {
                this.columnClassID = this.Columns["ClassID"];
                this.columnClassName = this.Columns["ClassName"];
            }
            
            private void InitClass() {
                this.columnClassID = new DataColumn("ClassID", typeof(int), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnClassID);
                this.columnClassName = new DataColumn("ClassName", typeof(string), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnClassName);
                this.Constraints.Add(new UniqueConstraint("Dataset2Key1", new DataColumn[] {
                                this.columnClassID}, true));
                this.columnClassID.AllowDBNull = false;
                this.columnClassID.Unique = true;
            }
            
            public ClassRow NewClassRow() {
                return ((ClassRow)(this.NewRow()));
            }
            
            protected override DataRow NewRowFromBuilder(DataRowBuilder builder) {
                return new ClassRow(builder);
            }
            
            protected override System.Type GetRowType() {
                return typeof(ClassRow);
            }
            
            protected override void OnRowChanged(DataRowChangeEventArgs e) {
                base.OnRowChanged(e);
                if ((this.ClassRowChanged != null)) {
                    this.ClassRowChanged(this, new ClassRowChangeEvent(((ClassRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowChanging(DataRowChangeEventArgs e) {
                base.OnRowChanging(e);
                if ((this.ClassRowChanging != null)) {
                    this.ClassRowChanging(this, new ClassRowChangeEvent(((ClassRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleted(DataRowChangeEventArgs e) {
                base.OnRowDeleted(e);
                if ((this.ClassRowDeleted != null)) {
                    this.ClassRowDeleted(this, new ClassRowChangeEvent(((ClassRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleting(DataRowChangeEventArgs e) {
                base.OnRowDeleting(e);
                if ((this.ClassRowDeleting != null)) {
                    this.ClassRowDeleting(this, new ClassRowChangeEvent(((ClassRow)(e.Row)), e.Action));
                }
            }
            
            public void RemoveClassRow(ClassRow row) {
                this.Rows.Remove(row);
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class ClassRow : DataRow {
            
            private ClassDataTable tableClass;
            
            internal ClassRow(DataRowBuilder rb) : 
                    base(rb) {
                this.tableClass = ((ClassDataTable)(this.Table));
            }
            
            public int ClassID {
                get {
                    return ((int)(this[this.tableClass.ClassIDColumn]));
                }
                set {
                    this[this.tableClass.ClassIDColumn] = value;
                }
            }
            
            public string ClassName {
                get {
                    try {
                        return ((string)(this[this.tableClass.ClassNameColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tableClass.ClassNameColumn] = value;
                }
            }
            
            public bool IsClassNameNull() {
                return this.IsNull(this.tableClass.ClassNameColumn);
            }
            
            public void SetClassNameNull() {
                this[this.tableClass.ClassNameColumn] = System.Convert.DBNull;
            }
            
            public PeopleRow[] GetPeopleRows() {
                return ((PeopleRow[])(this.GetChildRows(this.Table.ChildRelations["ClassPeople"])));
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class ClassRowChangeEvent : EventArgs {
            
            private ClassRow eventRow;
            
            private DataRowAction eventAction;
            
            public ClassRowChangeEvent(ClassRow row, DataRowAction action) {
                this.eventRow = row;
                this.eventAction = action;
            }
            
            public ClassRow Row {
                get {
                    return this.eventRow;
                }
            }
            
            public DataRowAction Action {
                get {
                    return this.eventAction;
                }
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class PeopleDataTable : DataTable, System.Collections.IEnumerable {
            
            private DataColumn columnname;
            
            private DataColumn columnClassID;
            
            private DataColumn columnage;
            
            internal PeopleDataTable() : 
                    base("People") {
                this.InitClass();
            }
            
            internal PeopleDataTable(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 nameColumn {
                get {
                    return this.columnname;
                }
            }
            
            internal DataColumn ClassIDColumn {
                get {
                    return this.columnClassID;
                }
            }
            
            internal DataColumn ageColumn {
                get {
                    return this.columnage;
                }
            }
            
            public PeopleRow this[int index] {
                get {
                    return ((PeopleRow)(this.Rows[index]));
                }
            }
            
            public event PeopleRowChangeEventHandler PeopleRowChanged;
            
            public event PeopleRowChangeEventHandler PeopleRowChanging;
            
            public event PeopleRowChangeEventHandler PeopleRowDeleted;
            
            public event PeopleRowChangeEventHandler PeopleRowDeleting;
            
            public void AddPeopleRow(PeopleRow row) {
                this.Rows.Add(row);
            }
            
            public PeopleRow AddPeopleRow(string name, ClassRow parentClassRowByClassPeople, int age) {
                PeopleRow rowPeopleRow = ((PeopleRow)(this.NewRow()));
                rowPeopleRow.ItemArray = new object[] {
                        name,
                        parentClassRowByClassPeople[0],
                        age};
                this.Rows.Add(rowPeopleRow);
                return rowPeopleRow;
            }
            
            public System.Collections.IEnumerator GetEnumerator() {
                return this.Rows.GetEnumerator();
            }
            
            public override DataTable Clone() {
                PeopleDataTable cln = ((PeopleDataTable)(base.Clone()));
                cln.InitVars();
                return cln;
            }
            
            protected override DataTable CreateInstance() {
                return new PeopleDataTable();
            }
            
            internal void InitVars() {
                this.columnname = this.Columns["name"];
                this.columnClassID = this.Columns["ClassID"];
                this.columnage = this.Columns["age"];
            }
            
            private void InitClass() {
                this.columnname = new DataColumn("name", typeof(string), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnname);
                this.columnClassID = new DataColumn("ClassID", typeof(int), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnClassID);
                this.columnage = new DataColumn("age", typeof(int), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnage);
            }
            
            public PeopleRow NewPeopleRow() {
                return ((PeopleRow)(this.NewRow()));
            }
            
            protected override DataRow NewRowFromBuilder(DataRowBuilder builder) {
                return new PeopleRow(builder);
            }
            
            protected override System.Type GetRowType() {
                return typeof(PeopleRow);
            }
            
            protected override void OnRowChanged(DataRowChangeEventArgs e) {
                base.OnRowChanged(e);
                if ((this.PeopleRowChanged != null)) {
                    this.PeopleRowChanged(this, new PeopleRowChangeEvent(((PeopleRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowChanging(DataRowChangeEventArgs e) {
                base.OnRowChanging(e);
                if ((this.PeopleRowChanging != null)) {
                    this.PeopleRowChanging(this, new PeopleRowChangeEvent(((PeopleRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleted(DataRowChangeEventArgs e) {
                base.OnRowDeleted(e);
                if ((this.PeopleRowDeleted != null)) {
                    this.PeopleRowDeleted(this, new PeopleRowChangeEvent(((PeopleRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleting(DataRowChangeEventArgs e) {
                base.OnRowDeleting(e);
                if ((this.PeopleRowDeleting != null)) {
                    this.PeopleRowDeleting(this, new PeopleRowChangeEvent(((PeopleRow)(e.Row)), e.Action));
                }
            }
            
            public void RemovePeopleRow(PeopleRow row) {
                this.Rows.Remove(row);
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class PeopleRow : DataRow {
            
            private PeopleDataTable tablePeople;
            
            internal PeopleRow(DataRowBuilder rb) : 
                    base(rb) {
                this.tablePeople = ((PeopleDataTable)(this.Table));
            }
            
            public string name {
                get {
                    try {
                        return ((string)(this[this.tablePeople.nameColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tablePeople.nameColumn] = value;
                }
            }
            
            public int ClassID {
                get {
                    try {
                        return ((int)(this[this.tablePeople.ClassIDColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tablePeople.ClassIDColumn] = value;
                }
            }
            
            public int age {
                get {
                    try {
                        return ((int)(this[this.tablePeople.ageColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tablePeople.ageColumn] = value;
                }
            }
            
            public ClassRow ClassRow {
                get {
                    return ((ClassRow)(this.GetParentRow(this.Table.ParentRelations["ClassPeople"])));
                }
                set {
                    this.SetParentRow(value, this.Table.ParentRelations["ClassPeople"]);
                }
            }
            
            public bool IsnameNull() {
                return this.IsNull(this.tablePeople.nameColumn);
            }
            
            public void SetnameNull() {
                this[this.tablePeople.nameColumn] = System.Convert.DBNull;
            }
            
            public bool IsClassIDNull() {
                return this.IsNull(this.tablePeople.ClassIDColumn);
            }
            
            public void SetClassIDNull() {
                this[this.tablePeople.ClassIDColumn] = System.Convert.DBNull;
            }
            
            public bool IsageNull() {
                return this.IsNull(this.tablePeople.ageColumn);
            }
            
            public void SetageNull() {
                this[this.tablePeople.ageColumn] = System.Convert.DBNull;
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class PeopleRowChangeEvent : EventArgs {
            
            private PeopleRow eventRow;
            
            private DataRowAction eventAction;
            
            public PeopleRowChangeEvent(PeopleRow row, DataRowAction action) {
                this.eventRow = row;
                this.eventAction = action;
            }
            
            public PeopleRow Row {
                get {
                    return this.eventRow;
                }
            }
            
            public DataRowAction Action {
                get {
                    return this.eventAction;
                }
            }
        }
    }
}
