BBS.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:6k
- //------------------------------------------------------------------------------
- // 创建标识: Copyright (C) 2009 Socansoft.com 版权所有
- // 创建描述: SocanCode代码生成器 V4.3.2.3 自动创建于 2009-12-7 19:55:37
- //
- // 功能描述:
- //
- // 修改标识:
- // 修改描述:
- //------------------------------------------------------------------------------
- using System;
- using System.Data;
- using System.Data.Common;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- namespace SqlServerDAL
- {
- /// <summary>
- /// 数据访问类 BBS
- /// </summary>
- public class BBS : DALHelper
- {
- /// <summary>
- /// 增加一条数据
- /// </summary>
- public int Add(Model.BBS model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("INSERT INTO BBS(");
- strSql.Append("ZT,ZTZZ,HF,DJ,ZHHF,FL,ZTNR)");
- strSql.Append(" VALUES (");
- strSql.Append("@in_ZT,@in_ZTZZ,@in_HF,@in_DJ,@in_ZHHF,@in_FL,@in_ZTNR)");
DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ZT", DbType.AnsiString, model.ZT),
- DataBaseOAHelper.CreateInDbParameter("@in_ZTZZ", DbType.AnsiString, model.ZTZZ),
- DataBaseOAHelper.CreateInDbParameter("@in_HF", DbType.Int32, model.HF),
- DataBaseOAHelper.CreateInDbParameter("@in_DJ", DbType.Int32, model.DJ),
- DataBaseOAHelper.CreateInDbParameter("@in_ZHHF", DbType.String, model.ZHHF),
- DataBaseOAHelper.CreateInDbParameter("@in_FL", DbType.AnsiString, model.FL),
- DataBaseOAHelper.CreateInDbParameter("@in_ZTNR", DbType.String, model.ZTNR)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public int Update(Model.BBS model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("UPDATE BBS SET ");
- strSql.Append("ZT=@in_ZT,");
- strSql.Append("ZTZZ=@in_ZTZZ,");
- strSql.Append("HF=@in_HF,");
- strSql.Append("DJ=@in_DJ,");
- strSql.Append("ZHHF=@in_ZHHF,");
- strSql.Append("FL=@in_FL,");
- strSql.Append("ZTNR=@in_ZTNR");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ZT", DbType.AnsiString, model.ZT),
- DataBaseOAHelper.CreateInDbParameter("@in_ZTZZ", DbType.AnsiString, model.ZTZZ),
- DataBaseOAHelper.CreateInDbParameter("@in_HF", DbType.Int32, model.HF),
- DataBaseOAHelper.CreateInDbParameter("@in_DJ", DbType.Int32, model.DJ),
- DataBaseOAHelper.CreateInDbParameter("@in_ZHHF", DbType.String, model.ZHHF),
- DataBaseOAHelper.CreateInDbParameter("@in_FL", DbType.AnsiString, model.FL),
- DataBaseOAHelper.CreateInDbParameter("@in_ZTNR", DbType.String, model.ZTNR),
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, model.ID)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 删除一条数据
- /// </summary>
- public int Delete(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("DELETE FROM BBS ");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 得到最大ID
- /// </summary>
- public int GetMaxId()
- {
- object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, "SELECT MAX(ID) FROM BBS", null);
- return DataBaseOAHelper.GetInt(obj);
- }
- /// <summary>
- /// 是否存在该记录
- /// </summary>
- public bool Exists(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT COUNT(1) FROM BBS");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), cmdParms);
- return DataBaseOAHelper.GetInt(obj) > 0;
- }
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public Model.BBS GetModel(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT * FROM BBS ");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- Model.BBS model = null;
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), cmdParms))
- {
- while (dr.Read())
- {
- model = GetModel(dr);
- }
- return model;
- }
- }
- /// <summary>
- /// 获取泛型数据列表
- /// </summary>
- public List<Model.BBS> GetList()
- {
- StringBuilder strSql = new StringBuilder("SELECT * FROM BBS");
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
- {
- List<Model.BBS> lst = GetList(dr);
- return lst;
- }
- }
- /// <summary>
- /// 得到数据条数
- /// </summary>
- public int GetCount(string condition)
- {
- return DataBaseOAHelper.GetCount("BBS", condition);
- }
- /// <summary>
- /// 分页获取泛型数据列表
- /// </summary>
- public List<Model.BBS> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
- {
- using (DbDataReader dr = DataBaseOAHelper.GetPageList("BBS", pageSize, pageIndex, fldSort, fldDir, condition))
- {
- List<Model.BBS> lst = GetList(dr);
- return lst;
- }
- }
- #region -------- 私有方法,通常情况下无需修改 --------
- /// <summary>
- /// 由一行数据得到一个实体
- /// </summary>
- private Model.BBS GetModel(DbDataReader dr)
- {
- Model.BBS model = new Model.BBS();
- model.ID = DataBaseOAHelper.GetInt(dr["ID"]);
- model.ZT = DataBaseOAHelper.GetString(dr["ZT"]);
- model.ZTZZ = DataBaseOAHelper.GetString(dr["ZTZZ"]);
- model.HF = DataBaseOAHelper.GetInt(dr["HF"]);
- model.DJ = DataBaseOAHelper.GetInt(dr["DJ"]);
- model.ZHHF = DataBaseOAHelper.GetDateTime(dr["ZHHF"]);
- model.FL = DataBaseOAHelper.GetString(dr["FL"]);
- model.ZTNR = DataBaseOAHelper.GetString(dr["ZTNR"]);
- return model;
- }
- /// <summary>
- /// 由DbDataReader得到泛型数据列表
- /// </summary>
- private List<Model.BBS> GetList(DbDataReader dr)
- {
- List<Model.BBS> lst = new List<Model.BBS>();
- while (dr.Read())
- {
- lst.Add(GetModel(dr));
- }
- return lst;
- }
- #endregion
- }
- }