实例介绍
【实例简介】
DTcms V3.0源码说明:
版本号:V3.0.0
数据库:MSSQL2005、MSSQL2000或ACCESS
DTcms V3.0增强与改进的功能有:
1、系统架构发生了改变;
2、去除模型概念与改进扩展字段;
3、增加分站功能;
4、增加手机短信功能;
5、增加生成静态功能;
6、全新的后台界面;
7、对模板标签的改进;
温馨提示:具体的对比请留意晚上发布的对比视频。
【实例截图】
【核心代码】
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DTcms.Common;
using LitJson;
namespace DTcms.Web.UI
{
/// <summary>
/// 购物车帮助类
/// </summary>
public partial class ShopCart
{
#region 基本增删改方法====================================
/// <summary>
/// 获得购物车列表
/// </summary>
public static IList<Model.cart_items> GetList(int group_id)
{
IDictionary<string, int> dic = GetCart();
if (dic != null)
{
IList<Model.cart_items> iList = new List<Model.cart_items>();
foreach (var item in dic)
{
BLL.article bll = new BLL.article();
Model.article model = bll.GetModel(Convert.ToInt32(item.Key));
if (model == null || !model.fields.ContainsKey("sell_price"))
{
continue;
}
Model.cart_items modelt = new Model.cart_items();
modelt.id = model.id;
modelt.title = model.title;
modelt.img_url = model.img_url;
if (model.fields.ContainsKey("point"))
{
modelt.point = Utils.StrToInt(model.fields["point"], 0);
}
modelt.price = Utils.StrToDecimal(model.fields["sell_price"], 0);
modelt.user_price = Utils.StrToDecimal(model.fields["sell_price"], 0);
if (model.fields.ContainsKey("stock_quantity"))
{
modelt.stock_quantity = Utils.StrToInt(model.fields["stock_quantity"], 0);
}
//会员价格
if (model.group_price != null)
{
Model.user_group_price gmodel = model.group_price.Find(p => p.group_id == group_id);
if (gmodel != null)
{
modelt.user_price = gmodel.price;
}
}
modelt.quantity = item.Value;
iList.Add(modelt);
}
return iList;
}
return null;
}
/// <summary>
/// 添加到购物车
/// </summary>
public static bool Add(string Key, int Quantity)
{
IDictionary<string, int> dic = GetCart();
if (dic != null)
{
if (dic.ContainsKey(Key))
{
dic[Key] = Quantity;
AddCookies(JsonMapper.ToJson(dic));
return true;
}
}
else
{
dic = new Dictionary<string, int>();
}
//不存在的则新增
dic.Add(Key, Quantity);
AddCookies(JsonMapper.ToJson(dic));
return true;
}
/// <summary>
/// 更新购物车数量
/// </summary>
public static bool Update(string Key, int Quantity)
{
if (Quantity == 0)
{
Clear(Key);
return true;
}
IDictionary<string, int> dic = GetCart();
if (dic != null && dic.ContainsKey(Key))
{
dic[Key] = Quantity;
AddCookies(JsonMapper.ToJson(dic));
return true;
}
return false;
}
/// <summary>
/// 移除购物车
/// </summary>
/// <param name="Key">主键 0为清理所有的购物车信息</param>
public static void Clear(string Key)
{
if (Key == "0")//为0的时候清理全部购物车cookies
{
Utils.WriteCookie(DTKeys.COOKIE_SHOPPING_CART, "", -43200);
}
else
{
IDictionary<string, int> dic = GetCart();
if (dic != null)
{
dic.Remove(Key);
AddCookies(JsonMapper.ToJson(dic));
}
}
}
#endregion
#region 扩展方法==========================================
public static Model.cart_total GetTotal(int group_id)
{
Model.cart_total model = new Model.cart_total();
IList<Model.cart_items> iList = GetList(group_id);
if (iList != null)
{
foreach (Model.cart_items modelt in iList)
{
model.total_num ;
model.total_quantity = modelt.quantity;
model.payable_amount = modelt.price * modelt.quantity;
model.real_amount = modelt.user_price * modelt.quantity;
model.total_point = modelt.point * modelt.quantity;
}
}
return model;
}
#endregion
#region 私有方法==========================================
/// <summary>
/// 获取cookies值
/// </summary>
private static IDictionary<string, int> GetCart()
{
IDictionary<string, int> dic = new Dictionary<string, int>();
if (!string.IsNullOrEmpty(GetCookies()))
{
return JsonMapper.ToObject<Dictionary<string, int>>(GetCookies());
}
else
{
return null;
}
}
/// <summary>
/// 添加对象到cookies
/// </summary>
/// <param name="strValue"></param>
private static void AddCookies(string strValue)
{
Utils.WriteCookie(DTKeys.COOKIE_SHOPPING_CART, strValue, 43200); //存储一个月
}
/// <summary>
/// 获取cookies
/// </summary>
/// <returns></returns>
private static string GetCookies()
{
return Utils.GetCookie(DTKeys.COOKIE_SHOPPING_CART);
}
#endregion
}
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论