📄 goods.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace TBLibrary.Shop.ShopManage
{
/// <summary>
/// Goods 的摘要说明。
/// </summary>
public class Goods : TBLibrary.Shop.DbBase.Base
{
public Goods()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 获取某物货的所有的信息
/// </summary>
public static DataView GetGoods(int id)
{
string strSql = "SELECT * From MerchandiseInfo Where id="+id;
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
/// <summary>
/// 获取某货物的基本信息
/// </summary>
/// <returns></returns>
public static DataView GetGoodsMessage(int id)
{
string strSql = "SELECT ID,ClassID,Name,PurchasePrice,MemberPrice,"
+"StockQty,SellQty From MerchandiseInfo Where ID="+id;
//MerchandiseInfo
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 显示所有货物的基本信息
/// </summary>
/// <returns></returns>
public static DataView GetAllGoodsMessage()
{
string strSql = "SELECT ID,ClassID,Name,PurchasePrice,MemberPrice,"
+"StockQty,SellQty From MerchandiseInfo ";
//MerchandiseInfo
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 获取简要货物信息
/// </summary>
/// <returns></returns>
public static DataView GetSimplenessGoodsMessage(int start,int maxValue,string condition,int conditionValue,string order)
{
string strSql;
if(conditionValue ==0)
{
strSql = "SELECT ID,ClassID,Name,MarketPrice,MemberPrice,Cover,SellQty,Hits From MerchandiseInfo"
+" Order by "+order;
}
else
{
strSql = "SELECT ID,ClassID,Name,MarketPrice,MemberPrice,Cover,SellQty,Hits From MerchandiseInfo "
+"Where "+condition+ "="+conditionValue+" Order by "+order;
}
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlPartDs(strSql,start,maxValue);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 返回排名前10的产品
/// </summary>
/// <returns></returns>
public static DataView GetTop10()
{
string strSql = "SELECT top 10 ID,Name,ClassID from MerchandiseInfo join on"
+"MerchandiseInfo.ClassID = Class_2.Class_2ID";
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
public static int GoodsCount()
{
string strSql = "SELECT Count(*)From MerchandiseInfo";
try
{
return (int)EexecuteSqlValue(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
//public static DataView GetGoodsMessage(int id)
//{
//string strSql ="Select ";
//}
public static void AddGoodMessage(int classID,string name,string description,string cover)
{
string strSql ="Insert into MerchandiseInfo(ClassID,Name,Description,Cover)Values"
+"("+classID+",'"+name+"','"+description+"','"+cover+"')";
try
{
EexecuteSqlValue(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
public static void AddStockMessage(float purchasePrice,float marketPrice,float memberPrice,int stockQty,int id)
{
//string strSql ="Insert into StockInfo (PurchasePrice,MarketPrice,MemberPrice,StockQty)Values"
//+"("+purchasePrice+","+marketPrice+","+memberPrice+","+stockQty+")Where MerchandiseID="+id;
string strSql = "Update StockInfo Set PurchasePrice = "+purchasePrice+",MarketPrice="+marketPrice+","
+"MemberPrice="+memberPrice+",StockQty="+stockQty+"";
//string strSql2 ="";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 添加货品信息
/// </summary>
/// <param name="classID"></param>
/// <param name="name"></param>
/// <param name="purchasePrice"></param>
/// <param name="marketPrice"></param>
/// <param name="memberPrice"></param>
/// <param name="stockQty"></param>
/// <param name="description"></param>
/// <param name="cover"></param>
public static void AddGoodsMessage(int classID,string name,float purchasePrice,float marketPrice,float memberPrice,int stockQty,string description,string cover,int se,int re)
{
string strSql ="Insert into MerchandiseInfo(classID,Name,PurchasePrice,MarketPrice,MemberPrice,"
+"StockQty,Description,Cover,SpecialOffer,Recommendation,GoodsTime)Values"
+"("+classID+",'"+name+"',"+purchasePrice+","+marketPrice+","+memberPrice+","+memberPrice+""
+""+stockQty+",'"+description+"','"+cover+"',"+se+","+re+",'"+DateTime.Now.ToString()+"')";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 更新货物信息
/// </summary>
/// <param name="id"></param>
/// <param name="classID"></param>
/// <param name="name"></param>
/// <param name="purchasePrice"></param>
/// <param name="marketPrice"></param>
/// <param name="memberPrice"></param>
/// <param name="stockQty"></param>
/// <param name="description"></param>
/// <param name="cover"></param>
public static void UpdateGoodsMessage(int id,int classID,string name,float purchasePrice,float marketPrice,float memberPrice,int stockQty,string description,string cover)
{
string strSql ="Update MerchandiseInfo set classID="+classID+",Name='"+name+"',"
+"PurchasePrice = "+purchasePrice+",MarketPrice="+memberPrice+",MemberPrice ="+memberPrice+""
+"Where ID="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 新新货物信息
/// </summary>
/// <param name="id"></param>
/// <param name="name"></param>
/// <param name="purchasePrice"></param>
/// <param name="memberPrice"></param>
/// <param name="stockQty"></param>
public static void UpdateBasicGoodsMessage(int id,string name,float purchasePrice,float memberPrice,float stockQty )
{
string strSql = "Update MerchandiseInfo set Name='"+name+"',PurchasePrice = "+purchasePrice+","
+"MarketPrice="+memberPrice+" Where ID ="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 删除货物信息
/// </summary>
/// <param name="id"></param>
public static void Deleted(int id)
{
string strSql = "Delete From MerchandiseInfo Where ID ="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 点击率加1
/// </summary>
/// <param name="id"></param>
public static void Hits(int id)
{
string strSql = "Update MerchandiseInfo set Hits=Hits+1 Where ID="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
public static DataView SearchV(string key,int con)
{
string strSql;
if(con ==0)
{
strSql ="Select * From SearchV Where Name like'%"+key+"%'";
}
else if(con==1)
{
strSql ="Select * From SearchV Where Description like'%"+key+"%'";
}
else
{
strSql ="Select * From SearchV ";
}
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="NameID"></param>
/// <param name="name"></param>
/// <param name="caption"></param>
/// <param name="content"></param>
public static void InsertComment(int nameID,string name,string caption,string content)
{
string strSql = "Insert into Comment(NameID,UserName,Caption,Content,PublishDate)Values('"+nameID+"','"+name+"','"+caption+"','"+content+"'"
+",'"+DateTime.Now.ToString()+"')";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 读取数量
/// </summary>
/// <param name="nameID"></param>
/// <returns></returns>
public static int CountComment(int nameID)
{
string strSql = "SELECT Count(*) From Comment Where NameID ="+nameID;
try
{
return (int)EexecuteSqlValue(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
public static DataView GetComment(int start,int maxValue,int goodsID)
{
string strSql = "SELECT * From Comment Where NameID ="+goodsID+" Order by PublishDate DESC";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlPartDs(strSql,start,maxValue);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -