Exemple #1
0
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.UserPoint model)
        {
            if (model == null || model.PointNum < 0)
            {
                return(-1);
            }

            //定义查询命令
            string cmdText = @"update [UserPoint] set UserID = @UserID,PointNum = @PointNum,LastUpdatedDate = @LastUpdatedDate where NumberID = @NumberID";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@NumberID",        SqlDbType.UniqueIdentifier),
                new SqlParameter("@UserID",          SqlDbType.UniqueIdentifier),
                new SqlParameter("@PointNum",        SqlDbType.Decimal),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value = Guid.Parse(model.NumberID.ToString());
            parms[1].Value = Guid.Parse(model.UserID.ToString());
            parms[2].Value = model.PointNum;
            parms[3].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
Exemple #2
0
        private void OnSave()
        {
            string sUser = cbbUser.Value.Trim();

            if (string.IsNullOrEmpty(sUser))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "用户为必选项,请检查", "错误提醒", "error");
                return;
            }
            string sPoint = txtPoint.Value.Trim();

            if (string.IsNullOrEmpty(sPoint))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "棋子数不能为空,请检查", "错误提醒", "error");
                return;
            }

            decimal pointNum = 0;

            if (!decimal.TryParse(sPoint, out pointNum))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "棋子数输入格式不正确,请检查", "错误提醒", "error");
                return;
            }

            if (bll == null)
            {
                bll = new BLL.UserPoint();
            }
            Model.UserPoint model = new Model.UserPoint();
            model.UserID          = sUser;
            model.PointNum        = pointNum;
            model.LastUpdatedDate = DateTime.Now;

            int effectCount = -1;

            if (!string.IsNullOrEmpty(nId))
            {
                model.NumberID = nId;
                effectCount    = bll.Update(model);
            }
            else
            {
                effectCount = bll.Insert(model);
            }

            if (effectCount == 110)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "已存在相同记录", "温馨提醒", "error");
                return;
            }
            if (effectCount > 0)
            {
                WebHelper.MessageBox.MessagerShow(this.Page, lbtnPostBack, "操作成功");
            }
            else
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "操作失败");
            }
        }
Exemple #3
0
        /// <summary>
        /// 获取当前用户的点子数
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Model.UserPoint GetModelByUser(object userId)
        {
            Model.UserPoint model = null;

            string       cmdText = @"select top 1 NumberID,UserID,PointNum,LastUpdatedDate from [UserPoint] where UserID = @UserID order by LastUpdatedDate desc ";
            SqlParameter parm    = new SqlParameter("@UserID", SqlDbType.UniqueIdentifier);

            parm.Value = Guid.Parse(userId.ToString());

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new Model.UserPoint();
                        model.NumberID        = reader["NumberID"].ToString();
                        model.UserID          = reader["UserID"].ToString();
                        model.PointNum        = Decimal.Parse(reader["PointNum"].ToString());
                        model.LastUpdatedDate = DateTime.Parse(reader["LastUpdatedDate"].ToString());
                    }
                }
            }

            return(model);
        }
Exemple #4
0
        /// <summary>
        /// 保存数据
        /// </summary>
        private void OnSave()
        {
            string userName = txtUsername.Value.Trim();
            string psw      = txtPswset.Value.Trim();
            string email    = txtEmail.Value.Trim();

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(psw) || string.IsNullOrEmpty(email))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "用户名、密码、邮箱为必填项", "操作错误", "error");
                return;
            }
            if (string.Compare(Request.Cookies["AddUserVc"].Value.ToLower(), txtVc.Value.Trim().ToLower(), true) != 0)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "输入验证码不正确!", "操作错误", "error");
                return;
            }

            string errorMsg = string.Empty;

            try
            {
                MembershipUser user = Membership.CreateUser(userName, psw, email);

                if (user != null)
                {
                    Roles.AddUserToRole(user.UserName, "Users");

                    //系统自动分配该用户的棋子数
                    Model.UserPoint uModel = new Model.UserPoint();
                    uModel.UserID          = user.ProviderUserKey;
                    uModel.PointNum        = WebHelper.Common.POINTNUM;
                    uModel.LastUpdatedDate = DateTime.Now;
                    ThreadHelper.UserPoint uThread = new ThreadHelper.UserPoint(uModel);
                    uThread.ThreadStart();

                    WebHelper.MessageBox.MessagerShow(this.Page, lbtnSave, EnumMembershipCreateStatus.GetStatusMessage(MembershipCreateStatus.Success));
                }
            }
            catch (MembershipCreateUserException ex)
            {
                errorMsg = EnumMembershipCreateStatus.GetStatusMessage(ex.StatusCode);
            }
            catch (HttpException ex)
            {
                errorMsg = ex.Message;
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, errorMsg, "系统提示");
                return;
            }
        }
