public bool AddToCache(GameInfo gameInfo) { lock (thisLock) { try { Dictionary<int, GameInfo> list = (Dictionary<int, GameInfo>)this.getCache(); if (!list.ContainsKey(gameInfo.ID)) { CommandHelper command = new CommandHelper("GameInfo", EditType.Insert); command.AddParameter("GameID", SqlDbType.Int, gameInfo.ID); command.AddParameter("GameName", SqlDbType.VarChar, gameInfo.Name); command.AddParameter("Currency", SqlDbType.VarChar, gameInfo.Currency); command.AddParameter("Multiple", SqlDbType.Decimal, gameInfo.Multiple); command.AddParameter("AgentsID", SqlDbType.VarChar, gameInfo.AgentsID); command.AddParameter("IsRelease", SqlDbType.Bit, gameInfo.IsRelease); command.AddParameter("ReleaseDate", SqlDbType.DateTime, gameInfo.ReleaseDate); command.AddParameter("PayStyle", SqlDbType.VarChar, gameInfo.PayStyle); command.AddParameter("GameWord", SqlDbType.VarChar, gameInfo.GameWord); command.AddParameter("SocketServer", SqlDbType.VarChar, gameInfo.SocketServer); command.AddParameter("SocketPort", SqlDbType.Int, gameInfo.SocketPort); command.Parser(); SqlHelper.ExecuteNonQuery(config.connectionString, CommandType.Text, command.Sql, command.Parameters); list.Add(gameInfo.ID, gameInfo); } else { CommandHelper command = new CommandHelper("GameInfo", EditType.Update); command.AddParameter("GameName", SqlDbType.VarChar, gameInfo.Name); command.AddParameter("Currency", SqlDbType.VarChar, gameInfo.Currency); command.AddParameter("Multiple", SqlDbType.Decimal, gameInfo.Multiple); command.AddParameter("AgentsID", SqlDbType.VarChar, gameInfo.AgentsID); command.AddParameter("IsRelease", SqlDbType.Bit, gameInfo.IsRelease); command.AddParameter("ReleaseDate", SqlDbType.DateTime, gameInfo.ReleaseDate); command.AddParameter("PayStyle", SqlDbType.VarChar, gameInfo.PayStyle); command.AddParameter("GameWord", SqlDbType.VarChar, gameInfo.GameWord); command.AddParameter("SocketServer", SqlDbType.VarChar, gameInfo.SocketServer); command.AddParameter("SocketPort", SqlDbType.Int, gameInfo.SocketPort); command.Filter = new CommandFilter(); command.Filter.Condition = "GameID=@GameID"; command.Filter.AddParam("@GameID", SqlDbType.Int, 0, gameInfo.ID); command.Parser(); SqlHelper.ExecuteNonQuery(config.connectionString, CommandType.Text, command.Sql, command.Parameters); list[gameInfo.ID] = gameInfo; return true; } this.addCache(list); return true; } catch (Exception ex) { this.SaveLog(ex); return false; } } }
public GameInfo GetGameInfo(int gameId) { CacheGame cacheGame = new CacheGame(); var list = cacheGame.GetGame(); var gameInfo = new GameInfo(); foreach (var item in list) { if (item.ID == gameId) { gameInfo = item; break; } } return gameInfo; }
protected override bool InitCache() { try { Dictionary<int, GameInfo> list = new Dictionary<int, GameInfo>(); string sql = "SELECT [GameID],[GameName],[Currency],[Multiple],[GameWord],[AgentsID],[IsRelease],[ReleaseDate],[PayStyle],[SocketServer],[SocketPort] FROM GameInfo ORDER BY GameID"; using (SqlDataReader reader = SqlHelper.ExecuteReader(config.connectionString, CommandType.Text, sql)) { while (reader.Read()) { var gameInfo = new GameInfo() { ID = ConvertHelper.ToInt(reader["GameID"]), Name = ConvertHelper.ToString(reader["GameName"]), Currency = ConvertHelper.ToString(reader["Currency"]), Multiple = ConvertHelper.ToDecimal(reader["Multiple"]), AgentsID = ConvertHelper.ToString(reader["AgentsID"]), IsRelease = ConvertHelper.ToBool(reader["IsRelease"]), ReleaseDate = ConvertHelper.ToDateTime(reader["ReleaseDate"]), PayStyle = ConvertHelper.ToString(reader["PayStyle"]), GameWord = Convert.ToString(reader["GameWord"]), SocketServer = ConvertHelper.ToString(reader["SocketServer"]), SocketPort = Convert.ToInt32(reader["SocketPort"]) }; list.Add(gameInfo.ID, gameInfo); } } this.addCache(list); return true; } catch (Exception ex) { this.SaveLog(ex); return false; } }