📄 order.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace TBLibrary.Shop.ShopManage
{
/// <summary>
/// TempStore 的摘要说明。
/// </summary>
public class Order:TBLibrary.Shop.DbBase.Base
{
/// <summary>
/// 用户是否已在购物车添加了该物品
/// </summary>
/// <param name="id"></param>
public static bool IsExit(string orderNumber,int goodsID)
{
string strSql = "Select ID From OrderDetails Where(OrderID="+orderNumber+")And(GoodsID ="+goodsID+")";
try
{
EexecuteSqlValue(strSql);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 添加购物车信息
/// </summary>
/// <param name="goodsID"></param>
/// <param name="userID"></param>
public static void Add(string orderNumber,int goodsID,int userID)
{
if(!IsExit(orderNumber,goodsID))
{
string strSql ="Insert into OrderDetails(OrderID,GoodsID,UserID)values('"+orderNumber+"',"+goodsID+","+userID+")";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
throw new Exception("你已经购买了此商品");
}
}
/// <summary>
/// 删除购物车某种货物信息
/// </summary>
/// <param name="goodsID"></param>
/// <param name="userID"></param>
public static void Delete(int goodsID,int userID)
{
string strSql = "Delete From OrderDetails Where GoodsID="+goodsID+" And UserID="+userID;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 清除购车
/// </summary>
/// <param name="userID"></param>
public static void Clear(int userID)
{
string strSql = "Delete From OrderDetails Where userID="+userID;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 得到购物车信息
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public static DataView GetShopingGoods(string OrderID)
{
string strSql ="Select * From OrdersV Where OrderID ="+OrderID;
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 更改数量
/// </summary>
/// <param name="orderID"></param>
/// <param name="qty"></param>
/// <param name="totalPrice"></param>
public static void UpDateQty(string orderID,int qty,double totalPrice,int goodsID)
{
string strSql = "UpDate OrderDetails Set Qty ="+qty+",GoodsTotalPrice ="
+totalPrice+" Where (OrderID = '"+orderID+"')And(GoodsID='"+goodsID+"')";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 建立菜单
/// </summary>
/// <param name="orderID"></param>
/// <param name="totalPrice"></param>
public static void CreateOrderToDB(string orderID,double totalPrice,int userID)
{
string strSql = "Insert into Orders(OrderID,DateTime,TotalPrice,userID)values('"+orderID+"','"+DateTime.Now.ToString()+"','"+totalPrice+"',"+userID+")";
//string strSql2 ="Update MerchandiseInfo Set SellQty=(Select )"
//StockQty"
//DateTime.Now.t
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 更新数据库存量
/// </summary>
/// <param name="goodsID"></param>
/// <param name="qty"></param>
public static void UpdateStoc(int goodsID,int qty)
{
string strSql = "Update MerchandiseInfo set SellQty=SellQty+"+qty+",StockQty=StockQty-"+qty+" Where ID="+goodsID;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 读取会员订单信息
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public static DataView ReadOrder(int userID)
{
string strSql ="Select * From Orders Where UserID ="+userID;//(Select OrderID From OrderDetails Where userID="+userID+")";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 读取某一定单的信息
/// </summary>
/// <param name="orderID"></param>
/// <returns></returns>
public static DataView ReadOrderDetail(string orderID)
{
string strSql ="Select * From DetailsOrderV Where OrderID ="+orderID;
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 添加收藏
/// </summary>
/// <param name="goodsID"></param>
/// <param name="userID"></param>
public static void AddFav(int goodsID,int userID)
{
if(!IsFavExit(goodsID,userID))
{
string strSql ="Insert into AddFav(goodsID,UserID,FavTime)values("+goodsID+","+userID+",'"+DateTime.Now.ToString()+"')";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
throw new Exception("你已经收藏了该产品");
}
}
/// <summary>
/// 读取收藏
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public static DataView ReadFav(int userID)
{
string strSql = "Select * From AddFavV Where userID ="+userID;
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 删除收藏夹内容
/// </summary>
/// <param name="goodsID"></param>
/// <param name="userID"></param>
public static void DeleFav(int goodsID,int userID)
{
string strSql="Delete From AddFav Where(GoodsID="+goodsID+")And(UserID ="+userID+")";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 看看是否收藏
/// </summary>
/// <param name="goodsID"></param>
/// <param name="userID"></param>
/// <returns></returns>
public static bool IsFavExit(int goodsID,int userID)
{
string strSql = "Select ID From AddFav Where(GoodsID="+goodsID+")And(UserID ="+userID+")";
try
{
EexecuteSqlValue(strSql);
return true;
}
catch
{
return false;
}
}
//管理定订
/// <summary>
/// 删除订单
/// </summary>
/// <param name="orderID"></param>
public static void DeletedOrder(string orderID)
{
string strSql ="Delete From Orders Where OrderID ='"+orderID+"'";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 更新订单状态
/// </summary>
/// <param name="orderId"></param>
/// <param name="status"></param>
public static void UpdateOrder(string orderId,string status)
{
string strSql ="Update Orders set status ='"+status+"'where OrderID='"+orderId+"'";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 读取所有的订单信息
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static DataView ReadAllOrder(string state)
{
string strSql;
if(state == null)
{
strSql = "Select * From AdminOrderV";
}
else
{
strSql ="Select * From AdminOrderV Where status ='"+state+"'";
}
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -