public Result(Employee e1, Exam_Details e2,Questions[] q1, Answers[] a1) { InitializeComponent(); emp = e1; ed = e2; a = a1; q = q1; }
public CheckSolution(Questions[] q1, Answers[] a1, Employee e1, Exam_Details ed1) { InitializeComponent(); q = q1; a = a1; emp = e1; ed = ed1; }
// //Accepts and assigns Question, Answers, Bookmark array, index, time left, Employee and Exam Details // public MatchTheColumnTest(Questions[] que, Answers[] ans, Bookmark[] b1, int ind, int timeleft1, Employee e, Exam_Details exd) { InitializeComponent(); q = que; a = ans; index = ind; b = b1; timeLeft = timeleft1; emp = e; ed = exd; }
// //Accepts and assigns Question, Answers, Bookmark array, index, time left, Employee and Exam Details // public PictureQuestionSingleAns(Questions[] que, Answers[] ans, Bookmark[] b1, int ind, int timeleft1, Employee e, Exam_Details exd) { InitializeComponent(); q = que; a = ans; b = b1; index = ind; timeLeft = timeleft1; emp = e; ed = exd; }
// //Initializes the fields of Answers array including answers // public Answers[] initializeAnswersArray(Answers[] a, Questions[] q, Exam_Details ed, Employee emp) { for (int i = 0; i < q.Length; i++) { a[i] = new Answers(); a[i].exam_ID = ed.exam_ID; a[i].employee_Id = emp.employee_Id; a[i].question_ID = q[i].question_ID; a = this.storeAnswer(a, i, ""); } return a; }
// //Calculates marks for each question and the total, stores them in Answers array, DAL call to store the answers in the Answers table, and final results in the Result table // public bool submit(Answers[] a, Questions[] q, Employee emp, Exam_Details ed) { //Calculates marks for each question (stores them in Answers array), total and percentage int score = 0; int outOf = 0; float per = 0; for (int i = 0; i < q.Length; i++) { if (a[i].answer.Equals(q[i].solution)) a[i].marks = q[i].marks; else a[i].marks = 0; score += a[i].marks; outOf += q[i].marks; } per = (score *100) / outOf; //DAL call to store the answers in the Answers table bool feed = d.submitAnswers(a); //DAL call to store final result in the Result table if (feed) { Results re = new Results(); re.employee_ID = emp.employee_Id; re.exam_ID = ed.exam_ID; re.score = score; re.percentage = per; ResultsDAL rb = new ResultsDAL(); bool feed1 = rb.addScore(re); if (feed1) { ResultStatusDAL rsd = new ResultStatusDAL(); ResultStatus rs = new ResultStatus(); rs.employee_ID = emp.employee_Id; rs.exam_Type = ed.exam_Type; if (re.percentage >= 50.0) rs.status = "Passed"; else rs.status = "Failed"; bool feed2 = rsd.updateStatus(rs); if (feed2) return true; else return false; } else return false; } else return false; }
// //Stores the answers in the Answer table, returns true if successful, else false // public bool submitAnswers(Answers [] a) { da = new SqlDataAdapter(); cb = new SqlCommandBuilder(da); conn.Open(); tran = conn.BeginTransaction(); da.SelectCommand = new SqlCommand( "Select * from Answers", conn, tran); ds = new DataSet(); da.Fill(ds, "Answers"); dt = ds.Tables["Answers"]; for (int i = 0; i < a.Length; i++) { drow = dt.NewRow(); drow["Employee_ID"] = a[i].employee_Id; drow["Exam_ID"] = a[i].exam_ID; drow["Question_ID"] = a[i].question_ID; drow["Answer"] = a[i].answer; drow["Marks"] = a[i].marks; dt.Rows.Add(drow); } try { int updates = da.Update(ds, "Answers"); } catch (Exception ex) { if (tran != null) { tran.Rollback(); tran = null; conn.Close(); return false; } } finally { if (tran != null) { tran.Commit(); tran = null; } } conn.Close(); return true; }
//Calculate Detailed Result public bool calculateResult(Answers[] a, Questions[] q, Results r, Employee emp) { bool flag = true; int count = q.Length; int total = 0; string[] abc; ResultsDAL d = new ResultsDAL(); int i = d.getSectionCount(r); DetailedReports[] re = new DetailedReports[i]; abc = new string[i]; int[] section = new int[i]; abc = d.loadSection(r, i); int[] totalQuestions = d.totalSectionQuestions(abc, r); for (int j = 0; j < count; j++) { //total = total + q[j].marks; if (a[j].answer.Equals(q[j].solution)) { string click = q[j].section; for (int k = 0; k < i; k++) { if (click == abc[k]) section[k]++; } } } for (int k = 0; k < i; k++) { re[k] = new DetailedReports(); re[k].employee_ID = emp.employee_Id; re[k].exam_ID = r.exam_ID; re[k].section = abc[k]; re[k].percentage = (section[k] * 100) / totalQuestions[k]; flag = d.addDetailedResult(re[k]); } return flag; }
// //Stores the given answer for given question in the Answer array and returns the array // public Answers[] storeAnswer(Answers [] a, int index, string ans) { a[index].answer = ans; return a; }