promotionadd.aspx.cs
来自「易想商城系统」· CS 代码 · 共 352 行
CS
352 行
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using YXShop.Common;
using Shop.Web.UI;
namespace YXShop.Web.Admin.Product
{
public partial class PromotionAdd : System.Web.UI.Page
{
YXShop.BLL.Promotion bll = new YXShop.BLL.Promotion();
YXShop.BLL.MemberRand membBll = new YXShop.BLL.MemberRand();
private static int OpId = 0;
protected string WhetherDidAndNone = "";
BasePage bp = new BasePage();
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(YXShop.Web.Admin.Product.PromotionAdd));
DropDownList2.Attributes.Add("onchange", "SelectChangeIt(this)");
if (!Page.IsPostBack)
{
InitMember(cbUser, "");
BindGiftList(gift_list);
OpId = string.IsNullOrEmpty(Request.QueryString["ID"]) ? 0 : Convert.ToInt32(Request.QueryString["ID"]);
if (OpId > 0)
{
if (!PowerTree.PowerPass.isPass("002003004", PowerTree.PowerPanel.PowerType.update))
{
bp = new BasePage();
bp.PageError("对不起,你没有修改促销活动的权限!", "../index.aspx");
}
Bind(OpId);
}
else
{
if (!PowerTree.PowerPass.isPass("002003002", PowerTree.PowerPanel.PowerType.add))
{
bp = new BasePage();
bp.PageError("对不起,你没有添加促销活动的权限!", "../index.aspx");
}
BindPreferential(DropDownList2, 0);
}
}
}
public static int Statu = 0;
#region 填充数据
/// <summary>
/// 初始化数据
/// </summary>
/// <param name="id"></param>
private void Bind(int id)
{
YXShop.BLL.Product p = new YXShop.BLL.Product();
List<YXShop.Model.Promotion> li = bll.GetById(id);
string productList;
foreach (YXShop.Model.Promotion prom in li)
{
PromName.Text = prom.SP_Name;
productList = prom.SP_ProList;
dpStart.Date = prom.SP_StartTime;
dpEnd.Date = prom.SP_EndTime;
MemberLevel.Text = prom.SP_MinConsume.ToString();
TextBox3.Text = prom.SP_MaxConsume.ToString();
//会员等级
InitMember(cbUser, prom.SP_UserRank);
SelectProduct1.PName = this.ProString(Convert.ToInt32(prom.SP_ProList));
this.SelectProduct1.PID = Convert.ToInt32(prom.SP_ProList);
//活动礼品
this.hidGiftInfo.Value = prom.SP_GifiList + ",";
if (prom.SP_GifiList != string.Empty)
{
string[] gift = prom.SP_GifiList.Split(',');
for (int i = 0; i < gift.Length; i++)
{
this.BindGift(Convert.ToInt32(gift[0]));
}
}
BindPreferential(DropDownList2, (int)prom.SP_Fashion);
switch ((int)prom.SP_Fashion)
{
case 1:
someMethod.Style.Value = "display:none;";
activeList.Style.Value = "display:block;";
break;
case 2:
TextBox9.Text = prom.SP_M.ToString();
someMethod.Style.Value = "display:block;";
activeList.Style.Value = "display:none;";
break;
case 3:
TextBox9.Text = prom.SP_P.ToString();
someMethod.Style.Value = "display:block;";
activeList.Style.Value = "display:none;";
break;
default:
break;
}
}
//Statu = 2;
}
#endregion
#region 查询产品数据
protected string ProString(int id)
{
YXShop.BLL.Product datab = new YXShop.BLL.Product();
List<YXShop.Model.Product> data = datab.GetId(id);
if (data.Count > 0)
{
return data[0].Pro_Name;
}
return string.Empty;
}
#endregion
YXShop.BLL.Pro_Gift bllGift = new YXShop.BLL.Pro_Gift();
/// <summary>
/// 绑定礼品
/// </summary>
/// <param name="giftList"></param>
/// <param name="lb"></param>
private void BindGift(int strId)
{
List<YXShop.Model.Pro_Gift> li = bllGift.GetAll();
foreach (YXShop.Model.Pro_Gift da in li)
{
if (da.ProG_ID == strId)
{
this.gift_lb.Items.Add(new ListItem(da.ProG_Name, da.ProG_ID.ToString()));
}
}
}
/// <summary>
/// 优惠方式
/// </summary>
/// <param name="dll"></param>
private void BindPreferential(DropDownList ddl, int index)
{
ListItem li = null;
for (int i = 1; i < 4; i++)
{
li = new ListItem();
li.Value = i.ToString();
li.Text = preferentialMethod(i);
if (i == index)
{
li.Selected = true;
Statu = index;
}
ddl.Items.Add(li);
li = null;
}
}
private ListItem GetSelectedItem(DropDownList ddl)
{
ListItem lItem = new ListItem();
foreach (ListItem li in ddl.Items)
{
if (li.Selected)
{
lItem.Text = li.Text;
lItem.Value = li.Value;
break;
}
}
return lItem;
}
/// <summary>
/// 选定优惠方式
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
private string preferentialMethod(int num)
{
string tempStr = string.Empty;
switch (num)
{
case 1:
tempStr = "享受赠品";
break;
case 2:
tempStr = "享受现金减免";
break;
case 3:
tempStr = "享受价格折扣";
break;
default:
break;
}
return tempStr;
}
/// <summary>
/// 绑定礼品列表
/// </summary>
/// <param name="lBox"></param>
private void BindGiftList(ListBox lBox)
{
lBox.Items.Clear();
List<YXShop.Model.Pro_Gift> li = bllGift.GetAll();
ListItem lItem = null;
foreach (YXShop.Model.Pro_Gift gift in li)
{
lItem = new ListItem();
lItem.Value = gift.ProG_ID.ToString();
lItem.Text = gift.ProG_Name;
lBox.Items.Add(lItem);
lItem = null;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.SelectProduct1.PName == string.Empty)
{
this.Label1.Text = " * 请选择商品!";
return;
}
if (OpId > 0)
{
if (bll.Amend(this.CreateProm(OpId)) > 0)
{
bp.PageRight("优惠商品修改成功.", "PromotionList.aspx");
}
}
else
{
if (bll.Create(this.CreateProm(OpId)) > 0)
{
bp.PageRight("优惠商品添加成功.<li><a href='PromotionAdd.aspx'>继续添加</a></li>", "PromotionList.aspx");
}
}
}
/// <summary>
/// 组建模型参数
/// </summary>
/// <param name="promId"></param>
/// <returns></returns>
private YXShop.Model.Promotion CreateProm(int promId)
{
YXShop.Model.Promotion Prom = new YXShop.Model.Promotion();
if (promId > 0)
Prom.SP_ID = promId;
Prom.SP_Name = PromName.Text.Trim();
Prom.SP_StartTime = dpStart.Date;
Prom.SP_EndTime = dpEnd.Date;
Prom.SP_UserRank = this.GetRankList(cbUser);
Prom.SP_MinConsume = MemberLevel.Text.Trim() != string.Empty ? Convert.ToDecimal(MemberLevel.Text.Trim()) : 0;
Prom.SP_MaxConsume = TextBox3.Text.Trim() != string.Empty ? Convert.ToDecimal(TextBox3.Text.Trim()) : 0;
Prom.SP_Fashion = GetSelectedItem(DropDownList2).Value != string.Empty ? Convert.ToInt32(GetSelectedItem(DropDownList2).Value) : 0;//
Prom.SP_GifiList = hidGiftInfo.Value.TrimEnd(',');
Prom.SP_Explain = TextBox8.Text.Trim();
Prom.SP_ProList = SelectProduct1.PID.ToString();
Prom.SP_M = Prom.SP_P = TextBox9.Text.Trim() != string.Empty ? Convert.ToDecimal(TextBox9.Text.Trim()) : 0;
return Prom;
}
/// <summary>
/// 得到礼品列表
/// </summary>
/// <param name="lBox"></param>
/// <returns></returns>
private string GetGiftList(ListBox lBox)
{
string giftListStr = string.Empty;
foreach (ListItem li in lBox.Items)
{
giftListStr += string.Format("{0},", li.Value);
}
return giftListStr.TrimEnd(',');
}
public bool isNumeric(string num)
{
if (string.IsNullOrEmpty(num))
{
return false;
}
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("^[0-9]+$");
return r.IsMatch(num);
}
/// <summary>
///会员信息
/// </summary>
/// <param name="cbli"></param>
/// <param name="membList"></param>
private void InitMember(CheckBoxList cbli, string membList)
{
cbli.Items.Clear();
ListItem lItem = null;
List<YXShop.Model.MemberRand> li = membBll.GetAll();
string[] mList = membList.Split(',');
bool bl = false;
for (int i = 0; i < li.Count; i++)
{
lItem = new ListItem();
string userRank = li[i].Rank_ID.ToString();
lItem.Value = userRank;
lItem.Text = li[i].Rank_name;
for (int j = 0; j < mList.Length; j++)
{
if (isNumeric(mList[j]))
{
if (userRank == mList[j].Trim())
{
lItem.Selected = true;
bl = false;
}
}
}
cbli.Items.Add(lItem);
lItem = null;
}
if (!bl)
{
cbli.Items[0].Selected = true;
}
}
/// <summary>
/// 得到适用会员列表
/// </summary>
/// <param name="cbli"></param>
/// <returns></returns>
private string GetRankList(CheckBoxList cbli)
{
string reStr = string.Empty;
foreach (ListItem li in cbli.Items)
{
if (li.Selected)
reStr += li.Value + ",";
}
return reStr.TrimEnd(',');
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?