1. 程式人生 > >12-資料訪問層

12-資料訪問層

using Entity;
using System.Data.SqlClient;
using System.Data;
public class CarDAL
{
/// <summary>
/// 新增房車資訊
/// </summary>
/// <param name="car"></param>
/// <returns></returns>
public int CarAdd(Car car)
{
try
{
var parms = new[]
{
new SqlParameter("@ID",car.ID),
new SqlParameter("@CarName",car.CarName),
new SqlParameter("@CarPinPaiID",car.CarPinPaiID),
new SqlParameter("@CarTypeID",car.CarTypeID),
new SqlParameter("@CarTyoeID2",car.CarTyoeID2),
new SqlParameter("@CarImg",car.CarImg),
new SqlParameter("@CarRemark",car.CarRemark),
new SqlParameter("@CarXingShi",car.CarXingShi),
new SqlParameter("@CarQuDong",car.CarQuDong),
new SqlParameter("@CarFaDongJi",car.CarFaDongJi),
new SqlParameter("@CarZhouJu",car.CarZhouJu),
new SqlParameter("@CarPaiLiang",car.CarPaiLiang),
new SqlParameter("@CarZhiLiang",car.CarZhiLiang),
new SqlParameter("@CarNiuJu",car.CarNiuJu),
new SqlParameter("@CarZhengBei",car.CarZhengBei),
new SqlParameter("@CarRanYou",car.CarRanYou),
new SqlParameter("@CarYouXiang",car.CarYouXiang),
new SqlParameter("@CarPriceID",car.CarPriceID),
new SqlParameter("@CarXingTypeID",car.CarXingTypeID),
new SqlParameter("@CarGroupID",car.CarGroupID),
new SqlParameter("@CarZiXun",car.CarZiXun),
new SqlParameter("@CarPaiFang",car.CarPaiFang),
new SqlParameter("@CarPrice",car.CarPrice),
new SqlParameter("@CarXingNum",car.CarXingNum),
new SqlParameter("@CarTypeXing",car.CarTypeXing),
new SqlParameter("@CarBaoYang",car.CarBaoYang),
new SqlParameter("@CarGong",car.CarGong),
new SqlParameter("@CarCreateTime",car.CarCreateTime),
new SqlParameter("@CarBianSuXiang",car.CarBianSuXiang),
new SqlParameter("@CarLongWidth",car.CarLongWidth),
new SqlParameter("@CarZhanTing",car.CarZhanTing),
new SqlParameter("@CarChangName",car.CarChangName),
new SqlParameter("@CarChangAddress",car.CarChangAddress),
new SqlParameter("@CarChangPhone",car.CarChangPhone),
new SqlParameter("@CarChangRemark",car.CarChangRemark),
new SqlParameter("@DataTable_Action_",car.DataTable_Action_)
};
var result = DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Car_InsertUpdateDelete", parms);
return result;
}
catch (Exception)
{

throw;
}
}
/// <summary>
/// 汽車品牌
/// </summary>
/// <returns></returns>
public List<CarPinPai> GetCarPinPai()
{
return DBHelper.ExecuteObjects<CarPinPai>("select * from CarPinPai");
}
/// <summary>
/// 汽車價格區間
/// </summary>
/// <returns></returns>
public List<CarPrice> GetCarPrice()
{
return DBHelper.ExecuteObjects<CarPrice>("select * from CarPrice");
}
/// <summary>
/// 汽車型別
/// </summary>
/// <returns></returns>
public List<CarXingType> GetCarXingType()
{
return DBHelper.ExecuteObjects<CarXingType>("select * from CarXingType");
}
/// <summary>
/// 汽車分組
/// </summary>
/// <returns></returns>
public List<CarGroup> GetCarGroup()
{
return DBHelper.ExecuteObjects<CarGroup>("select * from CarGroup");
}

/// <summary>
/// 圖片新增
/// </summary>
/// <param name="carImg"></param>
/// <returns></returns>
public int AddImg(CarImg carImg)
{
string sql = string.Format("insert into CarImg values('{0}','{1}','{2}','{3}')", carImg.ImgTitle, carImg.ImgUlr, carImg.ImgTypeID, carImg.ImgTime);
var result = DBHelper.ExecuteNonQuery(sql);
return result;
}
/// <summary>
/// 汽車分組
/// </summary>
/// <returns></returns>
public List<CarImgType> GetCarImgType()
{
return DBHelper.ExecuteObjects<CarImgType>("select * from CarImgType");
}
/// <summary>
/// 圖片顯示
/// </summary>
/// <returns></returns>
public List<CarImg> GetImgList()
{
return DBHelper.ExecuteObjects<CarImg>("select a.*,b.CarImgTypeName AS CarImgTypeName from CarImg a join CarImgType b on a.ImgTypeID = b.ID ");
}
/// <summary>
/// 刪除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int Delete(int id)
{
return DBHelper.ExecuteNonQuery(string.Format("DELETE dbo.CarImg WHERE ID ='{0}'", id));
}
/// <summary>
/// 房車資訊顯示
/// </summary>
/// <returns></returns>
public List<Car> GetCarList()
{
return DBHelper.ExecuteObjects<Car>("select * from Car");
}
}