private static universityStudent _getUniversityStudentFromStudentNumber(string StudentNumber) { SqlConnection conn = new SqlConnection(conRegistrationDB); conn.Open(); string query = "SELECT [student_number],[firstname],[lastname],[id_Number]"; query = query + " FROM [RegistrationDB].[dbo].[registered_students] WHERE [student_number] = '" + StudentNumber + "' "; SqlCommand cmd = new SqlCommand(query, conn); DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader()); universityStudent _student = new universityStudent(); _student.StudentNumber = StudentNumber; if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; if (dr.IsNull("firstname")) { _student.FirstName = null; } else { _student.FirstName = (string)dr["firstname"]; }; if (dr.IsNull("lastname")) { _student.LastName = null; } else { _student.LastName = (string)dr["lastname"]; }; if (dr.IsNull("id_number")) { _student.IDNumber = null; } else { _student.IDNumber = (string)dr["id_Number"]; }; } conn.Close(); return _student; }
private void btnMatchConfirm_Click(object sender, EventArgs e) { //cancelMatchScan = true; bool enrolledForCourse = true; bckScanFinger.CancelAsync(); Application.DoEvents(); attendanceRecord NewAttendance = new attendanceRecord(); student ThisMatchedStudent = dlRegistration.GetStudentFromStudentNumber(txtMatchStudentNumber.Text); course EnrolledCourse = new course("a","a"); //See if there were multiple course codes selected. If more than one selected see for which one the student is registered if (cmbCourses.Items.Count >= 1) { List<course> courses = dlRegistration.getCoursesForStudentNumber(ThisMatchedStudent.StudentNumber); List<course> _selectedCourses = new List<course>(); foreach (course courseItem in cmbCourses.Items) { course _tempCourse = new course(courseItem.CourseCode, courseItem.Description); _selectedCourses.Add(_tempCourse); } foreach (course courseItem in _selectedCourses) { foreach (course matchCourse in courses) { if (matchCourse.CourseCode == courseItem.CourseCode) EnrolledCourse = new course(matchCourse.CourseCode, matchCourse.Description); } } //Lets make sure the student is enrolled in this course if (EnrolledCourse.CourseCode == "a") { enrolledForCourse = false; course tempCourse = (course)cmbCourses.Items[0]; EnrolledCourse = new course(tempCourse.CourseCode, tempCourse.Description); } } else { course tempCourse = (course)cmbCourses.Items[0]; EnrolledCourse = new course(tempCourse.CourseCode,tempCourse.Description); } byte[] templateBuffer = (byte[])fingerprintTemplate.Save(); if (ThisMatchedStudent.Enrolled) { //If the student has a registered fingerprint then check the grace setting. //We use the score2 pvtComplSyncClass as the grace setting //Before we confirm the student as attended we have to check the student number typed in the text box //if the textbox student number is the same as the matchedStudentNumber then //we can use the ThisMatchedStudent otherwise //we have match the student again using the given template //and use that as the category and score result if (txtMatchStudentNumber.Text == matchedStudentNumber) { NewAttendance.FingerAID = matchedFingerID - 1; NewAttendance.FingerAImage = new byte[0]; NewAttendance.FingerATemplate = templateBuffer; NewAttendance.FingerBID = 0; NewAttendance.FingerBImage = new byte[0]; NewAttendance.FingerBTemplate = new byte[0]; NewAttendance.ScanResult = "A"; NewAttendance.score1 = matchedScore; NewAttendance.score2 = 0; strConfirmMessage = "Identified: " + ThisMatchedStudent.FirstName + " " + ThisMatchedStudent.LastName + ". Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Green; } else { //The student changed the student number. This means that we now have to first see if the template scanned //belong to the new studentnumber if (VerifyFingerprint(ThisMatchedStudent, fingerprintTemplate)) { NewAttendance.FingerAID = matchedFingerID - 1; NewAttendance.FingerAImage = new byte[0]; NewAttendance.FingerATemplate = templateBuffer; NewAttendance.FingerBID = 0; NewAttendance.FingerBImage = new byte[0]; NewAttendance.FingerBTemplate = new byte[0]; if (enrolledForCourse) { NewAttendance.ScanResult = "A"; } else { NewAttendance.ScanResult = "B"; } NewAttendance.score1 = matchedScore; NewAttendance.score2 = 0; strConfirmMessage = "Identified: " + ThisMatchedStudent.FirstName + " " + ThisMatchedStudent.LastName + ". Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Green; } else { //If the template does not belong to the new student then we need to look at the grace //If grace is anything less than 3 then we add the matched FingedID and template, but with a score //of 0 and a ScanResult of "C" int grace = 0; bool converted = Int32.TryParse(ThisMatchedStudent.CardHistory, out grace); if (converted) { if (grace < 3) { NewAttendance.FingerAID = 6; NewAttendance.FingerAImage = new byte[0]; NewAttendance.FingerATemplate = templateBuffer; NewAttendance.FingerBID = 0; NewAttendance.FingerBImage = new byte[0]; NewAttendance.FingerBTemplate = new byte[0]; NewAttendance.ScanResult = "C"; NewAttendance.score1 = 0; NewAttendance.score2 = 0; strConfirmMessage = "No Match: " + ThisMatchedStudent.FirstName + " " + ThisMatchedStudent.LastName + ". Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Red; //We have to update the registration system with the grace number } else { //Fingerprints didn't match give it a "D" score NewAttendance.FingerAID = 0; NewAttendance.FingerAImage = new byte[0]; NewAttendance.FingerATemplate = new byte[0]; NewAttendance.FingerBID = 0; NewAttendance.FingerBImage = new byte[0]; NewAttendance.FingerBTemplate = new byte[0]; NewAttendance.ScanResult = "D"; NewAttendance.score1 = 0; NewAttendance.score2 = 0; strConfirmMessage = "No Match: " + ThisMatchedStudent.FirstName + " " + ThisMatchedStudent.LastName + ". Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Red; } } else { //If the conversion failed then there were no grace period then we can update the user NewAttendance.FingerAID = 6; NewAttendance.FingerAImage = new byte[0]; NewAttendance.FingerATemplate = templateBuffer; NewAttendance.FingerBID = 0; NewAttendance.FingerBImage = new byte[0]; NewAttendance.FingerBTemplate = new byte[0]; NewAttendance.ScanResult = "C"; NewAttendance.score1 = 0; NewAttendance.score2 = 0; strConfirmMessage = "No Match: " + ThisMatchedStudent.FirstName + " " + ThisMatchedStudent.LastName + ". Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Red; //We have to update the registration system with the grace number } } } //If the grace setting is anything less than 3 then mark the student's record as graced //and increment the grace NewAttendance.StudentNumber = ThisMatchedStudent.StudentNumber; NewAttendance.CardNumber = ThisMatchedStudent.CardNumber; NewAttendance.AuditNumber = ""; NewAttendance.ClassTime = DateTime.Now; NewAttendance.CourseCode = EnrolledCourse.CourseCode; NewAttendance.TimeStamp = DateTime.Now; NewAttendance.lat = ""; NewAttendance.lon = ""; } else { //What happens if the student is not enrolled? //If the student is not fingerprint enrolled then create a record in the registration DB for the user //and mark the grace as 1 NewAttendance.StudentNumber = txtMatchStudentNumber.Text; NewAttendance.CardNumber = ""; NewAttendance.AuditNumber = ""; NewAttendance.ClassTime = DateTime.Now; NewAttendance.CourseCode = EnrolledCourse.CourseCode; NewAttendance.FingerAID = 6; NewAttendance.FingerAImage = new byte[0]; NewAttendance.FingerATemplate = templateBuffer; NewAttendance.FingerBID = 0; NewAttendance.FingerBImage = new byte[0]; NewAttendance.FingerBTemplate = new byte[0]; NewAttendance.ScanResult = "X"; NewAttendance.score1 = 0; NewAttendance.TimeStamp = DateTime.Now; NewAttendance.lat = ""; NewAttendance.lon = ""; universityStudent tempStudent = new universityStudent(); tempStudent = dlRegistration.GetUniversityStudentFromStudentNumber(txtMatchStudentNumber.Text); if (tempStudent.FirstName != null || tempStudent.LastName != null) { strConfirmMessage = "Fingerprint not enrolled: " + ThisMatchedStudent.FirstName + " " + ThisMatchedStudent.LastName + ". Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Orange; } else { strConfirmMessage = "Fingerprint not enrolled: Student number: " + ThisMatchedStudent.StudentNumber; lblConfirmMessage.ForeColor = Color.Orange; } //We have to now register the student's fingerprints here } dlExamID.InsertAttendanceRecord(NewAttendance); //Prepare the screen for next student btnMatchConfirm.Enabled = false; txtMatchStudentNumber.Enabled = false; lblMatchResult.Text = ""; txtMatchStudentNumber.Text = ""; nfView1.Template = null; nfView1.Image = null; nfView1.ResultImage = null; lblIdentifyActionMessage.Text = "Please scan right index finger"; loadConfirmMessage(); }