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

            //定义查询命令
            string cmdText = @"update [RunLottery] set LotteryNum = @LotteryNum,Status = @Status,LastUpdatedDate = @LastUpdatedDate,BetNum = @BetNum,TotalPointNum = @TotalPointNum,WinnerNum = @WinnerNum,WinPointNum = @WinPointNum where NumberID = @NumberID";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@NumberID",        SqlDbType.UniqueIdentifier),
                new SqlParameter("@LotteryNum",      SqlDbType.NVarChar, 50),
                new SqlParameter("@Status",          SqlDbType.TinyInt),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime),
                new SqlParameter("@BetNum",          SqlDbType.Int),
                new SqlParameter("@TotalPointNum",   SqlDbType.Decimal),
                new SqlParameter("@WinnerNum",       SqlDbType.Int),
                new SqlParameter("@WinPointNum",     SqlDbType.Decimal),
            };
            parms[0].Value = Guid.Parse(model.NumberID.ToString());
            parms[1].Value = model.LotteryNum;
            parms[2].Value = model.Status;
            parms[3].Value = model.LastUpdatedDate;
            parms[4].Value = model.BetNum;
            parms[5].Value = model.TotalPointNum;
            parms[6].Value = model.WinnerNum;
            parms[7].Value = model.WinPointNum;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
示例#2
0
        /// <summary>
        /// 添加数据到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Model.RunLottery model)
        {
            if (model == null)
            {
                return(-1);
            }

            string cmdText = "insert into [RunLottery] (LotteryNum,LastUpdatedDate,Status,RunDate) values (@LotteryNum,@LastUpdatedDate,@Status,@RunDate)";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@LotteryNum",      SqlDbType.NVarChar,  50),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime),
                new SqlParameter("@Status",          SqlDbType.TinyInt),
                new SqlParameter("@RunDate",         SqlDbType.DateTime)
            };
            parms[0].Value = model.LotteryNum;
            parms[1].Value = model.LastUpdatedDate;
            parms[2].Value = model.Status;
            parms[3].Value = model.RunDate;

            //执行数据库操作
            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
示例#3
0
        /// <summary>
        /// 获取对应的数据
        /// </summary>
        /// <param name="numberId"></param>
        /// <returns></returns>
        public Model.RunLottery GetModel(string numberId)
        {
            Model.RunLottery model = null;

            string       cmdText = @"select top 1 NumberID,Period,LotteryNum,LastUpdatedDate,Status,RunDate,BetNum,TotalPointNum,WinnerNum,WinPointNum from [RunLottery] where NumberID = @NumberID ";
            SqlParameter parm    = new SqlParameter("@NumberID", SqlDbType.UniqueIdentifier);

            parm.Value = Guid.Parse(numberId);

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new Model.RunLottery();
                        model.NumberID        = reader["NumberID"].ToString();
                        model.Period          = int.Parse(reader["Period"].ToString());
                        model.LotteryNum      = reader["LotteryNum"].ToString();
                        model.LastUpdatedDate = DateTime.Parse(reader["LastUpdatedDate"].ToString());
                        model.RunDate         = DateTime.Parse(reader["RunDate"].ToString());
                        model.BetNum          = Int32.Parse(reader["BetNum"].ToString());
                        model.TotalPointNum   = decimal.Parse(reader["TotalPointNum"].ToString());
                        model.WinnerNum       = Int32.Parse(reader["WinnerNum"].ToString());
                        model.WinPointNum     = decimal.Parse(reader["WinPointNum"].ToString());
                    }
                }
            }

            return(model);
        }
示例#4
0
 private void Bind()
 {
     if (!string.IsNullOrEmpty(nId))
     {
         BLL.RunLottery   rlBll = new BLL.RunLottery();
         Model.RunLottery model = rlBll.GetModel(nId);
         if (model != null)
         {
             lbBetPeriod.InnerText = model.Period.ToString();
         }
     }
 }
