protected void Page_Load(object sender, EventArgs e) { this.radMatch.Items[0].Text = "模糊匹配"; this.radMatch.Items[1].Text = "精确匹配"; this.radDisable.Items[0].Text = "启用"; this.radDisable.Items[1].Text = "禁用"; this.chkNo.Enabled = (ReplyHelper.GetMismatchReply() == null); this.chkSub.Enabled = (ReplyHelper.GetSubscribeReply() == null); IList <CouponInfo> allUsedCoupons = CouponHelper.GetAllUsedCoupons(1); if (allUsedCoupons != null && allUsedCoupons.Count > 0) { foreach (CouponInfo item in allUsedCoupons) { if (CouponHelper.GetCouponSurplus(item.CouponId) > 0) { this.ddlCoupon.Items.Add(new ListItem(item.CouponName.ToNullString(), item.CouponId.ToNullString())); } } } if (this.ddlCoupon.Items.Count == 0) { this.ddlsubType.Items.RemoveAt(1); this.ddlCoupon.Items.Add(new ListItem("请选择优惠券", "0")); } if (!this.chkNo.Enabled) { this.chkNo.ToolTip = "该类型已被使用"; } if (!this.chkSub.Enabled) { this.chkSub.ToolTip = "该类型已被使用"; } }
public int GetCouponSurplus(int CouponId) { HiddenField hiddenField = this.hidSelectCouponIds; hiddenField.Value = hiddenField.Value + CouponId + ","; return(CouponHelper.GetCouponSurplus(CouponId)); }
private DataGridViewModel <Dictionary <string, object> > GetDataList(CouponsSearch query) { DataGridViewModel <Dictionary <string, object> > dataGridViewModel = new DataGridViewModel <Dictionary <string, object> >(); if (query != null) { DbQueryResult couponInfos = CouponHelper.GetCouponInfos(query, ""); dataGridViewModel.rows = DataHelper.DataTableToDictionary(couponInfos.Data); dataGridViewModel.total = couponInfos.TotalRecords; foreach (Dictionary <string, object> row in dataGridViewModel.rows) { CouponInfo couponInfo = row.ToObject <CouponInfo>(); int couponSurplus = CouponHelper.GetCouponSurplus(couponInfo.CouponId); row.Add("LastCount", couponSurplus); int couponObtainUserNum = CouponHelper.GetCouponObtainUserNum(couponInfo.CouponId); int couponObtainNum = CouponHelper.GetCouponObtainNum(couponInfo.CouponId, 0); row.Add("UserCount", couponObtainUserNum); row.Add("UserGetCount", couponObtainNum); int couponUsedNum = CouponHelper.GetCouponUsedNum(couponInfo.CouponId); row.Add("UseCount", couponUsedNum); row.Add("IsCouponEnd", this.IsCouponEnd(couponInfo.ClosingTime)); } } return(dataGridViewModel); }
public string GetCouponsListJson(DataTable dt, HttpContext context) { string text = context.Request.Form["client"].ToNullString(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("\"list\":["); for (int i = 0; i < dt.Rows.Count; i++) { stringBuilder.Append("{"); stringBuilder.Append("\"CouponId\":\"" + dt.Rows[i]["CouponId"].ToString() + "\","); stringBuilder.Append("\"title\":\"" + dt.Rows[i]["CouponName"].ToString() + "\","); stringBuilder.Append("\"Price\":\"" + dt.Rows[i]["Price"].ToDecimal(0).F2ToString("f2") + "\","); stringBuilder.Append("\"Surplus\":\"" + CouponHelper.GetCouponSurplus(dt.Rows[i]["CouponId"].ToInt(0)).ToString() + "\","); stringBuilder.Append("\"OrderUseLimit\":\"" + ((dt.Rows[i]["OrderUseLimit"].ToDecimal(0) == decimal.Zero) ? "无限制" : ("满" + dt.Rows[i]["OrderUseLimit"].ToDecimal(0).F2ToString("f2") + "元使用")) + "\","); StringBuilder stringBuilder2 = stringBuilder; string[] obj = new string[5] { "\"Use_time\":\"", null, null, null, null }; object obj2; DateTime value; if (!dt.Rows[i]["StartTime"].ToDateTime().HasValue) { obj2 = ""; } else { value = dt.Rows[i]["StartTime"].ToDateTime().Value; obj2 = value.ToString("yyyy.MM.dd"); } obj[1] = (string)obj2; obj[2] = "至"; object obj3; if (!dt.Rows[i]["ClosingTime"].ToDateTime().HasValue) { obj3 = ""; } else { value = dt.Rows[i]["ClosingTime"].ToDateTime().Value; obj3 = value.ToString("yyyy.MM.dd"); } obj[3] = (string)obj3; obj[4] = "\","; stringBuilder2.Append(string.Concat(obj)); stringBuilder.Append("\"type\":\"1\","); stringBuilder.Append("\"link\":\"/" + text + "/CouponDetails.aspx?couponId=" + dt.Rows[i]["CouponId"].ToString() + "\""); stringBuilder.Append("},"); } string str = stringBuilder.ToString().TrimEnd(','); return(str + "]"); }
private string GetCouponSurplus(int CouponId) { int couponSurplus = CouponHelper.GetCouponSurplus(CouponId); int cantObtainUserNum = CouponHelper.GetCantObtainUserNum(CouponId); if (couponSurplus >= this.UserNum - cantObtainUserNum) { return(couponSurplus.ToString()); } return("<span>" + couponSurplus + "</span><span style='color:red;'>(数量不足)</span>"); }
private void BindRegisterCoupons() { SiteSettings masterSettings = SettingsManager.GetMasterSettings(); if (!masterSettings.IsOpenGiftCoupons) { HttpContext.Current.Response.Redirect("RegisteredCouponsEnd.aspx"); } this.hidIsOpenGiftCoupons.Value = (masterSettings.IsOpenGiftCoupons ? "1" : "0"); this.btnToGo.NavigateUrl = ""; string sWhere = "and COUPONID IN ('" + masterSettings.GiftCouponList.Replace(",", "','") + "')"; DbQueryResult couponInfos = CouponHelper.GetCouponInfos(this.GetCouponsSearch(), sWhere); decimal num = default(decimal); if (couponInfos.Data != null) { DataTable data = couponInfos.Data; data.Columns.Add("ItemIndex"); data.Columns.Add("isEnd"); int num2 = 0; foreach (DataRow row in data.Rows) { int couponSurplus = CouponHelper.GetCouponSurplus(row["CouponId"].ToInt(0)); if (couponSurplus <= 0) { row["isEnd"] = "couponed"; } if (row["ClosingTime"].ToDateTime().HasValue&& row["ClosingTime"].ToDateTime().Value < DateTime.Now) { row["isEnd"] = "couponed"; } num += row["Price"].ToDecimal(0); if (data.Rows.Count == num2 + 1 && data.Rows.Count % 2 == 1) { row["ItemIndex"] = -1; } else { row["ItemIndex"] = num2; } num2++; } this.rptRegisterCoupons.DataSource = data; this.rptRegisterCoupons.DataBind(); } this.lblTotalPrice.Text = num.F2ToString("f2"); }
private void BindRegisterCoupons() { SiteSettings masterSettings = SettingsManager.GetMasterSettings(); this.hidIsOpenGiftCoupons.Value = (masterSettings.IsOpenGiftCoupons ? "1" : "0"); this.btnToGo.Text = (masterSettings.IsOpenGiftCoupons ? "去注册" : "去购物"); this.btnToGo.NavigateUrl = (masterSettings.IsOpenGiftCoupons ? "/Register.aspx" : "/"); MemberInfo user = HiContext.Current.User; if (masterSettings.IsOpenGiftCoupons) { string sWhere = "and COUPONID IN ('" + masterSettings.GiftCouponList.Replace(",", "','") + "')"; DbQueryResult couponInfos = CouponHelper.GetCouponInfos(this.GetCouponsSearch(), sWhere); decimal num = default(decimal); if (couponInfos.Data != null) { DataTable data = couponInfos.Data; data.Columns.Add("isEnd"); foreach (DataRow row in data.Rows) { num += row["Price"].ToDecimal(0); int couponSurplus = CouponHelper.GetCouponSurplus(row["CouponId"].ToInt(0)); if (couponSurplus <= 0) { row["isEnd"] = "end"; } if (row["ClosingTime"].ToDateTime().HasValue&& row["ClosingTime"].ToDateTime().Value < DateTime.Now) { row["isEnd"] = "end"; } } this.rptRegisterCoupons.DataSource = couponInfos.Data; this.rptRegisterCoupons.DataBind(); } this.lblTotalPrice.Text = num.F2ToString("f2"); if (user.UserId > 0 && user.IsLogined) { this.btnToGo.NavigateUrl = "RegisteredCoupons.aspx?isOldUser=true"; } } if (this.isOldUser) { this.hidIsOpenGiftCoupons.Value = "2"; this.btnToGo.Text = "去购物"; this.btnToGo.NavigateUrl = "/"; } }
private void btnOK_Click(object sender, EventArgs e) { SiteSettings masterSettings = SettingsManager.GetMasterSettings(); masterSettings.IsOpenGiftCoupons = this.ooOpen.SelectedValue; if (this.ooOpen.SelectedValue) { masterSettings.GiftCouponList = this.hidSelectCouponIds.Value; int num = 0; string[] array = masterSettings.GiftCouponList.Split(','); foreach (string text in array) { if (!string.IsNullOrEmpty(text)) { CouponInfo eFCoupon = CouponHelper.GetEFCoupon(text.ToInt(0)); if (eFCoupon == null) { this.ShowMsg("保存失败!部分优惠券已过期或剩余数量不足,请删除后重新选择。", false); this.Refresh(); return; } int couponSurplus = CouponHelper.GetCouponSurplus(text.ToInt(0)); if (eFCoupon.ClosingTime < DateTime.Now || couponSurplus <= 0) { this.ShowMsg("保存失败!部分优惠券已过期或剩余数量不足,请删除后重新选择。", false); this.Refresh(); return; } num++; } } if (num > 10) { this.ShowMsg("只可以选择10张优惠券,请删除部分优惠券。", false); this.Refresh(); return; } } else { masterSettings.GiftCouponList = ""; } SettingsManager.Save(masterSettings); this.BindCouponList(); this.ShowMsg("保存成功", true, ""); }
protected void Page_Load(object sender, EventArgs e) { this.radMatch.Items[0].Text = "模糊匹配"; this.radMatch.Items[1].Text = "精确匹配"; this.radDisable.Items[0].Text = "启用"; this.radDisable.Items[1].Text = "禁用"; this.chkNo.Enabled = (ReplyHelper.GetMismatchReply() == null); this.chkSub.Enabled = (ReplyHelper.GetSubscribeReply() == null); if (!this.chkNo.Enabled) { this.chkNo.ToolTip = "该类型已被使用"; } if (!this.chkSub.Enabled) { this.chkSub.ToolTip = "该类型已被使用"; } IList <CouponInfo> allUsedCoupons = CouponHelper.GetAllUsedCoupons(1); if (allUsedCoupons != null) { foreach (CouponInfo item in allUsedCoupons) { if (CouponHelper.GetCouponSurplus(item.CouponId) > 0) { this.ddlCoupon.Items.Add(new ListItem(item.CouponName.ToNullString(), item.CouponId.ToNullString())); } } } if (this.ddlCoupon.Items.Count == 0) { this.ddlsubType.Items.RemoveAt(1); this.ddlCoupon.Items.Add(new ListItem("请选择优惠券", "0")); } if (!base.IsPostBack) { this.id = base.GetUrlIntParam("id"); this.BindSingleArticle(this.id); } else { this.uploadpic.Src = this.hdpic.Value; } }
public void BindCoupons() { this.Items.Clear(); this.Items.Add(new ListItem { Text = "请选择优惠券", Value = "0" }); IList <CouponInfo> allUsedCoupons = CouponHelper.GetAllUsedCoupons(1); allUsedCoupons.ForEach(delegate(CouponInfo x) { if (CouponHelper.GetCouponSurplus(x.CouponId) > 0) { this.Items.Add(new ListItem { Text = x.CouponName, Value = x.CouponId.ToString() }); } }); }
private int GetCouponSurplus(int CouponId) { return(CouponHelper.GetCouponSurplus(CouponId)); }
protected void btnAddActivity_Click(object sender, EventArgs e) { string sharePic = string.Empty; if (this.hidUploadImages.Value.Trim().Length > 0) { try { sharePic = this.UploadImage(); } catch { this.ShowMsg("图片上传失败,您选择的不是图片类型的文件,或者网站的虚拟目录没有写入文件的权限", false); return; } } if (!this.calendarEndDate.SelectedDate.HasValue) { this.ShowMsg("请选择活动结束时间", false); } else { DateTime value = this.calendarEndDate.SelectedDate.Value; DateTime?t = this.calendarStartDate.Text.ToDateTime(); int freeTimes = default(int); int consumptionIntegral = default(int); if ((DateTime?)value < t) { this.ShowMsg("活动开始时间不能晚于活动结束时间", false); } else if (!int.TryParse(this.txtMaxNum.Text, out freeTimes) || freeTimes.ToString() != this.txtMaxNum.Text) { this.ShowMsg("可抽奖次数必须是整数", false); } else if (!int.TryParse(this.txtUsePoints.Text, out consumptionIntegral)) { this.ShowMsg("每次参与消耗的积分不能为空,且是整数", false); } else { ActivityInfo activityInfo = ActivityHelper.GetActivityInfo(this.activityid); activityInfo.ActivityName = Globals.StripHtmlXmlTags(this.txtActiveName.Text); activityInfo.Description = this.txtdesc.Text; DateTime value2 = this.calendarEndDate.SelectedDate.Value; if (value2.Second == 0) { value2.AddSeconds(59.0); } activityInfo.EndDate = value2; activityInfo.ShareDetail = this.txtKeyword.Text; activityInfo.SharePic = sharePic; activityInfo.FreeTimes = freeTimes; activityInfo.ConsumptionIntegral = consumptionIntegral; Database database = DatabaseFactory.CreateDatabase(); using (DbConnection dbConnection = database.CreateConnection()) { dbConnection.Open(); DbTransaction dbTransaction = dbConnection.BeginTransaction(); try { if (ActivityHelper.UpdateActivityInfo(activityInfo, dbTransaction)) { string value3 = this.hidJson.Value; if (string.IsNullOrEmpty(value3)) { dbTransaction.Rollback(); this.ShowMsg("获得奖项不能为空!", false); } else { decimal d = default(decimal); bool flag = true; List <ActivityAwardItemInfo> activityItemList = ActivityHelper.GetActivityItemList(activityInfo.ActivityId); List <ActivityAwardItemInfo> list = JsonHelper.ParseFormJson <List <ActivityAwardItemInfo> >(value3); int[] array = new int[activityItemList.Count]; int num = 0; string text = ""; foreach (ActivityAwardItemInfo item in list) { if (item.AwardId > 0) { text = text + item.AwardId + ","; } } text = text.Remove(text.Length - 1); ActivityHelper.DeleteEidAwardItem(this.activityid, text, dbTransaction); foreach (ActivityAwardItemInfo item2 in activityItemList) { array[num] = item2.AwardId; num++; } if (list.Any()) { foreach (ActivityAwardItemInfo item3 in list) { if (item3.PrizeType == 2) { int couponSurplus = CouponHelper.GetCouponSurplus(item3.PrizeValue); if (item3.AwardNum > couponSurplus) { dbTransaction.Rollback(); this.ShowMsg("优惠券奖项数量不能大于总数!", false); return; } } d += item3.HitRate; item3.ActivityId = this.activityid; bool flag2 = false; if (array.Contains(item3.AwardId)) { if (item3.AwardId > 0) { ActivityAwardItemInfo newItemInfo = this.GetNewItemInfo(item3); if (!ActivityHelper.UpdateActivityAwardItemInfo(newItemInfo, dbTransaction)) { dbTransaction.Rollback(); this.ShowMsg("编辑失败!", false); return; } } else if (ActivityHelper.AddActivityAwardItemInfo(item3, dbTransaction) <= 0) { dbTransaction.Rollback(); this.ShowMsg("编辑失败!", false); return; } continue; } if (item3.AwardId > 0) { flag = ActivityHelper.DeleteActivityAwardItemByActivityId(item3.AwardId, dbTransaction); continue; } int num2 = ActivityHelper.AddActivityAwardItemInfo(item3, dbTransaction); if (num2 > 0) { flag = true; continue; } dbTransaction.Rollback(); this.ShowMsg("编辑失败!", false); return; } } if (d > 100m) { dbTransaction.Rollback(); this.ShowMsg("奖项概率总和不能大于100%!", false); } else if (flag) { dbTransaction.Commit(); this.ShowMsg("编辑成功!", true); base.Response.Redirect("NewLotteryActivity.aspx?type=" + this.type, true); base.Response.End(); } else { dbTransaction.Rollback(); this.ShowMsg("编辑失败!", false); } } } } catch (Exception ex) { dbTransaction.Rollback(); Globals.WriteLog("ActivityLog.txt", "Methed:Edit , Id:" + activityInfo.ActivityId + " , Msg:" + ex.Message); this.ShowMsg(ex.Message, false); } finally { dbConnection.Close(); } } } } }
protected void btnAddActivity_Click(object sender, EventArgs e) { string sharePic = string.Empty; if (this.hidUploadImages.Value.Trim().Length > 0) { try { sharePic = this.UploadImage(); } catch { this.ShowMsg("图片上传失败,您选择的不是图片类型的文件,或者网站的虚拟目录没有写入文件的权限", false); return; } } int freeTimes = default(int); int consumptionIntegral = default(int); if (string.IsNullOrEmpty(Globals.StripHtmlXmlTags(this.txtActiveName.Text))) { this.ShowMsg("标题不能为空,或者危险字符!", false); } else if (!this.calendarStartDate.SelectedDate.HasValue) { this.ShowMsg("请选择活动开始时间", false); } else if (!this.calendarEndDate.SelectedDate.HasValue) { this.ShowMsg("请选择活动结束时间", false); } else if (this.calendarEndDate.SelectedDate.Value < this.calendarStartDate.SelectedDate.Value) { this.ShowMsg("活动开始时间不能晚于活动结束时间", false); } else if (!int.TryParse(this.txtMaxNum.Text, out freeTimes) || freeTimes.ToString() != this.txtMaxNum.Text) { this.ShowMsg("可抽奖次数必须是整数", false); } else if (!int.TryParse(this.txtUsePoints.Text, out consumptionIntegral)) { this.ShowMsg("每次参与消耗的积分不能为空,且是整数", false); } else { ActivityInfo activityInfo = new ActivityInfo(); activityInfo.ActivityName = Globals.StripHtmlXmlTags(this.txtActiveName.Text); activityInfo.ActivityType = this.type; activityInfo.Description = this.txtdesc.Text; activityInfo.StartDate = this.calendarStartDate.SelectedDate.Value; activityInfo.EndDate = this.calendarEndDate.SelectedDate.Value.AddSeconds(59.0); activityInfo.ShareDetail = this.txtKeyword.Text; activityInfo.SharePic = sharePic; activityInfo.ResetType = ((!this.ooOpen.SelectedValue) ? 1 : 2); activityInfo.FreeTimes = freeTimes; activityInfo.ConsumptionIntegral = consumptionIntegral; activityInfo.CreateDate = DateTime.Now; Database database = DatabaseFactory.CreateDatabase(); using (DbConnection dbConnection = database.CreateConnection()) { dbConnection.Open(); DbTransaction dbTransaction = dbConnection.BeginTransaction(); try { long num = ActivityHelper.AddActivityInfo(activityInfo, dbTransaction); if (num > 0) { string value = this.hidJson.Value; if (string.IsNullOrEmpty(value)) { dbTransaction.Rollback(); this.ShowMsg("获得奖项不能为空!", false); } else { bool flag = true; decimal d = default(decimal); List <ActivityAwardItemInfo> list = JsonHelper.ParseFormJson <List <ActivityAwardItemInfo> >(value); if (list.Any()) { foreach (ActivityAwardItemInfo item in list) { if (item.PrizeType == 2) { int couponSurplus = CouponHelper.GetCouponSurplus(item.PrizeValue); if (item.AwardNum > couponSurplus) { dbTransaction.Rollback(); this.ShowMsg("优惠券奖项数量不能大于总数!", false); return; } } d += item.HitRate; if (d > 100m) { dbTransaction.Rollback(); this.ShowMsg("奖项概率总和不能大于100%!", false); return; } item.ActivityId = num.ToInt(0); int num2 = ActivityHelper.AddActivityAwardItemInfo(item, dbTransaction); if (num2 <= 0) { flag = false; dbTransaction.Rollback(); } } } if (flag) { dbTransaction.Commit(); this.ShowMsg("添加成功", true, "NewLotteryActivity.aspx?type=" + this.type); } } } else { dbTransaction.Rollback(); this.ShowMsg("添加失败!", false); } } catch (Exception ex) { dbTransaction.Rollback(); Globals.WriteLog("ActivityLog.txt", "Methed:btnAddActivity_Click , Id:" + activityInfo.ActivityId + " , Msg:" + ex.Message); this.ShowMsg(ex.Message, false); } finally { dbConnection.Close(); } } } }