usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Data;usingSystem.Data.SQLite;namespacefaceattendance{classDBHelper { PublicSqliteconnection Conn; PublicDBHelper () {connectdatabase (); } Private voidConnectdatabase () {conn=NewSqliteconnection ("Data source=. \\.. \\.. \\FACEINFO.DB3; Verson = 3;");//Create a DB instance, specify the file locationConn. Open ();//Open the database and create it automatically if the file does not exist if(conn = =NULL)Throw NewException ("database connection failed. Check to see if the database file exists. "); } Public voidInsertPerson (intIdstringNamestringSexstringPositionstringFaceinfo,stringdes) { stringsql =NULL; if(des = =NULL) {SQL="INSERT into info values ("+14061143+", '"+ name +"', '"+ Sex +"', '"+ Position +"',"+ des +");"; } Else{SQL="INSERT into info values ("+14061143+", '"+ name +"', '"+ Sex +"', '"+ Position +"', '"+ des +"');"; } sqlitecommand Command=Newsqlitecommand (SQL, conn); Command. ExecuteNonQuery (); Command. Dispose (); } Public voidInsertattendance (intIdstringTime ) { stringsql ="INSERT into signinfo values ("+id+", '"+time+"');"; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Command. ExecuteNonQuery (); Command. Dispose (); } PublicList<peopleinfo>Getpeopleinfo () {List<peopleinfo> FACERLT =NewList<peopleinfo>(); stringsql ="SELECT * from info;"; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Sqlitedatareader Reader=command. ExecuteReader (); intj =0; while(reader. Read ()) {J++; Peopleinfo people=NewPeopleinfo (); People. Id= Reader. GetInt32 (0); People.name= (string) reader["NAME"]; People.sex= (string) reader["SEX"]; People.position= (string) reader["JOB"]; stringFS = (string) reader["Faceinfo"]; string[] FSA = fs. Split (';'); for(inti =0; I < -; i++) People.faceinfo[i]= (float) convert.todouble (Fsa[i]); People.des= (string) reader["MSG"]; Facerlt.add (people); } command. Dispose (); Reader. Dispose (); returnFACERLT; } Public voidInsertpersonrecord (stringNamestringTime ) { stringsql ="INSERT into Personrecord values ('"+ name +"', '"+ Time +"');"; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Command. ExecuteNonQuery (); Command. Dispose (); } PublicPeopleinfo Getpersoninfo (intId) {stringsql ="SELECT * from info WHERE Id ="+Id; Sqlitecommand Command=Newsqlitecommand (SQL, conn); Sqlitedatareader Reader=command. ExecuteReader (); Reader. Read (); Peopleinfo people=NewPeopleinfo (); People. Id= Reader. GetInt32 (0); People.name= (string) reader["NAME"]; People.sex= (string) reader["SEX"]; People.position= (string) reader["JOB"]; People.des= (string) reader["MSG"]; returnpeople; } }}
Sqllite Database Operation classes