//绑定信息 public void DataListBindEnrollList() { //检查是否有活动届次和活动类型数据 if (!(ddlGameCategory.Items.Count > 0 && ddlGameType.Items.Count > 0)) { Javascript.GoHistory(-1, "当前暂无活动届次和活动类型信息:(", Page); return; } DalOperationAboutGameDrawList doan = new DalOperationAboutGameDrawList(); DataTable dt = doan.GetList(int.Parse(ddlGameCategory.SelectedValue), int.Parse(ddlGameType.SelectedValue)).Tables[0]; this.AspNetPager3.RecordCount = dt.Rows.Count; AspNetPager3.PageSize = CommonUtility.pageSize; PagedDataSource pds = new PagedDataSource(); //定义一个PagedDataSource类来执行分页功 pds.DataSource = dt.DefaultView; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager3.CurrentPageIndex - 1; pds.PageSize = AspNetPager3.PageSize; this.dlEnroll.DataSource = pds; this.dlEnroll.DataBind(); if (pds.Count == 0) { this.dlEnroll.ShowFooter = true; } else { this.dlEnroll.ShowFooter = false; } }
protected void Button2_Click(object sender, EventArgs e) { if (txtGameTypeTitle.Text.Trim().Length == 0) { Javascript.GoHistory(-1, "请填写活动类型名称:)", Page); return; } int groupCapability = 0; if (!(CommonUtility.SafeCheckByParams<String>(txtGroupCapability.Text.Trim(), ref groupCapability) && groupCapability > 0)) { Javascript.GoHistory(-1, "每组人数必须为大于0的整数,请修改:)", Page); return; } try { DalOperationAboutGameType dal = new DalOperationAboutGameType(); //如果修改了组容量值,则首先判断是否已经有人开始抽签,如果有的话,则不允许修改组容量,但是可以修改其他内容 if (txtGroupCapability.Text.Trim() != hidGroupCapability.Value.Trim()) { DalOperationAboutGameDrawList _dal = new DalOperationAboutGameDrawList(); if (_dal.CheckIsDrawByGameCategoryId(int.Parse(ddlGameCategory.SelectedValue), gameTypeId).Tables[0].Rows.Count > 0) { Javascript.GoHistory(-1, "当有已有教师参加抽签,禁止修改分组人数,因为这样会造成抽签数据错误,\\n,请重新发布活动届次!", Page); return; } } dal.Update(new GameType { gameTypeTitle = txtGameTypeTitle.Text.Trim(), updateTime = DateTime.Now, allowSexType = rblTeacher.SelectedValue, gameTypeId = gameTypeId, groupCapability = groupCapability, gameCategoryId = int.Parse(ddlGameCategory.SelectedValue) }); Javascript.RefreshParentWindow("修改活动类型成功:)", "/Administrator/DrawManage.aspx?fragment=2", Page); } catch (Exception ex) { MongoDBLog.LogRecord(ex); Javascript.GoHistory(-1, "修改活动类型失败:(", Page); return; } }
//依据组别绑定组号信息 protected void dlstGroupNum_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataList dataList = (DataList)e.Item.FindControl("dlstGroupIndex"); DataRowView rowv = (DataRowView)e.Item.DataItem; string groupNum = rowv["groupNum"].ToString().Trim(); int gameCategoryId = int.Parse(rowv["gameCategoryId"].ToString().Trim()); int gameTypeId = int.Parse(rowv["gameTypeId"].ToString().Trim()); DalOperationAboutGameDrawList dal = new DalOperationAboutGameDrawList(); DataSet ds = dal.GetGroupIndexList(groupNum, gameCategoryId, gameTypeId); dataList.DataSource = ds.Tables[0].DefaultView; dataList.DataBind(); } }
//绑定组别 protected void DataListBindGroupNum() { //检查是否有活动届次和活动类型数据 if (!(ddlDrawGameCategory.Items.Count > 0 && ddlDrawGameType.Items.Count > 0)) { Javascript.GoHistory(-1, "当前暂无活动届次和活动类型信息:(", Page); return; } DalOperationAboutGameDrawList dal = new DalOperationAboutGameDrawList(); DataTable dt = dal.GetGroupNumList(int.Parse(ddlDrawGameCategory.SelectedValue), int.Parse(ddlDrawGameType.SelectedValue)).Tables[0]; this.dlstGroupNum.DataSource = dt; this.dlstGroupNum.DataBind(); }
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); } } } } }