📄 coupon.aspx.cs
字号:
namespace PowerEasy.WebSite.Admin.Shop
{
using PowerEasy.Common;
using PowerEasy.CommonModel;
using PowerEasy.Controls;
using PowerEasy.Enumerations;
using PowerEasy.Model.CommonModel;
using PowerEasy.Model.Shop;
using PowerEasy.Shop;
using PowerEasy.UserManage;
using PowerEasy.Web.UI;
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Coupon : AdminPage
{
protected Button BtnLimit;
protected Button BtnSave;
protected Button BtnSelectProduct;
protected CheckBoxList ChklUserGroup;
protected DatePicker DpkBeginDate;
protected DatePicker DpkEndDate;
protected DatePicker DpkUseEndDate;
protected HiddenField HdnAllValue;
protected HiddenField HdnCouponID;
protected HiddenField HdnLimit;
protected HiddenField HdnLimitAllValue;
protected HiddenField HdnSelecedtProduct;
protected Label LblProductLimitTitle;
protected Label LblSelectProductTitle;
protected Label LblTitle;
protected ListBox LstLimit;
protected ListBox LstSelectedProduct;
private string m_Action;
private int m_CouponId;
protected PlaceHolder PlhList;
protected PlaceHolder PlhProductLimit;
protected PlaceHolder PlhSelectProduct;
protected RadioButtonList RadlCouponCreateType;
protected RadioButtonList RadlProductLimit;
protected RadioButtonList RadlState;
protected ScriptManager ScriptManager1;
protected ExtendedSiteMapPath SmpNavigator;
protected TextBox TxtCouponName;
protected TextBox TxtCouponNumPattern;
protected TextBox TxtLimitNum;
protected TextBox TxtMoney;
protected TextBox TxtOrderMoney;
protected TextBox TxtOrderTotalMoney;
protected CustomValidator ValcLimitModel;
protected CustomValidator ValcLimitProduct;
protected RegularExpressionValidator Vale;
protected RegularExpressionValidator ValeOrderTotalMoney;
protected PowerEasy.Controls.RequiredFieldValidator ValrCouponName;
protected PowerEasy.Controls.RequiredFieldValidator ValrCouponNumPattern;
protected PowerEasy.Controls.RequiredFieldValidator ValrLimitNum;
protected PowerEasy.Controls.RequiredFieldValidator ValrMoney;
protected PowerEasy.Controls.RequiredFieldValidator ValrOrderTotalMoney;
protected CustomValidator ValxSelectedModel;
protected CustomValidator ValxSelectedProduct;
protected DateValidator VdateBeginDate;
protected DateValidator VdateEndDate;
protected DateValidator VdateUseEndDate;
protected MoneyValidator VmoneyMoney;
protected NumberValidator VnumLimitNum;
protected void BtnSave_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
CouponInfo couponInfo = new CouponInfo();
couponInfo.CouponName = this.TxtCouponName.Text;
couponInfo.Money = DataConverter.CDecimal(this.TxtMoney.Text);
couponInfo.CouponNumPattern = this.TxtCouponNumPattern.Text;
couponInfo.BeginDate = this.DpkBeginDate.Date;
couponInfo.EndDate = this.DpkEndDate.Date;
couponInfo.UseEndDate = this.DpkUseEndDate.Date;
couponInfo.LimitNum = DataConverter.CLng(this.TxtLimitNum.Text);
couponInfo.State = DataConverter.CLng(this.RadlState.SelectedValue);
StringBuilder sb = new StringBuilder();
foreach (ListItem item in this.ChklUserGroup.Items)
{
if (item.Selected)
{
StringHelper.AppendString(sb, item.Value);
}
}
couponInfo.UserGroup = sb.ToString();
couponInfo.OrderTotalMoney = DataConverter.CDecimal(this.TxtOrderTotalMoney.Text);
couponInfo.CouponCreateType = (CouponCreateType) DataConverter.CLng(this.RadlCouponCreateType.SelectedValue);
if (couponInfo.CouponCreateType == CouponCreateType.OrderTotalMoney)
{
couponInfo.CouponCreateContent = DataConverter.CDecimal(this.TxtOrderMoney.Text).ToString();
}
else
{
couponInfo.CouponCreateContent = this.HdnSelecedtProduct.Value;
}
couponInfo.ProductLimitType = (ProductLimitType) DataConverter.CLng(this.RadlProductLimit.SelectedValue);
couponInfo.ProductLimitContent = this.HdnLimit.Value;
if (this.m_Action == "Modify")
{
couponInfo.CouponId = DataConverter.CLng(this.HdnCouponID.Value);
if (PowerEasy.Shop.Coupon.Update(couponInfo))
{
AdminPage.WriteSuccessMsg("修改优惠券成功!", "CouponManage.aspx");
}
else
{
AdminPage.WriteErrMsg("<li>修改优惠券失败!</li>");
}
}
else if (PowerEasy.Shop.Coupon.Add(couponInfo))
{
AdminPage.WriteSuccessMsg("添加优惠券成功!", "CouponManage.aspx");
}
else
{
AdminPage.WriteErrMsg("<li>添加优惠券失败!</li>");
}
}
}
private void IniModify()
{
if (this.m_CouponId == 0)
{
AdminPage.WriteErrMsg("<li>请输入优惠券ID</li>");
}
this.LblTitle.Text = "修改优惠券";
this.TxtMoney.ReadOnly = true;
CouponInfo couponInfoById = PowerEasy.Shop.Coupon.GetCouponInfoById(this.m_CouponId, true);
if (couponInfoById.IsNull)
{
return;
}
this.HdnCouponID.Value = this.m_CouponId.ToString();
this.TxtCouponName.Text = couponInfoById.CouponName;
this.TxtCouponNumPattern.Text = couponInfoById.CouponNumPattern;
this.TxtMoney.Text = couponInfoById.Money.ToString("0.00");
this.RadlState.SelectedValue = couponInfoById.State.ToString();
this.DpkBeginDate.Text = couponInfoById.BeginDate.ToString("yyyy-MM-dd");
this.DpkEndDate.Text = couponInfoById.EndDate.ToString("yyyy-MM-dd");
this.RadlCouponCreateType.SelectedValue = ((int) couponInfoById.CouponCreateType).ToString();
this.TxtLimitNum.Text = couponInfoById.LimitNum.ToString();
this.DpkUseEndDate.Text = couponInfoById.UseEndDate.ToString("yyyy-MM-dd");
this.RadlProductLimit.SelectedValue = ((int) couponInfoById.ProductLimitType).ToString();
this.TxtOrderTotalMoney.Text = couponInfoById.OrderTotalMoney.ToString("0.00");
switch (couponInfoById.CouponCreateType)
{
case CouponCreateType.AllProduct:
this.PlhSelectProduct.Visible = false;
break;
case CouponCreateType.NominateModel:
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (string str in couponInfoById.CouponCreateContent.Split(new char[] { ',' }))
{
ModelInfo modelInfoById = ModelManager.GetModelInfoById(DataConverter.CLng(str));
if (!modelInfoById.IsNull)
{
dictionary.Add(modelInfoById.ModelId.ToString(), modelInfoById.ModelName);
}
}
this.LstSelectedProduct.DataSource = dictionary;
this.LstSelectedProduct.DataBind();
this.HdnSelecedtProduct.Value = couponInfoById.CouponCreateContent;
this.LblSelectProductTitle.Text = "指定模型:";
this.BtnSelectProduct.Attributes.Add("onclick", "SelectModel();return false");
this.PlhSelectProduct.Visible = true;
this.PlhList.Visible = true;
break;
}
case CouponCreateType.NominateProduct:
{
Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
foreach (string str2 in couponInfoById.CouponCreateContent.Split(new char[] { ',' }))
{
ProductInfo productById = Product.GetProductById(DataConverter.CLng(str2));
if (!productById.IsNull)
{
dictionary2.Add(productById.ProductId.ToString(), DataSecurity.HtmlDecode(productById.ProductName));
}
}
this.LstSelectedProduct.DataSource = dictionary2;
this.LstSelectedProduct.DataBind();
this.HdnSelecedtProduct.Value = couponInfoById.CouponCreateContent;
this.LblSelectProductTitle.Text = "指定商品:";
this.BtnSelectProduct.Attributes.Add("onclick", "SelectProductToList();return false");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -