Beispiel #1
0
        public void LoadRooms()
        {
            m_reader = new XmlTextReader(m_fileName);
            XmlDocument xml = new XmlDocument();
            xml.Load(m_reader);
            XmlNodeList nodes = xml.GetElementsByTagName("Rooms");
            if ((nodes.Item(0).Attributes["Count"].Value.Equals("0")))
                return;

            foreach (XmlNode node in nodes.Item(0).ChildNodes)
            {
                String name = null;
                String label = null;
                int capacity = 0;
                Boolean lecturerPC = false;
                Boolean smartboard = false;
                Boolean tv = false;
                Boolean projector = false;
                Boolean networkLab = false;
                Color color = Color.Empty;

                foreach (XmlNode data in node.ChildNodes)
                {
                    try
                    {
                        if (data.Name.Equals(m_roomCols[0]))
                        {
                            name = data.InnerText;
                        }
                        else if (data.Name.Equals(m_roomCols[1]))
                        {
                            label = data.InnerText;
                        }
                        else if (data.Name.Equals(m_roomCols[2]))
                        {
                            capacity = int.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals(m_roomCols[3]))
                        {
                            lecturerPC = Boolean.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals(m_roomCols[4]))
                        {
                            smartboard = Boolean.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals(m_roomCols[5]))
                        {
                            tv = Boolean.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals(m_roomCols[6]))
                        {
                            projector = Boolean.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals(m_roomCols[7]))
                        {
                            networkLab = Boolean.Parse(data.InnerText);
                        }
                        else if (data.Name.Equals(m_roomCols[8]))
                        {
                            color = Color.FromArgb(int.Parse(data.InnerText));
                        }

                        if (name != null && label != null && capacity != 0 && color != Color.Empty)
                        {
                            Room room = new Room(name, label, color, capacity);
                            room.SetEquipment(0, lecturerPC);
                            room.SetEquipment(1, smartboard);
                            room.SetEquipment(2, tv);
                            room.SetEquipment(3, projector);
                            room.SetEquipment(4, networkLab);
                            DataCollection.Instance.Add(room);
                        }
                    }
                    catch
                    {
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        private void dataLecTable_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;

            //  Input for row will
            if (validate(dgv, e))
            {
                switch (tabControl1.SelectedIndex)
                {
                    case 0:	//	Lecturer DGV
                        dgv = dataLecTable;
                        if (dgv.Rows[e.RowIndex].Cells[0].Value != null &&
                            dgv.Rows[e.RowIndex].Cells[1].Value != null &&
                            dgv.Rows[e.RowIndex].Cells[2].Value != null &&
                            dgv.Rows[e.RowIndex].Cells[3].Value != null)
                        {
                            string name = dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                            string label = dgv.Rows[e.RowIndex].Cells[1].Value.ToString();
                            int hours;
                            if (!int.TryParse(dgv.Rows[e.RowIndex].Cells[2].Value.ToString(), out hours)) //converts int to bool, if invalid then return false
                            {
                                return;
                            }
                            Color colour = dgv.Rows[e.RowIndex].Cells[3].Style.BackColor;
                            Lecturer lect = new Lecturer(name, hours, label, colour);
                            if (!loading)
                            {
                                try
                                {
                                    DataCollection.Instance.Lecturers[e.RowIndex] = lect;
                                }
                                catch
                                {

                                    DataCollection.Instance.Insert(lect, e.RowIndex);
                                }

                            }
                        }
                        break;

                    case 1:	//	Module DGV
                        dgv = dataSubTable;
                        if (dgv.Rows[e.RowIndex].Cells[0].Value != null &&
                            dgv.Rows[e.RowIndex].Cells[1].Value != null &&
                            dgv.Rows[e.RowIndex].Cells[2].Value != null &&
                            dgv.Rows[e.RowIndex].Cells[3].Value != null)
                        {
                            String subject = dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                            String label = dgv.Rows[e.RowIndex].Cells[1].Value.ToString();
                            String courseLevel = dgv.Rows[e.RowIndex].Cells[2].Value.ToString();
                            Color colour = dgv.Rows[e.RowIndex].Cells[3].Style.BackColor;
                            Module mod = new Module(subject, label, courseLevel, colour);
                            if (!loading)
                            {
                                try
                                {
                                    DataCollection.Instance.Modules[e.RowIndex] = mod;
                                }
                                catch
                                {

                                    DataCollection.Instance.Insert(mod, e.RowIndex);
                                }

                            }
                        }
                        break;

                    case 2:	//	Room DGV
                        dgv = dataRoomTable;
                        if (dgv.Rows[e.RowIndex].Cells[0].Value != null &&
                           dgv.Rows[e.RowIndex].Cells[1].Value != null &&
                           dgv.Rows[e.RowIndex].Cells[2].Value != null &&
                           dgv.Rows[e.RowIndex].Cells[8].Value != null)
                        {
                            String name = dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                            String label = dgv.Rows[e.RowIndex].Cells[1].Value.ToString();
                            String sCap = dgv.Rows[e.RowIndex].Cells[2].Value.ToString();
                            Color colour = dgv.Rows[e.RowIndex].Cells[8].Style.BackColor;
                            int capacity;
                            try
                            {
                                capacity = int.Parse(sCap);
                            }
                            catch
                            {
                                return;
                            }
                            Room room = new Room(name, label, colour, capacity);
                            room.SetEquipment(0, dgv.Rows[e.RowIndex].Cells[3].Value != null ? true : false);
                            room.SetEquipment(1, dgv.Rows[e.RowIndex].Cells[4].Value != null ? true : false);
                            room.SetEquipment(2, dgv.Rows[e.RowIndex].Cells[5].Value != null ? true : false);
                            room.SetEquipment(3, dgv.Rows[e.RowIndex].Cells[6].Value != null ? true : false);
                            room.SetEquipment(4, dgv.Rows[e.RowIndex].Cells[7].Value != null ? true : false);
                            if (!loading)
                            {
                                try
                                {
                                    DataCollection.Instance.Rooms[e.RowIndex] = room;
                                }
                                catch
                                {

                                    DataCollection.Instance.Insert(room, e.RowIndex);
                                }

                            }
                        }
                        break;

                    case 3:	//	Group DGV
                        dgv = dataClassTable;
                        if (dgv.Rows[e.RowIndex].Cells[0].Value != null &&
                          dgv.Rows[e.RowIndex].Cells[1].Value != null &&
                          dgv.Rows[e.RowIndex].Cells[2].Value != null &&
                          dgv.Rows[e.RowIndex].Cells[3].Value != null)
                        {
                            string group = dgv.Rows[e.RowIndex].Cells[0].Value.ToString();
                            string label = dgv.Rows[e.RowIndex].Cells[1].Value.ToString();
                            string sStudents = dgv.Rows[e.RowIndex].Cells[2].Value.ToString();
                            Color colour = dgv.Rows[e.RowIndex].Cells[3].Style.BackColor;
                            int numStudents;
                            try
                            {
                                numStudents = int.Parse(sStudents);
                            }
                            catch
                            {
                                return;
                            }
                            Group grp = new Group(group, label, colour, numStudents);
                            if (!loading)
                            {
                                try
                                {
                                    DataCollection.Instance.Groups[e.RowIndex] = grp;
                                }
                                catch
                                {

                                    DataCollection.Instance.Insert(grp, e.RowIndex);
                                }

                            }
                        }
                        break;
                    default:
                        break;
                }
                FormMain main = (FormMain)(this.MdiParent);
                main.populateTab();
                main.populateViewMenu();
            }
        }