protected override void SetButtons() { txtRedeemCode.Enabled = EnableRedeemCode; ShowDeactivate = false; if (this.PrimaryKeyIndex > 0) { ShowDeactivate = true; hccCoupon CurrentCoupon = hccCoupon.GetById(this.PrimaryKeyIndex); if (CurrentCoupon != null) { if (CurrentCoupon.IsActive) { btnDeactivate.Text = "Retire"; UseReactivateBehavior = false; } else { btnDeactivate.Text = "Reactivate"; UseReactivateBehavior = true; } } } btnDeactivate.Visible = ShowDeactivate; }
protected void txtRedeemCode_TextChanged(object sender, EventArgs e) { try { string redeemCode = txtRedeemCode.Text.Trim(); // check if this code exists in the db hccCoupon coupon = hccCoupon.GetBy(redeemCode); //if so, load coupon to form if (coupon == null) { string strTemp = txtRedeemCode.Text.Trim().ToUpper(); Clear(); txtRedeemCode.Text = strTemp; lblcouponvalidation.Visible = false; txtTitle.Enabled = true; txtDescription.Enabled = true; txtAmount.Enabled = true; ddlDiscountTypes.Enabled = true; ddlUsageTypes.Enabled = true; txtStartDate.Enabled = true; txtEndDate.Enabled = true; } else { if (Request.QueryString.AllKeys.Contains("CouponID")) { this.PrimaryKeyIndex = coupon.CouponID; CurrentCoupon = coupon; LoadForm(); txtTitle.Enabled = true; txtDescription.Enabled = true; txtAmount.Enabled = true; ddlDiscountTypes.Enabled = true; ddlUsageTypes.Enabled = true; txtStartDate.Enabled = true; txtEndDate.Enabled = true; } else { lblcouponvalidation.Text = "Coupon already exists"; lblcouponvalidation.Visible = true; txtTitle.Enabled = false; txtDescription.Enabled = false; txtAmount.Enabled = false; ddlDiscountTypes.Enabled = false; ddlUsageTypes.Enabled = false; txtStartDate.Enabled = false; txtEndDate.Enabled = false; } } } catch { throw; } }
void gvwActiveCoupons_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { hccCoupon coupon = (hccCoupon)e.Row.DataItem; Enums.CouponDiscountType discType = (Enums.CouponDiscountType)coupon.DiscountTypeID; Enums.CouponUsageType discUsage = (Enums.CouponUsageType)coupon.UsageTypeID; string tempDetails = string.Empty, tempDates = string.Empty; Label lblDetails = (Label)e.Row.FindControl("lblDetails"); Label lblEffectiveDates = (Label)e.Row.FindControl("lblEffectiveDates"); try { switch (discType) { case Enums.CouponDiscountType.Monetary: tempDetails = string.Format("{0:c} for {1}", coupon.Amount, Enums.GetEnumDescription(discUsage)); break; case Enums.CouponDiscountType.Percentage: tempDetails = string.Format("{0:p} for {1}", coupon.Amount / 100, Enums.GetEnumDescription(discUsage)); break; default: break; } lblDetails.Text = tempDetails; } catch { } try { if (coupon.StartDate.HasValue) { tempDates = "Start: " + coupon.StartDate.Value.ToShortDateString(); if (coupon.EndDate.HasValue) { tempDates += " - End: " + coupon.EndDate.Value.ToShortDateString(); } } else { if (coupon.EndDate.HasValue) { tempDates += "End: " + coupon.EndDate.Value.ToShortDateString(); } } lblEffectiveDates.Text = tempDates; } catch { } } }
protected override void LoadForm() { try { BindddlDiscountTypes(); BindddlUsageTypes(); if (CurrentCoupon == null) // try to get from viewstate primary key id { CurrentCoupon = hccCoupon.GetById(this.PrimaryKeyIndex); } if (CurrentCoupon != null) { txtRedeemCode.Text = CurrentCoupon.RedeemCode.ToUpper(); txtTitle.Text = CurrentCoupon.Title; txtDescription.Text = CurrentCoupon.Description; txtAmount.Text = CurrentCoupon.Amount.ToString("f2"); ddlDiscountTypes.SelectedIndex = ddlDiscountTypes.Items.IndexOf( ddlDiscountTypes.Items.FindByValue(CurrentCoupon.DiscountTypeID.ToString())); ddlUsageTypes.SelectedIndex = ddlUsageTypes.Items.IndexOf( ddlUsageTypes.Items.FindByValue(CurrentCoupon.UsageTypeID.ToString())); if (CurrentCoupon.StartDate.HasValue) { //txtStartDate.Text = CurrentCoupon.StartDate.Value.ToShortDateString(); txtStartDate.Text = CurrentCoupon.StartDate.Value.ToString("MM/dd/yyyy"); } if (CurrentCoupon.EndDate.HasValue) { //txtEndDate.Text = CurrentCoupon.EndDate.Value.ToShortDateString(); txtEndDate.Text = CurrentCoupon.EndDate.Value.ToString("MM/dd/yyyy"); } } if (CurrentCoupon.IsActive) { ShowDeactivate = true; UseReactivateBehavior = false; } else { ShowDeactivate = true; UseReactivateBehavior = true; } SetButtons(); } catch { throw; } }
public UsedCoupon(hccCart cart) { DateUsed = cart.PurchaseDate.Value; if (cart.CouponID.HasValue) { hccCoupon coup = hccCoupon.GetById(cart.CouponID.Value); if (coup != null) { CouponInfo = coup.ToString(); } } PurchaseInfo = cart.ToString(); }
protected void btnDeactivate_Click(object sender, EventArgs e) { hccCoupon coupon = hccCoupon.GetById(this.PrimaryKeyIndex); if (coupon == null) { coupon = CurrentCoupon; } if (coupon != null) { coupon.Activate(UseReactivateBehavior); this.OnSaved(new ControlSavedEventArgs(coupon.CouponID)); } }
protected override void SaveForm() { try { hccCoupon coupon = hccCoupon.GetById(this.PrimaryKeyIndex); if (coupon == null) { coupon = new hccCoupon { CreatedBy = (Guid)Helpers.LoggedUser.ProviderUserKey, CreatedDate = DateTime.Now, IsActive = true }; } coupon.RedeemCode = txtRedeemCode.Text.Trim().ToUpper(); coupon.Title = txtTitle.Text.Trim(); coupon.Description = txtDescription.Text.Trim(); coupon.Amount = decimal.Parse(txtAmount.Text.Trim()); coupon.DiscountTypeID = int.Parse(ddlDiscountTypes.SelectedValue); coupon.UsageTypeID = int.Parse(ddlUsageTypes.SelectedValue); if (string.IsNullOrWhiteSpace(txtStartDate.Text)) { coupon.StartDate = null; } else { coupon.StartDate = DateTime.Parse(txtStartDate.Text); } if (string.IsNullOrWhiteSpace(txtEndDate.Text)) { coupon.EndDate = null; } else { coupon.EndDate = DateTime.Parse(txtEndDate.Text); } coupon.Save(); this.OnSaved(new ControlSavedEventArgs(coupon.CouponID)); } catch { throw; } }