예제 #1
0
        /// <summary>
        /// 获取最新获奖记录
        /// </summary>
        /// <returns>返回中奖记录集合</returns>
        public List<LotteryLog> GetLotteryLog()
        {
            List<LotteryLog> list = new List<LotteryLog>();
            try
            {
                string sql = "select top 10 * from LotteryLog where LotteryName !='谢谢参与' order by LotteryTime desc";

                using (SqlDataReader reder = db.GetReader(sql))
                {
                    while (reder.Read())
                    {
                        LotteryLog ll = new LotteryLog((int)reder["Id"], reder["UserName"].ToString(), (int)reder["Points"], (int)reder["LotteryNum"], reder["LotteryName"].ToString(), (DateTime)reder["LotteryTime"]);
                        list.Add(ll);
                    }
                }
                return list;
            }
            catch (SqlException ex)
            {
                throw new Exception("数据库异常!原因:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("未知异常!原因:" + ex.Message);
            }
            return list;
        }
예제 #2
0
 /// <summary>
 /// 添加一条中奖日志
 /// </summary>
 /// <param name="ll">中奖日志</param>
 /// <returns>返回是否添加成功</returns>
 public Boolean AddLotteryLog(LotteryLog ll)
 {
     try
     {
         string sql = "insert into LotteryLog(UserName,Points,LotteryNum,LotteryName)values (@UserName,@Points,@LotteryNum,@LotterName)";
         SqlParameter[] sp = new SqlParameter[]
         {
              new SqlParameter("@UserName",ll.UserName),
             new SqlParameter("@Points",ll.Points),
             new SqlParameter("@LotteryNum",ll.LotteryNum),
             new SqlParameter("@LotterName",ll.LotterName)
         };
         return db.ExecuteNonQuery(sql, sp);
     }
     catch (SqlException ex)
     {
         throw new Exception("数据库异常!原因:" + ex.Message);
     }
     catch (Exception ex)
     {
         throw new Exception("未知异常!原因:" + ex.Message);
     }
 }
예제 #3
0
 /// <summary>
 /// 进行抽奖
 /// </summary>
 /// <returns></returns>
 public string LotteryRes(string UserName)
 {
     int LotteryNum = 0;
     string LotteryText = "";
     LotteryLog ll = new LotteryLog(0, UserName, 10, 0, "", DateTime.Now);
     Random ran = new Random();
     int RandKey = ran.Next(1, 100000);
     if (RandKey > 899 && RandKey <= 999)
     {
         if (RandKey % 2 == 0)
         {
             LotteryNum = 2;
         }
         else
         {
             LotteryNum = 10;
         }
         AddUserMoney(UserName, 100);
         LotteryText = "恭喜您获得平台币一百元,现已到账,请查收!请再接再厉向大奖发力!";
         ll.LotterName = "平台币一百元";
     }
     else if (RandKey > 7725 && RandKey <= 7925)
     {
         AddUserMoney(UserName, 10);
         LotteryText = "恭喜您获得平台币十元,现已到账,请查收!请再接再厉向大奖发力!";
         ll.LotterName = "平台币十百元";
         if (RandKey % 2 == 0)
         {
             LotteryNum = 4;
         }
         else
         {
             LotteryNum = 12;
         }
     }
     else if (RandKey > 33332 && RandKey <= 34332)
     {
         AddUserMoney(UserName, 5);
         LotteryText = "恭喜您获得平台币五元,现已到账,请查收!请再接再厉向大奖发力!";
         ll.LotterName = "平台币五元";
         if (RandKey % 2 == 0)
         {
             LotteryNum = 5;
         }
         else
         {
             LotteryNum = 13;
         }
     }
     else if (RandKey > 55553 && RandKey <= 57553)
     {
         LotteryText = "恭喜您获得平台币一元,现已到账,请查收!请再接再厉向大奖发力!";
         ll.LotterName = "平台币一元";
         if (RandKey % 2 == 0)
         {
             LotteryNum = 7;
         }
         else
         {
             LotteryNum = 15;
         }
     }
     else
     {
         LotteryText = "很遗憾这次您啥也没中,不过还是要感谢您的参与!预祝您下次中大奖!";
         ll.LotterName = "谢谢参与";
         int RandKey2 = ran.Next(1, 6);
         switch (RandKey2)
         {
             case 1:
                 LotteryNum = 3;
                 break;
             case 2:
                 LotteryNum = 6;
                 break;
             case 3:
                 LotteryNum = 8;
                 break;
             case 4:
                 LotteryNum = 11;
                 break;
             case 5:
                 LotteryNum = 14;
                 break;
             case 6:
                 LotteryNum = 16;
                 break;
             default:
                 break;
         }
     }
     ll.LotteryNum = LotteryNum;
     ls.AddLotteryLog(ll);
     return LotteryNum + "|" + LotteryText;
 }