//// ////Gets the next permitted number of attempts for an employee for a given exam_type //// //public Results getNextNoOfAttemptsByEmployeeForExamType(Results e) //{ // Exam_Types et = new Exam_Types(); // et.exam_Type = e.exam_Type; // et = em.getNoOfAttempts(et); // if (e.attempt_No == et.no_Of_Attempts) // e.attempt_No = 0; // else // e.attempt_No++; // return e; //} // //Validates fields before adding Exam Type // public String addExamType(Exam_Types e) { string feedback = ""; bool feed = false; int i = 0; if (e.subject == "") { feedback += (++i) + ". Subject "; feed = true; } if (e.level_Number <= 0) { feedback += (++i) + ". Level Number "; feed = true; } if (e.no_Of_Attempts <= 0) { feedback += (++i) + ". No of Attempts "; feed = true; } if (feed) { //Not valid: Returns erroneous fields return ("Please enter valid entries for: " + feedback); } else { //Valid: Adds Exam Type and returns assigned Exam Type or Error Message string feedDAL = em.addExamType(e); return feedDAL; } }
// //On changing the Exam Type // private void examTypeCombo_SelectedIndexChanged(object sender, EventArgs e) { //Resets the other controls on change of Exam Type, also disables then in case of an invalid selection levelCombo.Enabled = false; noOfAttemptsCombo.Enabled = false; subjectText.Text = ""; subjectText.Enabled = false; update.Enabled = false; if (examTypeCombo.SelectedIndex != -1) { //Gets the details of the selected Exam Type Exam_Types et = new Exam_Types(); Exam_TypeBS cs = new Exam_TypeBS(); et.exam_Type = examTypeCombo.SelectedItem.ToString(); et = cs.getExamType(et); //Enables the other controls levelCombo.Enabled = true; noOfAttemptsCombo.Enabled = true; subjectText.Enabled = true; update.Enabled = true; //Loads the Exam Type subjectText.Text = et.subject; levelCombo.SelectedItem = et.level_Number; noOfAttemptsCombo.SelectedItem = et.no_Of_Attempts; } else MessageBox.Show("Please select a valid Exam Type."); }
// //Deletes an Exam Type with given Exam Type, and returns a success or error message // public string deleteExamType(Exam_Types et) { try { conn.Open(); cmd = new SqlCommand("Delete Exam_Types where Exam_Type='" + et.exam_Type + "'", conn); int i = cmd.ExecuteNonQuery(); conn.Close(); if(i==1) return "Exam Type " + et.exam_Type + " is successfully deleted"; else return "Attempt unsuccessful. Sorry for the inconvenience."; } catch (Exception ex) { conn.Close(); return "Attempt unsuccessful. Sorry for the inconvenience."; } }
//// ////Returns the number of attempts for the exam_type in the results entity //// //public Exam_Types getNoOfAttempts(Exam_Types r) //{ // conn.Open(); // cmd = new SqlCommand("Select No_Of_Attempts from Exam_Types where Exam_Type='" + r.exam_Type + "'", conn); // r.no_Of_Attempts = Convert.ToInt32(cmd.ExecuteScalar()); // conn.Close(); // return r; //} // //Adds Exam Type and returns assigned Exam Type (or Error Message) // public string addExamType(Exam_Types e) { e.exam_Type = this.getNext(); try { conn.Open(); cmd = new SqlCommand("Insert into Exam_Types(Exam_Type,Subject,Level_Number,No_Of_Attempts) values('" +e.exam_Type + "','" + e.subject + "'," + e.level_Number + "," + e.no_Of_Attempts + ")", conn); int i = cmd.ExecuteNonQuery(); conn.Close(); if(i==1) return "Exam Type was successfully added & assigned Exam Type " + e.exam_Type + "."; else return "Some error occured. Sorry for the inconvenience."; } catch (Exception ex) { conn.Close(); return "Some error occured. Sorry for the inconvenience."; } }
// //Deletes the selected Exam & pops up a Success or Error message // protected void delete_Click(object sender, EventArgs e) { if (examTypeCombo.SelectedIndex != -1) { //DialogResult result = MessageBox.Show("Are you sure you want delete " + examTypeCombo.SelectedItem.ToString() + "?", "Delete Exam Type", MessageBoxButtons.YesNo); //if (result == DialogResult.Yes) Exam_Types r = new Exam_Types(); r.exam_Type = examTypeCombo.SelectedItem.ToString(); string feedback = ed.deleteExamType(r); System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(feedback)</SCRIPT>"); //MessageBox.Show(feedback); } else System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Please select a valid Exam ID.')</SCRIPT>"); //MessageBox.Show("Please select a valid Exam Type."); this.Page_Load(sender, e); }
// //On click of Add button, validates, adds exam type, displays assigned exam type // private void add_Click(object sender, EventArgs e) { if ((levelCombo.SelectedIndex == -1 )|| (noOfAttemptsCombo.SelectedIndex == -1)) MessageBox.Show("Please select a valid entry."); else { Exam_Types em = new Exam_Types(); Exam_TypeBS cs = new Exam_TypeBS(); em.subject = subjectText.Text.ToString(); string temp = levelCombo.Text.ToString(); em.level_Number = Convert.ToInt32(levelCombo.SelectedItem); em.no_Of_Attempts = Convert.ToInt32(noOfAttemptsCombo.SelectedItem); //Call to BLL to validate and add Exam Type string feedback = cs.addExamType(em); MessageBox.Show(feedback, "Add Exam Type"); subjectText.Text = ""; levelCombo.SelectedIndex = 0; noOfAttemptsCombo.SelectedIndex = 0; } }
// //Deletes the selected Exam Type & pops up a Success or Error message // private void delete_Click(object sender, EventArgs e) { if (examTypeCombo.SelectedIndex != -1) { DialogResult result = MessageBox.Show("Are you sure you want delete " + examTypeCombo.SelectedItem.ToString() + "?", "Delete Exam Type", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Exam_Types r = new Exam_Types(); r.exam_Type = examTypeCombo.SelectedItem.ToString(); string feedback = ed.deleteExamType(r); MessageBox.Show(feedback); } } else MessageBox.Show("Please select a valid Exam Type."); this.DeleteExamType_Load(sender, e); }
// //Gets other fields of a Exam Type given the Exam Type // public Exam_Types getExamType(Exam_Types e) { conn.Open(); cmd = new SqlCommand("select Subject, Level_Number, No_Of_Attempts from Exam_Types where Exam_Type ='"+e.exam_Type+"'", conn); dread = cmd.ExecuteReader(); dread.Read(); e.subject = dread[0].ToString(); e.level_Number = Convert.ToInt32(dread[1]); e.no_Of_Attempts = Convert.ToInt32(dread[2]); dread.Close(); conn.Close(); return e; }
// //Updates fields of Exam Type, returns Success or Error Message // public string updateExamType(Exam_Types e) { try { conn.Open(); cmd = new SqlCommand("Update Exam_Types SET Subject='" + e.subject + "',Level_Number=" + e.level_Number + ",No_Of_Attempts=" + e.no_Of_Attempts + " Where Exam_Type='" + e.exam_Type + "'", conn); int i = cmd.ExecuteNonQuery(); conn.Close(); if(i==1) return "Exam was successfully updated"; else return "Some error occured. Sorry for the inconvenience."; } catch (Exception ex) { conn.Close(); return "Some error occured. Sorry for the inconvenience."; } }
// //On Form Load: Displays Welcome Message, displays today's schedule, if any // private void EmpHome_Load(object sender, EventArgs e) { emp = b.getEmployee(emp); welcomeLabel.Text = "Welcome " + emp.first_Name + " " + emp.last_Name; ResultsBS r = new ResultsBS(); int count = r.getExamCountForEmployee(emp); Exam_Details[] er = new Exam_Details[count]; er = r.getExamIDsForEmployee(emp, count); er = eb.getSchedule(er); int[] index = eb.checkTodaysSchedule(er); Results[] res = new Results[index.Length]; for (int i = 0; i < index.Length; i++) { res[i] = new Results(); res[i].employee_ID = emp.employee_Id; res[i].exam_ID = er[index[i]].exam_ID; } //bool[] feed = new bool[index.Length]; res = r.checkIfAppeared(res); int total = 0; for (int i = res.Length - 1; i >= 0; i--) { if (res[i].score == -1) { total++; ed.exam_ID = res[i].exam_ID; } } if (total == 0) { examIDLabel.Text = "Sorry."; examTypeLabel.Text = "You dont have any test scheduled today."; dateLabel.Text = ""; durationLabel.Text = ""; noteLabel.Text = ""; skipTutorial.Enabled = false; takeTutorial.Enabled = false; } else { ed = eb.getExamDetails(ed); Exam_Types et1 = new Exam_Types(); et1.exam_Type = ed.exam_Type; et1 = et.getExamType(et1); examIDLabel.Text += ed.exam_ID; examTypeLabel.Text +=" " +et1.exam_Type + " (" + et1.subject + " Level " + et1.level_Number+")"; dateLabel.Text += ed.datetime.Date.ToShortDateString(); ; durationLabel.Text += +ed.duration; total--; if (total >= 1) noteLabel.Text += "You have " + total + " more exams scheduled today."; else noteLabel.Text = ""; } }
// //On form load: Displays the employee name and his result // private void Result_Load(object sender, EventArgs e) { employeeNameLabel.Text = emp.first_Name + " " + emp.last_Name; Results re = new Results(); re.Employee_ID = emp.employee_Id; re.exam_ID = ed.exam_ID; re = r.getResult(re); ResultStatus rs = new ResultStatus(); rs.employee_ID = emp.employee_Id; rs.exam_Type = ed.exam_Type; ResultStatusBS rsb = new ResultStatusBS(); rs = rsb.getResultStatus(rs); Exam_Types m = new Exam_Types(); m.exam_Type = ed.exam_Type; Exam_TypeBS exd = new Exam_TypeBS(); m = exd.getExamType(m); examLabel.Text = "Exam ID: " + ed.exam_ID + " Exam Type: " + ed.exam_Type + " Subject: " + m.subject + " Level: " + m.level_Number + " Attempt No: " + rs.attempt_No; if (rs.status == "Passed") congratulationsLabel.Text = "Congratulations ! You have passed! Your score is"+re.score+". Percentage: "+re.percentage+"%"; else { if (rs.attempt_No == m.no_Of_Attempts) { congratulationsLabel.Text = "Sorry, You have Failed in this Examination . Your score is" + re.score + ". Percentage: " + re.percentage + "%. You have no more attempts left for this exam"; } congratulationsLabel.Text = "Sorry , You have Failed in this Examination . Your score is"+re.score+". Percentage: "+re.percentage+"%. You have got " +(m.no_Of_Attempts-rs.attempt_No) + " attempts left for this exam"; } }
// //DAL call to get other fields of a Exam Type given the Exam Type // public Exam_Types getExamType(Exam_Types et) { et = em.getExamType(et); return et; }
// //DAl call to delete an Exam Type // public string deleteExamType(Exam_Types et) { string feed = em.deleteExamType(et); return feed; }
// //On click of Update button // private void update_Click(object sender, EventArgs e) { if ((examTypeCombo.SelectedIndex == -1) || (levelCombo.SelectedIndex == -1) || (noOfAttemptsCombo.SelectedIndex == -1)) MessageBox.Show("Please select a valid entry", "Error"); else { //Getting the input Exam_TypeBS js = new Exam_TypeBS(); Exam_Types em = new Exam_Types(); em.exam_Type = examTypeCombo.SelectedItem.ToString(); em.subject = subjectText.Text.ToString(); em.level_Number = (Convert.ToInt32(levelCombo.Text)); em.no_Of_Attempts = (Convert.ToInt32(noOfAttemptsCombo.Text)); //Business logic call, forwarded to DAL string feedback = js.updateExamType(em); MessageBox.Show(feedback, "Update Exam"); examTypeCombo.SelectedIndex = 0; subjectText.Text = ""; levelCombo.SelectedIndex = 0; noOfAttemptsCombo.SelectedIndex = 0; } }
// //On click of Add button, validates and adds applicants // private void add_Click(object sender, EventArgs e) { if (employeeIDCombo.SelectedIndex == -1 || examIDCombo.SelectedIndex == -1) { MessageBox.Show("Please select a valid entry.", "Error"); } else { //Creates Results objects Results r = new Results(); string id = employeeIDCombo.Text.ToString(); int pos = id.IndexOf(":"); r.employee_ID = id.Substring(0, pos); r.exam_ID = examIDCombo.Text.ToString(); //Gets exam type of exam ID Exam_Details ed = new Exam_Details(); ed.exam_ID = r.exam_ID; ed = edb.getExamDetails(ed); //Gets number of attempts for exam type Exam_Types et = new Exam_Types(); Exam_TypeBS etb = new Exam_TypeBS(); et.exam_Type = ed.exam_Type; et = etb.getExamType(et); //Creates ResultStatus objects ResultStatus rs = new ResultStatus(); rs.employee_ID = r.employee_ID; rs.exam_Type = ed.exam_Type; //Gets the attempts_no and status ResultStatusBS rsb = new ResultStatusBS(); rs = rsb.getResultStatus(rs); ResultsBS rb = new ResultsBS(); //Unscheduled if (rs.status == "Unscheduled") { rs.attempt_No = 1; rs.status = "Scheduled"; string feedback = rsb.addResultStatus(rs); if (feedback == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); } else { string feed = rb.addApplicant(r); if (feed == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); rsb.deleteResultStatus(rs); } else { //Succesfully scheduled MessageBox.Show(feed + feedback, "Scheduled", MessageBoxButtons.OK); examIDCombo.SelectedIndex = employeeIDCombo.SelectedIndex = 0; } } } //Scheduled else if (rs.status == "Scheduled") { MessageBox.Show("Employee " + rs.employee_ID + " already has an exam scheduled for exam type " + rs.exam_Type + ".", "Already Scheduled", MessageBoxButtons.OK); } //Passed else if (rs.status == "Passsed") { MessageBox.Show("Employee " + rs.employee_ID + " has passed an exam of exam type " + rs.exam_Type + ".", "Passed", MessageBoxButtons.OK); } //Failed else if (rs.status == "Failed") { ///Exhausted Attempts if (rs.attempt_No == et.no_Of_Attempts) { MessageBox.Show("Employee " + rs.employee_ID + " has used up the maximum number of attempts for exam type " + rs.exam_Type + ".", "Exhausted Attempts", MessageBoxButtons.OK); } //Attempts left else { rs.Attempt_No++; rs.status = "Scheduled"; string feedback = rsb.updateResultStatus(rs); if (feedback == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); } else { string feed = rb.addApplicant(r); if (feed == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); rs.attempt_No--; rsb.updateResultStatus(rs); } else { //Succesfully scheduled MessageBox.Show(feed + feedback, "Scheduled", MessageBoxButtons.OK); examIDCombo.SelectedIndex = employeeIDCombo.SelectedIndex = 0; } } } } } }