/* MultiTables DataGrid example for CS585. This example build with Visual Studio .NET 2003 Designer There is no database source, DataTables and DataRelations build in constructor Examples of embedded documentation tags for (/doc) or in Visual Studio Tools | Build comment web pages usage. To embed html in /// comments be sure to not check "For security include html as text" when using Tools | Build comment web pages in Visual Studio Mike Barnes 11/5/03 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace multiTables { /// /// MultiTables DataGrid example illustrates: /// ///

/// The DataTables and DataRelations are specified using Designer. /// They are the /// properties of the DataSet Semester. ///

public class MultiTables : System.Windows.Forms.Form { private System.Data.DataSet Semester; private System.Data.DataTable Profs; private System.Data.DataTable students; private System.Data.DataTable section; private System.Windows.Forms.DataGrid dataGrid1; private System.Data.DataView dataView1; private System.Data.DataColumn pid; private System.Data.DataColumn profName; private System.Data.DataColumn office; private System.Data.DataColumn sid; private System.Data.DataColumn studentName; private System.Data.DataColumn major; private System.Data.DataColumn sectionNumber; private System.Data.DataColumn professorID; private System.Data.DataColumn studentID; private System.Data.DataColumn className; private System.Data.DataTable deptFaculty; private System.Data.DataColumn dept; private System.Data.DataColumn profID; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; /// /// Constructor calls InitializeComponent() to build form from Designer /// specifcation and then creates DataRows for 4 DataTables, sets ///their values, /// and adds them to the DataTable. /// public MultiTables() { // Required for Windows Form Designer support InitializeComponent(); /// populate data tables here DataRow aRow; // do section tables first since it has relations aRow = section.NewRow(); aRow[0] = 461; aRow[1] = 20; aRow[2] = 261; aRow[3] = "CS 585"; section.Rows.Add(aRow); aRow = section.NewRow(); aRow[0] = 463; aRow[1] = 21; aRow[2] = 118; aRow[3] = "CS 310"; section.Rows.Add(aRow); aRow = section.NewRow(); aRow[0] = 550; aRow[1] = 20; aRow[2] = 115; aRow[3] = "CS 585"; section.Rows.Add(aRow); aRow = section.NewRow(); aRow[0] = 464; aRow[1] = 11; aRow[2] = 118; aRow[3] = "CS 465"; section.Rows.Add(aRow); aRow = section.NewRow(); aRow[0] = 463; aRow[1] = 21; aRow[2] = 115; aRow[3] = "CS 310"; section.Rows.Add(aRow); aRow = section.NewRow(); aRow[0] = 363; aRow[1] = 21; aRow[2] = 115; aRow[3] = "Math 482"; section.Rows.Add(aRow); aRow = Profs.NewRow(); // prof tables aRow[0] = 20; aRow[1] = "Barnes"; aRow[2] = "EA 1443"; Profs.Rows.Add(aRow); aRow = Profs.NewRow(); aRow[0] = 11; aRow[1] = "Salomon"; aRow[2] = "EA 1441"; Profs.Rows.Add(aRow); aRow = Profs.NewRow(); aRow[0] = 21; aRow[1] = "Henderson"; aRow[2] = "EA 1405"; Profs.Rows.Add(aRow); //populate student tables aRow = students.NewRow(); // student tables aRow[0] = 261; aRow[1] = "Brown"; aRow[2] = "Math"; students.Rows.Add(aRow); aRow = students.NewRow(); aRow[0] = 118; aRow[1] = "Gomez"; aRow[2] = "CS"; students.Rows.Add(aRow); aRow = students.NewRow(); aRow[0] = 115; aRow[1] = "Fisher"; aRow[2] = "CS"; students.Rows.Add(aRow); aRow = deptFaculty.NewRow(); aRow[0] = "CS"; aRow[1] = 20; deptFaculty.Rows.Add(aRow); aRow = deptFaculty.NewRow(); aRow[0] = "CS"; aRow[1] = 11; deptFaculty.Rows.Add(aRow); aRow = deptFaculty.NewRow(); aRow[0] = "CS"; aRow[1] = 21; deptFaculty.Rows.Add(aRow); aRow = deptFaculty.NewRow(); aRow[0] = "Math"; aRow[1] = 21; deptFaculty.Rows.Add(aRow); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Semester = new System.Data.DataSet(); this.Profs = new System.Data.DataTable(); this.pid = new System.Data.DataColumn(); this.profName = new System.Data.DataColumn(); this.office = new System.Data.DataColumn(); this.students = new System.Data.DataTable(); this.sid = new System.Data.DataColumn(); this.studentName = new System.Data.DataColumn(); this.major = new System.Data.DataColumn(); this.section = new System.Data.DataTable(); this.sectionNumber = new System.Data.DataColumn(); this.professorID = new System.Data.DataColumn(); this.studentID = new System.Data.DataColumn(); this.className = new System.Data.DataColumn(); this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.dataView1 = new System.Data.DataView(); this.deptFaculty = new System.Data.DataTable(); this.dept = new System.Data.DataColumn(); this.profID = new System.Data.DataColumn(); ((System.ComponentModel.ISupportInitialize)(this.Semester)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Profs)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.students)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.section)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.deptFaculty)).BeginInit(); this.SuspendLayout(); // // Semester // this.Semester.DataSetName = "CSUN"; this.Semester.Locale = new System.Globalization.CultureInfo("en-US"); this.Semester.Relations.AddRange(new System.Data.DataRelation[] { new System.Data.DataRelation("teaches", "Section", "Profs", new string[] { "prof-ID"}, new string[] {"pid"}, false), new System.Data.DataRelation("attends", "Section", "Students", new string[] {"student-ID"}, new string[] {"sid"}, false), new System.Data.DataRelation("memberOf", "Profs", "DeptFaculty", new string[] {"pid"}, new string[] {"profID"}, false)}); this.Semester.Tables.AddRange(new System.Data.DataTable[] { this.Profs, this.students, this.section, this.deptFaculty}); // // Profs // this.Profs.Columns.AddRange(new System.Data.DataColumn[] { this.pid, this.profName, this.office}); this.Profs.Constraints.AddRange(new System.Data.Constraint[] { new System.Data.UniqueConstraint("Constraint1", new string[] {"pid"}, false)}); this.Profs.TableName = "Profs"; // // pid // this.pid.AllowDBNull = false; this.pid.ColumnName = "pid"; this.pid.DataType = typeof(int); // // profName // this.profName.ColumnName = "name"; // // office // this.office.ColumnName = "office"; // // students // this.students.Columns.AddRange(new System.Data.DataColumn[] { this.sid, this.studentName, this.major}); this.students.TableName = "Students"; // // sid // this.sid.AllowDBNull = false; this.sid.ColumnName = "sid"; this.sid.DataType = typeof(int); // // studentName // this.studentName.ColumnName = "name"; // // major // this.major.ColumnName = "major"; // // section // this.section.Columns.AddRange(new System.Data.DataColumn[] { this.sectionNumber, this.professorID, this.studentID, this.className}); this.section.TableName = "Section"; // // sectionNumber // this.sectionNumber.AllowDBNull = false; this.sectionNumber.ColumnName = "snum"; this.sectionNumber.DataType = typeof(int); // // professorID // this.professorID.ColumnName = "prof-ID"; this.professorID.DataType = typeof(int); // // studentID // this.studentID.ColumnName = "student-ID"; this.studentID.DataType = typeof(int); // // className // this.className.ColumnName = "class"; // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.DataSource = this.Semester; this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(0, 0); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(376, 218); this.dataGrid1.TabIndex = 0; // // dataView1 // this.dataView1.Table = this.section; // // deptFaculty // this.deptFaculty.Columns.AddRange(new System.Data.DataColumn[] { this.dept, this.profID}); this.deptFaculty.Constraints.AddRange(new System.Data.Constraint[] { new System.Data.ForeignKeyConstraint("memberOf", "Profs", new string[] {"pid"}, new string[] {"profID"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)}); this.deptFaculty.TableName = "DeptFaculty"; // // dept // this.dept.ColumnName = "dept"; // // profID // this.profID.ColumnName = "profID"; this.profID.DataType = typeof(int); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(376, 218); this.Controls.Add(this.dataGrid1); this.Name = "Form1"; this.Text = "Semester Courses"; ((System.ComponentModel.ISupportInitialize)(this.Semester)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Profs)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.students)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.section)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.deptFaculty)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new MultiTables()); } } }