Department.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:8k
- //------------------------------------------------------------------------------
- // 创建标识: 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>
- /// 数据访问类 Department
- /// </summary>
- public class Department : DALHelper
- {
- /// <summary>
- /// 增加一条数据
- /// </summary>
- public int Add(Model.Department model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("INSERT INTO Department(");
- strSql.Append("DeptId,ParentDept,DeptName,DeptNo,TelNo,FaxNo,Manager,Leader1,Leader2,DeptFunc)");
- strSql.Append(" VALUES (");
- strSql.Append("@in_DeptId,@in_ParentDept,@in_DeptName,@in_DeptNo,@in_TelNo,@in_FaxNo,@in_Manager,@in_Leader1,@in_Leader2,@in_DeptFunc)");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_DeptId", DbType.Int32, model.DeptId),
- DataBaseOAHelper.CreateInDbParameter("@in_ParentDept", DbType.Int32, model.ParentDept),
- DataBaseOAHelper.CreateInDbParameter("@in_DeptName", DbType.String, model.DeptName),
- DataBaseOAHelper.CreateInDbParameter("@in_DeptNo", DbType.Int32, model.DeptNo),
- DataBaseOAHelper.CreateInDbParameter("@in_TelNo", DbType.String, model.TelNo),
- DataBaseOAHelper.CreateInDbParameter("@in_FaxNo", DbType.String, model.FaxNo),
- DataBaseOAHelper.CreateInDbParameter("@in_Manager", DbType.String, model.Manager),
- DataBaseOAHelper.CreateInDbParameter("@in_Leader1", DbType.String, model.Leader1),
- DataBaseOAHelper.CreateInDbParameter("@in_Leader2", DbType.String, model.Leader2),
- DataBaseOAHelper.CreateInDbParameter("@in_DeptFunc", DbType.String, model.DeptFunc)};
- return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
- }
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public int Update(Model.Department model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("UPDATE Department SET ");
- strSql.Append("DeptId=@in_DeptId,");
- strSql.Append("ParentDept=@in_ParentDept,");
- strSql.Append("DeptName=@in_DeptName,");
- strSql.Append("DeptNo=@in_DeptNo,");
- strSql.Append("TelNo=@in_TelNo,");
- strSql.Append("FaxNo=@in_FaxNo,");
- strSql.Append("Manager=@in_Manager,");
- strSql.Append("Leader1=@in_Leader1,");
- strSql.Append("Leader2=@in_Leader2,");
- strSql.Append("DeptFunc=@in_DeptFunc");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_DeptId", DbType.Int32, model.DeptId),
- DataBaseOAHelper.CreateInDbParameter("@in_ParentDept", DbType.Int32, model.ParentDept),
- DataBaseOAHelper.CreateInDbParameter("@in_DeptName", DbType.String, model.DeptName),
- DataBaseOAHelper.CreateInDbParameter("@in_DeptNo", DbType.Int32, model.DeptNo),
- DataBaseOAHelper.CreateInDbParameter("@in_TelNo", DbType.String, model.TelNo),
- DataBaseOAHelper.CreateInDbParameter("@in_FaxNo", DbType.String, model.FaxNo),
- DataBaseOAHelper.CreateInDbParameter("@in_Manager", DbType.String, model.Manager),
- DataBaseOAHelper.CreateInDbParameter("@in_Leader1", DbType.String, model.Leader1),
- DataBaseOAHelper.CreateInDbParameter("@in_Leader2", DbType.String, model.Leader2),
- DataBaseOAHelper.CreateInDbParameter("@in_DeptFunc", DbType.String, model.DeptFunc),
- 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 Department ");
- 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 Department", null);
- return DataBaseOAHelper.GetInt(obj);
- }
- /// <summary>
- /// 是否存在该记录
- /// </summary>
- public bool Exists(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT COUNT(1) FROM Department");
- 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.Department GetModel(int ID)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT * FROM Department ");
- strSql.Append(" WHERE ID=@in_ID");
- DbParameter[] cmdParms = {
- DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
- Model.Department 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.Department> GetList()
- {
- StringBuilder strSql = new StringBuilder("SELECT * FROM Department order by deptNo asc");
- using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
- {
- List<Model.Department> lst = GetList(dr);
- return lst;
- }
- }
- /// <summary>
- /// 得到数据条数
- /// </summary>
- public int GetCount(string condition)
- {
- return DataBaseOAHelper.GetCount("Department", condition);
- }
- /// <summary>
- /// 分页获取泛型数据列表
- /// </summary>
- public List<Model.Department> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
- {
- using (DbDataReader dr = DataBaseOAHelper.GetPageList("Department", pageSize, pageIndex, fldSort, fldDir, condition))
- {
- List<Model.Department> lst = GetList(dr);
- return lst;
- }
- }
- #region -------- 私有方法,通常情况下无需修改 --------
- /// <summary>
- /// 由一行数据得到一个实体
- /// </summary>
- private Model.Department GetModel(DbDataReader dr)
- {
- Model.Department model = new Model.Department();
- model.ID = DataBaseOAHelper.GetInt(dr["ID"]);
- model.DeptId = DataBaseOAHelper.GetInt(dr["DeptId"]);
- model.ParentDept = DataBaseOAHelper.GetInt(dr["ParentDept"]);
- model.DeptName = DataBaseOAHelper.GetString(dr["DeptName"]);
- model.DeptNo = DataBaseOAHelper.GetInt(dr["DeptNo"]);
- model.TelNo = DataBaseOAHelper.GetString(dr["TelNo"]);
- model.FaxNo = DataBaseOAHelper.GetString(dr["FaxNo"]);
- model.Manager = DataBaseOAHelper.GetString(dr["Manager"]);
- model.Leader1 = DataBaseOAHelper.GetString(dr["Leader1"]);
- model.Leader2 = DataBaseOAHelper.GetString(dr["Leader2"]);
- model.DeptFunc = DataBaseOAHelper.GetString(dr["DeptFunc"]);
- return model;
- }
- /// <summary>
- /// 由DbDataReader得到泛型数据列表
- /// </summary>
- private List<Model.Department> GetList(DbDataReader dr)
- {
- List<Model.Department> lst = new List<Model.Department>();
- while (dr.Read())
- {
- lst.Add(GetModel(dr));
- }
- return lst;
- }
- #endregion
- }
- }