private void ShowInfo(int id) { hidid.Value = id.ToString(); Model.wx_sTicket sstAction = sstBll.GetModel(id); IList <Model.wx_sttAwardItem> aItemlist = iBll.GetModelList("actId=" + id); Model.wx_requestRule rule = rBll.GetModelList("modelFunctionName='优惠券简单版' and modelFunctionId=" + id)[0]; txtKW.Text = rule.reqKeywords; if (sstAction.beginPic != null && sstAction.beginPic.Trim() != "/weixin/sticket/images/start.jpg") { txtImgUrl.Text = sstAction.beginPic; imgbeginPic.ImageUrl = sstAction.beginPic; } //banner if (sstAction.bannerPic != null && sstAction.bannerPic.Trim() != "/weixin/sticket/images/banner.jpg") { txtBanner.Text = sstAction.bannerPic; imgBanner.ImageUrl = sstAction.bannerPic; } txtactName.Text = sstAction.actionName; txtsuccTip.Text = sstAction.succTip; txtbrief.Value = sstAction.brief; txtbeginDate.Text = sstAction.beginDate.Value.ToString("yyyy-MM-dd HH:mm:ss"); txtendDate.Text = sstAction.endDate.Value.ToString("yyyy-MM-dd HH:mm:ss"); txtactContent.Value = sstAction.aContent; txtusedRemark.Value = sstAction.usedRemark; this.txtdjPwd.Text = sstAction.pwd; //结束 if (sstAction.endPic != null && sstAction.endPic.Trim() != "/weixin/sticket/images/end.jpg") { txtEndPic.Text = sstAction.endPic; imgEndPic.ImageUrl = sstAction.endPic; } txtendNotice.Text = sstAction.endNotice; txtendContent.Text = sstAction.endContent; //绑定奖项信息 IList <Model.wx_sttAwardItem> itemlist = iBll.GetModelList("actId=" + id + " order by sort_id asc"); if (itemlist != null && itemlist.Count > 0) { int count = itemlist.Count; TextBox txtJPName; TextBox txtRealNum; Model.wx_sttAwardItem itemEntity = new Model.wx_sttAwardItem(); for (int i = 1; i <= count; i++) { itemEntity = itemlist[(i - 1)]; txtJPName = this.FindControl("txt" + i + "JPName") as TextBox; txtRealNum = this.FindControl("txt" + i + "RealNum") as TextBox; txtJPName.Text = itemEntity.jpName; txtRealNum.Text = itemEntity.jpRealNum == null ? "0" : itemEntity.jpRealNum.Value.ToString(); } } }
/// <summary> /// 取中奖的项目 /// </summary> /// <param name="itemlist">所有的奖品信息</param> /// <param name="haszjlist">已经中奖的列表</param> /// <returns></returns> private Model.wx_sttAwardItem getZJItem(IList <Model.wx_sttAwardItem> itemlist, IList <Model.wx_sttAwardUser> haszjlist) { IList <Model.wx_sttAwardItem> zjItemlist = new List <Model.wx_sttAwardItem>();//剩余奖品列表 Model.wx_sttAwardItem tmpItem = new Model.wx_sttAwardItem(); Model.wx_sttAwardItem stmpItem = new Model.wx_sttAwardItem(); IList <Model.wx_sttAwardUser> thiszjRs; for (int i = 0; i < itemlist.Count; i++) { tmpItem = itemlist[i]; thiszjRs = (from user in haszjlist where user.jpName == tmpItem.jpName select user).ToArray <Model.wx_sttAwardUser>(); int tmpSYNum = 0; if (thiszjRs != null) { tmpSYNum = MyCommFun.Obj2Int(tmpItem.jpRealNum) - thiszjRs.Count; } if (tmpSYNum <= 0) { continue; } for (int j = 0; j < tmpSYNum; j++) { stmpItem = new Model.wx_sttAwardItem(); stmpItem.jpName = tmpItem.jpName; stmpItem.jxName = tmpItem.jxName; zjItemlist.Add(stmpItem); } } Random rd = new Random((int)DateTime.Now.Ticks); int jpIndex = rd.Next(0, zjItemlist.Count);//从0到zjItemlist.Count里随机出一个值 return(zjItemlist[jpIndex]); }
/// <summary> /// 添加奖品项目 /// </summary> private void EditAwardItem(int sstId) { //1删除原来的,2新增 iBll.DeleteByActId(sstId); Model.wx_sttAwardItem item = new Model.wx_sttAwardItem(); TextBox txtJPName; TextBox txtRealNum; int sort_id = 0; for (int i = 1; i <= 6; i++) { txtJPName = this.FindControl("txt" + i + "JPName") as TextBox; txtRealNum = this.FindControl("txt" + i + "RealNum") as TextBox; if (txtJPName.Text.Trim() != "" && txtRealNum.Text.Trim() != "" && MyCommFun.isNumber(txtRealNum.Text)) { sort_id++; //那么添加奖品信息 item.sort_id = sort_id; item.jpName = txtJPName.Text.Trim(); item.jpRealNum = MyCommFun.Str2Int(txtRealNum.Text.Trim()); item.actId = sstId; item.createDate = DateTime.Now; iBll.Add(item); } } }
/// <summary> /// 绑定页面上的基本信息 /// </summary> /// <param name="id">活动主键id</param> /// <param name="openid"></param> private void bindData(int id, string openid) { #region 活动详情 sstAction = actbll.GetModel(id); if (sstAction == null) { hidStatus.Value = "-2"; hidErrInfo.Value = "该活动不存在!"; return; } this.Title = sstAction.actionName; stitle = sstAction.actionName; sbrief = sstAction.brief; List <Model.wx_sttAwardItem> itemlist = itemBll.GetModelList("actId=" + id); StringBuilder sb = new StringBuilder(""); Model.wx_sttAwardItem item = new Model.wx_sttAwardItem(); int ttJpNum = 0;//最大的奖品数量 for (int i = 0; i < itemlist.Count; i++) { item = itemlist[i]; sb.Append("<p>优惠券名称:" + item.jpName + " 数量:" + item.jpRealNum + "</p>"); ttJpNum += item.jpRealNum.Value; } zjpic.ImageUrl = sstAction.bannerPic == null ? "images/banner.jpg" : sstAction.bannerPic; litJiangXing.Text = sb.ToString(); litusedRemark.Text = sstAction.usedRemark; litaContent.Text = sstAction.aContent; #endregion #region 判断 if (sstAction.endDate <= DateTime.Now) { //说明活动已经结束 //非活动期间 hidStatus.Value = "-1"; hidErrInfo.Value = "活动已结束!"; return; } else if (sstAction.beginDate > DateTime.Now) { //活动未开始 //非活动期间 hidStatus.Value = "-2"; hidErrInfo.Value = "活动尚未开始!"; return; } #endregion #region 计算中奖信息 Model.wx_sttAwardUser awardUser = ubll.getZJinfoByOpenid(id, openid); if (awardUser != null && awardUser.id > 0) { if (awardUser.uTel != null && awardUser.uTel.Trim() != "") { //说明已经提交成功了 hidStatus.Value = "3"; hidErrInfo.Value = "恭喜你中奖了!"; litJp.Text = awardUser.jpName; hidAwardId.Value = awardUser.id.ToString(); litSNM.Text = awardUser.sn; } else { //未提交 //中奖了 hidStatus.Value = "2"; hidErrInfo.Value = "恭喜你中奖了!"; litJiangPing.Text = awardUser.jpName; hidAwardId.Value = awardUser.id.ToString(); litSn.Text = awardUser.sn; } return; } IList <Model.wx_sttAwardUser> auserlist = ubll.getHasZJList(id); //已经中奖的人列表 int ZhongJiangNum = 0; //中奖人数 if (auserlist != null) { ZhongJiangNum = auserlist.Count; //已经中奖的人数 } int syZjNum = ttJpNum - ZhongJiangNum; //剩余的奖品数量 if (syZjNum <= 0) { //说明已经没有奖品了 hidStatus.Value = "-2"; hidErrInfo.Value = "优惠券已经被领取完了,请下次再来吧!"; return; } Random rd = new Random((int)DateTime.Now.Ticks); int radNum = rd.Next(0, syZjNum);//从0到剩余的奖品里随机出一个值 if (radNum < syZjNum) { //中奖了,再从剩余奖品里抽取一个奖品 Model.wx_sttAwardItem dajiang = getZJItem(itemlist, auserlist); if (dajiang != null) { //这是中的中奖了 string snumber = Get_snumber(id); int uId = ubll.Add(id, "", "", openid, dajiang.jpName, snumber); hidStatus.Value = "2"; hidErrInfo.Value = "恭喜你中奖了!"; litJiangPing.Text = dajiang.jpName; hidAwardId.Value = uId.ToString(); litSn.Text = snumber; return; } else { //奖品已经全部中完了 hidStatus.Value = "-2"; hidErrInfo.Value = "优惠券已经被领取完了,请下次再来吧!"; return; } } else { //这个条件说明:未中奖 //抛出未中奖的数据 hidStatus.Value = "-2"; hidErrInfo.Value = "优惠券已经被领取完了,请下次再来吧!"; return; } #endregion }
private void ShowInfo(int id) { hidid.Value = id.ToString(); Model.wx_sTicket sstAction = sstBll.GetModel(id); IList<Model.wx_sttAwardItem> aItemlist = iBll.GetModelList("actId=" + id); Model.wx_requestRule rule = rBll.GetModelList("modelFunctionName='优惠券简单版' and modelFunctionId=" + id)[0]; txtKW.Text = rule.reqKeywords; if (sstAction.beginPic != null && sstAction.beginPic.Trim() != "/weixin/sticket/images/start.jpg") { txtImgUrl.Text = sstAction.beginPic; imgbeginPic.ImageUrl = sstAction.beginPic; } //banner if (sstAction.bannerPic != null && sstAction.bannerPic.Trim() != "/weixin/sticket/images/banner.jpg") { txtBanner.Text = sstAction.bannerPic; imgBanner.ImageUrl = sstAction.bannerPic; } txtactName.Text = sstAction.actionName; txtsuccTip.Text = sstAction.succTip; txtbrief.Value = sstAction.brief; txtbeginDate.Text = sstAction.beginDate.Value.ToString("yyyy-MM-dd HH:mm:ss"); txtendDate.Text = sstAction.endDate.Value.ToString("yyyy-MM-dd HH:mm:ss"); txtactContent.Value = sstAction.aContent; txtusedRemark.Value = sstAction.usedRemark; this.txtdjPwd.Text = sstAction.pwd; //结束 if (sstAction.endPic != null && sstAction.endPic.Trim() != "/weixin/sticket/images/end.jpg") { txtEndPic.Text = sstAction.endPic; imgEndPic.ImageUrl = sstAction.endPic; } txtendNotice.Text = sstAction.endNotice; txtendContent.Text = sstAction.endContent; //绑定奖项信息 IList<Model.wx_sttAwardItem> itemlist = iBll.GetModelList("actId=" + id + " order by sort_id asc"); if (itemlist != null && itemlist.Count > 0) { int count = itemlist.Count; TextBox txtJPName; TextBox txtRealNum; Model.wx_sttAwardItem itemEntity = new Model.wx_sttAwardItem(); for (int i = 1; i <= count; i++) { itemEntity = itemlist[(i - 1)]; txtJPName = this.FindControl("txt" + i + "JPName") as TextBox; txtRealNum = this.FindControl("txt" + i + "RealNum") as TextBox; txtJPName.Text = itemEntity.jpName; txtRealNum.Text = itemEntity.jpRealNum == null ? "0" : itemEntity.jpRealNum.Value.ToString(); } } }
/// <summary> /// 添加奖品项目 /// </summary> private void EditAwardItem(int sstId) { //1删除原来的,2新增 iBll.DeleteByActId(sstId); Model.wx_sttAwardItem item = new Model.wx_sttAwardItem(); TextBox txtJPName; TextBox txtRealNum; int sort_id = 0; for (int i = 1; i <= 6; i++) { txtJPName = this.FindControl("txt" + i + "JPName") as TextBox; txtRealNum = this.FindControl("txt" + i + "RealNum") as TextBox; if ( txtJPName.Text.Trim() != "" && txtRealNum.Text.Trim() != "" && MyCommFun.isNumber(txtRealNum.Text)) { sort_id++; //那么添加奖品信息 item.sort_id = sort_id; item.jpName = txtJPName.Text.Trim(); item.jpRealNum = MyCommFun.Str2Int(txtRealNum.Text.Trim()); item.actId = sstId; item.createDate = DateTime.Now; iBll.Add(item); } } }
/// <summary> /// 绑定页面上的基本信息 /// </summary> /// <param name="id">活动主键id</param> /// <param name="openid"></param> private void bindData(int id, string openid) { #region 活动详情 sstAction = actbll.GetModel(id); if (sstAction == null) { hidStatus.Value = "-2"; hidErrInfo.Value = "该活动不存在!"; return; } this.Title = sstAction.actionName; stitle = sstAction.actionName; sbrief = sstAction.brief; List<Model.wx_sttAwardItem> itemlist = itemBll.GetModelList("actId=" + id); StringBuilder sb = new StringBuilder(""); Model.wx_sttAwardItem item = new Model.wx_sttAwardItem(); int ttJpNum = 0;//最大的奖品数量 for (int i = 0; i < itemlist.Count; i++) { item = itemlist[i]; sb.Append("<p>优惠券名称:" + item.jpName + " 数量:" + item.jpRealNum + "</p>"); ttJpNum += item.jpRealNum.Value; } zjpic.ImageUrl = sstAction.bannerPic == null ? "images/banner.jpg" : sstAction.bannerPic; litJiangXing.Text = sb.ToString(); litusedRemark.Text = sstAction.usedRemark; litaContent.Text = sstAction.aContent ; #endregion #region 判断 if (sstAction.endDate <= DateTime.Now) { //说明活动已经结束 //非活动期间 hidStatus.Value = "-1"; hidErrInfo.Value = "活动已结束!"; return; } else if (sstAction.beginDate > DateTime.Now) { //活动未开始 //非活动期间 hidStatus.Value = "-2"; hidErrInfo.Value = "活动尚未开始!"; return; } #endregion #region 计算中奖信息 Model.wx_sttAwardUser awardUser = ubll.getZJinfoByOpenid(id, openid); if (awardUser != null && awardUser.id > 0 ) { if (awardUser.uTel != null && awardUser.uTel.Trim() != "") { //说明已经提交成功了 hidStatus.Value = "3"; hidErrInfo.Value = "恭喜你中奖了!"; litJp.Text = awardUser.jpName; hidAwardId.Value = awardUser.id.ToString(); litSNM.Text = awardUser.sn; } else { //未提交 //中奖了 hidStatus.Value = "2"; hidErrInfo.Value = "恭喜你中奖了!"; litJiangPing.Text = awardUser.jpName; hidAwardId.Value = awardUser.id.ToString(); litSn.Text = awardUser.sn; } return; } IList<Model.wx_sttAwardUser> auserlist = ubll.getHasZJList(id);//已经中奖的人列表 int ZhongJiangNum = 0; //中奖人数 if (auserlist != null) { ZhongJiangNum = auserlist.Count; //已经中奖的人数 } int syZjNum = ttJpNum - ZhongJiangNum; //剩余的奖品数量 if (syZjNum <= 0) { //说明已经没有奖品了 hidStatus.Value = "-2"; hidErrInfo.Value = "优惠券已经被领取完了,请下次再来吧!"; return; } Random rd = new Random((int)DateTime.Now.Ticks); int radNum = rd.Next(0, syZjNum);//从0到剩余的奖品里随机出一个值 if (radNum < syZjNum) { //中奖了,再从剩余奖品里抽取一个奖品 Model.wx_sttAwardItem dajiang = getZJItem(itemlist, auserlist); if (dajiang != null) { //这是中的中奖了 string snumber = Get_snumber(id); int uId = ubll.Add(id, "", "", openid, dajiang.jpName, snumber); hidStatus.Value = "2"; hidErrInfo.Value = "恭喜你中奖了!"; litJiangPing.Text = dajiang.jpName; hidAwardId.Value = uId.ToString(); litSn.Text = snumber; return; } else { //奖品已经全部中完了 hidStatus.Value = "-2"; hidErrInfo.Value = "优惠券已经被领取完了,请下次再来吧!"; return; } } else { //这个条件说明:未中奖 //抛出未中奖的数据 hidStatus.Value = "-2"; hidErrInfo.Value = "优惠券已经被领取完了,请下次再来吧!"; return; } #endregion }
/// <summary> /// 取中奖的项目 /// </summary> /// <param name="itemlist">所有的奖品信息</param> /// <param name="haszjlist">已经中奖的列表</param> /// <returns></returns> private Model.wx_sttAwardItem getZJItem(IList<Model.wx_sttAwardItem> itemlist, IList<Model.wx_sttAwardUser> haszjlist) { IList<Model.wx_sttAwardItem> zjItemlist = new List<Model.wx_sttAwardItem>();//剩余奖品列表 Model.wx_sttAwardItem tmpItem = new Model.wx_sttAwardItem(); Model.wx_sttAwardItem stmpItem = new Model.wx_sttAwardItem(); IList<Model.wx_sttAwardUser> thiszjRs; for (int i = 0; i < itemlist.Count; i++) { tmpItem = itemlist[i]; thiszjRs = (from user in haszjlist where user.jpName == tmpItem.jpName select user).ToArray<Model.wx_sttAwardUser>(); int tmpSYNum = 0; if (thiszjRs != null) { tmpSYNum = MyCommFun.Obj2Int(tmpItem.jpRealNum) - thiszjRs.Count; } if (tmpSYNum <= 0) { continue; } for (int j = 0; j < tmpSYNum; j++) { stmpItem = new Model.wx_sttAwardItem(); stmpItem.jpName = tmpItem.jpName; stmpItem.jxName = tmpItem.jxName; zjItemlist.Add(stmpItem); } } Random rd = new Random((int)DateTime.Now.Ticks); int jpIndex = rd.Next(0, zjItemlist.Count);//从0到zjItemlist.Count里随机出一个值 return zjItemlist[jpIndex]; }