Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
 public void Remove(Module module)
 {
     if (Modules.Contains(module))
         Modules.Remove(module);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add Module
 /// </summary>
 /// <param name="module">Module instance to add into list</param>
 public void Add(Module module)
 {
     Modules.Add(module);
 }
Ejemplo n.º 4
0
 public void Insert(Module module, int index)
 {
     Modules.Insert(index, module);
 }