DAL层方法 动软生成的
using System;
using System.Data;
using System.Text;
using System.Data.OleDb;
using DbUtility;
namespace DAL
{
/// <summary>
/// 数据访问类:Article
/// </summary>
public partial class Article
{
public Article()
{}
#region Method
/// <summary>
/// 得到最大ID
/// </summary>
public int GetMaxId()
{
return DbHelperOleDb.GetMaxID("Id", "Article");
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int Id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) from Article");
strSql.Append(" where Id=@Id");
OleDbParameter[] parameters = {
new OleDbParameter("@Id", OleDbType.Integer)
};
parameters[0].Value = Id;
return DbHelperOleDb.Exists(strSql.ToString(),parameters);
}
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(Model.Article model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into Article(");
strSql.Append("Title,Keyword,[Describe],PicVedio,Brief,Author,Orilign,Hit,PubTime,[Content],ClassId,Vedio)");
strSql.Append(" values (");
strSql.Append("@Title,@Keyword,@Describe,@PicVedio,@Brief,@Author,@Orilign,@Hit,@PubTime,@Content,@ClassId,@Vedio)");
OleDbParameter[] parameters = {
new OleDbParameter("@Title", OleDbType.VarChar),
new OleDbParameter("@Keyword", OleDbType.VarChar),
new OleDbParameter("@Describe", OleDbType.VarChar),
new OleDbParameter("@PicVedio", OleDbType.VarChar),
new OleDbParameter("@Brief", OleDbType.VarChar),
new OleDbParameter("@Author", OleDbType.VarChar),
new OleDbParameter("@Orilign", OleDbType.VarChar),
new OleDbParameter("@Hit", OleDbType.Integer),
new OleDbParameter("@PubTime", OleDbType.Date),
new OleDbParameter("@Content", OleDbType.VarChar),
new OleDbParameter("@ClassId", OleDbType.Integer),
new OleDbParameter("@Vedio", OleDbType.VarChar)};
parameters[0].Value = model.Title;
parameters[1].Value = model.Keyword;
parameters[2].Value = model.Describe;
parameters[3].Value = model.PicVedio;
parameters[4].Value = model.Brief;
parameters[5].Value = model.Author;
parameters[6].Value = model.Orilign;
parameters[7].Value = model.Hit;
parameters[8].Value = model.PubTime;
parameters[9].Value = model.Content;
parameters[10].Value = model.ClassId;
parameters[11].Value = model.Vedio;
int rows=DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Model.Article model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update Article set ");
strSql.Append("Title=@Title,");
strSql.Append("Keyword=@Keyword,");
strSql.Append("[Describe]=@Describe,");
strSql.Append("PicVedio=@PicVedio,");
strSql.Append("Brief=@Brief,");
strSql.Append("Author=@Author,");
strSql.Append("Orilign=@Orilign,");
strSql.Append("Hit=@Hit,");
strSql.Append("PubTime=@PubTime,");
strSql.Append("Content=@Content,");
strSql.Append("ClassId=@ClassId,");
strSql.Append("Vedio=@Vedio");
strSql.Append(" where Id=@Id");
OleDbParameter[] parameters = {
new OleDbParameter("@Title", OleDbType.VarChar),
new OleDbParameter("@Keyword", OleDbType.VarChar),
new OleDbParameter("@Describe", OleDbType.VarChar),
new OleDbParameter("@PicVedio", OleDbType.VarChar),
new OleDbParameter("@Brief", OleDbType.VarChar),
new OleDbParameter("@Author", OleDbType.VarChar),
new OleDbParameter("@Orilign", OleDbType.VarChar),
new OleDbParameter("@Hit", OleDbType.Integer),
new OleDbParameter("@PubTime", OleDbType.Date),
new OleDbParameter("@Content", OleDbType.VarChar),
new OleDbParameter("@ClassId", OleDbType.Integer),
new OleDbParameter("@Vedio", OleDbType.VarChar) ,
new OleDbParameter("@Id", OleDbType.Integer)
};
parameters[0].Value = model.Title;
parameters[1].Value = model.Keyword;
parameters[2].Value = model.Describe;
parameters[3].Value = model.PicVedio;
parameters[4].Value = model.Brief;
parameters[5].Value = model.Author;
parameters[6].Value = model.Orilign;
parameters[7].Value = model.Hit;
parameters[8].Value = model.PubTime;
parameters[9].Value = model.Content;
parameters[10].Value = model.ClassId;
parameters[11].Value = model.Vedio;
parameters[12].Value = model.Id;
int rows=DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int Id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from Article ");
strSql.Append(" where Id=@Id");
OleDbParameter[] parameters = {
new OleDbParameter("@Id", OleDbType.Integer)
};
parameters[0].Value = Id;
int rows=DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 批量删除数据
/// </summary>
public bool DeleteList(string Idlist )
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from Article ");
strSql.Append(" where Id in ("+Idlist + ") ");
int rows=DbHelperOleDb.ExecuteSql(strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.Article GetModel(int Id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select Id,Title,Keyword,[Describe],PicVedio,Brief,Author,Orilign,Hit,PubTime,[Content],ClassId,Vedio from Article ");
strSql.Append(" where Id=@Id");
OleDbParameter[] parameters = {
new OleDbParameter("@Id", OleDbType.Integer)
};
parameters[0].Value = Id;
Model.Article model=new Model.Article();
DataSet ds=DbHelperOleDb.Query(strSql.ToString(),parameters);
if(ds.Tables[0].Rows.Count>0)
{
if(ds.Tables[0].Rows[0]["Id"]!=null && ds.Tables[0].Rows[0]["Id"].ToString()!="")
{
model.Id=int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
}
if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "")
{
model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
}
else
{
model.Title = "";
}
if (ds.Tables[0].Rows[0]["Keyword"] != null && ds.Tables[0].Rows[0]["Keyword"].ToString() != "")
{
model.Keyword = ds.Tables[0].Rows[0]["Keyword"].ToString();
}
else
{
model.Keyword = "";
}
if (ds.Tables[0].Rows[0]["Describe"] != null && ds.Tables[0].Rows[0]["Describe"].ToString() != "")
{
model.Describe = ds.Tables[0].Rows[0]["Describe"].ToString();
}
else
{
model.Describe = "";
}
if (ds.Tables[0].Rows[0]["PicVedio"] != null && ds.Tables[0].Rows[0]["PicVedio"].ToString() != "")
{
model.PicVedio = ds.Tables[0].Rows[0]["PicVedio"].ToString();
}
else
{
model.PicVedio = "";
}
if (ds.Tables[0].Rows[0]["Brief"] != null && ds.Tables[0].Rows[0]["Brief"].ToString() != "")
{
model.Brief = ds.Tables[0].Rows[0]["Brief"].ToString();
}
else
{
model.Brief = "";
}
if (ds.Tables[0].Rows[0]["Author"] != null && ds.Tables[0].Rows[0]["Author"].ToString() != "")
{
model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
}
else
{
model.Author = "";
}
if (ds.Tables[0].Rows[0]["Orilign"] != null && ds.Tables[0].Rows[0]["Orilign"].ToString() != "")
{
model.Orilign = ds.Tables[0].Rows[0]["Orilign"].ToString();
}
else
{
model.Orilign = "";
}
if (ds.Tables[0].Rows[0]["Hit"] != null && ds.Tables[0].Rows[0]["Hit"].ToString() != "")
{
model.Hit = int.Parse(ds.Tables[0].Rows[0]["Hit"].ToString());
}
else
{
model.Hit = 0;
}
if (ds.Tables[0].Rows[0]["PubTime"] != null && ds.Tables[0].Rows[0]["PubTime"].ToString() != "")
{
model.PubTime = DateTime.Parse(ds.Tables[0].Rows[0]["PubTime"].ToString());
}
if (ds.Tables[0].Rows[0]["Content"] != null && ds.Tables[0].Rows[0]["Content"].ToString() != "")
{
model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
}
else
{
model.Content = "";
}
if(ds.Tables[0].Rows[0]["ClassId"]!=null && ds.Tables[0].Rows[0]["ClassId"].ToString()!="")
{
model.ClassId=int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString());
}
if (ds.Tables[0].Rows[0]["Vedio"] != null && ds.Tables[0].Rows[0]["Vedio"].ToString() != "")
{
model.Vedio = ds.Tables[0].Rows[0]["Vedio"].ToString();
}
else
{
model.Vedio = "";
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select Id,Title,Keyword,[Describe],PicVedio,Brief,Author,Orilign,Hit,PubTime,[Content],ClassId,Vedio,IsRecom ");
strSql.Append(" FROM Article ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
return DbHelperOleDb.Query(strSql.ToString());
}
public DataSet GetListById(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select Id,[Title],Keyword,Article.[Describe],PicVedio,Brief,Author,Orilign,Hit,PubTime,[Content],Article.ClassId ,ZAClass.ClassName,ParentId,Vedio,IsRecom ");
strSql.Append(" FROM Article left join ZAClass on Article.ClassId=ZAClass.ClassId ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperOleDb.Query(strSql.ToString());
}
public string GetDataMaxId(string single)
{
string str = "select Max(Id) from Article where Id<" + Convert.ToInt32(single) + " ";
int i = DbHelperOleDb.Query(str).Tables[0].Rows[0][0].ToString() == "" ? 0 : Convert.ToInt32(DbHelperOleDb.Query(str).Tables[0].Rows[0][0].ToString());
if (i > 0)
{
return DbHelperOleDb.Query(str).Tables[0].Rows[0][0].ToString();
}
else
{
return "0";
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" Id,Title,Keyword,[Describe],PicVedio,Brief,Author,Orilign,Hit,PubTime,[Content],ClassId,Vedio ,IsRecom ");
strSql.Append(" FROM Article ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperOleDb.Query(strSql.ToString());
}
public OleDbDataReader Getreader(string num, string where)
{
string str = "select top " + Convert.ToInt32(num) + " * from Article where " + where + " ";
return DbHelperOleDb.ExecuteReader(str);
}
public bool deletepart(string infold)
{
StringBuilder strSql = new StringBuilder();
strSql.Append(" delete from Article");
if (infold != null && infold.Trim() != string.Empty)
{
strSql.Append(" where Id in(" + infold + ")");
}
object obj = DbHelperOleDb.ExecuteSql(strSql.ToString());
return obj == null ? false : Convert.ToInt32(obj) > 0;
}
#endregion Method
}
}