/// <summary> /// 根据Id查询参选人的信息 /// </summary> /// <param name="Id"></param> /// <returns></returns> public DataTable GetTabCandidateWhere(int Id) { MemoryCache cache4 = MemoryCache.Default; if (!cache4.Contains("xy" + Id.ToString())) { lock (obj2) { if (!cache4.Contains("xy" + Id.ToString())) { string strText = "SELECT Id,`Name`,Sex,Age,School,Img,Player,Awards,Evaluation,Story,Reason,Votes,Rank FROM tabcandidate WHERE Id=@Id"; MySqlParameter param = new MySqlParameter() { ParameterName = "Id", Value = Id, MySqlDbType = MySqlDbType.Int32 }; DataTable dt = MySQLCommon.ExecuteDataTable(strText, param); cache4.Set("xy" + Id.ToString(), dt, DateTimeOffset.Now.AddMinutes(1)); } } } DataTable dt2 = cache4["xy" + Id.ToString()] as DataTable; return(dt2); }
/// <summary> /// 查询所有参选人的信息 /// </summary> /// <returns></returns> public DataTable GetTabCandidate(string Award) { string key = getMd5Hash(Award); MemoryCache cache3 = MemoryCache.Default; if (!cache3.Contains(key)) { lock (obj) { if (!cache3.Contains(key)) { string strText = "SELECT Id,`Name`,Img,Votes,Rank FROM tabcandidate WHERE Award = '" + Award + "' ORDER BY Votes DESC"; DataTable dt = MySQLCommon.ExecuteDataTable(strText); int count = -1; int rank = 1; foreach (DataRow row in dt.Rows) { Int32 votes = 0; Int32.TryParse(row["Votes"].ToString(), out votes); row["Votes"] = votes; if (count <= votes) { count = votes; row["Rank"] = rank; } else { count = votes; rank++; row["Rank"] = rank; } if (dic.ContainsKey(Convert.ToInt32(row["Id"]))) { dic[Convert.ToInt32(row["Id"])] = Convert.ToInt32(row["Rank"]); } else { dic.Add(Convert.ToInt32(row["Id"]), Convert.ToInt32(row["Rank"])); } } cache3.Set(key, dt, DateTimeOffset.Now.AddMinutes(3)); } } } DataTable dt2 = cache3[key] as DataTable; return(dt2); }
public DataTable GetAward() { MemoryCache cache2 = MemoryCache.Default; if (!cache2.Contains("Index")) { lock (obj1) { if (!cache2.Contains("Index")) { string strText = "SELECT Award FROM `tabcandidate` GROUP BY Award"; DataTable dt = MySQLCommon.ExecuteDataTable(strText); cache2.Set("Index", dt, DateTimeOffset.Now.AddDays(1)); } } } DataTable dt2 = cache2["Index"] as DataTable; return(dt2); }