productdal.cs
来自「c#三层架构项目开发的全过程」· CS 代码 · 共 123 行
CS
123 行
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;
using System.Data.SqlClient;
namespace DAL.Goods
{
public class ProductDal
{
#region 查询所有商品ID
/// <summary>
/// 查询所有商品ID
/// </summary>
/// <returns>返回商品编号的数据集</returns>
public List<Model.Goods.ProductModel> SelectProductID()
{
string commandtext = "ProductID_Select";
DataSet ds = new DataSet();
SqlHelper.FillDataSet(SqlHelper.conStr,CommandType.StoredProcedure,commandtext,ds,new string [] {},null);
List<Model.Goods.ProductModel> li = new List<Model.Goods.ProductModel>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
Model.Goods.ProductModel inf = new Model.Goods.ProductModel();
inf.product_id = dr["Product_id"].ToString();
li.Add(inf);
}
return li;
}
#endregion
#region 通过商品ID查询商品信息
public List<Model.Goods.ProductModel> SelectProductByID(string productid)
{
string commandtext = "ProductByID_Select";
SqlParameter id = new SqlParameter("@Product_id", SqlDbType.Char, 20);
id.Value = productid;
DataSet ds = new DataSet();
SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { }, new SqlParameter[] { id });
List<Model.Goods.ProductModel> li = new List<Model.Goods.ProductModel>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
Model.Goods.ProductModel inf = new Model.Goods.ProductModel();
inf.product_id = dr["Product_id"].ToString();
inf.brand_id = (int)dr["brand_ID"];
inf.product_saleprice = (decimal)dr["Product_SalePrice"];
inf.Product_costprice = (decimal)dr["Product_CostPrice"];
inf.Product_tradeprice = (decimal)dr["Product_TradePrice"];
inf.product_name = dr["Product_Name"].ToString();
inf.brand_name = dr["brand_Name"].ToString();
inf.producttype_color = dr["ProductType_color"].ToString();
inf.producttype_s1 = Convert .ToInt32( dr["ProductType_S1"]);
inf.producttype_s2 = Convert .ToInt32(dr["ProductType_S2"]);
inf.producttype_s3 = Convert .ToInt32(dr["ProductType_S3"]);
inf.producttype_s4 = Convert.ToInt32(dr["ProductType_S4"]);
inf.producttype_s5 = Convert .ToInt32(dr["ProductType_S5"]);
inf.producttype_s6 = Convert .ToInt32(dr["ProductType_S6"]);
inf.producttype_s7 = Convert .ToInt32(dr["ProductType_S7"]);
li.Add(inf);
}
return li;
}
#endregion
//#region 通过商品ID保存商品信息
///// <summary>
///// 通过商品ID保存商品信息
///// </summary>
///// <param name="productid">商品ID</param>
///// <returns>返回保存商品信息的数据集</returns>
//public Model.Goods.ProductModel product(string productid)
//{
// string commandtext = "ProductByID_Select";
// SqlParameter id = new SqlParameter("@Product_id", SqlDbType.Char, 10);
// id.Value = productid;
// DataSet ds = new DataSet();
// SqlHelper.FillDataSet(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, ds, new string[] { }, new SqlParameter[] { id });
// Model.Goods.ProductModel inf = new Model.Goods.ProductModel();
// foreach (DataRow dr in ds.Tables[0].Rows)
// {
// inf.product_id = dr["Product_id"].ToString();
// inf.brand_id = (int)dr["brand_ID"];
// inf.product_saleprice = (decimal)dr["Product_SalePrice"];
// inf.product_costprice = (decimal)dr["Product_CostPrice"];
// inf.product_tradeprice = (decimal)dr["Product_TradePrice"];
// inf.product_name = dr["Product_Name"].ToString();
// inf.brand_name = dr["brand_Name"].ToString();
// inf.producttype_color = dr["ProductType_color"].ToString();
// }
// return inf;
//}
//#endregion
#region 查询商品品牌是否存在
/// <summary>
/// 查询商品品牌是否存在
/// </summary>
/// <returns></returns>
public bool SelectBrand(int brand_ID)
{
string commandtext = "BrandFromProduct_Select";
SqlParameter id = new SqlParameter("@brand_ID",SqlDbType.Int);
id.Value = brand_ID;
DataSet ds = new DataSet();
SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.conStr, CommandType.StoredProcedure, commandtext, new SqlParameter[] { id });
if (dr.Read())
{
dr.Close();
return true;
}
else
{
dr.Close();
return false;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?