/// <summary> /// 添加一个用户 /// </summary> /// <param name="aUser">用户</param> /// <returns>成功?</returns> public bool addUser(User aUser) { string cmdString = "INSERT INTO " + DBcolumns.TABLE_USER + " VALUES(\'" + aUser.UserId + "\',\'" + aUser.UserPwd + "\',\'" + aUser.UserName + "\'," + aUser.Sex + "," + aUser.Age + ",\'" + aUser.Birthday + "\',\'" + aUser.Address + "\',\'" + aUser.Time + "\')"; ExecuteNonQuery(cmdString, Constant.globalDbPath + "global.db"); return true; }
/// <summary> /// 将用户信息拼装成字符串序列 /// </summary> /// <param name="user"></param> /// <returns></returns> public static string UserData2String(User user) { string split = Constant.SPLIT; //ID卍昵称卍性别卍生日卍地址卍注册时间 string data = user.UserId + split + user.UserName + split + user.Sex + split + user.Birthday + split + user.Address + split + user.Time; return data; }
/// <summary> /// 查询用户信息 /// </summary> /// <param name="userId">用户ID</param> /// <returns>用户资料</returns> public User queryUser(string userId) { string cmdString = "SELECT * FROM " + DBcolumns.TABLE_USER + " WHERE " + DBcolumns.USER_ID + " =\'" + userId + "\'"; ; SQLiteConnection conn = new SQLiteConnection("Data Source=" + Constant.globalDbPath + "global.db"); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(cmdString, conn); SQLiteDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { User u = new User(); u.UserId = dr.GetString(0); u.UserPwd = ""; u.UserName = dr.GetString(2); u.Sex = dr.GetInt32(3); u.Age = dr.GetInt32(4); u.Birthday = dr.GetString(5); u.Address = dr.GetString(6); u.Time = dr.GetString(7); u.Remark = ""; conn.Close(); return u; } conn.Close(); return null; }