Exemple #5
0
 private void Bind()
 {
     if (!string.IsNullOrEmpty(nId))
     {
         if (bll == null)
         {
             bll = new BLL.UserPoint();
         }
         Model.UserPoint model = bll.GetModel(nId);
         if (model != null)
         {
             cbbUser.Value  = model.UserID.ToString();
             txtPoint.Value = model.PointNum.ToString();
         }
     }
 }
        private void Bind()
        {
            decimal pointNum = 0;

            BLL.UserPoint   uBll   = new BLL.UserPoint();
            Model.UserPoint uModel = uBll.GetModelByUser(WebHelper.Common.GetUserId());
            if (uModel != null)
            {
                pointNum = uModel.PointNum;
            }
            Label lbMyPoint = lvUser.FindControl("lbMyPoint") as Label;

            if (lbMyPoint != null)
            {
                lbMyPoint.Text = pointNum.ToString("N");
            }
        }
Exemple #7
0
        /// <summary>
        /// 获取数据分页列表,并返回所有记录数
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public IList <Model.UserPoint> GetList(int pageIndex, int pageSize, out int totalCount, string sqlWhere, params SqlParameter[] commandParameters)
        {
            //获取数据集总数
            string cmdText = "select count(*) from [UserPoint] t1 ";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            totalCount = (int)SqlHelper.ExecuteScalar(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, commandParameters);
            //返回分页数据
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            cmdText = @"select * from(select row_number() over(order by t1.CreateDate desc) as RowNumber,t1.NumberID,t1.UserID,t1.PointNum,t1.LastUpdatedDate from [UserPoint] t1 ";
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            IList <Model.UserPoint> list = null;

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, commandParameters))
            {
                if (reader != null && reader.HasRows)
                {
                    list = new List <Model.UserPoint>();

                    while (reader.Read())
                    {
                        Model.UserPoint model = new Model.UserPoint();
                        model.NumberID        = reader["NumberID"].ToString();
                        model.UserID          = reader["UserID"].ToString();
                        model.PointNum        = Decimal.Parse(reader["PointNum"].ToString());
                        model.LastUpdatedDate = DateTime.Parse(reader["LastUpdatedDate"].ToString());

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Exemple #8
0
        /// <summary>
        /// 启用多线程操作
        /// </summary>
        public override void ThreadWork()
        {
            base.IsBackground = true;

            BLL.UserPoint bll = new BLL.UserPoint();

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                Model.UserPoint uModel = bll.GetModelByUser(this.model.UserID);
                if (uModel != null)
                {
                    bll.Update(this.model);
                }
                else
                {
                    bll.Insert(model);
                }

                scope.Complete();
            }
        }
Exemple #9
0
        /// <summary>
        /// 添加数据到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Model.UserPoint model)
        {
            if (model == null)
            {
                return(-1);
            }

            string cmdText = "insert into [UserPoint] (UserID,PointNum,LastUpdatedDate) values (@UserID,@PointNum,@LastUpdatedDate)";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@UserID",          SqlDbType.UniqueIdentifier),
                new SqlParameter("@PointNum",        SqlDbType.Decimal),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value = Guid.Parse(model.UserID.ToString());
            parms[1].Value = model.PointNum;
            parms[2].Value = model.LastUpdatedDate;

            //执行数据库操作
            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
        public static void WorkProcess()
        {
            Console.WriteLine("开奖程序已开启 \r\n");
            Random rnd = new Random();

            int[] minItems = { 1, 2, 3 };
            int[] allItems = { 1, 2, 3, 4, 5, 6, 7, 8 };
            int[] items;
            //string[] names = { "兵", "炮", "傌", "俥", "相", "仕", "帥", "棋王" };

            int timeNum    = 0;
            int totalCount = 0;

            try
            {
                LotteryItem liBll = new LotteryItem();
                List <Model.LotteryItem> liList = liBll.GetList(1, 1000, out totalCount, "", null);
                if (liList == null || liList.Count == 0)
                {
                    Console.WriteLine("系统需要预先设置开奖元素,已终止执行!");
                    Console.ReadLine();
                    return;
                }

                LotterySln.BLL.RunLottery     rlBll  = new LotterySln.BLL.RunLottery();
                LotterySln.BLL.UserBetLottery ublBll = new LotterySln.BLL.UserBetLottery();
                LotterySln.BLL.UserPoint      uBll   = new LotterySln.BLL.UserPoint();

                while (true)
                {
                    timeNum++;

                    if (timeNum > 10)
                    {
                        timeNum = 0;
                    }
                    if (timeNum < 8)
                    {
                        items = minItems;
                    }
                    else
                    {
                        items = allItems;
                    }
                    //处于最大的预备时间
                    DateTime maxCurrDate = DateTime.Now;
                    //上一期期数
                    int lastPeriod = 0;
                    //上一期开奖时间
                    DateTime lastRunTime = DateTime.MinValue;
                    //上一次执行时间
                    DateTime currRunTime = DateTime.MinValue;
                    //上期已开奖的数字
                    int lastNum = -1;
                    //当前期ID
                    object   numberId = null;
                    DateTime currTime = DateTime.Now;
                    if (currTime < DateTime.Parse(currTime.ToString("yyyy-MM-dd")).AddHours(9))
                    {
                        currTime = DateTime.Parse(currTime.ToString("yyyy-MM-dd")).AddHours(9);
                    }

                    List <Model.RunLottery> rlList = rlBll.GetList(1, 6, out totalCount, "", null);
                    if (rlList == null || rlList.Count == 0)
                    {
                        //每期都要保证有5期是预设奖期,进行投注
                        for (int i = 1; i <= 5; i++)
                        {
                            double           currMin = i * 5;
                            Model.RunLottery rlModel = new Model.RunLottery();
                            rlModel.LotteryNum      = string.Empty;
                            rlModel.RunDate         = currTime.AddMinutes(currMin);
                            rlModel.Status          = 0;
                            rlModel.LastUpdatedDate = currTime.AddMinutes(currMin);

                            rlBll.Insert(rlModel);
                        }

                        //睡眠一分钟
                        Thread.Sleep(30000);
                    }
                    else
                    {
                        #region  序非第一次运行

                        //获取当前即将开奖的期
                        Model.RunLottery currModel = null;

                        //将获取上一期开奖时间和开奖数字
                        List <Model.RunLottery> lastList = rlList.FindAll(x => x.Status == 1);
                        if (lastList != null && lastList.Count > 0)
                        {
                            Model.RunLottery lastModel = lastList.OrderByDescending(x => x.Period).First();
                            if (lastModel != null)
                            {
                                lastRunTime = lastModel.RunDate;
                                lastNum     = Int32.Parse(lastModel.LotteryNum);
                                lastPeriod  = lastModel.Period;
                            }
                        }

                        List <Model.RunLottery> currReadyList = rlList.FindAll(x => x.Status == 0);
                        if (currReadyList != null && currReadyList.Count > 0)
                        {
                            //获取当前最大开奖时间
                            currModel   = currReadyList.OrderByDescending(x => x.Period).First();
                            maxCurrDate = currModel.RunDate;

                            //获取当前即将开奖的期
                            currModel = currReadyList.OrderBy(x => x.Period).First();
                            if (currModel != null)
                            {
                                numberId    = currModel.NumberID;
                                currRunTime = currModel.RunDate;
                            }
                        }

                        //如果已控制了开奖结果,则直接开奖,否则系统随机开奖
                        if (currModel != null && !string.IsNullOrEmpty(currModel.LotteryNum))
                        {
                            #region 控制开奖

                            int currNum = Int32.Parse(currModel.LotteryNum);

                            //对应赔率
                            decimal fixRatio = liList.Find(x => x.ItemCode == currNum.ToString()).FixRatio;

                            TimeSpan spaceTs = currRunTime.AddMilliseconds(-8000) - DateTime.Now;
                            if (spaceTs.TotalMilliseconds > 0)
                            {
                                Thread.Sleep(spaceTs);
                            }

                            int     betNum        = 0;   //已投注数
                            decimal totalPointNum = 0;   //棋子总数
                            int     winnerNum     = 0;   //中奖人数
                            decimal winPointNum   = 0;   //中奖支出棋子总数

                            //提前处理投注等问题
                            List <Model.UserBetLottery> ublList = ublBll.GetList(1, 10000000, out totalCount, "and RunLotteryID = '" + numberId + "' ", null);
                            if (ublList != null && ublList.Count > 0)
                            {
                                betNum        = ublList.Count;
                                totalPointNum = ublList.Sum(x => x.TotalPointNum);

                                foreach (Model.UserBetLottery ublModel in ublList)
                                {
                                    //判断是否中奖
                                    if (ublModel.ItemAppend.IndexOf(currNum.ToString()) > -1)
                                    {
                                        decimal dWinPointNum = 0;

                                        string[] currItemArr    = ublModel.ItemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        string[] currBetNumArr  = ublModel.BetNumAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        int      currItemArrLen = currItemArr.Length;
                                        for (int i = 0; i < currItemArrLen; i++)
                                        {
                                            if (currItemArr[i] == currNum.ToString())
                                            {
                                                dWinPointNum = fixRatio * int.Parse(currBetNumArr[i]);
                                            }
                                        }

                                        //中奖支出棋子
                                        winPointNum          = winPointNum + dWinPointNum;
                                        ublModel.WinPointNum = dWinPointNum;

                                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                                        {
                                            ublBll.Update(ublModel);

                                            Model.UserPoint uModel = uBll.GetModelByUser(ublModel.UserID);
                                            if (uModel != null)
                                            {
                                                uModel.PointNum = uModel.PointNum + dWinPointNum;
                                                uBll.Update(uModel);
                                            }

                                            scope.Complete();
                                        }
                                    }
                                }

                                //计算中奖人数
                                winnerNum = ublList.Where(x => x.WinPointNum > 0).GroupBy(x => x.UserID).Count();
                            }

                            spaceTs = currRunTime.AddMilliseconds(-1000) - DateTime.Now;
                            if (spaceTs.TotalMilliseconds > 0)
                            {
                                Thread.Sleep(spaceTs);
                            }

                            currModel.Status          = 1;
                            currModel.LastUpdatedDate = DateTime.Now;
                            currModel.BetNum          = betNum;
                            currModel.TotalPointNum   = totalPointNum;
                            currModel.WinnerNum       = winnerNum;
                            currModel.WinPointNum     = winPointNum;

                            rlBll.Update(currModel);

                            //每天最多开奖结束时间为第二天14:00
                            int h = maxCurrDate.Hour;
                            if (h > 1 && h <= 2)
                            {
                                maxCurrDate = DateTime.Parse(maxCurrDate.ToString("yyyy-MM-dd")).AddHours(9);
                            }
                            else
                            {
                                maxCurrDate = maxCurrDate.AddMinutes(5);
                            }

                            Model.RunLottery rlModel = new Model.RunLottery();
                            rlModel.LotteryNum      = string.Empty;
                            rlModel.RunDate         = maxCurrDate;
                            rlModel.Status          = 0;
                            rlModel.LastUpdatedDate = maxCurrDate;

                            rlBll.Insert(rlModel);

                            Console.WriteLine("第{0}期  开奖结果 {1}  开奖时间 {2} 系统时间 {3}", currModel.Period, currNum, currModel.RunDate, currModel.LastUpdatedDate);

                            #endregion
                        }
                        else
                        {
                            #region 系统随机开奖

                            //保证开奖,避免当前期开的奖与上一期的相同
                            while (true)
                            {
                                int currNum = rnd.Next(1, items.Length);

                                //对应赔率
                                decimal fixRatio = liList.Find(x => x.ItemCode == currNum.ToString()).FixRatio;

                                //尽量避免当前期开的奖与上一期的相同
                                if (currNum != lastNum)
                                {
                                    TimeSpan spaceTs = currRunTime.AddMilliseconds(-8000) - DateTime.Now;
                                    if (spaceTs.TotalMilliseconds > 0)
                                    {
                                        Thread.Sleep(spaceTs);
                                    }

                                    int     betNum        = 0;   //已投注数
                                    decimal totalPointNum = 0;   //棋子总数
                                    int     winnerNum     = 0;   //中奖人数
                                    decimal winPointNum   = 0;   //中奖支出棋子总数

                                    //提前处理投注等问题
                                    List <Model.UserBetLottery> ublList = ublBll.GetList(1, 10000000, out totalCount, "and RunLotteryID = '" + numberId + "' ", null);
                                    if (ublList != null && ublList.Count > 0)
                                    {
                                        betNum        = ublList.Count;
                                        totalPointNum = ublList.Sum(x => x.TotalPointNum);

                                        foreach (LotterySln.Model.UserBetLottery ublModel in ublList)
                                        {
                                            //判断是否中奖
                                            if (ublModel.ItemAppend.IndexOf(currNum.ToString()) > -1)
                                            {
                                                decimal dWinPointNum = 0;

                                                string[] currItemArr    = ublModel.ItemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                                string[] currBetNumArr  = ublModel.BetNumAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                                int      currItemArrLen = currItemArr.Length;
                                                for (int i = 0; i < currItemArrLen; i++)
                                                {
                                                    if (currItemArr[i] == currNum.ToString())
                                                    {
                                                        dWinPointNum = fixRatio * int.Parse(currBetNumArr[i]);
                                                    }
                                                }

                                                //中奖支出棋子
                                                winPointNum          = winPointNum + dWinPointNum;
                                                ublModel.WinPointNum = dWinPointNum;

                                                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                                                {
                                                    ublBll.Update(ublModel);

                                                    Model.UserPoint uModel = uBll.GetModelByUser(ublModel.UserID);
                                                    if (uModel != null)
                                                    {
                                                        uModel.PointNum = uModel.PointNum + dWinPointNum;
                                                        uBll.Update(uModel);
                                                    }

                                                    scope.Complete();
                                                }
                                            }
                                        }

                                        //计算中奖人数
                                        winnerNum = ublList.Where(x => x.WinPointNum > 0).GroupBy(x => x.UserID).Count();
                                    }

                                    spaceTs = currRunTime.AddMilliseconds(-1000) - DateTime.Now;
                                    if (spaceTs.TotalMilliseconds > 0)
                                    {
                                        Thread.Sleep(spaceTs);
                                    }

                                    currModel.LotteryNum      = currNum.ToString();
                                    currModel.Status          = 1;
                                    currModel.LastUpdatedDate = DateTime.Now;
                                    currModel.BetNum          = betNum;
                                    currModel.TotalPointNum   = totalPointNum;
                                    currModel.WinnerNum       = winnerNum;
                                    currModel.WinPointNum     = winPointNum;

                                    rlBll.Update(currModel);

                                    //每天最多开奖结束时间为第二天14:00
                                    int h = maxCurrDate.Hour;
                                    if (h > 1 && h <= 2)
                                    {
                                        maxCurrDate = DateTime.Parse(maxCurrDate.ToString("yyyy-MM-dd")).AddHours(9);
                                    }
                                    else
                                    {
                                        maxCurrDate = maxCurrDate.AddMinutes(5);
                                    }

                                    Model.RunLottery rlModel = new Model.RunLottery();
                                    rlModel.LotteryNum      = string.Empty;
                                    rlModel.RunDate         = maxCurrDate;
                                    rlModel.Status          = 0;
                                    rlModel.LastUpdatedDate = maxCurrDate;

                                    rlBll.Insert(rlModel);

                                    Console.WriteLine("第{0}期  开奖结果 {1}  开奖时间 {2} 系统时间 {3}", currModel.Period, currNum, currModel.RunDate, currModel.LastUpdatedDate);

                                    break;
                                }
                            }

                            #endregion
                        }

                        //每次开奖完后睡眠4分钟后继续循环,以便控制当前期开奖
                        Thread.Sleep(360000);

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("程序发生了异常,原因:{0}", ex.Message);
                Console.ReadLine();
            }
        }
Exemple #11
0
 public UserPoint(Model.UserPoint model)
 {
     this.model = model;
 }
        private void OnSave(object nId)
        {
            BLL.PrizeTicket   ptBll   = new BLL.PrizeTicket();
            Model.PrizeTicket ptModel = ptBll.GetModel(nId.ToString());
            if (ptModel == null)
            {
                WebHelper.MessageBox.Messager(this.Page, rpData.Controls[0], "没有找到相关奖品");
                return;
            }

            decimal pointNum = ptModel.PointNum;

            BLL.UserPoint uBll     = new BLL.UserPoint();
            object        userId   = WebHelper.Common.GetUserId();
            DateTime      currTime = DateTime.Now;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                Model.UserPoint uModel = uBll.GetModelByUser(userId);
                if (uModel == null)
                {
                    WebHelper.MessageBox.Messager(this.Page, rpData.Controls[0], "您的棋子数额不足,无法兑换");
                    return;
                }
                decimal userPointNum = uModel.PointNum;
                decimal currPointNum = userPointNum - pointNum;
                if (currPointNum < 0)
                {
                    WebHelper.MessageBox.Messager(this.Page, rpData.Controls[0], "您的棋子数额不足,无法兑换");
                    return;
                }

                Model.UserTicket utModel = new Model.UserTicket();
                utModel.PrizeTicketID   = ptModel.NumberID;
                utModel.UserID          = userId;
                utModel.Status          = 0;
                utModel.LastUpdatedDate = currTime;

                BLL.UserTicket utBll = new BLL.UserTicket();
                if (utBll.Insert(utModel) > 0)
                {
                    uModel.PointNum        = currPointNum;
                    uModel.LastUpdatedDate = currTime;

                    if (uBll.Update(uModel) > 0)
                    {
                        //操作成功,提交事务
                        scope.Complete();

                        Response.Redirect("/u/ta.html");
                    }
                    else
                    {
                        WebHelper.MessageBox.Messager(this.Page, rpData.Controls[0], "奖品兑换失败,无法兑换", "系统异常");
                        return;
                    }
                }
                else
                {
                    WebHelper.MessageBox.Messager(this.Page, rpData.Controls[0], "奖品兑换失败,无法兑换", "系统异常");
                    return;
                }
            }
        }
Exemple #13
0
        private void OnSave()
        {
            string userName = txtUserName.Value.Trim();
            string password = txtPsw.Value.Trim();
            string email    = txtEmail.Value.Trim();
            string sVc      = txtVc.Value.Trim();

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "用户名、密码、邮箱为必填项", "操作错误", "error");
                return;
            }

            Regex r = new Regex(@"(([0-9]+)|([a-zA-Z]+)){6,30}");

            if (!r.IsMatch(password))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "密码正确格式由数字或字母组成的字符串,且最小6位,最大30位", "操作错误", "error");
                return;
            }
            r = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
            if (!r.IsMatch(email))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "请输入正确的电子邮箱格式", "操作错误", "error");
                return;
            }

            if (string.IsNullOrEmpty(sVc))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "验证码输入不能为空!", "操作错误", "error");
                return;
            }

            if (sVc.ToLower() != Request.Cookies["RegisterVc"].Value.ToLower())
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "验证码输入不正确,请检查!", "操作错误", "error");
                return;
            }

            string errorMsg = string.Empty;

            try
            {
                MembershipUser user = Membership.CreateUser(userName, password, email);

                if (user != null)
                {
                    Roles.AddUserToRole(user.UserName, "Users");

                    //系统自动分配该用户的棋子数
                    Model.UserPoint uModel = new Model.UserPoint();
                    uModel.UserID          = user.ProviderUserKey;
                    uModel.PointNum        = WebHelper.Common.POINTNUM;
                    uModel.LastUpdatedDate = DateTime.Now;
                    ThreadHelper.UserPoint uThread = new ThreadHelper.UserPoint(uModel);
                    uThread.ThreadStart();

                    WebHelper.MessageBox.Show(this.Page, lbtnPostBack, string.Format("{0}即将跳转到登录页,请先登录", EnumMembershipCreateStatus.GetStatusMessage(MembershipCreateStatus.Success)), "Login.aspx");
                }
            }
            catch (MembershipCreateUserException ex)
            {
                errorMsg = EnumMembershipCreateStatus.GetStatusMessage(ex.StatusCode);
            }
            catch (HttpException ex)
            {
                errorMsg = ex.Message;
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, errorMsg, "系统提示");
                return;
            }
        }
        private void OnSave()
        {
            string sItemAppend = hItemAppend.Value.Trim();

            if (string.IsNullOrEmpty(sItemAppend))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "投注项不能为空", "错误提示");
                return;
            }

            string[] items = sItemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (items.Length < 1)
            {
                return;
            }

            BLL.RunLottery rlBll = new BLL.RunLottery();

            Model.RunLottery rlModel = rlBll.GetModel(nId);
            if (rlModel == null)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "不存在的开奖期,非法操作", "错误提示");
                return;
            }

            DateTime runDate = rlModel.RunDate;
            TimeSpan ts      = runDate - DateTime.Now;

            if ((ts.TotalMilliseconds - 8000) < 0)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "当前第" + rlModel.Period + "期,已停止投注", "温馨提示");
                return;
            }

            string[] itemArr = items[0].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            int totalBetNum = Int32.Parse(itemArr[1]);

            if (totalBetNum <= 0)
            {
                return;
            }

            object userId = WebHelper.Common.GetUserId();

            //获取当前用户的棋子数
            BLL.UserPoint   uBll   = new BLL.UserPoint();
            Model.UserPoint uModel = uBll.GetModelByUser(userId);
            if (uModel == null)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "您的棋子数不足,不能进行投注!", "系统提示");
                return;
            }

            if ((uModel.PointNum - totalBetNum) < 0)
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "您的棋子数不足,不能进行投注!", "系统提示");
                return;
            }

            string itemAppend   = string.Empty;
            string betNumAppend = string.Empty;
            int    index        = 0;

            foreach (string s in items)
            {
                index++;
                if (index > 1)
                {
                    string[] nvArr = s.Split('|');
                    itemAppend   += nvArr[0] + ",";
                    betNumAppend += nvArr[1] + ",";
                }
            }

            BLL.Order            ublBll   = new BLL.Order();
            Model.UserBetLottery ublModel = new Model.UserBetLottery();
            ublModel.LastUpdatedDate = DateTime.Now;
            ublModel.UserID          = userId;
            ublModel.RunLotteryID    = rlModel.NumberID;
            ublModel.TotalPointNum   = totalBetNum;
            ublModel.ItemAppend      = itemAppend.Trim(',');
            ublModel.BetNumAppend    = betNumAppend.Trim(',');
            ublModel.WinPointNum     = 0;

            int effectCount = -1;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                uModel.PointNum = uModel.PointNum - totalBetNum;
                if (uBll.Update(uModel) > 0)
                {
                    ublBll.Insert(ublModel);
                    effectCount = 1;
                }

                scope.Complete();
            }

            if (effectCount > 0)
            {
                WebHelper.MessageBox.Show(this.Page, lbtnSave, "当前第" + rlModel.Period + "期,投注成功!", Request.Url.ToString());
            }
            else
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnSave, "当前第" + rlModel.Period + "期,投注失败,请检查", "系统提示");
            }
        }
Exemple #15
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Model.UserPoint model)
 {
     return(dal.Update(model));
 }
Exemple #16
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(Model.UserPoint model)
 {
     return(dal.Insert(model));
 }