//function that runs a scan on a timer private void signInScan(object source, ElapsedEventArgs e) { //gets the bytes of the proxID from a scan Byte[] Id = new Byte[8]; int nBits = pcProxDLLAPI.getActiveID(8); //if bits are received from the scan, sets the scannedID variable to the //proxID bits that we want if (nBits > 0) { String s = nBits.ToString() + " Bit ID [0]..[7]: "; String proxID = ""; string checkerID = ""; string checkersName = ""; for (short i = 2; i > -1; i--) { Id[i] = pcProxDLLAPI.getActiveID_byte(i); s = s + String.Format("{0:X2}.", Id[i]); proxID += String.Format("{0:X2}", Id[i]); } checkerID = Int32.Parse(proxID.Substring(1), System.Globalization.NumberStyles.HexNumber).ToString("D5"); Console.Out.WriteLine("checkers hex id:" + proxID); Console.Out.WriteLine("checkers decimal id:" + checkerID); Console.Out.WriteLine("checkers barcode: " + MainWindow.AppWindow.getAttendanceWriter().getStudentsBarcode(checkerID)); //if the last ID scanned is the same ID, does not check it for authorization if (!lastID.Equals(checkerID)) { //perform successful scan if the authorized list contains the id scanned //else says they are either not in the database or aren't authorized if (authorizedCheckerIDs.Contains(checkerID)) { lastID = checkerID; Dispatcher.Invoke(() => { MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Green); labelID.Foreground = new SolidColorBrush(Colors.ForestGreen); checkersName = attendanceWriter.getAuthorizedCheckersName(checkerID); labelID.Text = checkersName + "\nis an authorized Christian Life and Worship Credit Checker"; buttonCancelScan.IsEnabled = false; Panel.SetZIndex(buttonCancelScan, -1); Panel.SetZIndex(buttonProceed, 1); buttonProceed.IsEnabled = true; circleAnimationScan.Opacity = 0; }); this.chapelCheckerId = checkerID; scanTimer.Stop(); Dispatcher.Invoke(() => { attendanceWriter.setChapelCheckerID(checkerID); }); //playHappySound(); } else { lastID = checkerID; Dispatcher.Invoke(() => { checkersName = attendanceWriter.getStudentsName(checkerID); if (checkersName.Equals("Student")) { labelID.Text = checkersName + " is not in the Database\n\nTry Updating Database"; MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Red); } else { labelID.Text = checkersName + "\nis not an Authorized Christian Life and Worship Credit Checker"; MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Red); } }); //playFailSound(); } } } else { Dispatcher.Invoke(() => { MainWindow.AppWindow.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#014983")); circleAnimationScan.Fill = new SolidColorBrush(Colors.White); }); } }
// the scan function that runs on a timer private void scanCard(object source, ElapsedEventArgs e) { //initializes string variables string scannedID = ""; string studentName = ""; //gets the bits of the proxID from a scan Byte[] Id = new Byte[8]; int nBits = pcProxDLLAPI.getActiveID(8); //if bits are received from the scan, sets the scannedID variable to the //proxID bits that we want if (nBits > 0) { string s = nBits.ToString() + " Bit ID [0]..[7]: "; string proxID = ""; for (short i = 2; i > -1; i--) { Id[i] = pcProxDLLAPI.getActiveID_byte(i); s = s + string.Format("{0:X2}.", Id[i]); proxID += string.Format("{0:X2}", Id[i]); } scannedID = Int32.Parse(proxID.Substring(1), System.Globalization.NumberStyles.HexNumber).ToString("D5"); Console.Out.WriteLine("checkers hex id:" + proxID); Console.Out.WriteLine("checkers decimal id:" + scannedID); Console.Out.WriteLine("checkers barcode: " + MainWindow.AppWindow.getAttendanceWriter().getStudentsBarcode(scannedID)); if (!lastNotInDatabaseID.Equals(scannedID) && MainWindow.AppWindow.getAttendanceWriter().getStudentsBarcode(scannedID).Length == 0) { lastNotInDatabaseID = scannedID; lastIDforCredit = ""; lastNoCreditIDalready = ""; lastNoCreditID = ""; lastIDforCreditAlready = ""; int screenHeight; Dispatcher.Invoke(() => { studentName = attendanceWriter.getStudentsName(scannedID); labelID.Text = ""; labelID2.Foreground = new SolidColorBrush(Colors.White); screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; labelID2.Width = screenWidth; labelID2.Text = "Student was not found in the database.\nTake ID to CTS!"; }); //playFailSound(); if (noCreditChecked) { Dispatcher.Invoke(() => { buttonNoCredit.IsEnabled = true; Panel.SetZIndex(buttonCancelNoCredit, -1); buttonCancelNoCredit.Opacity = 0; buttonCancelNoCredit.IsEnabled = false; }); noCreditChecked = false; } } //performs a successful scan for credit if the following: // //the last id for credit does not equal the currently scannedID // //the noCredit checkbox is unchecked // //the noCreditList does not contain the currently scannedID // //the creditList does not contain the currently scannedID // else if (!lastIDforCredit.Equals(scannedID) && !noCreditChecked && !noCreditList.Contains(scannedID) && !creditList.Contains(scannedID) && !lastNotInDatabaseID.Equals(scannedID)) { lastIDforCredit = scannedID; lastNotInDatabaseID = ""; lastNoCreditIDalready = ""; lastNoCreditID = ""; lastIDforCreditAlready = ""; Dispatcher.Invoke(() => { circleAnimation.Fill = new SolidColorBrush(Colors.Green); MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Green); studentName = attendanceWriter.getStudentsName(scannedID); screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; labelID.Foreground = new SolidColorBrush(Colors.White); labelID.Width = screenWidth; labelID.Text = studentName; labelID2.Foreground = new SolidColorBrush(Colors.White); labelID2.Width = screenWidth; labelID2.Text = "will receive credit."; }); playHappySound(); creditList.Add(scannedID); attendanceWriter.setNoCredit(0); attendanceWriter.WriteAttendanceTextFile(scannedID); } //performs a no credit scan for no credit if the following: // //the last no credit id does not equal the currently scannedID // //the noCredit checkbox is checked // //the noCreditList does not contain the currently scannedID // else if (!lastNoCreditID.Equals(scannedID) && noCreditChecked && !noCreditList.Contains(scannedID) && !lastNotInDatabaseID.Equals(scannedID)) { lastNoCreditID = scannedID; lastNotInDatabaseID = ""; lastNoCreditIDalready = ""; lastIDforCreditAlready = ""; lastIDforCredit = ""; Dispatcher.Invoke(() => { circleAnimation.Fill = new SolidColorBrush(Colors.Red); MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Red); screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; studentName = attendanceWriter.getStudentsName(scannedID); labelID.Foreground = new SolidColorBrush(Colors.White); labelID.Width = screenWidth; labelID.Text = studentName; labelID2.Foreground = new SolidColorBrush(Colors.White); labelID2.Width = screenWidth; labelID2.Text = "will not receive credit."; buttonNoCredit.IsEnabled = true; Panel.SetZIndex(buttonCancelNoCredit, -1); buttonCancelNoCredit.Opacity = 0; buttonCancelNoCredit.IsEnabled = false; }); noCreditList.Add(scannedID); attendanceWriter.setNoCredit(1); attendanceWriter.WriteAttendanceTextFile(scannedID); noCreditChecked = false; } //performs a no longer can receive credit scan if the following: // //the last id for no credit does not equal the currently scannedID // //the last id for no credit already does not equal the currently scannedID // //the no credit list does contain the currently scannedID // else if (!lastNoCreditIDalready.Equals(scannedID) && !lastNoCreditID.Equals(scannedID) && noCreditList.Contains(scannedID) && !lastNotInDatabaseID.Equals(scannedID)) { lastNoCreditIDalready = scannedID; lastNotInDatabaseID = ""; lastIDforCreditAlready = ""; lastNoCreditID = ""; lastIDforCredit = ""; Dispatcher.Invoke(() => { circleAnimation.Fill = new SolidColorBrush(Colors.Red); MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Red); screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; studentName = attendanceWriter.getStudentsName(scannedID); labelID.Foreground = new SolidColorBrush(Colors.White); labelID.Width = screenWidth; labelID.Text = studentName; labelID2.Foreground = new SolidColorBrush(Colors.White); labelID2.Width = screenWidth; labelID2.Text = "can no longer receive credit."; buttonNoCredit.IsEnabled = true; Panel.SetZIndex(buttonCancelNoCredit, -1); buttonCancelNoCredit.Opacity = 0; buttonCancelNoCredit.IsEnabled = false; }); noCreditChecked = false; //playFailSound(); } //performs an already received credit scan if the following: // //the last id for credit already does not equal the currently scannedID // //the last id for credit does not equal the currently scannedID // //the credit list does contain the scannedID // //the no credit list does not contain the currently scannedID // else if (!lastIDforCreditAlready.Equals(scannedID) && !lastIDforCredit.Equals(scannedID) && creditList.Contains(scannedID) && !noCreditList.Contains(scannedID) && !lastNotInDatabaseID.Equals(scannedID)) { lastIDforCreditAlready = scannedID; lastNotInDatabaseID = ""; lastNoCreditIDalready = ""; lastNoCreditID = ""; lastIDforCredit = ""; Dispatcher.Invoke(() => { circleAnimation.Fill = new SolidColorBrush(Colors.Green); MainWindow.AppWindow.Background = new SolidColorBrush(Colors.Green); screenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; studentName = attendanceWriter.getStudentsName(scannedID); labelID.Foreground = new SolidColorBrush(Colors.White); labelID.Width = screenWidth; labelID.Text = studentName; labelID2.Foreground = new SolidColorBrush(Colors.White); labelID2.Width = screenWidth; labelID2.Text = "has already received credit."; }); playHappySound(); } else { Dispatcher.Invoke(() => { circleAnimation.Fill = new SolidColorBrush(Colors.White); MainWindow.AppWindow.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#014983")); }); } } else { Dispatcher.Invoke(() => { circleAnimation.Fill = new SolidColorBrush(Colors.White); MainWindow.AppWindow.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#014983")); }); } }