Exemplo n.º 1
0
        protected void dlEnroll_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                UserCookiesInfo user = BllOperationAboutUser.GetUserCookiesInfo();

                DalOperationAboutGameDrawList dal = new DalOperationAboutGameDrawList();
                if (e.CommandName == "draw")
                {
                    int gameCategoryId = int.Parse(e.CommandArgument.ToString().Split(",".ToCharArray())[0]);
                    int gameTypeId = int.Parse(e.CommandArgument.ToString().Split(",".ToCharArray())[1]);

                    DalOperationAboutGameCategory dalgc = new DalOperationAboutGameCategory();
                    DataTable _dt = dalgc.CheckIsOpenDrawByGameCategoryId(gameCategoryId).Tables[0];
                    //首先判断当前届次和活动类型是否已经开放抽签
                    if (_dt.Rows.Count == 0)
                    {
                        Javascript.GoHistory(-1, "参数错误:(", Page);
                        return;
                    }

                    if (_dt.Rows[0]["isOpenDraw"].ToString().Trim() != "1")
                    {
                        Javascript.GoHistory(-1, "当前活动届次和活动类型暂未开放抽签:(", Page);
                        return;
                    }

                    //其次判断是否已经抽过签
                    if (dal.Exists(user.userNo, gameCategoryId, gameTypeId) > 0)
                    {
                        Javascript.GoHistory(-1, "当前活动届次和活动类型已经抽过签,请勿重复抽签哟:)", Page);
                        return;
                    }
                    //使用事务进行抽签控制
                    using (TransactionScope scope = new TransactionScope())
                    {
                        try
                        {
                            DalOperationAboutGameType dalgt = new DalOperationAboutGameType();
                            //首先获取组容量
                            int _groupCapability = int.Parse(dalgt.GetGroupCapabilityByGameTypeId(gameCategoryId, gameTypeId).Tables[0].Rows[0]["groupCapability"].ToString().Trim());
                            //其次获取总报名人数
                            DalOperationAboutGameEnrollList dalel = new DalOperationAboutGameEnrollList();
                            int _enrollListCount = int.Parse(dalel.GetEnrollListCountByGameCategoryIdAndGameTypeId(gameCategoryId, gameTypeId).Tables[0].Rows[0][0].ToString().Trim());

                            //获取分组数
                            int groupMod = _enrollListCount % _groupCapability;

                            int groupCount = 0;

                            if (groupMod == 0)
                            {
                                groupCount = _enrollListCount / _groupCapability;
                            }
                            else
                            {
                                groupCount = (_enrollListCount / _groupCapability) + 1;
                            }

                            //先判断需要几个字母
                            string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                            //所需要使用的字母个数
                            string usedCharacters = characters.Substring(0, groupCount);
                            //Response.Write(usedCharacters.Length);

                            List<string> listGroupNumAndIndex = new List<string>();

                            List<string> listNotUsedGroupNumAndIndex = new List<string>();

                            for (int i = 0; i < usedCharacters.Length; i++)
                            {
                                for (int j = 0; j < _groupCapability; j++)
                                {
                                    //最后一组编号需要连续,因此需要进行特殊处理
                                    if (groupMod != 0)
                                    {
                                        //访问到最后一组
                                        if (i == usedCharacters.Length - 1)
                                        {
                                            if (groupMod >= j + 1)
                                            {
                                                //Response.Write(usedCharacters.Substring(i, 1) + (j + 1).ToString() + "ss<br/>");
                                                listGroupNumAndIndex.Add(usedCharacters.Substring(i, 1) + (j + 1).ToString());
                                            }
                                        }
                                        else
                                        {
                                            listGroupNumAndIndex.Add(usedCharacters.Substring(i, 1) + (j + 1).ToString());
                                        }
                                    }
                                    else
                                    {
                                        //Response.Write(usedCharacters.Substring(i, 1) + (j + 1).ToString() + "aa<br/>");
                                        listGroupNumAndIndex.Add(usedCharacters.Substring(i, 1) + (j + 1).ToString());
                                    }
                                }
                            }
                            //Response.Write(listGroupNumAndIndex.Count + "<br/>");

                            //获取已经使用的编号列表
                            DataTable _dtGroupNumAndIndex = dal.GetGroupNumAndIndexByGameCategoryIdAndGameTypeId(gameCategoryId, gameTypeId).Tables[0];

                            List<string> listGroupNumAndIndexCopy = new List<string>();

                            foreach (string _item in listGroupNumAndIndex)
                            {
                                //Response.Write(_item + "<br/>");
                                listGroupNumAndIndexCopy.Add(_item);
                            }

                            foreach (string _item in listGroupNumAndIndex)
                            {
                                for (int j = 0; j < _dtGroupNumAndIndex.Rows.Count; j++)
                                {
                                    if (_dtGroupNumAndIndex.Rows[j]["groupNumAndIndex"].ToString().Trim() == _item)
                                    {
                                        //Response.Write(_item + "<br/>");
                                        //移除已使用的编号
                                        listGroupNumAndIndexCopy.Remove(_item);
                                    }
                                }
                            }

                            //Response.Write(listGroupNumAndIndexCopy.Count + "<br/>");

                            //为使效果更随机,再次对编号数组使用随机方法打乱
                            while (listGroupNumAndIndexCopy.Count > 0)
                            {
                                Random random = new Random();
                                int _index = int.Parse(random.NextDouble().ToString().Substring(2, 4)) % listGroupNumAndIndexCopy.Count;

                                listNotUsedGroupNumAndIndex.Insert(0, listGroupNumAndIndexCopy[_index]);

                                listGroupNumAndIndexCopy.RemoveAt(_index);
                            }

                            //Response.Write(groupMod + "groupMod<br/>");

                            //Response.Write(groupCount + "groupCount<br/>");

                            //Response.Write(listNotUsedGroupNumAndIndex.Count + "listNotUsedGroupNumAndIndex<br/>");

                            Random random1 = new Random();

                            int _index1 = int.Parse(random1.NextDouble().ToString().Substring(2, 4)) % listNotUsedGroupNumAndIndex.Count;
                            //Response.Write(_index1 + "<br/>");
                            //Response.End();

                            //得到随机取到的编号值
                            string _result = string.Empty;

                            _result = listNotUsedGroupNumAndIndex[_index1];

                            if (string.IsNullOrEmpty(_result))
                            {
                                Javascript.GoHistory(-1, "抽签失败:(,请重试", Page);
                                return;
                            }

                            dal.Add(new GameDrawList { gameCategoryId = gameCategoryId, gameTypeId = gameTypeId, groupIndex = int.Parse(_result.Substring(1, 1)), groupNum = _result.Substring(0, 1), updateTime = DateTime.Now, teacherNo = user.userNo });
                            scope.Complete();
                            Javascript.AlertAndRedirect("抽签成功!", "/Administrator/EnrollManage.aspx?fragment=2&page=" + pageIndex + "&gameCategoryId=" + gameCategoryId + "&gameTypeId=" + gameTypeId, Page);
                        }
                        catch (System.Exception ex)
                        {
                            MongoDBLog.LogRecord(ex);
                            Javascript.GoHistory(-1, "抽签失败:(,请重试", Page);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        //绑定信息
        public void DataListBindEnrollList()
        {
            //检查是否有活动届次和活动类型数据

            if (!(ddlGameCategory.Items.Count > 0 && ddlGameType.Items.Count > 0))
            {
                Javascript.GoHistory(-1, "当前暂无活动届次和活动类型信息:(", Page);
                return;
            }

            UserCookiesInfo user = BllOperationAboutUser.GetUserCookiesInfo();
            DalOperationAboutGameEnrollList doan = new DalOperationAboutGameEnrollList();
            DataTable dt = doan.GetListByTeacherNo_GameCategoryId_GameTypeId(user.userNo, int.Parse(ddlGameCategory.SelectedValue), int.Parse(ddlGameType.SelectedValue)).Tables[0];

            this.AspNetPager1.RecordCount = dt.Rows.Count;
            AspNetPager1.PageSize = CommonUtility.pageSize;

            PagedDataSource pds = new PagedDataSource();    //定义一个PagedDataSource类来执行分页功
            pds.DataSource = dt.DefaultView;
            pds.AllowPaging = true;
            if (_pageIndex == 0)
            {
                _pageIndex = 1;
            }

            pds.CurrentPageIndex = _pageIndex - 1;
            pds.PageSize = AspNetPager1.PageSize;

            this.dlEnroll.DataSource = pds;
            this.dlEnroll.DataBind();

            if (pds.Count == 0)
            {
                this.dlEnroll.ShowFooter = true;
            }
            else
            {
                this.dlEnroll.ShowFooter = false;
            }
        }
Exemplo n.º 3
0
        protected void btnEnroll_Click(object sender, EventArgs e)
        {
            UserCookiesInfo user = BllOperationAboutUser.GetUserCookiesInfo();
            DalOperationAboutGameEnrollList dal = new DalOperationAboutGameEnrollList();
            DateTime _now = DateTime.Now;

            DalOperationAboutGameCategory dalgc = new DalOperationAboutGameCategory();

            //首先检查报名时间是否已经截止
            if (dalgc.CheckGameCategoryIsOverTimeByGameCategoryId(int.Parse(ddlEnrollGameCategory.SelectedValue), _now).Tables[0].Rows.Count == 0)
            {
                Javascript.GoHistory(-1, "当前所选活动届次报名已经截止:(", Page);
                return;
            }

            if (dal.Exists(user.userNo, int.Parse(ddlEnrollGameCategory.SelectedValue), int.Parse(ddlEnrollGameType.SelectedValue)) > 0)
            {
                Javascript.AlertAndRedirect("当前所选活动届次和活动类型已经报名,点击确定查看报名信息", "/Administrator/EnrollManage.aspx?fragment=2", Page);
                return;
            }

            try
            {
                dal.Add(new GameEnrollList { gameCategoryId = int.Parse(ddlEnrollGameCategory.SelectedValue), gameTypeId = int.Parse(ddlEnrollGameType.SelectedValue), teacherNo = user.userNo, updateTime = _now });
                Javascript.AlertAndRedirect("报名成功:)", "/Administrator/EnrollManage.aspx?fragment=2", Page);
            }
            catch (System.Exception ex)
            {
                MongoDBLog.LogRecord(ex);
                Javascript.GoHistory(-1, "报名失败:)", Page);
            }
        }