示例#5
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 List <Model.RunLottery> GetList(int pageIndex, int pageSize, out int totalCount, string sqlWhere, params SqlParameter[] cmdParms)
        {
            //获取数据集总数
            string cmdText = "select count(*) from [RunLottery] t1 left join dbo.LotteryItem t2 on t2.ItemCode = t1.LotteryNum ";

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

            cmdText = @"select * from(select row_number() over(order by t1.Period desc) as RowNumber,t1.NumberID,t1.Period,t1.LotteryNum,t1.LastUpdatedDate,t1.Status,t1.RunDate,t1.BetNum,t1.TotalPointNum,t1.WinnerNum,t1.WinPointNum,t2.ItemName from [RunLottery] t1 
                      left join dbo.LotteryItem t2 on t2.ItemCode = t1.LotteryNum";
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            List <Model.RunLottery> list = new List <Model.RunLottery>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Model.RunLottery model = new Model.RunLottery();
                        model.NumberID        = Guid.Parse(reader["NumberID"].ToString());
                        model.Period          = int.Parse(reader["Period"].ToString());
                        model.LotteryNum      = reader["LotteryNum"].ToString();
                        model.RunDate         = DateTime.Parse(reader["RunDate"].ToString());
                        model.LastUpdatedDate = DateTime.Parse(reader["LastUpdatedDate"].ToString());
                        model.Status          = short.Parse(reader["Status"].ToString());
                        model.RunDate         = DateTime.Parse(reader["RunDate"].ToString());
                        model.BetNum          = Int32.Parse(reader["BetNum"].ToString());
                        model.TotalPointNum   = decimal.Parse(reader["TotalPointNum"].ToString());
                        model.WinnerNum       = Int32.Parse(reader["WinnerNum"].ToString());
                        model.WinPointNum     = decimal.Parse(reader["WinPointNum"].ToString());
                        model.ItemName        = reader["ItemName"].ToString();

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
        private void OnSave()
        {
            BLL.RunLottery rlBll   = new BLL.RunLottery();
            bool           isRight = false;

            //获取所有行
            RepeaterItemCollection ric = rpData.Items;

            foreach (RepeaterItem item in ric)
            {
                //找到CheckBox
                HtmlInputText txt = item.FindControl("txtLotteryNum") as HtmlInputText;

                if (txt != null)
                {
                    if (!string.IsNullOrEmpty(txt.Value.Trim()))
                    {
                        HtmlInputHidden hNid = item.FindControl("hNid") as HtmlInputHidden;
                        if (hNid != null)
                        {
                            if (!string.IsNullOrEmpty(hNid.Value.Trim()))
                            {
                                Model.RunLottery rlModel = rlBll.GetModel(hNid.Value.Trim());
                                if (rlModel != null)
                                {
                                    rlModel.LotteryNum = txt.Value.Trim();

                                    if (rlBll.Update(rlModel) > 0)
                                    {
                                        if (!isRight)
                                        {
                                            isRight = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (isRight)
            {
                WebHelper.MessageBox.MessagerShow(this.Page, lbtnPostBack, "操作成功");
            }
            else
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "操作失败", "系统提示");
            }
        }
        /// <summary>
        /// 获取当前ID对应数据
        /// </summary>
        /// <param name="nId"></param>
        /// <returns></returns>
        public static Model.RunLottery GetModel(object nId)
        {
            BLL.RunLottery bll = new BLL.RunLottery();

            if (!enableCaching)
            {
                return(bll.GetModel(nId.ToString()));
            }

            string key = "runLottery_" + nId.ToString() + "";

            Model.RunLottery data = (Model.RunLottery)HttpRuntime.Cache[key];

            if (data == null)
            {
                data = bll.GetModel(nId.ToString());

                AggregateCacheDependency cd = DependencyFactory.GetRunLotteryDependency();
                HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(timeOut), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }

            return(data);
        }
示例#8
0
        /// <summary>
        /// Process a batch of asynchronous orders from the queue and submit them to the database within a transaction
        /// </summary>
        private static void ProcessOrders()
        {
            // the transaction timeout should be long enough to handle all of orders in the batch
            TimeSpan tsTimeout = TimeSpan.FromSeconds(Convert.ToDouble(transactionTimeout * batchSize));

            RunLottery rlBll = new RunLottery();
            Order      order = new Order();

            while (true)
            {
                // queue timeout variables
                TimeSpan datetimeStarting = new TimeSpan(DateTime.Now.Ticks);
                double   elapsedTime      = 0;

                int processedItems = 0;

                List <Model.UserBetLottery> queueOrders = new List <Model.UserBetLottery>();

                //OrderInfo orderData = orderQueue.Receive(timeout);
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tsTimeout))
                {
                    // Receive the orders from the queue
                    for (int j = 0; j < batchSize; j++)
                    {
                        try
                        {
                            //only receive more queued orders if there is enough time
                            if ((elapsedTime + queueTimeout + transactionTimeout) < tsTimeout.TotalSeconds)
                            {
                                queueOrders.Add(order.ReceiveFromQueue(queueTimeout));
                            }
                            else
                            {
                                j = batchSize;   // exit loop
                            }

                            //update elapsed time
                            elapsedTime = new TimeSpan(DateTime.Now.Ticks).TotalSeconds - datetimeStarting.TotalSeconds;
                        }
                        catch (TimeoutException)
                        {
                            //exit loop because no more messages are waiting
                            j = batchSize;
                        }
                    }

                    if (queueOrders.Count > 0)
                    {
                        foreach (Model.UserBetLottery ublModel in queueOrders)
                        {
                            order.Insert(ublModel);

                            Model.RunLottery rlModel = rlBll.GetModel(ublModel.RunLotteryID.ToString());
                            rlModel.TotalPointNum = rlModel.TotalPointNum + ublModel.TotalPointNum;
                            rlModel.BetNum        = rlModel.BetNum + 1;
                            rlBll.Update(rlModel);

                            processedItems++;
                            totalOrdersProcessed++;
                        }
                    }

                    //batch complete or MSMQ receive timed out
                    ts.Complete();
                }

                Console.WriteLine("(Thread Id " + Thread.CurrentThread.ManagedThreadId + ") batch finished, " + processedItems + " items, in " + elapsedTime.ToString() + " seconds.");
            }
        }
示例#9
0
        public string GetSinglePeriod(string numberId)
        {
            if (string.IsNullOrEmpty(numberId))
            {
                return("[]");
            }

            Guid gId = Guid.Empty;

            Guid.TryParse(numberId, out gId);
            if (gId == Guid.Empty)
            {
                return("[]");
            }

            Model.RunLottery rlModel = WebHelper.RunLotteryDataProxy.GetModel(gId);
            if (rlModel == null)
            {
                return("[]");
            }

            List <Model.UserBetLottery> ublList = WebHelper.UserBetLotteryDataProxy.GetListByRunLotteryID(gId);
            bool isUblList = true;

            if (ublList == null || ublList.Count == 0)
            {
                isUblList = false;
            }

            List <Model.LotteryItem> list = WebHelper.LotteryItemDataProxy.GetList();

            string jsonAppend = "[";

            if (list != null)
            {
                string itemName = list.Find(x => x.ItemCode == rlModel.LotteryNum).ItemName;

                decimal allTotalBetNum = 0;
                decimal allTotalWinNum = 0;

                int index = -1;
                foreach (Model.LotteryItem model in list)
                {
                    decimal currTotalBetNum = 0;
                    decimal currTotalWinNum = 0;
                    if (isUblList)
                    {
                        List <Model.UserBetLottery> currUblList = ublList.FindAll(x => x.ItemAppend.Contains(model.ItemCode));
                        if (currUblList != null && currUblList.Count > 0)
                        {
                            foreach (Model.UserBetLottery currUblModel in currUblList)
                            {
                                if (model.ItemCode == rlModel.LotteryNum)
                                {
                                    currTotalWinNum += currUblModel.WinPointNum;
                                }

                                string[] currItemArr    = currUblModel.ItemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                string[] currBetNumArr  = currUblModel.BetNumAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                int      currItemArrLen = currItemArr.Length;
                                for (int i = 0; i < currItemArrLen; i++)
                                {
                                    if (currItemArr[i] == model.ItemCode)
                                    {
                                        currTotalBetNum += Int32.Parse(currBetNumArr[i]);
                                    }
                                }
                            }
                        }
                    }

                    allTotalBetNum += currTotalBetNum;
                    allTotalWinNum += currTotalWinNum;

                    string sCurrBetNum = currTotalBetNum > 0 ? currTotalBetNum.ToString() : "-";
                    string sCurrWinNum = currTotalWinNum > 0 ? currTotalWinNum.ToString() : "-";

                    index++;
                    if (index > 0)
                    {
                        jsonAppend += ",";
                    }
                    jsonAppend += "{\"ItemCode\":\"" + model.ItemCode + "\",\"ItemName\":\"" + model.ItemName + "\",\"CurrRatio\":\" X" + model.FixRatio + "\",\"NId\":\"" + model.NumberID + "\",\"BetNum\":\"" + sCurrBetNum + "\",\"WinNum\":\"" + sCurrWinNum + "\",\"allBetNum\":\"allBetNumV\",\"allWinNum\":\"allWinNumV\",\"allBetWinNum\":\"allBetWinNumV\",\"allBetWinRatio\":\"allBetWinRatioV\",\"Period\":\"" + rlModel.Period + "\",\"LotteryNum\":\"" + itemName + "\",\"RunDate\":\"" + rlModel.RunDate.ToString("MM/dd HH:mm") + "\"}";
                }

                string allBetWinRatio = "0";
                if (allTotalWinNum > 0)
                {
                    allBetWinRatio = "1:" + Math.Round(allTotalBetNum / allTotalWinNum, 0) + "";
                }

                jsonAppend = jsonAppend.Replace("allBetNumV", allTotalBetNum.ToString());
                jsonAppend = jsonAppend.Replace("allWinNumV", allTotalWinNum.ToString());
                jsonAppend = jsonAppend.Replace("allBetWinNumV", (allTotalWinNum - allTotalWinNum).ToString());
                jsonAppend = jsonAppend.Replace("allBetWinRatioV", allBetWinRatio);
            }

            jsonAppend += "]";

            return(jsonAppend);
        }
示例#10
0
        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();
            }
        }
示例#11
0
        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 + "期,投注失败,请检查", "系统提示");
            }
        }
示例#12
0
 public RunLottery(Model.RunLottery model)
 {
     this.model = model;
 }
示例#13
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Model.RunLottery model)
 {
     return(dal.Update(model));
 }
示例#14
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(Model.RunLottery model)
 {
     return(dal.Insert(model));
 }