c# - implementing for loop to check data -
i want able retrieve template (fingerprint) database , compare onto current template captured using fingerprint reader. using web service not working.
public fgrtemplate stuverifications(int id) { cn.open(); sqlcommand com = new sqlcommand("select template tblfingerprint id = '" + id + "'", cn); //com.parameters.addwithvalue("id", i); sqldatareader sd = com.executereader(); while (sd.read()) { fgrtemplate fingerprint = new fgrtemplate() { id = sd.getint32(0), studentid = sd.getint32(1), description = sd.getstring(2) //template = sd.getbyte(3) }; cn.close(); return fingerprint; } cn.close(); return new fgrtemplate();
the code below matches 2 template
//3rd step - match against registered template string[] fingerpos_str = new string[] { "unknown finger", "right thumb", "right index finger", "right middle finger", "right ring finger", "right little finger", "left thumb", "left index finger", "left middle finger", "left ring finger", "left little finger"}; int32 err; sgfpmfingerposition finger_pos = sgfpmfingerposition.fingpos_uk; bool finger_found = false; sgfpmansitemplateinfo sample_info = new sgfpmansitemplateinfo(); foreach (fgrtemplate m_storedtemplate in studentverifications(s.id)) //err = m_fpm.getansitemplateinfo(m_storedtemplate, sample_info); (int = 0; < sample_info.totalsamples; i++) { bool matched = false; err = m_fpm.matchansitemplate(m_storedtemplate, i, m_vrfmin, 0, m_securitylevel, ref matched); if (matched) { finger_found = true; finger_pos = (sgfpmfingerposition)sample_info.sampleinfo[i].fingernumber; // break; } } if (err == (int32)sgfpmerror.error_none) { if (finger_found) richtextbox1.text = "the matched data found. finger position: " + fingerpos_str[(int32)finger_pos]; else richtextbox1.text = "cannot find matched data"; } else richtextbox1.text = "matchansitemplate() error : " + err;
i want able check each row in database having difficulties in doing so. how implement loop in situation.
many thanks
use ienumerable this:
public ienumerable<fgrtemplate> stuverifications(int id) { cn.open(); sqlcommand com = new sqlcommand("select template tblfingerprint id = '" + id + "'", cn); //com.parameters.addwithvalue("id", i); sqldatareader sd = com.executereader(); while (sd.read()) { fgrtemplate fingerprint = new fgrtemplate() { id = sd.getint32(0), studentid = sd.getint32(1), description = sd.getstring(2) //template = sd.getbyte(3) }; yield return fingerprint; } cn.close();
this return collection of fgrtemplates (one each row) can foreach through after.
then go through each template (note guessing @ how method want loop works, may not right):
foreach(fgrtemplate t in stuverifications(id)) { err = m_fpm.matchansitemplate(t, i, m_vrfmin, 0, m_securitylevel, ref matched); if (matched) display student name else error message }
Comments
Post a Comment