using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBUtility;
using System.Data;
namespace DAL
{
public class Product
{
public Product()
{ }
#region 成员方法
public bool Exists(int P_ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) from Product");
strSql.Append("where P_ID="+ P_ID +"");
return DbHelperOledb.Exists(strSql.ToString());
}
public int Count()
{
StringBuilder sql = new StringBuilder();
sql.Append("select count(1) from product");
return Convert.ToInt32(DbHelperOledb.ExecuteScalar(sql.ToString()));
}
public void Add(Model.Product model)
{
StringBuilder strSql = new StringBuilder();
StringBuilder strSql1 = new StringBuilder();
StringBuilder strSql2 = new StringBuilder();
if (model.P_ID != null)
{
strSql1.Append("P_ID,");
strSql2.Append("" + model.P_ID + ",");
}
if (model.P_Name != null)
{
strSql1.Append("P_Name,");
strSql2.Append("'" + model.P_Name + "',");
}
if (model.P_ClassID != null)
{
strSql1.Append("P_ClassID,");
strSql2.Append("" + model.P_ClassID + ",");
}
if (model.P_ParentID != null)
{
strSql1.Append("P_ParentID,");
strSql2.Append("" + model.P_ParentID + ",");
}
if (model.P_ClassCode != null)
{
strSql1.Append("P_ClassCode,");
strSql2.Append("'" + model.P_ClassCode + "',");
}
if (model.P_Show != null)
{
strSql1.Append("P_Show,");
strSql2.Append("" + model.P_Show + ",");
}
if (model.P_Demo != null)
{
strSql1.Append("P_Demo,");
strSql2.Append("'" + model.P_Demo + "',");
}
if (model.P_Content != null)
{
strSql1.Append("P_Content,");
strSql2.Append("'" + model.P_Content + "',");
}
if (model.P_PhotoUrl != null)
{
strSql1.Append("P_PhotoUrl,");
strSql2.Append("'" + model.P_PhotoUrl + "',");
}
if (model.P_PhotoUrlSmall != null)
{
strSql1.Append("P_PhotoUrlSmall,");
strSql2.Append("'" + model.P_PhotoUrlSmall + "',");
}
if (model.P_Uptime != null)
{
strSql1.Append("P_Uptime,");
strSql2.Append("'" + model.P_Uptime + "',");
}
strSql.Append("insert into Product(");
strSql.Append(strSql1.ToString().Remove(strSql1.Length-1));
strSql.Append(")");
strSql.Append("values(");
strSql.Append(strSql2.ToString().Remove(strSql2.Length-1));
strSql.Append(")");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
public void Update(Model.Product model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Product set ");
if(model.P_Name!=null)
{
strSql.Append("P_Name='"+ model.P_Name +"',");
}
if (model.P_ClassID != null)
{
strSql.Append("P_ClassID=" + model.P_ClassID + ",");
}
if (model.P_ParentID != null)
{
strSql.Append("P_ParentID=" + model.P_ParentID + ",");
}
if (model.P_ClassCode != null)
{
strSql.Append("P_ClassCode='" + model.P_ClassCode + "',");
}
if (model.P_Show != null)
{
strSql.Append("P_Show=" + model.P_Show + ",");
}
if (model.P_Demo != null)
{
strSql.Append("P_Demo='" + model.P_Demo + "',");
}
if (model.P_Content != null)
{
strSql.Append("P_Content='" + model.P_Content + "',");
}
if (model.P_PhotoUrl != null)
{
strSql.Append("P_PhotoUrl='" + model.P_PhotoUrl + "',");
}
if (model.P_PhotoUrlSmall != null)
{
strSql.Append("P_PhotoUrlSmall='" + model.P_PhotoUrlSmall + "',");
}
if (model.P_Uptime != null)
{
strSql.Append("P_Uptime='" + model.P_Uptime + "',");
}
int n = strSql.ToString().LastIndexOf(",");
strSql.Remove(n, 1);
strSql.Append("where P_ID="+model.P_ID);//+" "
DbHelperOledb.ExecuteSql(strSql.ToString());
}
public void Delete(int P_ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from Product");
strSql.Append(" where P_ID="+ P_ID +" ");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
public Model.Product GetModel(int P_ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
strSql.Append(" P_ID,P_Name,P_ClassID,P_ParentID,P_ClassCode,P_Show,P_Demo,P_Content,P_PhotoUrl,P_PhotoUrlSmall,P_Uptime ");
strSql.Append(" from Product ");
strSql.Append(" where P_ID=" + P_ID + " ");
Model.Product model = new Model.Product();
DataSet ds = DbHelperOledb.Query(strSql.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["P_ID"].ToString() != "")
{
model.P_ID = int.Parse(ds.Tables[0].Rows[0]["P_ID"].ToString());
}
model.P_Name = ds.Tables[0].Rows[0]["P_Name"].ToString();
if (ds.Tables[0].Rows[0]["P_ClassID"].ToString() != "")
{
model.P_ClassID = int.Parse(ds.Tables[0].Rows[0]["P_ClassID"].ToString());
}
if (ds.Tables[0].Rows[0]["P_ParentID"].ToString() != "")
{
model.P_ParentID = int.Parse(ds.Tables[0].Rows[0]["P_ParentID"].ToString());
}
model.P_ClassCode = ds.Tables[0].Rows[0]["P_ClassCode"].ToString();
if (ds.Tables[0].Rows[0]["P_Show"].ToString() != "")
{
model.P_Show = int.Parse(ds.Tables[0].Rows[0]["P_Show"].ToString());
}
model.P_Demo = ds.Tables[0].Rows[0]["P_Demo"].ToString();
model.P_Content = ds.Tables[0].Rows[0]["P_Content"].ToString();
model.P_PhotoUrl = ds.Tables[0].Rows[0]["P_PhotoUrl"].ToString();
model.P_PhotoUrlSmall = ds.Tables[0].Rows[0]["P_PhotoUrlSmall"].ToString();
if (ds.Tables[0].Rows[0]["P_Uptime"].ToString() != "")
{
model.P_Uptime = DateTime.Parse(ds.Tables[0].Rows[0]["P_Uptime"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select [Product].*,[ProductClass].PC_ClassName ");
strSql.Append(" FROM [Product] inner join [ProductClass] ");
strSql.Append(" on [Product].P_ClassID=[ProductClass].PC_ID");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by P_ID desc");
return DbHelperOledb.Query(strSql.ToString());
}
/// <summary>
/// 获得符合查询条件的前Num记录
/// </summary>
/// <param name="num">要查询的条数</param>
/// <param name="strWhere">查询条件</param>
/// <returns></returns>
public DataSet GetList(int num, string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top " + num + " [Product].*,[ProductClass].PC_ClassName ");
strSql.Append(" FROM [Product] inner join [ProductClass] ");
strSql.Append(" on [Product].P_ClassID=[ProductClass].PC_ID");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by P_ID desc");
return DbHelperOledb.Query(strSql.ToString());
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL;
namespace BLL
{
public class Product
{
public Product()
{ }
DAL.Product dal = new DAL.Product();
public bool Exists(int P_ID)
{
return dal.Exists(P_ID);
}
public int Count()
{
return dal.Count();
}
/// <summary>
/// 增加一条数据
/// </summary>
public void Add(Model.Product model)
{
dal.Add(model);
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(Model.Product model)
{
dal.Update(model);
}
/// <summary>
/// 删除一条数据
/// </summary>
public void Delete(int P_ID)
{
dal.Delete(P_ID);
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.Product GetModel(int P_ID)
{
return dal.GetModel(P_ID);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
return dal.GetList(strWhere);
}
/// <summary>
/// 获得符合查询条件的前Num记录
/// </summary>
/// <param name="num">要查询的条数</param>
/// <param name="strWhere">查询条件</param>
/// <returns></returns>
public DataSet GetList(int num, string strWhere)
{
return dal.GetList(num, strWhere);
}
public List<Model.Product> GetModelList(string strWhere)
{
DataSet ds = dal.GetList(strWhere);
return DataTableToList(ds.Tables[0]);
}
public List<Model.Product> DataTableToList(DataTable dt)
{
List<Model.Product> modelList=new List<Model.Product>();
int rowsCount = dt.Rows.Count;
if(rowsCount>0)
{
Model.Product model;
for (int n = 0; n < rowsCount;n++ )
{
model = new Model.Product();
if (dt.Rows[n]["P_ID"].ToString() != "")
{
model.P_ID = int.Parse(dt.Rows[n]["P_ID"].ToString());
}
model.P_Name = dt.Rows[n]["P_Name"].ToString();
if (dt.Rows[n]["P_ClassID"].ToString() != "")
{
model.P_ClassID = int.Parse(dt.Rows[n]["P_ClassID"].ToString());
}
if (dt.Rows[n]["P_ParentID"].ToString() != "")
{
model.P_ParentID = int.Parse(dt.Rows[n]["P_ParentID"].ToString());
}
model.P_ClassCode = dt.Rows[n]["P_ClassCode"].ToString();
if (dt.Rows[n]["P_Show"].ToString() != "")
{
model.P_Show = int.Parse(dt.Rows[n]["P_Show"].ToString());
}
model.P_Demo = dt.Rows[n]["P_Demo"].ToString();
model.P_Content = dt.Rows[n]["P_Content"].ToString();
model.P_PhotoUrl = dt.Rows[n]["P_PhotoUrl"].ToString();
model.P_PhotoUrlSmall = dt.Rows[n]["P_PhotoUrlSmall"].ToString();
if (dt.Rows[n]["P_Uptime"].ToString() != "")
{
model.P_Uptime = DateTime.Parse(dt.Rows[n]["P_Uptime"].ToString());
}
modelList.Add(model);
}
}
return modelList;
}
public DataSet GetAllList()
{
return GetList("");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Model
{
public class Product
{
public Product()
{ }
#region Model
private int? _p_id;
private string _p_name;
private int _p_classid;
private int _p_parentid;
private string _p_classcode;
private int _p_show;
private string _p_demo;
private string _p_content;
private string _p_photourl;
private string _p_photourlsmall;
private DateTime _p_uptime;
public int? P_ID
{
set { _p_id = value; }
get { return _p_id; }
}
/// <summary>
///
/// </summary>
public string P_Name
{
set { _p_name = value; }
get { return _p_name; }
}
/// <summary>
///
/// </summary>
public int P_ClassID
{
set { _p_classid = value; }
get { return _p_classid; }
}
/// <summary>
///
/// </summary>
public int P_ParentID
{
set { _p_parentid = value; }
get { return _p_parentid; }
}
/// <summary>
///
/// </summary>
public string P_ClassCode
{
set { _p_classcode = value; }
get { return _p_classcode; }
}
/// <summary>
///
/// </summary>
public int P_Show
{
set { _p_show = value; }
get { return _p_show; }
}
/// <summary>
///
/// </summary>
public string P_Demo
{
set { _p_demo = value; }
get { return _p_demo; }
}
/// <summary>
///
/// </summary>
public string P_Content
{
set { _p_content = value; }
get { return _p_content; }
}
/// <summary>
///
/// </summary>
public string P_PhotoUrl
{
set { _p_photourl = value; }
get { return _p_photourl; }
}
/// <summary>
///
/// </summary>
public string P_PhotoUrlSmall
{
set { _p_photourlsmall = value; }
get { return _p_photourlsmall; }
}
/// <summary>
///
/// </summary>
public DateTime P_Uptime
{
set { _p_uptime = value; }
get { return _p_uptime; }
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBUtility;
using Model;
using System.Data;
namespace DAL
{
public class ProductClass
{
public ProductClass()
{ }
#region 成员方法
///<summary>
///是否存在该记录
/// </summary>
public bool Exists(int PC_Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) from ProductClass");
strSql.Append("where PC_Id=" + PC_Id + "");
return DbHelperOledb.Exists(strSql.ToString());
}
///<summary>
///增加一条数据
/// </summary>
public void Add(Model.ProductClass model)
{
StringBuilder strSql = new StringBuilder();
StringBuilder strSql1 = new StringBuilder();
StringBuilder strSql2 = new StringBuilder();
if(model.PC_Id!=null)
{
strSql1.Append("PC_Id");
strSql2.Append(""+ model.PC_Id +",");
}
if (model.PC_ClassName != null)
{
strSql1.Append("PC_ClassName,");
strSql2.Append("'" + model.PC_ClassName + "',");
}
if (model.PC_ParentID != null)
{
strSql1.Append("PC_ParentID,");
strSql2.Append("" + model.PC_ParentID + ",");
}
if (model.PC_ClassCode != null)
{
strSql1.Append("PC_ClassCode,");
strSql2.Append("'" + model.PC_ClassCode + "',");
}
if (model.PC_ClassLevel != null)
{
strSql1.Append("PC_ClassLevel,");
strSql2.Append("" + model.PC_ClassLevel + ",");
}
if (model.PC_ClassIsLock != null)
{
strSql1.Append("PC_ClassIsLock,");
strSql2.Append("" + (model.PC_ClassIsLock ? 1 : 0) + ",");
}
strSql.Append("insert into ProductClass(");
strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
strSql.Append(")");
strSql.Append(" value(");
strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
strSql.Append(")");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(Model.ProductClass model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update ProductClass set ");
if (model.PC_Id != null)
{
strSql.Append("PC_Id=" + model.PC_Id + ",");
}
if (model.PC_ClassName != null)
{
strSql.Append("PC_ClassName='" + model.PC_ClassName + "',");
}
if (model.PC_ParentID != null)
{
strSql.Append("PC_ParentID=" + model.PC_ParentID + ",");
}
if (model.PC_ClassCode != null)
{
strSql.Append("PC_ClassCode='" + model.PC_ClassCode + "',");
}
if (model.PC_ClassLevel != null)
{
strSql.Append("PC_ClassLevel=" + model.PC_ClassLevel + ",");
}
if (model.PC_ClassIsLock != null)
{
strSql.Append("PC_ClassIsLock=" + (model.PC_ClassIsLock ? 1 : 0) + ",");
}
int n = strSql.ToString().LastIndexOf(",");
strSql.Remove(n, 1);
strSql.Append(" where PC_Id=" + model.PC_Id + " ");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 删除一条数据
/// </summary>
public void Delete(int PC_Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from ProductClass ");
strSql.Append(" where PC_Id=" + PC_Id + " ");
DbHelperOledb.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.ProductClass GetModel(int PC_Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
strSql.Append(" PC_Id,PC_ClassName,PC_ParentID,PC_ClassCode,PC_ClassLevel,PC_ClassIsLock ");
strSql.Append(" from ProductClass ");
strSql.Append(" where PC_Id=" + PC_Id + " ");
Model.ProductClass model = new Model.ProductClass();
DataSet ds = DbHelperOledb.Query(strSql.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["PC_Id"].ToString() != "")
{
model.PC_Id = int.Parse(ds.Tables[0].Rows[0]["PC_Id"].ToString());
}
model.PC_ClassName = ds.Tables[0].Rows[0]["PC_ClassName"].ToString();
if (ds.Tables[0].Rows[0]["PC_ParentID"].ToString() != "")
{
model.PC_ParentID = int.Parse(ds.Tables[0].Rows[0]["PC_ParentID"].ToString());
}
model.PC_ClassCode = ds.Tables[0].Rows[0]["PC_ClassCode"].ToString();
if (ds.Tables[0].Rows[0]["PC_ClassLevel"].ToString() != "")
{
model.PC_ClassLevel = int.Parse(ds.Tables[0].Rows[0]["PC_ClassLevel"].ToString());
}
if (ds.Tables[0].Rows[0]["PC_ClassIsLock"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["PC_ClassIsLock"].ToString() == "1") || (ds.Tables[0].Rows[0]["PC_ClassIsLock"].ToString().ToLower() == "true"))
{
model.PC_ClassIsLock = true;
}
else
{
model.PC_ClassIsLock = false;
}
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select PC_Id,PC_ClassName,PC_ParentID,PC_ClassCode,PC_ClassLevel,PC_ClassIsLock ");
strSql.Append(" FROM ProductClass ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by PC_ClassCode");
return DbHelperOledb.Query(strSql.ToString());
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;
namespace BLL
{
public class ProductClass
{
private readonly DAL.ProductClass dal = new DAL.ProductClass();
public ProductClass()
{ }
#region 成员方法
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int PC_Id)
{
return dal.Exists(PC_Id);
}
/// <summary>
/// 增加一条数据
/// </summary>
public void Add(Model.ProductClass model)
{
dal.Add(model);
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(Model.ProductClass model)
{
dal.Update(model);
}
/// <summary>
/// 删除一条数据
/// </summary>
public void Delete(int PC_Id)
{
dal.Delete(PC_Id);
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.ProductClass GetModel(int PC_Id)
{
return dal.GetModel(PC_Id);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
return dal.GetList(strWhere);
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<Model.ProductClass> GetModelList(string strWhere)
{
DataSet ds = dal.GetList(strWhere);
return DataTableToList(ds.Tables[0]);
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<Model.ProductClass> DataTableToList(DataTable dt)
{
List<Model.ProductClass> modelList = new List<Model.ProductClass>();
int rowsCount = dt.Rows.Count;
if(rowsCount > 0)
{
Model.ProductClass model;
for (int n = 0; n < rowsCount; n++ )
{
model = new Model.ProductClass();
if(dt.Rows[n]["PC_Id"].ToString() != "")
{
model.PC_Id = int.Parse(dt.Rows[n]["PC_Id"].ToString());
}
model.PC_ClassName = dt.Rows[n]["PC_ClassName"].ToString();
if(dt.Rows[n]["PC_ParengtID"].ToString() != "")
{
model.PC_ParentID = int.Parse(dt.Rows[n]["PC_ParentID"].ToString());
}
model.PC_ClassCode = dt.Rows[n]["PC_ClassCode"].ToString();
if (dt.Rows[n]["PC_ClassLevel"].ToString() != "")
{
model.PC_ClassLevel = int.Parse(dt.Rows[n]["PC_ClassLevel"].ToString());
}
if (dt.Rows[n]["PC_ClassIsLock"].ToString() != "")
{
if ((dt.Rows[n]["PC_ClassIsLock"].ToString() == "1") || (dt.Rows[n]["PC_ClassIsLock"].ToString().ToLower() == "true"))
{
model.PC_ClassIsLock = true;
}
else
{
model.PC_ClassIsLock = false;
}
}
modelList.Add(model);
}
}
return modelList;
}
///<summary>
///获得数据列表
/// </summary>
public DataSet GetAllList()
{
return GetList("");
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace Model
{
public class ProductClass
{
public ProductClass()
{ }
#region Model
private int? _pc_id;
private string _pc_classname;
private int _pc_parentid;
private string _pc_classcode;
private int _pc_classlevel;
private bool _pc_classislock;
public int? PC_Id
{
set { _pc_id = value; }
get { return _pc_id; }
}
public string PC_ClassName
{
set { _pc_classname = value; }
get { return _pc_classname; }
}
public int PC_ParentID
{
set { _pc_parentid = value; }
get { return _pc_parentid; }
}
public string PC_ClassCode
{
set { _pc_classcode = value; }
get { return _pc_classcode; }
}
public int PC_ClassLevel
{
set { _pc_classlevel = value; }
get { return _pc_classlevel; }
}
public bool PC_ClassIsLock
{
set { _pc_classislock = value; }
get { return _pc_classislock; }
}
#endregion
}
}