Пример #1
0
        private static bool _insertRecord(attendanceRecord record)
        {
            bool returnedValue;
            SqlConnection conn = new SqlConnection(conExamIDDB);
            conn.Open();
            string query = "INSERT INTO [dbo].[ExamIDUnit] ";
            query = query + "([examidunit_id]";
            query = query + ",[auditnumber]";
            query = query + ",[examdate]";
            query = query + ",[examnumber]";
            query = query + ",[mode]";
            query = query + ",[studentnumber]";
            query = query + ",[cardnumber]";
            query = query + ",[creator]";
            query = query + ",[fingerA_id]";
            query = query + ",[fingerB_id]";
            query = query + ",[fingerA_image]";
            query = query + ",[fingerB_image]";
            query = query + ",[uploadtime]";
            query = query + ",[TimeStamp]";
            query = query + ",[Deleted]";
            query = query + ",[score1]";
            query = query + ",[score2]";
            query = query + ",[category]";
            query = query + ",[fingerA_template]";
            query = query + ",[fingerB_template]";
            query = query + ",[lat]";
            query = query + ",[lon])";
            query = query + " VALUES";
            query = query + "(@examidunit_id";
            query = query + ",@auditnumber";
            query = query + ",@examdate";
            query = query + ",@examnumber";
            query = query + ",@mode";
            query = query + ",@studentnumber";
            query = query + ",@cardnumber";
            query = query + ",@creator";
            query = query + ",@fingerA_id";
            query = query + ",@fingerB_id";
            query = query + ",@fingerA_image";
            query = query + ",@fingerB_image";
            query = query + ",@uploadtime";
            query = query + ",@TimeStamp";
            query = query + ",@Deleted";
            query = query + ",@score1";
            query = query + ",@score2";
            query = query + ",@category";
            query = query + ",@fingerA_template";
            query = query + ",@fingerB_template";
            query = query + ",@lat";
            query = query + ",@lon)";

            SqlCommand cmd = new SqlCommand(query, conn);
            cmd.Parameters.Add("@examidunit_id", SqlDbType.NVarChar).Value = Guid.NewGuid().ToString();
            cmd.Parameters.Add("@auditnumber", SqlDbType.NVarChar).Value = record.AuditNumber;
            cmd.Parameters.Add("@examdate", SqlDbType.DateTime).Value = record.ClassTime;
            cmd.Parameters.Add("@examnumber", SqlDbType.NVarChar).Value = record.CourseCode;
            cmd.Parameters.Add("@mode", SqlDbType.NVarChar).Value = "1";
            cmd.Parameters.Add("@studentnumber",SqlDbType.NVarChar).Value = record.StudentNumber;
            cmd.Parameters.Add("@cardnumber",SqlDbType.NVarChar).Value = record.CardNumber;
            cmd.Parameters.Add("@creator",SqlDbType.NVarChar).Value = "";
            cmd.Parameters.Add("@fingerA_id",SqlDbType.Int).Value = record.FingerAID;
            cmd.Parameters.Add("@fingerB_id",SqlDbType.Int).Value = record.FingerBID;
            cmd.Parameters.Add("@fingerA_image",SqlDbType.Image).Value = record.FingerAImage;
            cmd.Parameters.Add("@fingerB_image",SqlDbType.Image).Value = record.FingerBImage;
            cmd.Parameters.Add("@uploadtime",SqlDbType.DateTime).Value = DateTime.Now;
            cmd.Parameters.Add("@TimeStamp",SqlDbType.DateTime).Value = record.TimeStamp;
            cmd.Parameters.Add("@Deleted",SqlDbType.NVarChar).Value = "";
            cmd.Parameters.Add("@score1",SqlDbType.Int).Value = record.score1;
            cmd.Parameters.Add("@score2",SqlDbType.Int).Value = record.score2;
            cmd.Parameters.Add("@category",SqlDbType.NVarChar).Value = record.ScanResult;
            cmd.Parameters.Add("@fingerA_template",SqlDbType.Image).Value = record.FingerATemplate;
            cmd.Parameters.Add("@fingerB_template",SqlDbType.Image).Value = record.FingerBTemplate;
            cmd.Parameters.Add("@lat",SqlDbType.NVarChar).Value = record.lat;
            cmd.Parameters.Add("@lon", SqlDbType.NVarChar).Value = record.lon;

            cmd.CommandType = CommandType.Text;

            try
            {
                cmd.ExecuteNonQuery();
                returnedValue = true;

            }
            catch (Exception)
            {
                returnedValue = false;

            }
            finally
            {
                conn.Close();
            }
            return returnedValue;
        }
Пример #2
0
        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();
        }
Пример #3
0
 public static bool InsertAttendanceRecord(attendanceRecord record)
 {
     return _insertRecord(record);
 }