usersDAL.cs
资源名称:OASystem.rar [点击查看]
上传用户:lishan0805
上传日期:2019-12-08
资源大小:12048k
文件大小:31k
源码类别:
OA系统
开发平台:
C#
- // ===================================================================
- // 产品(COM.OA.SqlServerDAL)项目
- //====================================================================
- // wangyp @Copy Right 2006-2008
- // 文件:usersDAL.cs
- // 项目名称:工程项目管理
- // 创建时间:2008-9-23
- // 负责人:wangyp
- // 先创建SqlHelper.cs文件,引用System.Configuration程序集和实体(COM.OA.Entity)、产品规则(COM.OA.IDAL)项目、引用业务逻辑(COM.OA.BLL)项目
- // ===================================================================
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Text;
- using COM.OA.Entity;
- using COM.OA.IDAL;
- using COM.OA.BLL;
- namespace COM.OA.SqlServerDAL
- {
- /// <summary>
- /// 数据访问层dbo.users
- /// </summary>
- public partial class usersDAL : IusersDAL
- {
- #region 构造函数
- /// <summary>
- /// 数据层实例化
- /// </summary>
- public usersDAL()
- {
- }
- #endregion
- #region -----------实例化接口函数-----------
- #region 添加
- /// <summary>
- /// 向数据库中插入一条新记录
- /// </summary>
- /// <param name="users">users实体对象</param>
- /// <returns></returns>
- public int Insert(users users)
- {
- string sqlCommand = "usersInsert";
- int res;
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int),
- new SqlParameter("@u_username",SqlDbType.VarChar),
- new SqlParameter("@u_password",SqlDbType.VarChar),
- new SqlParameter("@u_dept_id",SqlDbType.Int),
- new SqlParameter("@u_em_id",SqlDbType.Int),
- new SqlParameter("@u_state",SqlDbType.Int),
- new SqlParameter("@u_logintime",SqlDbType.DateTime),
- new SqlParameter("@u_logindegree",SqlDbType.Int),
- new SqlParameter("@u_pwdbind",SqlDbType.VarChar),
- new SqlParameter("@u_g_id",SqlDbType.Int),
- new SqlParameter("@u_landip",SqlDbType.VarChar)
- };
- param[0].Direction = ParameterDirection.Output;
- param[1].Value = users.u_username;
- param[2].Value = users.u_password;
- param[3].Value = users.u_dept_id;
- param[4].Value = users.u_em_id;
- param[5].Value = users.u_state;
- param[6].Value = users.u_logintime;
- param[7].Value = users.u_logindegree;
- param[8].Value = users.u_pwdbind;
- param[9].Value = users.u_g_id;
- param[10].Value = users.u_landip;
- res = SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
- users.u_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
- return res;
- }
- /// <summary>
- /// 向数据库中插入一条新记录。带事务
- /// </summary>
- /// <param name="sp">事务对象</param>
- /// <param name="users">users实体对象</param>
- /// <returns></returns>
- public int Insert(SqlTransaction sp, users users)
- {
- string sqlCommand = "usersInsert";
- int res;
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int),
- new SqlParameter("@u_username",SqlDbType.VarChar),
- new SqlParameter("@u_password",SqlDbType.VarChar),
- new SqlParameter("@u_dept_id",SqlDbType.Int),
- new SqlParameter("@u_em_id",SqlDbType.Int),
- new SqlParameter("@u_state",SqlDbType.Int),
- new SqlParameter("@u_logintime",SqlDbType.DateTime),
- new SqlParameter("@u_logindegree",SqlDbType.Int),
- new SqlParameter("@u_pwdbind",SqlDbType.VarChar),
- new SqlParameter("@u_g_id",SqlDbType.Int),
- new SqlParameter("@u_landip",SqlDbType.VarChar)
- };
- param[0].Direction = ParameterDirection.Output;
- param[1].Value = users.u_username;
- param[2].Value = users.u_password;
- param[3].Value = users.u_dept_id;
- param[4].Value = users.u_em_id;
- param[5].Value = users.u_state;
- param[6].Value = users.u_logintime;
- param[7].Value = users.u_logindegree;
- param[8].Value = users.u_pwdbind;
- param[9].Value = users.u_g_id;
- param[10].Value = users.u_landip;
- res = SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
- users.u_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
- return res;
- }
- #endregion
- #region 更新
- /// <summary>
- /// 向数据表users更新一条记录
- /// </summary>
- /// <param name="users">users实体对象</param>
- /// <returns></returns>
- public int Update(users users)
- {
- string sqlCommand = "usersUpdate";
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int),
- new SqlParameter("@u_username",SqlDbType.VarChar),
- new SqlParameter("@u_password",SqlDbType.VarChar),
- new SqlParameter("@u_dept_id",SqlDbType.Int),
- new SqlParameter("@u_em_id",SqlDbType.Int),
- new SqlParameter("@u_state",SqlDbType.Int),
- new SqlParameter("@u_logintime",SqlDbType.DateTime),
- new SqlParameter("@u_logindegree",SqlDbType.Int),
- new SqlParameter("@u_pwdbind",SqlDbType.VarChar),
- new SqlParameter("@u_g_id",SqlDbType.Int),
- new SqlParameter("@u_landip",SqlDbType.VarChar)
- };
- param[0].Value = users.u_id;
- param[1].Value = users.u_username;
- param[2].Value = users.u_password;
- param[3].Value = users.u_dept_id;
- param[4].Value = users.u_em_id;
- param[5].Value = users.u_state;
- param[6].Value = users.u_logintime;
- param[7].Value = users.u_logindegree;
- param[8].Value = users.u_pwdbind;
- param[9].Value = users.u_g_id;
- param[10].Value = users.u_landip;
- return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
- }
- /// <summary>
- /// 向数据表users更新一条记录。带事务
- /// </summary>
- /// <param name="sp">事务对象</param>
- /// <param name="users">users实体对象</param>
- /// <returns></returns>
- public int Update(SqlTransaction sp, users users)
- {
- string sqlCommand = "usersUpdate";
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int),
- new SqlParameter("@u_username",SqlDbType.VarChar),
- new SqlParameter("@u_password",SqlDbType.VarChar),
- new SqlParameter("@u_dept_id",SqlDbType.Int),
- new SqlParameter("@u_em_id",SqlDbType.Int),
- new SqlParameter("@u_state",SqlDbType.Int),
- new SqlParameter("@u_logintime",SqlDbType.DateTime),
- new SqlParameter("@u_logindegree",SqlDbType.Int),
- new SqlParameter("@u_pwdbind",SqlDbType.VarChar),
- new SqlParameter("@u_g_id",SqlDbType.Int),
- new SqlParameter("@u_landip",SqlDbType.VarChar)
- };
- param[0].Value = users.u_id;
- param[1].Value = users.u_username;
- param[2].Value = users.u_password;
- param[3].Value = users.u_dept_id;
- param[4].Value = users.u_em_id;
- param[5].Value = users.u_state;
- param[6].Value = users.u_logintime;
- param[7].Value = users.u_logindegree;
- param[8].Value = users.u_pwdbind;
- param[9].Value = users.u_g_id;
- param[10].Value = users.u_landip;
- return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
- }
- #endregion
- #region 删除
- /// <summary>
- /// 删除数据表users中的一条记录
- /// </summary>
- /// <param name="u_id">u_id</param>
- /// <returns></returns>
- public int Delete(int u_id)
- {
- string sqlCommand = "usersDelete";
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int)
- };
- param[0].Value = u_id;
- return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
- }
- /// <summary>
- /// 删除数据表users中的一条记录
- /// </summary>
- /// <param name="users">users实体对象</param>
- /// <returns></returns>
- public int Delete(users users)
- {
- string sqlCommand = "usersDelete";
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int)
- };
- param[0].Value = users.u_id;
- return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
- }
- /// <summary>
- /// 删除数据表users中的一条记录,带事务
- /// </summary>
- /// <param name="sp">事务对象</param>
- /// <param name="u_id">u_id</param>
- /// <returns></returns>
- public int Delete(SqlTransaction sp, int u_id)
- {
- string sqlCommand = "usersDelete";
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int)
- };
- param[0].Value = u_id;
- return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
- }
- /// <summary>
- /// 删除数据表users中的一条记录,带事务
- /// </summary>
- /// <param name="sp">事务对象</param>
- /// <param name="users">users实体对象</param>
- /// <returns></returns>
- public int Delete(SqlTransaction sp, users users)
- {
- string sqlCommand = "usersDelete";
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int)
- };
- param[0].Value = users.u_id;
- return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
- }
- #endregion
- #region 实体对象
- /// <summary>
- /// 得到users实体对象
- /// </summary>
- /// <param name="row">row</param>
- /// <returns>users实体对象</returns>
- public users Select(DataRow row)
- {
- users obj = new users();
- if (row != null)
- {
- obj.u_id = ((row["u_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["u_id"]);
- obj.u_username = row["u_username"].ToString();
- obj.u_password = row["u_password"].ToString();
- obj.u_dept_id = ((row["u_dept_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["u_dept_id"]);
- obj.u_em_id = ((row["u_em_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["u_em_id"]);
- obj.u_state = ((row["u_state"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["u_state"]);
- obj.u_logintime = ((row["u_logintime"]) == DBNull.Value) ? DateTime.MinValue : Convert.ToDateTime(row["u_logintime"]);
- obj.u_logindegree = ((row["u_logindegree"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["u_logindegree"]);
- obj.u_pwdbind = row["u_pwdbind"].ToString();
- obj.u_g_id = ((row["u_g_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["u_g_id"]);
- obj.u_landip = row["u_landip"].ToString();
- }
- else
- {
- return null;
- }
- return obj;
- }
- /// <summary>
- /// 得到users实体对象
- /// </summary>
- /// <param name="dr">dr</param>
- /// <returns>users实体对象</returns>
- public users Select(IDataReader dr)
- {
- users obj = new users();
- obj.u_id = ((dr["u_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["u_id"]);
- obj.u_username = dr["u_username"].ToString();
- obj.u_password = dr["u_password"].ToString();
- obj.u_dept_id = ((dr["u_dept_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["u_dept_id"]);
- obj.u_em_id = ((dr["u_em_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["u_em_id"]);
- obj.u_state = ((dr["u_state"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["u_state"]);
- obj.u_logintime = ((dr["u_logintime"]) == DBNull.Value) ? DateTime.MinValue : Convert.ToDateTime(dr["u_logintime"]);
- obj.u_logindegree = ((dr["u_logindegree"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["u_logindegree"]);
- obj.u_pwdbind = dr["u_pwdbind"].ToString();
- obj.u_g_id = ((dr["u_g_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["u_g_id"]);
- obj.u_landip = dr["u_landip"].ToString();
- return obj;
- }
- /// <summary>
- /// 根据ID,返回一个users实体对象
- /// </summary>
- /// <param name="u_id">u_id</param>
- /// <returns>users实体对象</returns>
- public users Select(int u_id)
- {
- return this.Select(u_id, false, false);
- }
- /// <summary>
- /// 根据ID,返回一个users实体对象
- /// </summary>
- /// <param name="u_id">u_id</param>
- /// <param name="bParentTable">将users对象设置与父表关联</param>
- /// <param name="bChildrenTable">将users对象设置与子表关联</param>
- /// <returns>users实体对象</returns>
- public users Select(int u_id, bool bParentTable, bool bChildrenTable)
- {
- users obj = null;
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int)
- };
- param[0].Value = u_id;
- string sqlCommand = "usersSelect";
- using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
- {
- while (dr.Read())
- {
- obj = this.Select(dr);
- }
- }
- this.Select(obj, bParentTable, bChildrenTable);
- return obj;
- }
- /// <summary>
- /// 将users实体对象设置与父表和子表关联
- /// </summary>
- /// <param name="obj">users实体对象</param>
- /// <param name="bParentTable">是/否设置与父表对象关联</param>
- /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
- public void Select(users obj, bool bParentTable, bool bChildrenTable)
- {
- //关联的主表
- if (bParentTable)
- {
- obj.employee = employeeBLL.Select(obj.u_em_id);
- obj.groups = groupsBLL.Select(obj.u_g_id);
- obj.department = departmentBLL.Select(obj.u_dept_id);
- }
- //关联的子表集合
- if (bChildrenTable)
- {
- obj.addresslist = addresslistBLL.Select("al_u_id=" + obj.u_id.ToString());
- foreach (addresslist item in obj.addresslist)
- {
- item.users = obj;
- }
- obj.attendance = attendanceBLL.Select("att_u_id=" + obj.u_id.ToString());
- foreach (attendance item in obj.attendance)
- {
- item.users = obj;
- }
- obj.bbsrevert = bbsrevertBLL.Select("br_u_id=" + obj.u_id.ToString());
- foreach (bbsrevert item in obj.bbsrevert)
- {
- item.users = obj;
- }
- obj.document = documentBLL.Select("doc_u_id=" + obj.u_id.ToString());
- foreach (document item in obj.document)
- {
- item.users = obj;
- }
- obj.examine = examineBLL.Select("ex_u_id=" + obj.u_id.ToString());
- foreach (examine item in obj.examine)
- {
- item.users = obj;
- }
- obj.filerevert = filerevertBLL.Select("fre_u_id=" + obj.u_id.ToString());
- foreach (filerevert item in obj.filerevert)
- {
- item.users = obj;
- }
- obj.files = filesBLL.Select("f_takeu_id=" + obj.u_id.ToString());
- foreach (files item in obj.files)
- {
- item.users = obj;
- }
- obj.message = messageBLL.Select("m_u_id=" + obj.u_id.ToString());
- foreach (message item in obj.message)
- {
- item.users = obj;
- }
- obj.news = newsBLL.Select("n_u_id=" + obj.u_id.ToString());
- foreach (news item in obj.news)
- {
- item.users = obj;
- }
- obj.operate = operateBLL.Select("op_u_id=" + obj.u_id.ToString());
- foreach (operate item in obj.operate)
- {
- item.users = obj;
- }
- obj.sendword = sendwordBLL.Select("sw_u_id=" + obj.u_id.ToString());
- foreach (sendword item in obj.sendword)
- {
- item.users = obj;
- }
- obj.timeorder = timeorderBLL.Select("to_u_id=" + obj.u_id.ToString());
- foreach (timeorder item in obj.timeorder)
- {
- item.users = obj;
- }
- obj.worklog = worklogBLL.Select("w_u_id=" + obj.u_id.ToString());
- foreach (worklog item in obj.worklog)
- {
- item.users = obj;
- }
- obj.worksumup = worksumupBLL.Select("ws_u_id=" + obj.u_id.ToString());
- foreach (worksumup item in obj.worksumup)
- {
- item.users = obj;
- }
- }
- }
- #endregion
- #region 父表
- /// <summary>
- /// 设置实体对象(users)的父表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void employee(users users)
- {
- users.employee = employeeBLL.Select(users.u_em_id);
- }
- /// <summary>
- /// 设置实体对象(users)的父表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void groups(users users)
- {
- users.groups = groupsBLL.Select(users.u_g_id);
- }
- /// <summary>
- /// 设置实体对象(users)的父表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void department(users users)
- {
- users.department = departmentBLL.Select(users.u_dept_id);
- }
- #endregion
- #region 子表
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void addresslist(users users)
- {
- users.addresslist = addresslistBLL.Select("al_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void attendance(users users)
- {
- users.attendance = attendanceBLL.Select("att_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void bbsrevert(users users)
- {
- users.bbsrevert = bbsrevertBLL.Select("br_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void document(users users)
- {
- users.document = documentBLL.Select("doc_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void examine(users users)
- {
- users.examine = examineBLL.Select("ex_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void filerevert(users users)
- {
- users.filerevert = filerevertBLL.Select("fre_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void files(users users)
- {
- users.files = filesBLL.Select("f_takeu_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void message(users users)
- {
- users.message = messageBLL.Select("m_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void news(users users)
- {
- users.news = newsBLL.Select("n_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void operate(users users)
- {
- users.operate = operateBLL.Select("op_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void sendword(users users)
- {
- users.sendword = sendwordBLL.Select("sw_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void timeorder(users users)
- {
- users.timeorder = timeorderBLL.Select("to_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void worklog(users users)
- {
- users.worklog = worklogBLL.Select("w_u_id=" + users.u_id.ToString());
- }
- /// <summary>
- /// 设置实体对象(users)的子表对象
- /// </summary>
- /// <param name="users">实体对象</param>
- public void worksumup(users users)
- {
- users.worksumup = worksumupBLL.Select("ws_u_id=" + users.u_id.ToString());
- }
- #endregion
- #region 查询
- /// <summary>
- /// 得到数据表users所有记录
- /// </summary>
- /// <returns>结果集</returns>
- public IList<users> Select()
- {
- return this.Select(false, false);
- }
- /// <summary>
- /// 得到数据表users所有记录
- /// </summary>
- /// <param name="bParentTable">是/否设置与父表对象关联</param>
- /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
- /// <returns>结果集</returns>
- public IList<users> Select(bool bParentTable, bool bChildrenTable)
- {
- IList<users> list = new List<users>();
- string sqlCommand = "usersSelectAll";
- using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand))
- {
- while (dr.Read())
- {
- list.Add(this.Select(dr));
- }
- }
- foreach (users obj in list)
- {
- this.Select(obj, bParentTable, bChildrenTable);
- }
- return list;
- }
- /// <summary>
- /// 得到数据表users满足查询条件的记录
- /// </summary>
- /// <param name="where">查询条件</param>
- /// <returns>结果集</returns>
- public IList<users> Select(string where)
- {
- return this.Select(where, false, false);
- }
- /// <summary>
- /// 得到数据表users满足查询条件的记录
- /// </summary>
- /// <param name="where">查询条件</param>
- /// <param name="bParentTable">是/否设置与父表对象关联</param>
- /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
- /// <returns>结果集</returns>
- public IList<users> Select(string where, bool bParentTable, bool bChildrenTable)
- {
- IList<users> list = new List<users>();
- SqlParameter[] param ={
- new SqlParameter("@where",SqlDbType.VarChar,8000)
- };
- param[0].Value = where;
- string sqlCommand = "usersSelectByParams";
- using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
- {
- while (dr.Read())
- {
- list.Add(this.Select(dr));
- }
- }
- foreach (users obj in list)
- {
- this.Select(obj, bParentTable, bChildrenTable);
- }
- return list;
- }
- /// <summary>
- /// 得到数据表ArticalInfo满足外键字段查询条件的记录
- /// </summary>
- /// <param name="foreignFieldName">外键字段名称</param>
- /// <param name="foreignFieldValue">外键字段值</param>
- /// <returns>结果集</returns>
- public IList<users> Select(string foreignFieldName, int foreignFieldValue)
- {
- return this.Select(foreignFieldName, foreignFieldValue, false, false);
- }
- /// <summary>
- /// 得到数据表ArticalInfo满足外键字段查询条件的记录
- /// </summary>
- /// <param name="foreignFieldName">外键字段名称</param>
- /// <param name="foreignFieldValue">外键字段值</param>
- /// <param name="bParentTable">是/否设置与父表对象关联</param>
- /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
- /// <returns>结果集</returns>
- public IList<users> Select(string foreignFieldName, int foreignFieldValue, bool bParentTable, bool bChildrenTable)
- {
- return this.Select(string.Format("{0}='{1}'", foreignFieldName, foreignFieldValue), bParentTable, bChildrenTable);
- }
- /// <summary>
- /// 得到数据表users满足查询条件的记录数
- /// </summary>
- /// <param name="where">查询条件</param>
- /// <param name="recordCount">记录数</param>
- public void Select(string where, out int recordCount)
- {
- string sqlCommand = "usersCountByWhere";
- SqlParameter[] param ={
- new SqlParameter("@where",SqlDbType.VarChar,8000),
- new SqlParameter("@recordCount",SqlDbType.Int)
- };
- param[0].Value = where;
- param[1].Direction = ParameterDirection.Output;
- SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
- recordCount = Convert.ToInt32(param[1].Value);
- }
- /// <summary>
- /// 得到数据表users满足查询条件的分页记录
- /// </summary>
- /// <param name="pageSize">每页显示记录数</param>
- /// <param name="pageIndex">当前显示第几页</param>
- /// <param name="where">查询条件</param>
- /// <returns>结果集</returns>
- public IList<users> Select(int pageSize, int pageIndex, string where)
- {
- return this.Select(pageSize, pageIndex, where, false, false);
- }
- /// <summary>
- /// 得到数据表users满足查询条件的分页记录
- /// </summary>
- /// <param name="pageSize">每页显示记录数</param>
- /// <param name="pageIndex">当前显示第几页</param>
- /// <param name="where">查询条件</param>
- /// <param name="bParentTable">是/否设置与父表对象关联</param>
- /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
- /// <returns>结果集</returns>
- public IList<users> Select(int pageSize, int pageIndex, string where, bool bParentTable, bool bChildrenTable)
- {
- IList<users> list = new List<users>();
- string sqlCommand = "usersSelectByPagerParams";
- SqlParameter[] param ={
- new SqlParameter("@pageSize",SqlDbType.Int),
- new SqlParameter("@pageIndex",SqlDbType.Int),
- new SqlParameter("@where",SqlDbType.VarChar,8000)
- };
- param[0].Value = pageSize;
- param[1].Value = pageIndex;
- param[2].Value = where;
- using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
- {
- while (dr.Read())
- {
- list.Add(this.Select(dr));
- }
- }
- foreach (users obj in list)
- {
- this.Select(obj, bParentTable, bChildrenTable);
- }
- return list;
- }
- /// <summary>
- /// 得到数据表users满足查询条件记录
- /// </summary>
- /// <param name="commandType">命令类型</param>
- /// <param name="sqlCommand">SQL命令</param>
- /// <param name="SqlParameter[]">命令参数数组</param>
- /// <returns>结果集</returns>
- public IList<users> Select(CommandType commandType, string sqlCommand, params SqlParameter[] param)
- {
- return this.Select(false, false, commandType, sqlCommand, param);
- }
- /// <summary>
- /// 得到数据表users满足查询条件记录
- /// </summary>
- /// <param name="bParentTable">是/否设置与父表对象关联</param>
- /// <param name="bChildrenTable">是/否设置与子表对象关联</param>
- /// <param name="commandType">命令类型</param>
- /// <param name="sqlCommand">SQL命令</param>
- /// <param name="SqlParameter[]">命令参数数组</param>
- /// <returns>结果集</returns>
- public IList<users> Select(bool bParentTable, bool bChildrenTable, CommandType commandType, string sqlCommand, params SqlParameter[] param)
- {
- IList<users> list = new List<users>();
- using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, commandType, sqlCommand, param))
- {
- while (dr.Read())
- {
- list.Add(this.Select(dr));
- }
- }
- foreach (users obj in list)
- {
- this.Select(obj, bParentTable, bChildrenTable);
- }
- return list;
- }
- /// <summary>
- /// 根据主键检测是否存在该条记录
- /// </summary>
- /// <param name="u_id">u_id</param>
- /// <returns>存在/不存在</returns>
- public bool Exists(int u_id)
- {
- SqlParameter[] param ={
- new SqlParameter("@u_id",SqlDbType.Int)
- };
- param[0].Value = u_id;
- string sqlCommand = "usersIsExist";
- int a = Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param));
- if (a > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- #endregion
- #endregion
- }
- }
- //51aspx