用戶登錄  |  用戶注冊
首 頁源碼下載網絡學院最新源碼源碼排行屏蔽廣告
當前位置:新興網絡 > 源碼下載 > Asp.Net源碼 > 管理系統 > ASP.net 專業開源的OA辦公系統 > messageDAL.cs
loading...復制代碼
// =================================================================== 
// 產品(COM.OA.SqlServerDAL)項目
//====================================================================
// wangyp @Copy Right 2006-2008
// 文件:messageDAL.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.message
    /// </summary>
    public partial class messageDAL : ImessageDAL
    {
        #region 構造函數
        /// <summary>
        /// 數據層實例化
        /// </summary>
        public messageDAL()
        {
        }
        #endregion

        #region -----------實例化接口函數-----------

        #region 添加
        /// <summary>
        /// 向數據庫中插入一條新記錄
        /// </summary>
        /// <param name="message">message實體對象</param>
        /// <returns></returns>
        public int Insert(message message)
        {
            string sqlCommand = "messageInsert";
            int res;
            SqlParameter[] param ={
			new SqlParameter("@m_id",SqlDbType.Int),
			new SqlParameter("@m_title",SqlDbType.VarChar),
			new SqlParameter("@m_content",SqlDbType.VarChar),
			new SqlParameter("@m_u_id",SqlDbType.Int),
			new SqlParameter("@m_sendu_id",SqlDbType.Int),
			new SqlParameter("@m_g_id",SqlDbType.Int),
			new SqlParameter("@m_releasetime",SqlDbType.DateTime),
			new SqlParameter("@m_isreturn",SqlDbType.Int)
			};
            param[0].Direction = ParameterDirection.Output;
            param[1].Value = message.m_title;
            param[2].Value = message.m_content;
            param[3].Value = message.m_u_id;
            param[4].Value = message.m_sendu_id;
            param[5].Value = message.m_g_id;
            param[6].Value = message.m_releasetime;
            param[7].Value = message.m_isreturn;
            res = SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
            message.m_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
            return res;
        }
        /// <summary>
        /// 向數據庫中插入一條新記錄。帶事務
        /// </summary>
        /// <param name="sp">事務對象</param>
        /// <param name="message">message實體對象</param>
        /// <returns></returns>
        public int Insert(SqlTransaction sp, message message)
        {
            string sqlCommand = "messageInsert";
            int res;
            SqlParameter[] param ={
			new SqlParameter("@m_id",SqlDbType.Int),
			new SqlParameter("@m_title",SqlDbType.VarChar),
			new SqlParameter("@m_content",SqlDbType.VarChar),
			new SqlParameter("@m_u_id",SqlDbType.Int),
			new SqlParameter("@m_sendu_id",SqlDbType.Int),
			new SqlParameter("@m_g_id",SqlDbType.Int),
			new SqlParameter("@m_releasetime",SqlDbType.DateTime),
			new SqlParameter("@m_isreturn",SqlDbType.Int)
			};
            param[0].Direction = ParameterDirection.Output;
            param[1].Value = message.m_title;
            param[2].Value = message.m_content;
            param[3].Value = message.m_u_id;
            param[4].Value = message.m_sendu_id;
            param[5].Value = message.m_g_id;
            param[6].Value = message.m_releasetime;
            param[7].Value = message.m_isreturn;
            res = SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
            message.m_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
            return res;
        }
        #endregion

        #region 更新
        /// <summary>
        /// 向數據表message更新一條記錄
        /// </summary>
        /// <param name="message">message實體對象</param>
        /// <returns></returns>
        public int Update(message message)
        {
            string sqlCommand = "messageUpdate";
            SqlParameter[] param ={
				new SqlParameter("@m_id",SqlDbType.Int),
				new SqlParameter("@m_title",SqlDbType.VarChar),
				new SqlParameter("@m_content",SqlDbType.VarChar),
				new SqlParameter("@m_u_id",SqlDbType.Int),
				new SqlParameter("@m_sendu_id",SqlDbType.Int),
				new SqlParameter("@m_g_id",SqlDbType.Int),
				new SqlParameter("@m_releasetime",SqlDbType.DateTime),
				new SqlParameter("@m_isreturn",SqlDbType.Int)
				};
            param[0].Value = message.m_id;
            param[1].Value = message.m_title;
            param[2].Value = message.m_content;
            param[3].Value = message.m_u_id;
            param[4].Value = message.m_sendu_id;
            param[5].Value = message.m_g_id;
            param[6].Value = message.m_releasetime;
            param[7].Value = message.m_isreturn;
            return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
        }
        /// <summary>
        /// 向數據表message更新一條記錄。帶事務
        /// </summary>
        /// <param name="sp">事務對象</param>
        /// <param name="message">message實體對象</param>
        /// <returns></returns>
        public int Update(SqlTransaction sp, message message)
        {
            string sqlCommand = "messageUpdate";
            SqlParameter[] param ={
				new SqlParameter("@m_id",SqlDbType.Int),
				new SqlParameter("@m_title",SqlDbType.VarChar),
				new SqlParameter("@m_content",SqlDbType.VarChar),
				new SqlParameter("@m_u_id",SqlDbType.Int),
				new SqlParameter("@m_sendu_id",SqlDbType.Int),
				new SqlParameter("@m_g_id",SqlDbType.Int),
				new SqlParameter("@m_releasetime",SqlDbType.DateTime),
				new SqlParameter("@m_isreturn",SqlDbType.Int)
				};
            param[0].Value = message.m_id;
            param[1].Value = message.m_title;
            param[2].Value = message.m_content;
            param[3].Value = message.m_u_id;
            param[4].Value = message.m_sendu_id;
            param[5].Value = message.m_g_id;
            param[6].Value = message.m_releasetime;
            param[7].Value = message.m_isreturn;
            return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
        }
        #endregion

        #region 刪除
        /// <summary>
        /// 刪除數據表message中的一條記錄
        /// </summary>
        /// <param name="m_id">m_id</param>
        /// <returns></returns>
        public int Delete(int m_id)
        {
            string sqlCommand = "messageDelete";
            SqlParameter[] param ={
				new SqlParameter("@m_id",SqlDbType.Int)
			};
            param[0].Value = m_id;
            return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
        }
        /// <summary>
        /// 刪除數據表message中的一條記錄
        /// </summary>
        /// <param name="message">message實體對象</param>
        /// <returns></returns>
        public int Delete(message message)
        {
            string sqlCommand = "messageDelete";
            SqlParameter[] param ={
				new SqlParameter("@m_id",SqlDbType.Int)
			};
            param[0].Value = message.m_id;
            return SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
        }
        /// <summary>
        /// 刪除數據表message中的一條記錄,帶事務
        /// </summary>
        /// <param name="sp">事務對象</param>
        /// <param name="m_id">m_id</param>
        /// <returns></returns>
        public int Delete(SqlTransaction sp, int m_id)
        {
            string sqlCommand = "messageDelete";
            SqlParameter[] param ={
				new SqlParameter("@m_id",SqlDbType.Int)
			};
            param[0].Value = m_id;
            return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
        }

        /// <summary>
        /// 刪除數據表message中的一條記錄,帶事務
        /// </summary>
        /// <param name="sp">事務對象</param>
        /// <param name="message">message實體對象</param>
        /// <returns></returns>
        public int Delete(SqlTransaction sp, message message)
        {
            string sqlCommand = "messageDelete";
            SqlParameter[] param ={
				new SqlParameter("@m_id",SqlDbType.Int)
			};
            param[0].Value = message.m_id;
            return SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
        }
        #endregion

        #region 實體對象
        /// <summary>
        /// 得到message實體對象
        /// </summary>
        /// <param name="row">row</param>
        /// <returns>message實體對象</returns>
        public message Select(DataRow row)
        {
            message obj = new message();
            if (row != null)
            {
                obj.m_id = ((row["m_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["m_id"]);
                obj.m_title = row["m_title"].ToString();
                obj.m_content = row["m_content"].ToString();
                obj.m_u_id = ((row["m_u_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["m_u_id"]);
                obj.m_sendu_id = ((row["m_sendu_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["m_sendu_id"]);
                obj.m_g_id = ((row["m_g_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["m_g_id"]);
                obj.m_releasetime = ((row["m_releasetime"]) == DBNull.Value) ? DateTime.MinValue : Convert.ToDateTime(row["m_releasetime"]);
                obj.m_isreturn = ((row["m_isreturn"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["m_isreturn"]);
            }
            else
            {
                return null;
            }
            return obj;
        }

        /// <summary>
        /// 得到message實體對象
        /// </summary>
        /// <param name="dr">dr</param>
        /// <returns>message實體對象</returns>
        public message Select(IDataReader dr)
        {
            message obj = new message();
            obj.m_id = ((dr["m_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["m_id"]);
            obj.m_title = dr["m_title"].ToString();
            obj.m_content = dr["m_content"].ToString();
            obj.m_u_id = ((dr["m_u_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["m_u_id"]);
            obj.m_sendu_id = ((dr["m_sendu_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["m_sendu_id"]);
            obj.m_g_id = ((dr["m_g_id"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["m_g_id"]);
            obj.m_releasetime = ((dr["m_releasetime"]) == DBNull.Value) ? DateTime.MinValue : Convert.ToDateTime(dr["m_releasetime"]);
            obj.m_isreturn = ((dr["m_isreturn"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["m_isreturn"]);
            return obj;
        }

        /// <summary>
        /// 根據ID,返回一個message實體對象
        /// </summary>
        /// <param name="m_id">m_id</param>
        /// <returns>message實體對象</returns>
        public message Select(int m_id)
        {
            return this.Select(m_id, false, false);
        }
        /// <summary>
        /// 根據ID,返回一個message實體對象
        /// </summary>
        /// <param name="m_id">m_id</param>
        /// <param name="bParentTable">將message對象設置與父表關聯</param>
        /// <param name="bChildrenTable">將message對象設置與子表關聯</param>
        /// <returns>message實體對象</returns>
        public message Select(int m_id, bool bParentTable, bool bChildrenTable)
        {
            message obj = null;
            SqlParameter[] param ={
			new SqlParameter("@m_id",SqlDbType.Int)
			};
            param[0].Value = m_id;
            string sqlCommand = "messageSelect";
            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>
        /// 將message實體對象設置與父表和子表關聯
        /// </summary>
        /// <param name="obj">message實體對象</param>
        /// <param name="bParentTable">是/否設置與父表對象關聯</param>
        /// <param name="bChildrenTable">是/否設置與子表對象關聯</param>
        public void Select(message obj, bool bParentTable, bool bChildrenTable)
        {
            //關聯的主表
            if (bParentTable)
            {
                obj.users = usersBLL.Select(obj.m_u_id);
                obj.groups = groupsBLL.Select(obj.m_g_id);
            }
            //關聯的子表集合
            if (bChildrenTable)
            {
            }
        }
        #endregion

        #region 父表
        /// <summary>
        /// 設置實體對象(message)的父表對象
        /// </summary>
        /// <param name="message">實體對象</param>
        public void users(message message)
        {
            message.users = usersBLL.Select(message.m_u_id);
        }
        /// <summary>
        /// 設置實體對象(message)的父表對象
        /// </summary>
        /// <param name="message">實體對象</param>
        public void groups(message message)
        {
            message.groups = groupsBLL.Select(message.m_g_id);
        }
        #endregion

        #region 子表
        #endregion

        #region 查詢
        /// <summary>
        /// 得到數據表message所有記錄
        /// </summary>
        /// <returns>結果集</returns>
        public IList<message> Select()
        {
            return this.Select(false, false);
        }
        /// <summary>
        /// 得到數據表message所有記錄
        /// </summary>
        /// <param name="bParentTable">是/否設置與父表對象關聯</param>
        /// <param name="bChildrenTable">是/否設置與子表對象關聯</param>
        /// <returns>結果集</returns>
        public IList<message> Select(bool bParentTable, bool bChildrenTable)
        {
            IList<message> list = new List<message>();
            string sqlCommand = "messageSelectAll";
            using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand))
            {
                while (dr.Read())
                {
                    list.Add(this.Select(dr));
                }
            }
            foreach (message obj in list)
            {
                this.Select(obj, bParentTable, bChildrenTable);
            }
            return list;
        }
        /// <summary>
        /// 得到數據表message滿足查詢條件的記錄
        /// </summary>
        /// <param name="where">查詢條件</param>
        /// <returns>結果集</returns>
        public IList<message> Select(string where)
        {
            return this.Select(where, false, false);
        }
        /// <summary>
        /// 得到數據表message滿足查詢條件的記錄
        /// </summary>
        /// <param name="where">查詢條件</param>
        /// <param name="bParentTable">是/否設置與父表對象關聯</param>
        /// <param name="bChildrenTable">是/否設置與子表對象關聯</param>
        /// <returns>結果集</returns>
        public IList<message> Select(string where, bool bParentTable, bool bChildrenTable)
        {
            IList<message> list = new List<message>();
            SqlParameter[] param ={
			new SqlParameter("@where",SqlDbType.VarChar,8000)
			};
            param[0].Value = where;
            string sqlCommand = "messageSelectByParams";
            using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param))
            {
                while (dr.Read())
                {
                    list.Add(this.Select(dr));
                }
            }
            foreach (message 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<message> 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<message> Select(string foreignFieldName, int foreignFieldValue, bool bParentTable, bool bChildrenTable)
        {
            return this.Select(string.Format("{0}='{1}'", foreignFieldName, foreignFieldValue), bParentTable, bChildrenTable);
        }
        /// <summary>
        /// 得到數據表message滿足查詢條件的記錄數
        /// </summary>
        /// <param name="where">查詢條件</param>
        /// <param name="recordCount">記錄數</param>
        public void Select(string where, out int recordCount)
        {
            string sqlCommand = "messageCountByWhere";
            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>
        /// 得到數據表message滿足查詢條件的分頁記錄
        /// </summary>
        /// <param name="pageSize">每頁顯示記錄數</param>
        /// <param name="pageIndex">當前顯示第幾頁</param>
        /// <param name="where">查詢條件</param>
        /// <returns>結果集</returns>
        public IList<message> Select(int pageSize, int pageIndex, string where)
        {
            return this.Select(pageSize, pageIndex, where, false, false);
        }
        /// <summary>
        /// 得到數據表message滿足查詢條件的分頁記錄
        /// </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<message> Select(int pageSize, int pageIndex, string where, bool bParentTable, bool bChildrenTable)
        {
            IList<message> list = new List<message>();
            string sqlCommand = "messageSelectByPagerParams";
            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 (message obj in list)
            {
                this.Select(obj, bParentTable, bChildrenTable);
            }
            return list;
        }
        /// <summary>
        /// 得到數據表message滿足查詢條件記錄
        /// </summary>
        /// <param name="commandType">命令類型</param>
        /// <param name="sqlCommand">SQL命令</param>
        /// <param name="SqlParameter[]">命令參數數組</param>
        /// <returns>結果集</returns>
        public IList<message> Select(CommandType commandType, string sqlCommand, params SqlParameter[] param)
        {
            return this.Select(false, false, commandType, sqlCommand, param);
        }
        /// <summary>
        /// 得到數據表message滿足查詢條件記錄
        /// </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<message> Select(bool bParentTable, bool bChildrenTable, CommandType commandType, string sqlCommand, params SqlParameter[] param)
        {
            IList<message> list = new List<message>();
            using (SqlDataReader dr = SqlHelper.ExecuteReader(Conn.SqlConn, commandType, sqlCommand, param))
            {
                while (dr.Read())
                {
                    list.Add(this.Select(dr));
                }
            }
            foreach (message obj in list)
            {
                this.Select(obj, bParentTable, bChildrenTable);
            }
            return list;
        }
        /// <summary>
        /// 根據主鍵檢測是否存在該條記錄
        /// </summary>
        /// <param name="m_id">m_id</param>
        /// <returns>存在/不存在</returns>
        public bool Exists(int m_id)
        {
            SqlParameter[] param ={
                                 new SqlParameter("@m_id",SqlDbType.Int)
                                 };
            param[0].Value = m_id;
            string sqlCommand = "messageIsExist";
            int a = Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param));
            if (a > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #endregion
    }
}

175哪个门派赚钱快