Example #1
0
 public User(int uid)
 {
     this.uid          = uid;
     this.faceinfobase = null;
     this.userinfo     = null;
     this.moneyrecords = null;
 }
Example #2
0
        public static bool InitDB()
        {
            try
            {
                if (SQLEngine.Instance.Connection == null)
                {
                    return(false);
                }

                //创建数据库
                string sqlstr = "CREATE DATABASE IF NOT EXISTS " + DATABASE_NAME + ";"
                                + "use " + DATABASE_NAME + ";";
                MySqlCommand cmd = new MySqlCommand(sqlstr, SQLEngine.Instance.Connection);
                cmd.ExecuteNonQuery();
                //创建表
                FaceInfoBase.MakeTable();
                UserInfo.MakeTable();
                MoneyRecord.MakeTable();

                return(true);
            }catch (Exception ex)
            {
                return(false);
            }
        }
Example #3
0
        public static FaceInfoBase Create(FaceInfo faceinfo)
        {
            FaceInfoBase faceInfoBase = new FaceInfoBase(faceinfo);
            int          gender       = 1;
            int          faceType;

            switch (faceinfo.angleType)
            {
            case FaceData.FaceAngleType.Middle:
                faceType = 0;
                break;

            case FaceData.FaceAngleType.Up:
                faceType = 1;
                break;

            case FaceData.FaceAngleType.Down:
                faceType = 2;
                break;

            case FaceData.FaceAngleType.Left:
                faceType = 3;
                break;

            case FaceData.FaceAngleType.Right:
                faceType = 4;
                break;

            default:
                faceType = 5;
                break;
            }
            if (faceinfo.gender == FaceInfo.Gender.Femail)
            {
                gender = 0;
            }
            string sql = String.Format("INSERT INTO {0}" +
                                       "(gender, facetype, featurelength, featuredata, picdata)" +
                                       " VALUES({1}, {2}, {3}, @feature, @bmp);", table_name,
                                       faceinfo.gender, faceType, faceinfo.featureLenth);
            MySqlCommand cmd = new MySqlCommand(sql, SQLEngine.Instance.Connection);

            cmd.Parameters.Add("@feature", MySqlDbType.Binary, faceinfo.feature.Length);
            cmd.Parameters["@feature"].Value = faceinfo.feature;
            cmd.Parameters.Add("@bmp", MySqlDbType.Binary, PhotoImageInsert(faceinfo.FaceShotBmp).Length);
            cmd.Parameters["@bmp"].Value = PhotoImageInsert(faceinfo.FaceShotBmp);
            if (cmd.ExecuteNonQuery() != 1)
            {
                Console.WriteLine("Error UPDATE model {0}", faceinfo);
                return(null);
            }
            else
            {
                sql = String.Format("SELECT MAX(uid) FROM {0};", table_name);
                cmd = new MySqlCommand(sql, SQLEngine.Instance.Connection);
                faceInfoBase.uid = (Int32)cmd.ExecuteScalar();
                return(faceInfoBase);
            }
        }
Example #4
0
        public static List <FaceInfoBase> GetList(int gender)
        {
            if (gender >= 1)
            {
                gender = 1;//男
            }
            else
            {
                gender = 0;
            }
            List <FaceInfoBase> faceInfoBases = new List <FaceInfoBase>();
            string          sql = String.Format("SELECT * FROM {0} WHERE gender = {1};", table_name, gender);
            MySqlCommand    cmd = new MySqlCommand(sql, SQLEngine.Instance.Connection);
            MySqlDataReader rs  = cmd.ExecuteReader();

            while (rs.Read())
            {
                int      uid      = rs.GetInt32("uid");
                FaceInfo faceInfo = new FaceInfo();
                switch (rs.GetInt32("facetype"))
                {
                case 0:
                    faceInfo.angleType = FaceData.FaceAngleType.Middle;
                    break;

                case 1:
                    faceInfo.angleType = FaceData.FaceAngleType.Up;
                    break;

                case 2:
                    faceInfo.angleType = FaceData.FaceAngleType.Down;
                    break;

                case 3:
                    faceInfo.angleType = FaceData.FaceAngleType.Left;
                    break;

                case 4:
                    faceInfo.angleType = FaceData.FaceAngleType.Right;
                    break;

                default:
                    faceInfo.angleType = FaceData.FaceAngleType.Unknown;
                    break;
                }
                faceInfo.featureLenth = (short)rs.GetInt32("featurelength");
                faceInfo.feature      = (byte[])rs.GetValue(5);
                faceInfo.FaceShotBmp  = ReturnPhoto((byte[])rs.GetValue(6));
                FaceInfoBase faceInfoBase = new FaceInfoBase(faceInfo);
                faceInfoBase.uid = uid;
                faceInfoBases.Add(faceInfoBase);
            }
            rs.Close();
            return(faceInfoBases);
        }
Example #5
0
 public FaceInfoBase GetFaceInfoBase()
 {
     return(faceinfobase ?? (faceinfobase = FaceInfoBase.FindByUid(uid)));
 }
Example #6
0
        public static void Test()
        {
            FaceInfoBase.MakeTable();

            Console.WriteLine("这个接口可能没意义,暂时不实现");
        }