private void Form1_Load(object sender, EventArgs e) { var db = DAL.DbContext.Create(); USBApi.API_OpenUsb(); //display current date and time timer1.Start(); DateTime today = DateTime.Today; var validenrollmentdate = db.SelectSemSchoolYear(today); if (validenrollmentdate != null) { validenrollmentdate.Semester = db.Semesters.Get(validenrollmentdate.SemesterID); validenrollmentdate.Schoolyear = db.SchoolYears.Get(validenrollmentdate.SchoolYearID); } ShowSem.Text = validenrollmentdate.Semester.SemesterName.ToString() + " Sem"; ShowSY.Text = validenrollmentdate.Schoolyear.SchoolYearRange.ToString(); findThread = new Thread(new ThreadStart(myThread)); findThread.Start(); }
private void myThread() { var db = DAL.DbContext.Create(); byte[] data = new byte[100]; byte[] dataLen = new byte[1]; int nResult; while (true) { nResult = USBApi.API_InventoryOnce(data, dataLen); if (nResult == 0) { int i = 0; string onetagInfo = ""; for (i = 0; i < dataLen[0]; i++) { String strTmp = string.Format("{0:X2}", data[i]); onetagInfo += strTmp; } string epc = onetagInfo.Substring(4); DateTime today = DateTime.Today; var existEPC = db.Students.All().FirstOrDefault(s => s.EPC == epc); var validenrollmentdate = db.SelectSemSchoolYear(today); if (existEPC != null) { if (ValidateEnrollmentDate(existEPC, validenrollmentdate)) { //display data DisplayStudentInfo(existEPC); //record tap logs db.TapLogs.Insert(new TapLog { DateTimeTap = DateTime.Now, StudentID = existEPC.Id }); } else { DisplayStudentInfo(existEPC); DisplayNotEnrolled(); } } else { DisplayNotValid(); } } } }