private void btnGrade_Click(object sender, EventArgs e) { if (sender != null) { DialogResult dialogResult = MessageBox.Show("Do you want to exit and submit this test?", "Submit Test", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { return; } } ShowLoading(); try { List <bool> points = null; string className = ("Checker." + this.Test.OfficeApp + "." + this.Test.Name + "_" + this.Test.OfficeVersion).Replace(" ", "_"); switch (this.Test.OfficeApp) { case "Word": BaseWordTest wordTestChecker = this.CreateTestChecker(className) as BaseWordTest; Word.Application wordApp = this.Application as Word.Application; Word.Document document = wordApp.ActiveDocument; document.Save(); wordTestChecker.Document = document; points = wordTestChecker.Points; break; case "Excel": Excel.Application excelApp = Application as Excel.Application; excelApp.ActiveWorkbook.Close(true); string themeXmlContent = Checker.Utils.Excel.GetThemeXmlContent(WorkingFilePaths()); BaseExcelTest excelTestChecker = this.CreateTestChecker(className) as BaseExcelTest; excelTestChecker.ThemeXmlContent = themeXmlContent; LoadFileOffice(); excelTestChecker.Workbook = (Application as Excel.Application).ActiveWorkbook; points = excelTestChecker.Points; break; case "PowerPoint": break; } int correctedQuestions = points.FindAll(x => x == true).Count; this.Task.IsCompleted = true; this.Task.UsedTime = this.ucTimer.Current; this.Task.Points.Add(points); double score = Math.Min(Math.Ceiling((double)(correctedQuestions * (1000f / points.Count))), 1000f); this.Task.Score = Convert.ToInt32(score); Repository.updateTask(this.Task); CloseLoading(); MessageBox.Show($"Your Score: {this.Task.Score}\nCorrected Tasks: {correctedQuestions}/{points.Count}", "Your Result", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { log.Error(ex.Message); log.Error("Grade - " + Test.ToString()); } }