private void submitExamBtn_Click(object sender, EventArgs e) { string errMsg = ""; bool error = false; string remainingTime = remainingtimeLbl.Text; ExamLog.Add($"[{DateTime.Now}] [Student Tried to Submit SUBMIT EXAM] [Remaing time: {remainingTime}]"); foreach (var q in anExam.QuestionsList) { if (q.StudentAnswer == string.Empty || q.StudentAnswer == null) { error = true; errMsg = errMsg + $" Q{q.QuestionNumber}. "; } } if (error) { MessageBox.Show("Please provide answers for the following questions before you submit the exam" + errMsg); return; } bool saved = false; while (!saved) { try { if (MessageBox.Show("(Required) Please save your answers file to disk.", "Important Notice", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK) { SaveFileDialog adialog = new SaveFileDialog(); adialog.Filter = "FCT Exam File (*.FCTANS)|*.FCTANS"; adialog.DefaultExt = "FCTANS"; adialog.FileName = $"{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}-Submission-{studentIDTxtBox.Text}"; adialog.AddExtension = true; if (adialog.ShowDialog() == DialogResult.OK) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk] [File Location: ({adialog.FileName})]"); anExam.ExamLog = ExamLog; anExam.RequiredStudentDetails = requiredDetails; ExamHelper.SaveExamToFile(anExam, studentPassTxtBox.Text, adialog.FileName); aLogger.LogMessage($"[Student Saved Exam On Disk] [File Location: ({adialog.FileName})]", LogMsgType.Verbose); MessageBox.Show("Done, closing now."); this.Close(); } } else { ExamLog.Add($"[{DateTime.Now}] [Student did not save file to disk. You should save it.]"); } saved = true; } catch (Exception ex) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk (Process Failed) (exception: {ex.Message}] "); MessageBox.Show("[ERROR] File Did Not Save Correctly, please retry! \n" + ex.Message); } } }
private void submitExamBtn_Click(object sender, EventArgs e) { string errMsg = ""; bool error = false; string remainingTime = remainingtimeLbl.Text; ExamLog.Add($"[{DateTime.Now}] [Student Tried to Submit SUBMIT EXAM] [Remaing time: {remainingTime}]"); foreach (var q in anExam.QuestionsList) { if (q.StudentAnswer == string.Empty || q.StudentAnswer == null) { error = true; errMsg = errMsg + $" Q{q.QuestionNumber}. "; } } if (error) { MessageBox.Show("Please provide answers for the following questions before you submit the exam" + errMsg); return; } bool saved = false; anExam.RequiredStudentDetails.SequenceNumber = (long.Parse(anExam.RequiredStudentDetails.SequenceNumber) + 1).ToString(); while (!saved) { try { if (MessageBox.Show("(Recommended) Please save file to disk before submitting on network.", "Important Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveFileDialog adialog = new SaveFileDialog(); adialog.Filter = "FCT Exam File (*.FCTANS)|*.FCTANS"; adialog.DefaultExt = "FCTANS"; adialog.FileName = $"{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}-Submission-{studentIDTxtBox.Text}"; adialog.AddExtension = true; if (adialog.ShowDialog() == DialogResult.OK) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk] [File Location: ({adialog.FileName})]"); anExam.ExamLog = ExamLog; //anExam.RequiredStudentDetails = requiredDetails; ExamHelper.SaveExamToFile(anExam, examKeyTxtBox.Text, adialog.FileName); aLogger.LogMessage($"[Student Saved Exam On Disk] [File Location: ({adialog.FileName})]", LogMsgType.Verbose); } } else { ExamLog.Add($"[{DateTime.Now}] [Student Did not Select To Save File To Disk]"); } saved = true; } catch (Exception ex) { ExamLog.Add($"[{DateTime.Now}] [Student Saved Exam On Disk (Process Failed) (exception: {ex.Message}] "); MessageBox.Show("File Did Not Save Correctly, please retry!"); } } var reqDetailsEnc = anExam.RequiredStudentDetails; reqDetailsEnc.EncryptDetails(); aLogger.LogMessage("Submitting Exam Through Network ... (Started)", LogMsgType.Verbose); anExam.ExamLog = ExamLog; // anExam.RequiredStudentDetails = requiredDetails; if (client.ServiceProxy.SubmitExamEncryptedZipped(ExamHelper.GetExamFileWithoutSave(anExam, examKeyTxtBox.Text, sharedKeyISTxtBox.Text, (highSecChkBox.Checked ? Security.FilterationSecurityLevel.High : Security.FilterationSecurityLevel.Moderate)), reqDetailsEnc)) { aLogger.LogMessage("Submitting Exam Through Network ... (Done Succesfully.)", LogMsgType.Verbose); MessageBox.Show("Exam Submitted Correctly. Closing..."); client.Disconnect(); aLogger.LogMessage("Disconnected from server", LogMsgType.Verbose); this.Close(); } else { aLogger.LogMessage("Submitting Exam Through Network ... (Process Failed)", LogMsgType.Verbose); MessageBox.Show("ERROR: Submission Failed. "); } }