?? 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 + -