From 881ab1e981e3c30d2fa7ff18edaae11da1508e91 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 10 Mar 2016 19:31:05 +0100 Subject: [PATCH 1/2] abc def --- .../AddEditClassroom.Designer.cs | 141 +++++++++ .../Worksheet5 - Copy/AddEditClassroom.cs | 54 ++++ .../Worksheet5 - Copy/AddEditClassroom.resx | 120 ++++++++ Example1/Worksheet5 - Copy/App.config | 6 + Example1/Worksheet5 - Copy/Classroom.cs | 86 ++++++ .../ClassroomsForm.Designer.cs | 117 +++++++ Example1/Worksheet5 - Copy/ClassroomsForm.cs | 118 +++++++ .../Worksheet5 - Copy/ClassroomsForm.resx | 120 ++++++++ Example1/Worksheet5 - Copy/Computer.cs | 68 ++++ Example1/Worksheet5 - Copy/MainProgram.cs | 290 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++ Example1/Worksheet5 - Copy/Worksheet5.csproj | 82 +++++ Example1/Worksheet5 - Copy/Worksheet5.sln | 22 ++ 13 files changed, 1260 insertions(+) create mode 100644 Example1/Worksheet5 - Copy/AddEditClassroom.Designer.cs create mode 100644 Example1/Worksheet5 - Copy/AddEditClassroom.cs create mode 100644 Example1/Worksheet5 - Copy/AddEditClassroom.resx create mode 100644 Example1/Worksheet5 - Copy/App.config create mode 100644 Example1/Worksheet5 - Copy/Classroom.cs create mode 100644 Example1/Worksheet5 - Copy/ClassroomsForm.Designer.cs create mode 100644 Example1/Worksheet5 - Copy/ClassroomsForm.cs create mode 100644 Example1/Worksheet5 - Copy/ClassroomsForm.resx create mode 100644 Example1/Worksheet5 - Copy/Computer.cs create mode 100644 Example1/Worksheet5 - Copy/MainProgram.cs create mode 100644 Example1/Worksheet5 - Copy/Properties/AssemblyInfo.cs create mode 100644 Example1/Worksheet5 - Copy/Worksheet5.csproj create mode 100644 Example1/Worksheet5 - Copy/Worksheet5.sln diff --git a/Example1/Worksheet5 - Copy/AddEditClassroom.Designer.cs b/Example1/Worksheet5 - Copy/AddEditClassroom.Designer.cs new file mode 100644 index 0000000..3badb6e --- /dev/null +++ b/Example1/Worksheet5 - Copy/AddEditClassroom.Designer.cs @@ -0,0 +1,141 @@ +namespace Worksheet5 +{ + partial class AddEditClassroom + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (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.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.button1 = new System.Windows.Forms.Button(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.panel1 = new System.Windows.Forms.Panel(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.tableLayoutPanel1.SuspendLayout(); + this.panel2.SuspendLayout(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Controls.Add(this.panel2, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0); + this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(260, 238); + this.tableLayoutPanel1.TabIndex = 0; + // + // panel2 + // + this.panel2.Controls.Add(this.button1); + this.panel2.Controls.Add(this.checkBox1); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(3, 122); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(254, 113); + this.panel2.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(84, 77); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 2; + this.button1.Text = "Add"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(6, 27); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(67, 17); + this.checkBox1.TabIndex = 1; + this.checkBox1.Text = "projector"; + this.checkBox1.UseVisualStyleBackColor = true; + // + // panel1 + // + this.panel1.Controls.Add(this.textBox1); + this.panel1.Controls.Add(this.label1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(3, 3); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(254, 113); + this.panel1.TabIndex = 0; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(93, 38); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(146, 20); + this.textBox1.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 41); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(84, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Classroom name"; + // + // AddEditClassroom + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 262); + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "AddEditClassroom"; + this.Text = "Add Classroom"; + this.tableLayoutPanel1.ResumeLayout(false); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button1; + + } +} \ No newline at end of file diff --git a/Example1/Worksheet5 - Copy/AddEditClassroom.cs b/Example1/Worksheet5 - Copy/AddEditClassroom.cs new file mode 100644 index 0000000..c746587 --- /dev/null +++ b/Example1/Worksheet5 - Copy/AddEditClassroom.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Worksheet5 +{ + public partial class AddEditClassroom : Form + { + public AddEditClassroom() + { + InitializeComponent(); + } + + bool editing = false; + Classroom currentClassroom; + + public AddEditClassroom(Classroom classroomtoedit) + { + InitializeComponent(); + textBox1.Text = classroomtoedit.Classroomname; + checkBox1.Checked = classroomtoedit.Projectoravailable; + editing = true; + button1.Text = "Update classroom"; + this.Text = "Update classroom"; + currentClassroom = classroomtoedit; + } + + + private void button1_Click(object sender, EventArgs e) + { + if (!editing) { + string classroomname = textBox1.Text; + bool projector = checkBox1.Checked; + Classroom newClassroom = new Classroom(classroomname, projector, new List()); + MainProgram.rooms.Add(newClassroom); + } + else + { + currentClassroom.Classroomname = textBox1.Text; + currentClassroom.Projectoravailable = checkBox1.Checked; + } + + ClassroomsForm owner = (ClassroomsForm)this.Owner; + owner.updateGrid(); + this.Close(); + } + } +} diff --git a/Example1/Worksheet5 - Copy/AddEditClassroom.resx b/Example1/Worksheet5 - Copy/AddEditClassroom.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Example1/Worksheet5 - Copy/AddEditClassroom.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Example1/Worksheet5 - Copy/App.config b/Example1/Worksheet5 - Copy/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Example1/Worksheet5 - Copy/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Example1/Worksheet5 - Copy/Classroom.cs b/Example1/Worksheet5 - Copy/Classroom.cs new file mode 100644 index 0000000..04e43a5 --- /dev/null +++ b/Example1/Worksheet5 - Copy/Classroom.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Worksheet5 +{ + public class Classroom + { + string _classroomname; + + public string Classroomname + { + get { return _classroomname; } + set { _classroomname = value; } + } + + bool _projectoravailable; + + + public bool Projectoravailable + { + get { return _projectoravailable; } + set { _projectoravailable = value; } + } + + List _computersinclassroom; + + internal List Computersinclassroom + { + get { return _computersinclassroom; } + set { _computersinclassroom = value; } + } + + + + public Classroom(string classroomname,bool projectoravailable,List allComputers) + { + Classroomname = classroomname; + Projectoravailable = projectoravailable; + Computersinclassroom = allComputers; + } + + public Classroom(string v1,bool v2) + { + Classroomname = v1; + Projectoravailable = v2; + Computersinclassroom = new List(); + } + + public Classroom() + { + Classroomname = ""; + Projectoravailable = false; + Computersinclassroom = new List(); + } + + + + public string outputClassroom() + { + return "Name of classroom: " + Classroomname + " Projector: " + Projectoravailable; + } + + //hide the default ToString method with a new method that I have written + public override string ToString() + { + string output = ""; + output += "Name of classroom: " + Classroomname + " Projector: " + Projectoravailable + "\n"; + foreach (Computer c in Computersinclassroom) + { + output += c; + } + return output; + + + } + + public Classroom copyMe() + { + Classroom outputC = new Classroom(this.Classroomname, this.Projectoravailable, this.Computersinclassroom); + return outputC; + } + } +} diff --git a/Example1/Worksheet5 - Copy/ClassroomsForm.Designer.cs b/Example1/Worksheet5 - Copy/ClassroomsForm.Designer.cs new file mode 100644 index 0000000..9c91583 --- /dev/null +++ b/Example1/Worksheet5 - Copy/ClassroomsForm.Designer.cs @@ -0,0 +1,117 @@ +namespace Worksheet5 +{ + partial class ClassroomsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (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.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.panel1 = new System.Windows.Forms.Panel(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.button1 = new System.Windows.Forms.Button(); + this.tableLayoutPanel1.SuspendLayout(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.AutoSize = true; + this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 0); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 75.44484F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 24.55516F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(860, 305); + this.tableLayoutPanel1.TabIndex = 0; + // + // panel1 + // + this.panel1.Controls.Add(this.button1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(3, 233); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(854, 69); + this.panel1.TabIndex = 0; + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.ColumnHeadersVisible = false; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(3, 3); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView1.RowHeadersVisible = false; + this.dataGridView1.Size = new System.Drawing.Size(854, 224); + this.dataGridView1.TabIndex = 1; + this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(3, 16); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(322, 23); + this.button1.TabIndex = 0; + this.button1.Text = "Add Classroom"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // ClassroomsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(860, 305); + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "ClassroomsForm"; + this.Text = "ClassroomsForm"; + this.Load += new System.EventHandler(this.ClassroomsForm_Load); + this.tableLayoutPanel1.ResumeLayout(false); + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/Example1/Worksheet5 - Copy/ClassroomsForm.cs b/Example1/Worksheet5 - Copy/ClassroomsForm.cs new file mode 100644 index 0000000..0e00da9 --- /dev/null +++ b/Example1/Worksheet5 - Copy/ClassroomsForm.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Worksheet5 +{ + public partial class ClassroomsForm : Form + { + public ClassroomsForm() + { + InitializeComponent(); + } + + + public void updateGrid() + { + dataGridView1.Rows.Clear(); + dataGridView1.Columns.Clear(); + + DataGridViewCell cellStyle = new DataGridViewTextBoxCell(); + cellStyle.Style.BackColor = Color.Wheat; + + DataGridViewButtonColumn deleteButtonColumn = new DataGridViewButtonColumn(); + + deleteButtonColumn.Text = "Delete Classroom"; + deleteButtonColumn.UseColumnTextForButtonValue = true; + + + + DataGridViewButtonColumn updateButtonColumn = new DataGridViewButtonColumn(); + updateButtonColumn.Text = "Update Classroom"; + + updateButtonColumn.UseColumnTextForButtonValue = true; + + DataGridViewButtonColumn viewComputersButtonColumn = new DataGridViewButtonColumn(); + viewComputersButtonColumn.Text = "View computers"; + + viewComputersButtonColumn.UseColumnTextForButtonValue = true; + + dataGridView1.Columns.Add(new DataGridViewColumn(cellStyle)); + + dataGridView1.Columns.Add(updateButtonColumn); + dataGridView1.Columns.Add(viewComputersButtonColumn); + dataGridView1.Columns.Add(deleteButtonColumn); + + + foreach (Classroom classroom in MainProgram.rooms) + dataGridView1.Rows.Add(classroom.Classroomname); + } + + private void ClassroomsForm_Load(object sender, EventArgs e) + { + updateGrid(); + + + + + } + + private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) + { + // MessageBox.Show(e.ColumnIndex.ToString() + " " + e.RowIndex.ToString()); + //this event is triggered every time I click a cell + if (e.ColumnIndex==3) + { + //MessageBox.Show("Delete"); + string currentRoomName = dataGridView1.CurrentRow.Cells[0].Value.ToString(); + + + + Classroom classtodelete = MainProgram.rooms.Find(croom => croom.Classroomname == currentRoomName); + + //Classroom backupClassroom = classtodelete.copyMe(); + // Classroom backupClassroom = MainProgram.copyClassroom(classtodelete); + MessageBoxButtons confirmButtons = MessageBoxButtons.OKCancel; + + DialogResult result = MessageBox.Show("Are you sure you want to delete?","Delete", confirmButtons); + + if (result == DialogResult.OK) + { + MainProgram.rooms.Remove(classtodelete); + updateGrid(); + } + // MessageBox.Show(backupClassroom.ToString()); + } + if (e.ColumnIndex == 1) + { + string currentRoomName = dataGridView1.CurrentRow.Cells[0].Value.ToString(); + + Classroom classtoupdate = MainProgram.rooms.Find(croom => croom.Classroomname == currentRoomName); + + + AddEditClassroom addC = new AddEditClassroom(classtoupdate); + addC.ShowDialog(this); + } + + + + + + //MessageBox.Show(); + //MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString()); + } + + private void button1_Click(object sender, EventArgs e) + { + AddEditClassroom addC = new AddEditClassroom(); + addC.ShowDialog(this); + + } + } +} diff --git a/Example1/Worksheet5 - Copy/ClassroomsForm.resx b/Example1/Worksheet5 - Copy/ClassroomsForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Example1/Worksheet5 - Copy/ClassroomsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Example1/Worksheet5 - Copy/Computer.cs b/Example1/Worksheet5 - Copy/Computer.cs new file mode 100644 index 0000000..9dd4023 --- /dev/null +++ b/Example1/Worksheet5 - Copy/Computer.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Worksheet5 +{ + public class Computer:IComparable + { + string _computername; + + public string Computername + { + get { return _computername; } + set { _computername = value; } + } + string _computerstatus; + + public string Computerstatus + { + get { return _computerstatus; } + set { _computerstatus = value; } + } + int _numberoffaults; + + public int Numberoffaults + { + get { return _numberoffaults; } + set { _numberoffaults = value; } + } + + public Computer(string cname,string status,int faults) + { + Computername = cname; + Computerstatus = status; + Numberoffaults = faults; + } + + public int showNumberOfFaults() + { + return Numberoffaults; + } + + + public override string ToString() + { + string output = ""; + output = "==========================================\n"; + output += "Computer name: " + Computername + "\n"; + output += "Computer status: " + Computerstatus + "\n"; + output += "Number of faults: " + Numberoffaults + "\n"; + output += "==========================================\n"; + return output; + } + + + public int CompareTo(object other) + { + Computer referenceToOtherComputer = (Computer)other; + return this.Numberoffaults.CompareTo(referenceToOtherComputer.Numberoffaults); + + } + + + + } +} diff --git a/Example1/Worksheet5 - Copy/MainProgram.cs b/Example1/Worksheet5 - Copy/MainProgram.cs new file mode 100644 index 0000000..0219b46 --- /dev/null +++ b/Example1/Worksheet5 - Copy/MainProgram.cs @@ -0,0 +1,290 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Worksheet5 +{ + class MainProgram + { + + public static List rooms; + + + public static Classroom copyClassroom (Classroom c1) + { + Classroom copy = new Classroom(c1.Classroomname, c1.Projectoravailable, c1.Computersinclassroom); + return copy; + } + + //static method which will load a menu + static void Menu(String menutext) + { + int option = 0; + while (option!= 7) + { + Console.WriteLine(menutext); + option = Convert.ToInt32(Console.ReadKey(false).KeyChar.ToString()); + switch (option) + { + case 1: + opt1(); + break; + case 2: + opt2(); + break; + case 3: + opt3(); + break; + case 4: + opt4(); + break; + case 5: + opt5(); + break; + case 6: + opt6(); + break; + case 7: + opt7(); + break; + case 8: + break; + default: + Console.WriteLine("Error - incorrect option"); + break; + } + } + } + + + static void opt7() + { + ClassroomsForm frm = new ClassroomsForm(); + + Application.Run(frm); + + } + + static void opt1() + { + //list all classrooms + foreach(Classroom c in rooms) + { + Console.WriteLine(c); + } + + } + + static void opt2() + { + int roomscounter = 0; + + foreach (Classroom c in rooms) + { + if (c!=null) + { + roomscounter++; + } + } + + Console.WriteLine("Enter new classroom name: "); + string classroomname = Convert.ToString(Console.ReadLine()); + Console.WriteLine("Does the classroom have a projector? "); + bool projector = yesno(); + //create a new classroom with an empty array of computers + Classroom newClassroom = new Classroom(classroomname, projector,new List()); + + + + + rooms.Add(newClassroom); + } + + static void opt3() + { + int counter = 0; + //1. select classroom + + + foreach (Classroom cl in rooms) + { + if (cl!=null) + { + Console.WriteLine(counter + ") " + cl.Classroomname + " "); + counter++; + } + } + Console.WriteLine("Select a classroom:"); + int classroomchoice = Convert.ToInt32(Console.ReadLine()); + + //2. add computer to classroom + Computer c = newComputer(); + + List computersInClassroom = rooms[classroomchoice].Computersinclassroom; + + computersInClassroom.Add(c); + + } + + static void opt4() + { + Console.WriteLine("Select a classroom:"); + int classroomchoice = Convert.ToInt32(Console.ReadLine()); + + //2. add computer to classroom + Computer c = newComputer(); + + + + List computersInClassroom = rooms[classroomchoice].Computersinclassroom; + + int i =0; + foreach (Computer comp in computersInClassroom) + { + + Console.WriteLine(i + ") " + comp.Computername + " "); + } + } + + static void opt5() + { + + + + + } + + static void opt6() + { + //1. create an array containing all the computers in all the rooms + List allComputers = new List(); + + + + + + foreach (Classroom c in rooms) + { + if (c!=null) + { + foreach(Computer cm in c.Computersinclassroom) + { + allComputers.Add(cm); + } + } + + } + + allComputers.Sort(); + + foreach (Computer c in allComputers) + { + Console.WriteLine(c); + } + Console.ReadLine(); + + + + + } + + static bool yesno() + { + Console.WriteLine("y/n?"); + string input = Convert.ToString(Console.ReadKey(false).KeyChar); + bool accept = false; + + if (input == "y") + accept = true; + else if (input == "n") + accept = false; + + return accept; + } + + + static Computer newComputer() + { + Console.WriteLine("Enter computer name:"); + string computer = Console.ReadLine(); + Console.WriteLine("Enter computer status:"); + string status = Console.ReadLine(); + Console.WriteLine("Enter number of faults:"); + int numberOfFaults = Convert.ToInt32(Console.ReadLine()); + Computer pc = new Computer(computer, status, numberOfFaults); + return pc; + } + + static void updateStatusAndFaults(Computer pctoupdate) + { + Console.WriteLine("Enter computer status:"); + string status = Console.ReadLine(); + Console.WriteLine("Enter number of faults:"); + int numberOfFaults = Convert.ToInt32(Console.ReadLine()); + pctoupdate.Computerstatus = status; + pctoupdate.Numberoffaults = numberOfFaults; + } + + + static void Main(string[] args) + { + + //starting point of the application + //we will load the menu of the application + //here + rooms = new List(); + + + Computer PC1 = new Computer("L113-", "OK", 5); + Computer PC2 = new Computer("L11", "OK", 2); + Computer PC3 = new Computer("L1", "NOT OK", 3); + Computer PC4 = new Computer("L113-8", "NOT OK", 3); + + List computers = new List(); + + computers.Add(PC1); + computers.Add(PC2); + computers.Add(PC3); + computers.Add(PC4); + + //myClassroom = L113 + Classroom myClassroom = new Classroom("L113", true,computers); + + List computers2 = new List(); + + computers2.Add(new Computer("L114-1", "OK", 1)); + computers2.Add(new Computer("L114-2", "OK", 5)); + + //myClassroom2 = L114 + Classroom myClassroom2 = new Classroom("L114", true, computers2); + + //max classrooms = 4 + + + //first 2 classrooms + rooms.Add(myClassroom); + rooms.Add(myClassroom2); + + + String menu = + "1.) List all classrooms in system \t\n" + + "2.) Add new classroom \t\n" + + "3.) Add new computer to classroom \t\n" + + "4.) List all computers in classroom \t\n" + + "5.) Update computer status by computer name \t\n" + + "6.) List all computers ordered by fault \t\n" + + "7.) GUI \t\n" + + "8.) Quit \t\n"; + + Menu(menu); + + + + + Console.ReadLine(); + } + } +} diff --git a/Example1/Worksheet5 - Copy/Properties/AssemblyInfo.cs b/Example1/Worksheet5 - Copy/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..121941b --- /dev/null +++ b/Example1/Worksheet5 - Copy/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Worksheet4")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("MCAST")] +[assembly: AssemblyProduct("Worksheet4")] +[assembly: AssemblyCopyright("Copyright © MCAST 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("056322aa-ac96-4582-9064-5f4fb400fe1b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Example1/Worksheet5 - Copy/Worksheet5.csproj b/Example1/Worksheet5 - Copy/Worksheet5.csproj new file mode 100644 index 0000000..a242de6 --- /dev/null +++ b/Example1/Worksheet5 - Copy/Worksheet5.csproj @@ -0,0 +1,82 @@ + + + + + Debug + AnyCPU + {6272508D-E762-4E97-903F-6BA162258EE2} + Exe + Properties + Worksheet5 + Worksheet4 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + Form + + + AddEditClassroom.cs + + + + Form + + + ClassroomsForm.cs + + + + + + + + + + + AddEditClassroom.cs + + + ClassroomsForm.cs + + + + + \ No newline at end of file diff --git a/Example1/Worksheet5 - Copy/Worksheet5.sln b/Example1/Worksheet5 - Copy/Worksheet5.sln new file mode 100644 index 0000000..2726aa3 --- /dev/null +++ b/Example1/Worksheet5 - Copy/Worksheet5.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Worksheet5", "Worksheet5.csproj", "{45E69B23-084A-4805-9CC2-83B0841861A9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {45E69B23-084A-4805-9CC2-83B0841861A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45E69B23-084A-4805-9CC2-83B0841861A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45E69B23-084A-4805-9CC2-83B0841861A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45E69B23-084A-4805-9CC2-83B0841861A9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From f8b59ccf8f42433a473abcc18841717dd059d4f7 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 17 Mar 2016 18:35:49 +0100 Subject: [PATCH 2/2] ;l --- Example1/Example1.sln | 10 ++++++++-- Example1/Worksheet5 - Copy/AddEditClassroom.cs | 2 ++ .../{Worksheet5.csproj => Worksheet5a.csproj} | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) rename Example1/Worksheet5 - Copy/{Worksheet5.csproj => Worksheet5a.csproj} (98%) diff --git a/Example1/Example1.sln b/Example1/Example1.sln index a8b30a9..9a2a3b8 100644 --- a/Example1/Example1.sln +++ b/Example1/Example1.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example1", "Example1\Example1.csproj", "{AA5701F3-382B-42D2-B34A-21FEFF70F339}" EndProject @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example7", "Example7\Exampl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Worksheet5", "Worksheet5\Worksheet5.csproj", "{6272508D-E762-4E97-903F-6BA162258EE2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Worksheet5a", "Worksheet5 - Copy\Worksheet5a.csproj", "{CC222844-7427-4388-B806-3C6EA8ECF060}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,6 +83,10 @@ Global {6272508D-E762-4E97-903F-6BA162258EE2}.Debug|Any CPU.Build.0 = Debug|Any CPU {6272508D-E762-4E97-903F-6BA162258EE2}.Release|Any CPU.ActiveCfg = Release|Any CPU {6272508D-E762-4E97-903F-6BA162258EE2}.Release|Any CPU.Build.0 = Release|Any CPU + {CC222844-7427-4388-B806-3C6EA8ECF060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC222844-7427-4388-B806-3C6EA8ECF060}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC222844-7427-4388-B806-3C6EA8ECF060}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC222844-7427-4388-B806-3C6EA8ECF060}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Example1/Worksheet5 - Copy/AddEditClassroom.cs b/Example1/Worksheet5 - Copy/AddEditClassroom.cs index c746587..b73f65a 100644 --- a/Example1/Worksheet5 - Copy/AddEditClassroom.cs +++ b/Example1/Worksheet5 - Copy/AddEditClassroom.cs @@ -31,6 +31,8 @@ public AddEditClassroom(Classroom classroomtoedit) currentClassroom = classroomtoedit; } + + private void button1_Click(object sender, EventArgs e) { diff --git a/Example1/Worksheet5 - Copy/Worksheet5.csproj b/Example1/Worksheet5 - Copy/Worksheet5a.csproj similarity index 98% rename from Example1/Worksheet5 - Copy/Worksheet5.csproj rename to Example1/Worksheet5 - Copy/Worksheet5a.csproj index a242de6..db38b9d 100644 --- a/Example1/Worksheet5 - Copy/Worksheet5.csproj +++ b/Example1/Worksheet5 - Copy/Worksheet5a.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {6272508D-E762-4E97-903F-6BA162258EE2} + {CC222844-7427-4388-B806-3C6EA8ECF060} Exe Properties Worksheet5