public void GetTicket(int SubjectID, int UserID, bool IsRepeat = false) { var subject = new DAL.Coupons_Subject().GetEntity(SubjectID); if (subject == null) throw new Exception("活动不存在"); if (!subject.Inactive.HasValue || subject.Inactive.Value) throw new Exception("活动已结束!"); if (!IsRepeat && listDAL.Exist(new string[] { "subjectid", "userid" }, new object[] { SubjectID, UserID })) throw new Exception("已参加该活动"); //var lists = listDAL.GetEntityList("ismoney desc, money desc", new string[] { "subjectid", "userid" }, new object[] { SubjectID,"is not null" }); var lists = listDAL.Select(string.Format("subjectid={0} and userid is null", SubjectID), "ismoney desc, money desc"); if (lists != null && lists.Rows.Count > 0) { listDAL.Update("UserID", UserID, "id=" + lists.Rows[0]["ID"].ToString()); } else { throw new Exception("优惠券已派送完!"); } }
private void Delete(int id) { var dal = new DAL.Coupons_Subject(); var subject = dal.GetEntity(id); if (subject == null) { WebUtility.ShowAndGoBack(this, "活动不存在!"); return; } subject.Inactive = true; if (dal.Update(subject) > 0) { WebUtility.ShowMsg(this, "过期成功!", "Default.aspx"); return; } else { WebUtility.ShowAndGoBack(this, "过期失败!"); return; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var subjectid = WebUtility.GetRequestInt("subjectid", -1); var subject = new DAL.Coupons_Subject().GetEntity(subjectid); dtStartDate.Text = subject.StartDate.Value.ToString("yyyy/MM/dd"); dtEndDate.Text = subject.EndDate.Value.ToString("yyyy/MM/dd"); } }
protected void btnSubmit_OnClick(object sender, EventArgs e) { if (!Utility.IsFloat(txtMoney.Text)) { WebUtility.ShowMsg("金额格式有问题!"); return; } if (!Utility.IsInt(txtCount.Text)) { WebUtility.ShowMsg("数量为整数!"); return; } var count = Utility.GetInt(txtCount.Text, -1); var money = Utility.GetDecimal(txtMoney.Text, 0); var subjectid = WebUtility.GetRequestInt("subjectid", -1); var subject = new DAL.Coupons_Subject().GetEntity(subjectid); var startDate = Utility.GetDateTime(dtStartDate.Text, DateTime.MinValue); var endDate = Utility.GetDateTime(dtEndDate.Text, DateTime.MinValue); if (subject == null) { WebUtility.ShowMsg("参数有问题!"); return; } if (subject.Inactive.HasValue && subject.Inactive.Value) { WebUtility.ShowMsg("活动已删除或已结束,无需再生成码!"); return; } if (subject.EndDate.HasValue && subject.EndDate.Value < DateTime.Now) { WebUtility.ShowMsg("活动已结束,无需再生成码!"); return; } if (startDate < subject.StartDate || endDate > subject.EndDate) { WebUtility.ShowMsg("有效期不在活动范围内!"); return; } if (subject.CreateUserID.HasValue) { WebUtility.ShowMsg("这是商家活动,只有系统新建的活动才能添加优惠券!"); return; } var successCount = 0; var isMoney = false; if (ddlIsMoney.SelectedValue == "1") isMoney = true; foreach (var code in GeneralCode(count)) { var list = new Model.Coupons_List { EndDate = endDate, IsMoney = isMoney, IsUse = false, Money = money, StartDate = startDate, SubjectID = subject.ID, Password = code, Memo = "", Inactive = false, }; try { listDAL.Add(list); successCount++; } catch { } } WebUtility.ShowMsg(this, string.Format("成功生成{0}张券", successCount), "lists.aspx?subjectid=" + subject.ID); }