sumuptypeDAL.cs
上传用户:lishan0805
上传日期:2019-12-08
资源大小:12048k
文件大小:19k
源码类别:

OA系统

开发平台:

C#

  1. // =================================================================== 
  2. // 产品(COM.OA.SqlServerDAL)项目
  3. //====================================================================
  4. // wangyp @Copy Right 2006-2008
  5. // 文件:sumuptypeDAL.cs
  6. // 项目名称:工程项目管理
  7. // 创建时间:2008-9-23
  8. // 负责人:wangyp
  9. // 先创建SqlHelper.cs文件,引用System.Configuration程序集和实体(COM.OA.Entity)、产品规则(COM.OA.IDAL)项目、引用业务逻辑(COM.OA.BLL)项目
  10. // ===================================================================
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Data.SqlClient;
  16. using System.Text;
  17. using COM.OA.Entity;
  18. using COM.OA.IDAL;
  19. using COM.OA.BLL;
  20. namespace COM.OA.SqlServerDAL
  21. {
  22.     /// <summary>
  23.     /// 数据访问层dbo.sumuptype
  24.     /// </summary>
  25.     public partial class sumuptypeDAL : IsumuptypeDAL
  26.     {
  27.         #region 构造函数
  28.         /// <summary>
  29.         /// 数据层实例化
  30.         /// </summary>
  31.         public sumuptypeDAL()
  32.         {
  33.         }
  34.         #endregion
  35.         #region -----------实例化接口函数-----------
  36.         #region 添加
  37.         /// <summary>
  38.         /// 向数据库中插入一条新记录
  39.         /// </summary>
  40.         /// <param name="sumuptype">sumuptype实体对象</param>
  41.         /// <returns></returns>
  42.         public int Insert(sumuptype sumuptype)
  43.         {
  44.             string sqlCommand = "sumuptypeInsert";
  45.             int res;
  46.             SqlParameter[] param ={
  47. new SqlParameter("@st_id",SqlDbType.Int),
  48. new SqlParameter("@st_type",SqlDbType.VarChar)
  49. };
  50.             param[0].Direction = ParameterDirection.Output;
  51.             param[1].Value = sumuptype.st_type;
  52.             res = SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
  53.             sumuptype.st_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
  54.             return res;
  55.         }
  56.         /// <summary>
  57.         /// 向数据库中插入一条新记录。带事务
  58.         /// </summary>
  59.         /// <param name="sp">事务对象</param>
  60.         /// <param name="sumuptype">sumuptype实体对象</param>
  61.         /// <returns></returns>
  62.         public int Insert(SqlTransaction sp, sumuptype sumuptype)
  63.         {
  64.             string sqlCommand = "sumuptypeInsert";
  65.             int res;
  66.             SqlParameter[] param ={
  67. new SqlParameter("@st_id",SqlDbType.Int),
  68. new SqlParameter("@st_type",SqlDbType.VarChar)
  69. };
  70.             param[0].Direction = ParameterDirection.Output;
  71.             param[1].Value = sumuptype.st_type;
  72.             res = SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
  73.             sumuptype.st_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
  74.             return res;
  75.         }
  76.         #endregion
  77.         #region 更新
  78.         /// <summary>
  79.         /// 向数据表sumuptype更新一条记录
  80.         /// </summary>
  81.         /// <param name="sumuptype">sumuptype实体对象</param>
  82.         /// <returns></returns>
  83.         public int Update(sumuptype sumuptype)
  84.         {
  85.             string sqlCommand = "sumuptypeUpdate";
  86.             SqlParameter[] param ={
  87. new SqlParameter("@st_id",SqlDbType.Int),
  88. new SqlParameter("@st_type",SqlDbType.VarChar)
  89. };
  90.             param[0].Value = sumuptype.st_id;
  91.             param[1].Value = sumuptype.st_type;
  92.             return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
  93.         }
  94.         /// <summary>
  95.         /// 向数据表sumuptype更新一条记录。带事务
  96.         /// </summary>
  97.         /// <param name="sp">事务对象</param>
  98.         /// <param name="sumuptype">sumuptype实体对象</param>
  99.         /// <returns></returns>
  100.         public int Update(SqlTransaction sp, sumuptype sumuptype)
  101.         {
  102.             string sqlCommand = "sumuptypeUpdate";
  103.             SqlParameter[] param ={
  104. new SqlParameter("@st_id",SqlDbType.Int),
  105. new SqlParameter("@st_type",SqlDbType.VarChar)
  106. };
  107.             param[0].Value = sumuptype.st_id;
  108.             param[1].Value = sumuptype.st_type;
  109.             return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
  110.         }
  111.         #endregion
  112.         #region 删除
  113.         /// <summary>
  114.         /// 删除数据表sumuptype中的一条记录
  115.         /// </summary>
  116.         /// <param name="st_id">st_id</param>
  117.         /// <returns></returns>
  118.         public int Delete(int st_id)
  119.         {
  120.             string sqlCommand = "sumuptypeDelete";
  121.             SqlParameter[] param ={
  122. new SqlParameter("@st_id",SqlDbType.Int)
  123. };
  124.             param[0].Value = st_id;
  125.             return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
  126.         }
  127.         /// <summary>
  128.         /// 删除数据表sumuptype中的一条记录
  129.         /// </summary>
  130.         /// <param name="sumuptype">sumuptype实体对象</param>
  131.         /// <returns></returns>
  132.         public int Delete(sumuptype sumuptype)
  133.         {
  134.             string sqlCommand = "sumuptypeDelete";
  135.             SqlParameter[] param ={
  136. new SqlParameter("@st_id",SqlDbType.Int)
  137. };
  138.             param[0].Value = sumuptype.st_id;
  139.             return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
  140.         }
  141.         /// <summary>
  142.         /// 删除数据表sumuptype中的一条记录,带事务
  143.         /// </summary>
  144.         /// <param name="sp">事务对象</param>
  145.         /// <param name="st_id">st_id</param>
  146.         /// <returns></returns>
  147.         public int Delete(SqlTransaction sp, int st_id)
  148.         {
  149.             string sqlCommand = "sumuptypeDelete";
  150.             SqlParameter[] param ={
  151. new SqlParameter("@st_id",SqlDbType.Int)
  152. };
  153.             param[0].Value = st_id;
  154.             return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
  155.         }
  156.         /// <summary>
  157.         /// 删除数据表sumuptype中的一条记录,带事务
  158.         /// </summary>
  159.         /// <param name="sp">事务对象</param>
  160.         /// <param name="sumuptype">sumuptype实体对象</param>
  161.         /// <returns></returns>
  162.         public int Delete(SqlTransaction sp, sumuptype sumuptype)
  163.         {
  164.             string sqlCommand = "sumuptypeDelete";
  165.             SqlParameter[] param ={
  166. new SqlParameter("@st_id",SqlDbType.Int)
  167. };
  168.             param[0].Value = sumuptype.st_id;
  169.             return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
  170.         }
  171.         #endregion
  172.         #region 实体对象
  173.         /// <summary>
  174.         /// 得到sumuptype实体对象
  175.         /// </summary>
  176.         /// <param name="row">row</param>
  177.         /// <returns>sumuptype实体对象</returns>
  178.         public sumuptype Select(DataRow row)
  179.         {
  180.             sumuptype obj = new sumuptype();
  181.             if (row != null)
  182.             {
  183.                 obj.st_id = ((row["st_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["st_id"]);
  184.                 obj.st_type = row["st_type"].ToString();
  185.             }
  186.             else
  187.             {
  188.                 return null;
  189.             }
  190.             return obj;
  191.         }
  192.         /// <summary>
  193.         /// 得到sumuptype实体对象
  194.         /// </summary>
  195.         /// <param name="dr">dr</param>
  196.         /// <returns>sumuptype实体对象</returns>
  197.         public sumuptype Select(IDataReader dr)
  198.         {
  199.             sumuptype obj = new sumuptype();
  200.             obj.st_id = ((dr["st_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["st_id"]);
  201.             obj.st_type = dr["st_type"].ToString();
  202.             return obj;
  203.         }
  204.         /// <summary>
  205.         /// 根据ID,返回一个sumuptype实体对象
  206.         /// </summary>
  207.         /// <param name="st_id">st_id</param>
  208.         /// <returns>sumuptype实体对象</returns>
  209.         public sumuptype Select(int st_id)
  210.         {
  211.             return this.Select(st_id, false, false);
  212.         }
  213.         /// <summary>
  214.         /// 根据ID,返回一个sumuptype实体对象
  215.         /// </summary>
  216.         /// <param name="st_id">st_id</param>
  217.         /// <param name="bParentTable">将sumuptype对象设置与父表关联</param>
  218.         /// <param name="bChildrenTable">将sumuptype对象设置与子表关联</param>
  219.         /// <returns>sumuptype实体对象</returns>
  220.         public sumuptype Select(int st_id, bool bParentTable, bool bChildrenTable)
  221.         {
  222.             sumuptype obj = null;
  223.             SqlParameter[] param ={
  224. new SqlParameter("@st_id",SqlDbType.Int)
  225. };
  226.             param[0].Value = st_id;
  227.             string sqlCommand = "sumuptypeSelect";
  228.             using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
  229.             {
  230.                 while (dr.Read())
  231.                 {
  232.                     obj = this.Select(dr);
  233.                 }
  234.             }
  235.             this.Select(obj, bParentTable, bChildrenTable);
  236.             return obj;
  237.         }
  238.         /// <summary>
  239.         /// 将sumuptype实体对象设置与父表和子表关联
  240.         /// </summary>
  241.         /// <param name="obj">sumuptype实体对象</param>
  242.         /// <param name="bParentTable">是/否设置与父表对象关联</param>
  243.         /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
  244.         public void Select(sumuptype obj, bool bParentTable, bool bChildrenTable)
  245.         {
  246.             //关联的主表
  247.             if (bParentTable)
  248.             {
  249.             }
  250.             //关联的子表集合
  251.             if (bChildrenTable)
  252.             {
  253.                 obj.worksumup = worksumupBLL.Select("ws_st_id=" + obj.st_id.ToString());
  254.                 foreach (worksumup item in obj.worksumup)
  255.                 {
  256.                     item.sumuptype = obj;
  257.                 }
  258.             }
  259.         }
  260.         #endregion
  261.         #region 父表
  262.         #endregion
  263.         #region 子表
  264.         /// <summary>
  265.         /// 设置实体对象(sumuptype)的子表对象
  266.         /// </summary>
  267.         /// <param name="sumuptype">实体对象</param>
  268.         public void worksumup(sumuptype sumuptype)
  269.         {
  270.             sumuptype.worksumup = worksumupBLL.Select("ws_st_id=" + sumuptype.st_id.ToString());
  271.         }
  272.         #endregion
  273.         #region 查询
  274.         /// <summary>
  275.         /// 得到数据表sumuptype所有记录
  276.         /// </summary>
  277.         /// <returns>结果集</returns>
  278.         public IList<sumuptype> Select()
  279.         {
  280.             return this.Select(false, false);
  281.         }
  282.         /// <summary>
  283.         /// 得到数据表sumuptype所有记录
  284.         /// </summary>
  285.         /// <param name="bParentTable">是/否设置与父表对象关联</param>
  286.         /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
  287.         /// <returns>结果集</returns>
  288.         public IList<sumuptype> Select(bool bParentTable, bool bChildrenTable)
  289.         {
  290.             IList<sumuptype> list = new List<sumuptype>();
  291.             string sqlCommand = "sumuptypeSelectAll";
  292.             using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand))
  293.             {
  294.                 while (dr.Read())
  295.                 {
  296.                     list.Add(this.Select(dr));
  297.                 }
  298.             }
  299.             foreach (sumuptype obj in list)
  300.             {
  301.                 this.Select(obj, bParentTable, bChildrenTable);
  302.             }
  303.             return list;
  304.         }
  305.         /// <summary>
  306.         /// 得到数据表sumuptype满足查询条件的记录
  307.         /// </summary>
  308.         /// <param name="where">查询条件</param>
  309.         /// <returns>结果集</returns>
  310.         public IList<sumuptype> Select(string where)
  311.         {
  312.             return this.Select(where, false, false);
  313.         }
  314.         /// <summary>
  315.         /// 得到数据表sumuptype满足查询条件的记录
  316.         /// </summary>
  317.         /// <param name="where">查询条件</param>
  318.         /// <param name="bParentTable">是/否设置与父表对象关联</param>
  319.         /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
  320.         /// <returns>结果集</returns>
  321.         public IList<sumuptype> Select(string where, bool bParentTable, bool bChildrenTable)
  322.         {
  323.             IList<sumuptype> list = new List<sumuptype>();
  324.             SqlParameter[] param ={
  325. new SqlParameter("@where",SqlDbType.VarChar,8000)
  326. };
  327.             param[0].Value = where;
  328.             string sqlCommand = "sumuptypeSelectByParams";
  329.             using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
  330.             {
  331.                 while (dr.Read())
  332.                 {
  333.                     list.Add(this.Select(dr));
  334.                 }
  335.             }
  336.             foreach (sumuptype obj in list)
  337.             {
  338.                 this.Select(obj, bParentTable, bChildrenTable);
  339.             }
  340.             return list;
  341.         }
  342.         /// <summary>
  343.         /// 得到数据表ArticalInfo满足外键字段查询条件的记录
  344.         /// </summary>
  345.         /// <param name="foreignFieldName">外键字段名称</param>
  346.         /// <param name="foreignFieldValue">外键字段值</param>
  347.         /// <returns>结果集</returns>
  348.         public IList<sumuptype> Select(string foreignFieldName, int foreignFieldValue)
  349.         {
  350.             return this.Select(foreignFieldName, foreignFieldValue, false, false);
  351.         }
  352.         /// <summary>
  353.         /// 得到数据表ArticalInfo满足外键字段查询条件的记录
  354.         /// </summary>
  355.         /// <param name="foreignFieldName">外键字段名称</param>
  356.         /// <param name="foreignFieldValue">外键字段值</param>
  357.         /// <param name="bParentTable">是/否设置与父表对象关联</param>
  358.         /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
  359.         /// <returns>结果集</returns>
  360.         public IList<sumuptype> Select(string foreignFieldName, int foreignFieldValue, bool bParentTable, bool bChildrenTable)
  361.         {
  362.             return this.Select(string.Format("{0}='{1}'", foreignFieldName, foreignFieldValue), bParentTable, bChildrenTable);
  363.         }
  364.         /// <summary>
  365.         /// 得到数据表sumuptype满足查询条件的记录数
  366.         /// </summary>
  367.         /// <param name="where">查询条件</param>
  368.         /// <param name="recordCount">记录数</param>
  369.         public void Select(string where, out int recordCount)
  370.         {
  371.             string sqlCommand = "sumuptypeCountByWhere";
  372.             SqlParameter[] param ={
  373. new SqlParameter("@where",SqlDbType.VarChar,8000),
  374. new SqlParameter("@recordCount",SqlDbType.Int)
  375. };
  376.             param[0].Value = where;
  377.             param[1].Direction = ParameterDirection.Output;
  378.             SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
  379.             recordCount = Convert.ToInt32(param[1].Value);
  380.         }
  381.         /// <summary>
  382.         /// 得到数据表sumuptype满足查询条件的分页记录
  383.         /// </summary>
  384.         /// <param name="pageSize">每页显示记录数</param>
  385.         /// <param name="pageIndex">当前显示第几页</param>
  386.         /// <param name="where">查询条件</param>
  387.         /// <returns>结果集</returns>
  388.         public IList<sumuptype> Select(int pageSize, int pageIndex, string where)
  389.         {
  390.             return this.Select(pageSize, pageIndex, where, false, false);
  391.         }
  392.         /// <summary>
  393.         /// 得到数据表sumuptype满足查询条件的分页记录
  394.         /// </summary>
  395.         /// <param name="pageSize">每页显示记录数</param>
  396.         /// <param name="pageIndex">当前显示第几页</param>
  397.         /// <param name="where">查询条件</param>
  398.         /// <param name="bParentTable">是/否设置与父表对象关联</param>
  399.         /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
  400.         /// <returns>结果集</returns>
  401.         public IList<sumuptype> Select(int pageSize, int pageIndex, string where, bool bParentTable, bool bChildrenTable)
  402.         {
  403.             IList<sumuptype> list = new List<sumuptype>();
  404.             string sqlCommand = "sumuptypeSelectByPagerParams";
  405.             SqlParameter[] param ={
  406. new SqlParameter("@pageSize",SqlDbType.Int),
  407. new SqlParameter("@pageIndex",SqlDbType.Int),
  408. new SqlParameter("@where",SqlDbType.VarChar,8000)
  409. };
  410.             param[0].Value = pageSize;
  411.             param[1].Value = pageIndex;
  412.             param[2].Value = where;
  413.             using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
  414.             {
  415.                 while (dr.Read())
  416.                 {
  417.                     list.Add(this.Select(dr));
  418.                 }
  419.             }
  420.             foreach (sumuptype obj in list)
  421.             {
  422.                 this.Select(obj, bParentTable, bChildrenTable);
  423.             }
  424.             return list;
  425.         }
  426.         /// <summary>
  427.         /// 得到数据表sumuptype满足查询条件记录
  428.         /// </summary>
  429.         /// <param name="commandType">命令类型</param>
  430.         /// <param name="sqlCommand">SQL命令</param>
  431.         /// <param name="SqlParameter[]">命令参数数组</param>
  432.         /// <returns>结果集</returns>
  433.         public IList<sumuptype> Select(CommandType commandType, string sqlCommand, params SqlParameter[] param)
  434.         {
  435.             return this.Select(false, false, commandType, sqlCommand, param);
  436.         }
  437.         /// <summary>
  438.         /// 得到数据表sumuptype满足查询条件记录
  439.         /// </summary>
  440.         /// <param name="bParentTable">是/否设置与父表对象关联</param>
  441.         /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
  442.         /// <param name="commandType">命令类型</param>
  443.         /// <param name="sqlCommand">SQL命令</param>
  444.         /// <param name="SqlParameter[]">命令参数数组</param>
  445.         /// <returns>结果集</returns>
  446.         public IList<sumuptype> Select(bool bParentTable, bool bChildrenTable, CommandType commandType, string sqlCommand, params SqlParameter[] param)
  447.         {
  448.             IList<sumuptype> list = new List<sumuptype>();
  449.             using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, commandType, sqlCommand, param))
  450.             {
  451.                 while (dr.Read())
  452.                 {
  453.                     list.Add(this.Select(dr));
  454.                 }
  455.             }
  456.             foreach (sumuptype obj in list)
  457.             {
  458.                 this.Select(obj, bParentTable, bChildrenTable);
  459.             }
  460.             return list;
  461.         }
  462.         /// <summary>
  463.         /// 根据主键检测是否存在该条记录
  464.         /// </summary>
  465.         /// <param name="st_id">st_id</param>
  466.         /// <returns>存在/不存在</returns>
  467.         public bool Exists(int st_id)
  468.         {
  469.             SqlParameter[] param ={
  470.                                  new SqlParameter("@st_id",SqlDbType.Int)
  471.                                  };
  472.             param[0].Value = st_id;
  473.             string sqlCommand = "sumuptypeIsExist";
  474.             int a = Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param));
  475.             if (a > 0)
  476.             {
  477.                 return true;
  478.             }
  479.             else
  480.             {
  481.                 return false;
  482.             }
  483.         }
  484.         #endregion
  485.         #endregion
  486.     }
  487. }