/// <summary> /// Add a new assessment /// </summary> /// <param name="assessment">Assessment instance</param> /// <param name="moduleID">Module ID (NOT moduleCode)</param> public static void Set(Assessment assessment, string moduleCode, int studentID) { string sql = "INSERT INTO " + Assessment.TABLE + " VALUES (" + assessment.AID + "," + studentID + ",'" + moduleCode + "','" + assessment.Type + "'," + assessment.Weight + "," + assessment.Mark + ")"; DBConnection.Set(sql); }
/// <summary> /// Get a list of assessments /// </summary> /// <param name="moduleID">Module ID (NOT moduleCode)</param> /// <returns></returns> public static List<Assessment> Get(int studentID, string moduleCode) { List<Assessment> assessments = new List<Assessment>(); string sql = "SELECT * FROM " + Assessment.TABLE + " WHERE " + Student.STUDENT_ID + "=" + studentID + " AND " + Module.CODE + "='" + moduleCode + "'"; SQLiteDataReader reader = DBConnection.Get(sql); #region Creates a List<Assessment> while (reader.Read()) { Assessment assessment = new Assessment(); assessment.AID = int.Parse(reader[0].ToString()); assessment.Type = reader[3].ToString(); assessment.Weight = int.Parse(reader[4].ToString()); assessment.Mark = int.Parse(reader[5].ToString()); assessments.Add(assessment); } #endregion return assessments; }
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(); } }