Exemplo n.º 1
0
        public void Getcount(int ID)
        {
            MemoryCache cache1 = MemoryCache.Default;

            if (!cache1.Contains("tp" + ID.ToString()))
            {
                lock (ID.ToString())
                {
                    if (!cache1.Contains("tp" + ID.ToString()))
                    {
                        string         strtext = "select count(*) from tabvote where TabCanId=@ID";
                        MySqlParameter param   = new MySqlParameter()
                        {
                            ParameterName = "ID", Value = ID, MySqlDbType = MySqlDbType.Int32
                        };
                        object count = MySQLCommon.ExecuteScalar(strtext, param);

                        string           strtxt2 = "update tabcandidate set Votes=@Count where Id=@ID";
                        MySqlParameter[] param2  = new MySqlParameter[] {
                            new MySqlParameter()
                            {
                                ParameterName = "ID", Value = ID, MySqlDbType = MySqlDbType.Int32
                            },
                            new MySqlParameter()
                            {
                                ParameterName = "Count", Value = Convert.ToInt32(count), MySqlDbType = MySqlDbType.Int32
                            }
                        };
                        MySQLCommon.ExecuteNonQuery(strtxt2, param2);

                        cache1.Set("tp" + ID.ToString(), ID, DateTimeOffset.Now.AddMinutes(5));
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加投票信息
        /// </summary>
        /// <param name="vote"></param>
        /// <returns></returns>
        public int Addvote(TabVoteItems vote)
        {
            string strText = "insert into tabvote values(@Id,@Ip,@session,@user_agent,@Votetime,@TabCanId)";

            MySqlParameter[] param = new MySqlParameter[] {
                new MySqlParameter()
                {
                    ParameterName = "Id", Value = vote.Id, MySqlDbType = MySqlDbType.Int32
                },
                new MySqlParameter()
                {
                    ParameterName = "Ip", Value = vote.Ip, MySqlDbType = MySqlDbType.VarChar
                },
                new MySqlParameter()
                {
                    ParameterName = "session", Value = vote.session, MySqlDbType = MySqlDbType.VarChar
                },
                new MySqlParameter()
                {
                    ParameterName = "user_agent", Value = vote.user_agent, MySqlDbType = MySqlDbType.VarChar
                },
                new MySqlParameter()
                {
                    ParameterName = "Votetime", Value = vote.Votetime, MySqlDbType = MySqlDbType.DateTime
                },
                new MySqlParameter()
                {
                    ParameterName = "TabCanId", Value = vote.TabCanId, MySqlDbType = MySqlDbType.Int32
                }
            };
            return(MySQLCommon.ExecuteNonQuery(strText, param));
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        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);
        }