Exemplo n.º 1
0
        /// <summary>
        /// Edit existing details of a module
        /// </summary>
        /// <param name="module"></param>
        /// <param name="level"></param>
        /// <param name="mainform"></param>
        public ModuleForm(Module module, LevelType level, MainForm mainform)
        {
            InitializeComponent();

            this.module = module;
            this.level = level;
            this.mainform = mainform;

            //Set the values of the existing module
            textBoxMCode.Text = module.Code;
            textBoxMName.Text = module.Name;
            comboBoxCredit.SelectedValue = module.Credits;

            //Add assessment details
            foreach (Assessment asm in module.Assessments)
            {
                int index = dataGridView1.Rows.Add(1);
                dataGridView1.Rows[index].Cells[0].Value = asm.Type;
                dataGridView1.Rows[index].Cells[1].Value = asm.Weight;
            }
            //Flag variable to update or add a new module
            updateModule = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a list of modules
        /// </summary>
        /// <param name="studentID">Student ID</param>
        /// <param name="level">Level</param>
        public static List<Module> Get(int studentID, LevelType level)
        {
            List<Module> modules = new List<Module>();

            string sql = "SELECT * FROM " + Module.TABLE + " WHERE " + Student.STUDENT_ID + "=" + studentID + " AND "
                + Module.LEVEL + "=" + (int)level;

            SQLiteDataReader reader = DBConnection.Get(sql);

            #region Creates a List<Module>
            while (reader.Read())
            {
                Module module = new Module();
                module.Code = reader[1].ToString();
                module.Name = reader[2].ToString();
                module.Credits = int.Parse(reader[3].ToString());
                module.Assessments = Assessment.Get(studentID, module.Code);

                modules.Add(module);
            }
            #endregion

            return modules;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a new module
        /// </summary>
        /// <param name="module">Module instance</param>
        /// <param name="studentID">Student ID</param>
        /// <param name="level">Level</param>
        public static void Set(Module module, int studentID, LevelType level)
        {
            string sql = "INSERT INTO " + Module.TABLE + " VALUES (" + studentID + ",'" + module.Code + "','"
                            + module.Name + "'," + module.Credits + "," + (int)level + ")";

            DBConnection.Set(sql);

            //Delete all the assessments of the module
            Assessment.Delete(studentID, module.Code);

            //Insert all the assessments of the module
            foreach (Assessment assessment in module.Assessments)
            {
                Assessment.Set(assessment, module.Code, studentID);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get a module
        /// </summary>
        /// <param name="studentID">Student ID</param>
        /// <param name="level">Level</param>
        public static Module Get(int studentID, string moduleCode)
        {
            Module module = null;
            string sql = "SELECT * FROM " + Module.TABLE + " WHERE " + Student.STUDENT_ID + "=" + studentID + " AND "
                        + Module.CODE + "='" + moduleCode + "'";

            SQLiteDataReader reader = DBConnection.Get(sql);

            #region Creates a Module
            if (reader.Read())
            {
                module = new Module();
                module.Code = reader[1].ToString();
                module.Name = reader[2].ToString();
                module.Credits = int.Parse(reader[3].ToString());
                module.Assessments = Assessment.Get(studentID, moduleCode);

            }
            #endregion

            return module;
        }
Exemplo n.º 5
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            //Presence check
            if (textBoxMCode.Text.Length > 0 & textBoxMName.Text.Length > 0 & comboBoxCredit.SelectedItem != null)
            {
                //A new module
                if (updateModule == false)
                {
                    module = new Module();
                }
                //Set the details
                module.Code = textBoxMCode.Text;
                module.Name = textBoxMName.Text;
                module.Credits = int.Parse(comboBoxCredit.SelectedItem.ToString());
                //Create a new list of assessments(Old list is lost)
                module.Assessments = new List<Assessment>();

                //Add new assessments to the list
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    Assessment asm = new Assessment();
                    asm.AID=i+1;
                    //Set details of the assessment
                    asm.Type = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    try
                    {
                        asm.Weight = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
                    }
                    catch (FormatException ex)
                    {
                        //If weight is not a number
                        MessageBox.Show("Weight cannot contain non-numerical values");
                        return;
                    }

                    //Add assessment into the list
                    module.Assessments.Add(asm);
                }
                //If a new module
                if (updateModule == false)
                {
                    //Add new module to the list in level
                    student.Levels[((int)level) - 4].Modules.Add(module);
                }
                //Refresh all the module details
                mainform.LoadModules(level);
                this.Hide();
            }
        }