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

OA系统

开发平台:

C#

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