public int GetFaceIDByUid(int uid, FaceData.FaceAngleType type) { try { if (!_isDBInitialized) { return(ERROR_NOT_INIT); } int id = 0; MySqlDataReader reader = MySqlHelper.ExecuteReader(conn, "SELECT id FROM " + FACE_TABLE_NAME + " WHERE userid=@uid and angletype=@type;", new MySqlParameter("@uid", uid), new MySqlParameter("@type", (int)type)); if (reader.Read()) { id = reader.GetInt32(0); Console.WriteLine("GetFaceIDByUid ok. id={0}", reader[0]); } reader.Close(); return(id); } catch (Exception ex) { Console.WriteLine("DataAccess GetFaceIDByUid Error. " + ex.Message); return(ERROR_DB_FAILED); } }
public int DeleteFaceInfo(int uid, FaceData.FaceAngleType type) { try { if (!_isDBInitialized) { return(ERROR_NOT_INIT); } //删除表格所有内容 int ret = MySqlHelper.ExecuteNonQuery(conn, "DELETE FROM " + FACE_TABLE_NAME + " WHERE userid=@userid and angletype=@type;", new MySqlParameter("@userid", uid), new MySqlParameter("@type", type)); return(ret); } catch (Exception ex) { Console.WriteLine("DataAccess DeleteFaceInfo Error. " + ex.Message); return(ERROR_DB_FAILED); } }
public int LoadFaceData(ProgressBar proBar) { try { if (!_isDBInitialized) { return(ERROR_NOT_INIT); } int count = 0; int total = GetFaceCount(); if (total == 0) { Console.WriteLine("LoadFace no record, exit."); return(0); } if (proBar != null) { if (proBar.InvokeRequired) { Action a = () => { proBar.Maximum = total; proBar.Value = 0; }; proBar.Invoke(a); } else { proBar.Maximum = total; proBar.Value = 0; } } //装载用户信息 LoadUserInfo(); //获取所有人脸信息 MySqlDataReader reader = MySqlHelper.ExecuteReader(conn, "SELECT id,userid,featurelength,feature,angletype FROM " + FACE_TABLE_NAME); while (reader.Read()) { int fid = reader.GetInt32(reader.GetOrdinal("id")); int userid = reader.GetInt32(reader.GetOrdinal("userid")); int featurelength = reader.GetInt32(reader.GetOrdinal("featurelength")); byte[] feature = new byte[featurelength]; reader.GetBytes(reader.GetOrdinal("feature"), 0, feature, 0, featurelength); FaceData.FaceAngleType angletype = (FaceData.FaceAngleType)reader.GetInt32(reader.GetOrdinal("angletype")); FaceData fd = new FaceData(); fd.faceid = fid; fd.userid = userid; fd.featureLenth = (short)featurelength; fd.feature = feature; fd.angleType = angletype; _FaceDic.AddFace(userid, fd); count++; if (proBar != null) { if (proBar.InvokeRequired) { Action d = () => { proBar.Value++; }; proBar.Invoke(d); } else { proBar.Value++; } } } reader.Close(); Console.WriteLine("LoadFace ok. read count={0}", count); return(count); } catch (Exception ex) { Console.WriteLine("DataAccess LoadFace Error. " + ex.Message); return(ERROR_DB_FAILED); } }