private void Bind()
        {
            int totalCount = 0;

            string liAppend = "开奖:<select id=\"cbbLItem\" class=\"easyui-combobox\" style=\"width:200px;\">";

            BLL.LotteryItem          liBll  = new BLL.LotteryItem();
            List <Model.LotteryItem> liList = liBll.GetList(1, 1000, out totalCount, "", null);

            if (liList != null)
            {
                foreach (Model.LotteryItem model in liList)
                {
                    liAppend += "<option value=\"" + model.ItemCode + "\">" + model.ItemName + "</option>";
                }
            }

            liAppend += "</select>";

            dlgContent.InnerHtml = liAppend;

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

            rpData.DataSource = rlBll.GetDataSet(1, 5, out totalCount, "", null);;
            rpData.DataBind();
        }
 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();
         }
     }
 }
        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);
        }
        /// <summary>
        /// 获取当前开奖ID对应投注数列表
        /// </summary>
        /// <param name="nId"></param>
        /// <returns></returns>
        public static List <Model.RunLottery> GetList(int pageIndex, int pageSize, out int totalCount)
        {
            BLL.RunLottery bll = new BLL.RunLottery();
            totalCount = 0;

            if (!enableCaching)
            {
                return(bll.GetList(pageIndex, pageSize, out totalCount, "", null));
            }

            string key      = "runLottery_" + pageIndex + "_" + pageSize + "";
            string keyCount = "runLotteryCount_" + pageIndex + "_" + pageSize + "";
            List <Model.RunLottery> data = (List <Model.RunLottery>)HttpRuntime.Cache[key];

            if (HttpRuntime.Cache[keyCount] != null)
            {
                totalCount = (Int32)HttpRuntime.Cache[keyCount];
            }

            if (data == null)
            {
                data = bll.GetList(pageIndex, pageSize, out totalCount, "", null);

                if (pageIndex > 1)
                {
                    DateTime currTime = DateTime.Now;

                    AggregateCacheDependency cd = DependencyFactory.GetRunLotteryDependency();
                    HttpRuntime.Cache.Add(key, data, cd, currTime.AddMinutes(1), Cache.NoSlidingExpiration, CacheItemPriority.High, null);

                    HttpRuntime.Cache.Add(keyCount, totalCount, null, currTime.AddMinutes(1), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                }
            }

            return(data);
        }
        public string GetLatestLottery()
        {
            BLL.RunLottery bll        = new BLL.RunLottery();
            int            totalCount = 0;
            DataSet        ds         = bll.GetRunLotteryItem(1, 6, out totalCount, "", null);
            string         jsonAppend = "[";

            if (ds != null && ds.Tables.Count > 0)
            {
                EnumerableRowCollection <DataRow> erc = ds.Tables[0].AsEnumerable();
                DateTime currTime        = DateTime.Now;
                DateTime lastUpdatedDate = DateTime.MinValue;
                string   itemName        = "";

                int totalMilliseconds  = 0;
                int remainMilliseconds = 0;
                int betTime            = 0;

                DataRow dr = erc.Where(x => int.Parse(x["Status"].ToString()) == 0).OrderBy(x => Int32.Parse(x["Period"].ToString())).First();
                lastUpdatedDate = DateTime.Parse(dr["LastUpdatedDate"].ToString());
                itemName        = dr["ItemName"].ToString();

                TimeSpan ts = lastUpdatedDate - currTime;
                totalMilliseconds  = Int32.Parse(ts.TotalMilliseconds.ToString("0"));
                remainMilliseconds = totalMilliseconds + 3000;
                betTime            = remainMilliseconds - 8000;

                DataRow lastRow = null;
                var     q       = erc.Where(x => int.Parse(x["Status"].ToString()) == 1).OrderByDescending(x => Int32.Parse(x["Period"].ToString()));
                if (q != null && q.Count() > 0)
                {
                    lastRow = q.First();
                }

                if (lastRow != null)
                {
                    itemName = lastRow["ItemName"].ToString();
                }
                //else
                //{
                //    lastUpdatedDate = DateTime.Parse(dr["LastUpdatedDate"].ToString());
                //    itemName = dr["ItemName"].ToString();

                //    TimeSpan ts = lastUpdatedDate - currTime;
                //    totalMilliseconds = Int32.Parse(ts.TotalMilliseconds.ToString("0"));
                //    remainMilliseconds = totalMilliseconds + 30000;
                //    betTime = remainMilliseconds - 8000;
                //}

                //jsonAppend += "{\"Period\":\"" + dr["Period"].ToString() + "\",\"ItemName\":\"" + lastRow["ItemName"].ToString() + "\",\"Lud\":\"" + remainMilliseconds + "\",\"EndTime\":\"" + currTime.AddMilliseconds(remainMilliseconds) + "\",\"BetTime\":\"" + betTime + "\"}";

                if (totalMilliseconds >= 0 && totalMilliseconds <= 300000)
                {
                    jsonAppend += "{\"Period\":\"" + dr["Period"].ToString() + "\",\"ItemName\":\"" + itemName + "\",\"Lud\":\"" + remainMilliseconds + "\",\"EndTime\":\"" + dr["RunDate"].ToString() + "\",\"BetTime\":\"" + betTime + "\"}";
                }
                else
                {
                    //间隔2分钟
                    jsonAppend += "{\"Period\":\"0\",\"ItemName\":\"准备中\",\"Lud\":\"60000\",\"EndTime\":\"开奖未开始\"}";
                }
            }
            else
            {
                //间隔2分钟
                jsonAppend += "{\"Period\":\"0\",\"ItemName\":\"准备中\",\"Lud\":\"60000\",\"EndTime\":\"开奖未开始\"}";
            }

            jsonAppend += "]";

            return(jsonAppend);
        }
        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 + "期,投注失败,请检查", "系统提示");
            }
        }