Sys_Code.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:7k
- //------------------------------------------------------------------------------
- // 创建标识: Copyright (C) 2009 Socansoft.com 版权所有
- // 创建描述: SocanCode代码生成器 V4.3.2.3 自动创建于 2009-11-15 20:10:34
- //
- // 功能描述:
- //
- // 修改标识:
- // 修改描述:
- //------------------------------------------------------------------------------
- using System;
- using System.Data;
- using System.Data.Common;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- namespace SqlServerDAL
- {
- /// <summary>
- /// 数据访问类 Sys_Code
- /// </summary>
- public class Sys_Code : DALHelper
- {
- /// <summary>
- /// 增加一条数据
- /// </summary>
- public int Add(Model.Sys_Code model)
- {
- model.CodeId = GetMaxId() + 1;
- StringBuilder strSql = new StringBuilder();
- strSql.Append("INSERT INTO Sys_Code(");
- strSql.Append("CodeId,CodeNo,CodeName,CodeOrder,CodeRemark,CodeFlag,FuncCode,Reserve)");
- strSql.Append(" VALUES (");
- strSql.Append("@in_CodeId,@in_CodeNo,@in_CodeName,@in_CodeOrder,@in_CodeRemark,@in_CodeFlag,@in_FuncCode,@in_Reserve)");
DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CodeId", DbType.Int32, model.CodeId),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeNo", DbType.String, model.CodeNo),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeName", DbType.String, model.CodeName),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeOrder", DbType.String, model.CodeOrder),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeRemark", DbType.String, model.CodeRemark),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeFlag", DbType.String, model.CodeFlag),
- DataBaseOAHelper.CreateInDbParameter("@in_FuncCode", DbType.String, model.FuncCode),
- DataBaseOAHelper.CreateInDbParameter("@in_Reserve", DbType.Int32, model.Reserve)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public int Update(Model.Sys_Code model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("UPDATE Sys_Code SET ");
- strSql.Append("CodeNo=@in_CodeNo,");
- strSql.Append("CodeName=@in_CodeName,");
- strSql.Append("CodeOrder=@in_CodeOrder,");
- strSql.Append("CodeRemark=@in_CodeRemark,");
- strSql.Append("CodeFlag=@in_CodeFlag,");
- strSql.Append("FuncCode=@in_FuncCode,");
- strSql.Append("Reserve=@in_Reserve");
- strSql.Append(" WHERE CodeId=@in_CodeId");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CodeNo", DbType.String, model.CodeNo),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeName", DbType.String, model.CodeName),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeOrder", DbType.String, model.CodeOrder),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeRemark", DbType.String, model.CodeRemark),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeFlag", DbType.String, model.CodeFlag),
- DataBaseOAHelper.CreateInDbParameter("@in_FuncCode", DbType.String, model.FuncCode),
- DataBaseOAHelper.CreateInDbParameter("@in_Reserve", DbType.Int32, model.Reserve),
- DataBaseOAHelper.CreateInDbParameter("@in_CodeId", DbType.Int32, model.CodeId)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 删除一条数据
- /// </summary>
- public int Delete(int CodeId)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("DELETE FROM Sys_Code ");
- strSql.Append(" WHERE CodeId=@in_CodeId");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CodeId", DbType.Int32, CodeId)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 得到最大ID
- /// </summary>
- public int GetMaxId()
- {
- object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, "SELECT MAX(CodeId) FROM Sys_Code", null);
- return DataBaseOAHelper.GetInt(obj);
- }
- /// <summary>
- /// 是否存在该记录
- /// </summary>
- public bool Exists(int CodeId)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT COUNT(1) FROM Sys_Code");
- strSql.Append(" WHERE CodeId=@in_CodeId");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CodeId", DbType.Int32, CodeId)};
- object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), cmdParms);
- return DataBaseOAHelper.GetInt(obj) > 0;
- }
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public Model.Sys_Code GetModel(int CodeId)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT * FROM Sys_Code ");
- strSql.Append(" WHERE CodeId=@in_CodeId");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_CodeId", DbType.Int32, CodeId)};
- Model.Sys_Code 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.Sys_Code> GetList()
- {
- StringBuilder strSql = new StringBuilder("SELECT * FROM Sys_Code");
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
- {
- List<Model.Sys_Code> lst = GetList(dr);
- return lst;
- }
- }
- /// <summary>
- /// 得到数据条数
- /// </summary>
- public int GetCount(string condition)
- {
- return DataBaseOAHelper.GetCount("Sys_Code", condition);
- }
- /// <summary>
- /// 分页获取泛型数据列表
- /// </summary>
- public List<Model.Sys_Code> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
- {
- using (DbDataReader dr = DataBaseOAHelper.GetPageList("Sys_Code", pageSize, pageIndex, fldSort, fldDir, condition))
- {
- List<Model.Sys_Code> lst = GetList(dr);
- return lst;
- }
- }
- #region -------- 私有方法,通常情况下无需修改 --------
- /// <summary>
- /// 由一行数据得到一个实体
- /// </summary>
- private Model.Sys_Code GetModel(DbDataReader dr)
- {
- Model.Sys_Code model = new Model.Sys_Code();
- model.CodeId = DataBaseOAHelper.GetInt(dr["CodeId"]);
- model.CodeNo = DataBaseOAHelper.GetString(dr["CodeNo"]);
- model.CodeName = DataBaseOAHelper.GetString(dr["CodeName"]);
- model.CodeOrder = DataBaseOAHelper.GetString(dr["CodeOrder"]);
- model.CodeRemark = DataBaseOAHelper.GetString(dr["CodeRemark"]);
- model.CodeFlag = DataBaseOAHelper.GetString(dr["CodeFlag"]);
- model.FuncCode = DataBaseOAHelper.GetString(dr["FuncCode"]);
- model.Reserve = DataBaseOAHelper.GetInt(dr["Reserve"]);
- return model;
- }
- /// <summary>
- /// 由DbDataReader得到泛型数据列表
- /// </summary>
- private List<Model.Sys_Code> GetList(DbDataReader dr)
- {
- List<Model.Sys_Code> lst = new List<Model.Sys_Code>();
- while (dr.Read())
- {
- lst.Add(GetModel(dr));
- }
- return lst;
- }
- #endregion
- }
- }