CarsKeep.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:7k
- //------------------------------------------------------------------------------
- // 创建标识: 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>
- /// 数据访问类 CarsKeep
- /// </summary>
- public class CarsKeep : DALHelper
- {
- /// <summary>
- /// 增加一条数据
- /// </summary>
- public int Add(Model.CarsKeep model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("INSERT INTO CarsKeep(");
- strSql.Append("CPH,WHLX,WHYY,WHRQ,JBR,WHFY,BZ)");
- strSql.Append(" VALUES (");
- strSql.Append("@in_CPH,@in_WHLX,@in_WHYY,@in_WHRQ,@in_JBR,@in_WHFY,@in_BZ)");
DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CPH", DbType.AnsiString, model.CPH),
- DataBaseOAHelper.CreateInDbParameter("@in_WHLX", DbType.AnsiString, model.WHLX),
- DataBaseOAHelper.CreateInDbParameter("@in_WHYY", DbType.AnsiString, model.WHYY),
- DataBaseOAHelper.CreateInDbParameter("@in_WHRQ", DbType.String, model.WHRQ),
- DataBaseOAHelper.CreateInDbParameter("@in_JBR", DbType.AnsiString, model.JBR),
- DataBaseOAHelper.CreateInDbParameter("@in_WHFY", DbType.Currency, model.WHFY),
- DataBaseOAHelper.CreateInDbParameter("@in_BZ", DbType.String, model.BZ)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public int Update(Model.CarsKeep model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("UPDATE CarsKeep SET ");
- strSql.Append("CPH=@in_CPH,");
- strSql.Append("WHLX=@in_WHLX,");
- strSql.Append("WHYY=@in_WHYY,");
- strSql.Append("WHRQ=@in_WHRQ,");
- strSql.Append("JBR=@in_JBR,");
- strSql.Append("WHFY=@in_WHFY,");
- strSql.Append("BZ=@in_BZ");
- strSql.Append(" WHERE Id=@in_Id");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CPH", DbType.AnsiString, model.CPH),
- DataBaseOAHelper.CreateInDbParameter("@in_WHLX", DbType.AnsiString, model.WHLX),
- DataBaseOAHelper.CreateInDbParameter("@in_WHYY", DbType.AnsiString, model.WHYY),
- DataBaseOAHelper.CreateInDbParameter("@in_WHRQ", DbType.String, model.WHRQ),
- DataBaseOAHelper.CreateInDbParameter("@in_JBR", DbType.AnsiString, model.JBR),
- DataBaseOAHelper.CreateInDbParameter("@in_WHFY", DbType.Currency, model.WHFY),
- DataBaseOAHelper.CreateInDbParameter("@in_BZ", DbType.String, model.BZ),
- 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 CarsKeep ");
- 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 CarsKeep", null);
- return DataBaseOAHelper.GetInt(obj);
- }
- /// <summary>
- /// 是否存在该记录
- /// </summary>
- public bool Exists(int Id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT COUNT(1) FROM CarsKeep");
- 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.CarsKeep GetModel(int Id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT * FROM CarsKeep ");
- strSql.Append(" WHERE Id=@in_Id");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_Id", DbType.Int32, Id)};
- Model.CarsKeep 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.CarsKeep> GetList()
- {
- StringBuilder strSql = new StringBuilder("SELECT * FROM CarsKeep");
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
- {
- List<Model.CarsKeep> lst = GetList(dr);
- return lst;
- }
- }
- /// <summary>
- /// 得到数据条数
- /// </summary>
- public int GetCount(string condition)
- {
- return DataBaseOAHelper.GetCount("CarsKeep", condition);
- }
- /// <summary>
- /// 分页获取泛型数据列表
- /// </summary>
- public List<Model.CarsKeep> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
- {
- using (DbDataReader dr = DataBaseOAHelper.GetPageList("CarsKeep", pageSize, pageIndex, fldSort, fldDir, condition))
- {
- List<Model.CarsKeep> lst = GetList(dr);
- return lst;
- }
- }
- #region -------- 私有方法,通常情况下无需修改 --------
- /// <summary>
- /// 由一行数据得到一个实体
- /// </summary>
- private Model.CarsKeep GetModel(DbDataReader dr)
- {
- Model.CarsKeep model = new Model.CarsKeep();
- model.Id = DataBaseOAHelper.GetInt(dr["Id"]);
- model.CPH = DataBaseOAHelper.GetString(dr["CPH"]);
- model.WHLX = DataBaseOAHelper.GetString(dr["WHLX"]);
- model.WHYY = DataBaseOAHelper.GetString(dr["WHYY"]);
- model.WHRQ = DataBaseOAHelper.GetDateTime(dr["WHRQ"]);
- model.JBR = DataBaseOAHelper.GetString(dr["JBR"]);
- model.WHFY = DataBaseOAHelper.GetDecimal(dr["WHFY"]);
- model.BZ = DataBaseOAHelper.GetString(dr["BZ"]);
- return model;
- }
- /// <summary>
- /// 由DbDataReader得到泛型数据列表
- /// </summary>
- private List<Model.CarsKeep> GetList(DbDataReader dr)
- {
- List<Model.CarsKeep> lst = new List<Model.CarsKeep>();
- while (dr.Read())
- {
- lst.Add(GetModel(dr));
- }
- return lst;
- }
- #endregion
- }
- }