예제 #1
0
        //保存到数据库
        public void SaveDB()
        {
            StringBuilder          sb = new StringBuilder();
            List <SQLiteParameter> lp = new List <SQLiteParameter>();

            sb.Append("update UserMagic set ");

            sb.Append(" Level=@Level, "); lp.Add(new SQLiteParameter("Level", Level));
            sb.Append(" Key=@Key, "); lp.Add(new SQLiteParameter("Key", Key));
            sb.Append(" Experience=@Experience, "); lp.Add(new SQLiteParameter("Experience", Experience));
            sb.Append(" IsTempSpell=@IsTempSpell, "); lp.Add(new SQLiteParameter("IsTempSpell", IsTempSpell));
            sb.Append(" CastTime=@CastTime "); lp.Add(new SQLiteParameter("CastTime", CastTime));

            sb.Append(" where  Spell=@Spell and userid=@userid"); lp.Add(new SQLiteParameter("Spell", Spell)); lp.Add(new SQLiteParameter("userid", userid));
            //执行更新
            int ucount = MirRunDB.Execute(sb.ToString(), lp.ToArray());

            //没有得更新,则执行插入
            if (ucount <= 0)
            {
                sb.Clear();
                lp.Clear();
                sb.Append("insert into UserMagic(Level,Key,Experience,IsTempSpell,CastTime,Spell,userid) values(@Level,@Key,@Experience,@IsTempSpell,@CastTime,@Spell,@userid) ");

                lp.Add(new SQLiteParameter("Level", Level));
                lp.Add(new SQLiteParameter("Key", Key));
                lp.Add(new SQLiteParameter("Experience", Experience));
                lp.Add(new SQLiteParameter("IsTempSpell", IsTempSpell));
                lp.Add(new SQLiteParameter("CastTime", CastTime));

                lp.Add(new SQLiteParameter("Spell", Spell)); lp.Add(new SQLiteParameter("userid", userid));
                //执行插入
                MirRunDB.Execute(sb.ToString(), lp.ToArray());
            }
        }
예제 #2
0
        public static List <UserMagic> loadByUserid(int userid)
        {
            List <UserMagic> list = new List <UserMagic>();
            DbDataReader     read = MirRunDB.ExecuteReader("select * from UserMagic where userid=@userid", new SQLiteParameter("userid", userid));

            while (read.Read())
            {
                if (read.IsDBNull(read.GetOrdinal("Spell")))
                {
                    continue;
                }
                UserMagic magic = new UserMagic((Spell)read.GetByte(read.GetOrdinal("Spell")));
                magic.userid      = userid;
                magic.Level       = read.GetByte(read.GetOrdinal("Level"));
                magic.Key         = read.GetByte(read.GetOrdinal("Key"));
                magic.Experience  = (ushort)read.GetInt32(read.GetOrdinal("Experience"));
                magic.CastTime    = read.GetInt64(read.GetOrdinal("CastTime"));
                magic.IsTempSpell = read.GetBoolean(read.GetOrdinal("IsTempSpell"));
                list.Add(magic);
            }
            return(list);
        }