protected void btnSave_Click(object sender, EventArgs e) { Activity_Awards award = new Activity_Awards { addTime = DateTime.Now, cycleId = Convert.ToInt32((string) ddlActivity.SelectedValue), dayCount = Convert.ToInt32((string) txtDay_Count.Text.Trim()), editTime = DateTime.Now, name = txtTitle.Text.Trim(), remark = txtRemark.Text.Trim(), sponsorId = CommonHelp.GetSponsor(ddlSponsor.SelectedValue), status = CommonHelp.GetStatus(ddlStatus.SelectedIndex), sumCount = Convert.ToInt32((string) txtCount.Text.Trim()), }; try { db.Activity_Awards.InsertOnSubmit(award); db.SubmitChanges(); //.AddOperatingLog("奖品", "添加", "添加了奖品 ID:" + award.Id + ",Title:" + award.name); StringHelper.Alert(this, "奖品发布成功!", "AwardList.aspx"); } catch (Exception ex) { //.AddErrorLog(ex); this.Message.Text = "发布失败! 失败原因:" + ex.Message + "。详细错误信息请查看错误日志。"; } }
protected void Submit_Click(object sender, EventArgs e) { string name = txtName.Text.Trim(); string phone = txtPhone.Text.Trim(); string code = txtCode.Text.Trim(); #region 数据验证 if (string.IsNullOrEmpty(code)) { this.Alert("兑奖码不能为空"); txtCode.Focus(); return; } if (string.IsNullOrEmpty(name)) { this.Alert("姓名不能为空"); txtName.Focus(); return; } if (string.IsNullOrEmpty(phone)) { this.Alert("电话不能为空"); txtPhone.Focus(); return; } if (!RegexHelper.IsCNMobileNum(phone)) { this.Alert("电话号码格式错误"); txtPhone.Focus(); return; } Activity_AwardUser awardUser = RelayQuery.GetActivity_AwardUser(code); if (awardUser == null) { this.Alert("兑奖码无效"); } #endregion lock (_obj) { Thread.Sleep(new Random().Next(500, 1001)); if (awardUser.isAward) { this.Alert("兑奖码已使用,请耐心等待工作人员联系"); return; } RelayQuery.UpdateUserInfo(name, phone, code); //不论有没有奖品可以兑换用户都可以 int? sponsorId = awardUser.Activity_Relay.SponsorId; var award = new Activity_Awards(); string message = ""; if (sponsorId.HasValue) //如果有的话就是景区门票 { award = RelayQuery.GetAward(sponsorId); if (award != null) { RelayQuery.UpdateAwardInfo(award, code); message = "你最近鸿运当头,获得了" + award.name; this.Alert(message); return; } } award = RelayQuery.GetAward(null); if (award == null) { this.Alert("前100位名额已满,下次早点来哦!"); } RelayQuery.UpdateAwardInfo(award, code); message = "人品爆发,你获得了" + award.name; this.Alert(message); } }
/// <summary> /// 修改奖品的数量 /// 修改 awardId和isAward这两个属性 /// </summary> /// <param name="award"></param> /// <param name="winCode"></param> public static void UpdateAwardInfo(Activity_Awards award, string winCode) { ipowdb_suibian_webDataContext db = ConnHelper.ipowdb_suibian_web(); Activity_AwardUser awardUser = db.Activity_AwardUser.Where(s => s.winCode == winCode).FirstOrDefault(); Activity_Awards awardInDb = db.Activity_Awards.Where(s => s.Id == award.Id && s.status && s.isDel == false).Single(); awardInDb.useredCount++; awardInDb.sumCount -= 1; db.SubmitChanges(); if (awardUser != null) { awardUser.awardId = award.Id; awardUser.isAward = true; awardUser.AwardDate = DateTime.Now; db.SubmitChanges(); } }