• MessageDAL


    using System;
    using System.Data;
    using System.Text;
    using System.Data.SqlClient;
    namespace Website.DAL
    {
    	/// <summary>
    	/// 数据访问类Message。
    	/// </summary>
    	public class Message
    	{
    		public Message()
    		{}
    		#region  成员方法
    
    		/// <summary>
    		/// 得到最大ID
    		/// </summary>
    		public int GetMaxId()
    		{
    		return DbHelperSQL.GetMaxID("MessageId", "Message"); 
    		}
    
    		/// <summary>
    		/// 是否存在该记录
    		/// </summary>
    		public bool Exists(int MessageId)
    		{
    			StringBuilder strSql=new StringBuilder();
    			strSql.Append("select count(1) from Message");
    			strSql.Append(" where MessageId=@MessageId ");
    			SqlParameter[] parameters = {
    					new SqlParameter("@MessageId", SqlDbType.Int,4)};
    			parameters[0].Value = MessageId;
    
    			return DbHelperSQL.Exists(strSql.ToString(),parameters);
    		}
    
    
    		/// <summary>
    		/// 增加一条数据
    		/// </summary>
    		public int Add(Website.Model.Message model)
    		{
    			StringBuilder strSql=new StringBuilder();
    			strSql.Append("insert into Message(");
    			strSql.Append("MessageContent,MessageAddTime,MessageAddId,MessageToId,MessageIsDisplay)");
    			strSql.Append(" values (");
    			strSql.Append("@MessageContent,@MessageAddTime,@MessageAddId,@MessageToId,@MessageIsDisplay)");
    			strSql.Append(";select @@IDENTITY");
    			SqlParameter[] parameters = {
    					new SqlParameter("@MessageContent", SqlDbType.VarChar,400),
    					new SqlParameter("@MessageAddTime", SqlDbType.DateTime),
    					new SqlParameter("@MessageAddId", SqlDbType.Int,4),
    					new SqlParameter("@MessageToId", SqlDbType.Int,4),
    					new SqlParameter("@MessageIsDisplay", SqlDbType.Int,4)};
    			parameters[0].Value = model.MessageContent;
    			parameters[1].Value = model.MessageAddTime;
    			parameters[2].Value = model.MessageAddId;
    			parameters[3].Value = model.MessageToId;
    			parameters[4].Value = model.MessageIsDisplay;
    
    			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
    			if (obj == null)
    			{
    				return 1;
    			}
    			else
    			{
    				return Convert.ToInt32(obj);
    			}
    		}
    		/// <summary>
    		/// 更新一条数据
    		/// </summary>
    		public void Update(Website.Model.Message model)
    		{
    			StringBuilder strSql=new StringBuilder();
    			strSql.Append("update Message set ");
    			strSql.Append("MessageContent=@MessageContent,");
    			strSql.Append("MessageAddTime=@MessageAddTime,");
    			strSql.Append("MessageAddId=@MessageAddId,");
    			strSql.Append("MessageToId=@MessageToId,");
    			strSql.Append("MessageIsDisplay=@MessageIsDisplay");
    			strSql.Append(" where MessageId=@MessageId ");
    			SqlParameter[] parameters = {
    					new SqlParameter("@MessageId", SqlDbType.Int,4),
    					new SqlParameter("@MessageContent", SqlDbType.VarChar,400),
    					new SqlParameter("@MessageAddTime", SqlDbType.DateTime),
    					new SqlParameter("@MessageAddId", SqlDbType.Int,4),
    					new SqlParameter("@MessageToId", SqlDbType.Int,4),
    					new SqlParameter("@MessageIsDisplay", SqlDbType.Int,4)};
    			parameters[0].Value = model.MessageId;
    			parameters[1].Value = model.MessageContent;
    			parameters[2].Value = model.MessageAddTime;
    			parameters[3].Value = model.MessageAddId;
    			parameters[4].Value = model.MessageToId;
    			parameters[5].Value = model.MessageIsDisplay;
    
    			DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
    		}
    
    		/// <summary>
    		/// 删除一条数据
    		/// </summary>
    		public void Delete(int MessageId)
    		{
    			StringBuilder strSql=new StringBuilder();
    			strSql.Append("delete Message ");
    			strSql.Append(" where MessageId=@MessageId ");
    			SqlParameter[] parameters = {
    					new SqlParameter("@MessageId", SqlDbType.Int,4)};
    			parameters[0].Value = MessageId;
    
    			DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
    		}
    
    
    		/// <summary>
    		/// 得到一个对象实体
    		/// </summary>
    		public Website.Model.Message GetModel(int MessageId)
    		{
    			StringBuilder strSql=new StringBuilder();
    			strSql.Append("select MessageId,MessageContent,MessageAddTime,MessageAddId,MessageToId,MessageIsDisplay from Message ");
    			strSql.Append(" where MessageId=@MessageId ");
    			SqlParameter[] parameters = {
    					new SqlParameter("@MessageId", SqlDbType.Int,4)};
    			parameters[0].Value = MessageId;
    
    			Website.Model.Message model=new Website.Model.Message();
    			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
    			if(ds.Tables[0].Rows.Count>0)
    			{
    				if(ds.Tables[0].Rows[0]["MessageId"].ToString()!="")
    				{
    					model.MessageId=int.Parse(ds.Tables[0].Rows[0]["MessageId"].ToString());
    				}
    				model.MessageContent=ds.Tables[0].Rows[0]["MessageContent"].ToString();
    				if(ds.Tables[0].Rows[0]["MessageAddTime"].ToString()!="")
    				{
    					model.MessageAddTime=DateTime.Parse(ds.Tables[0].Rows[0]["MessageAddTime"].ToString());
    				}
    				if(ds.Tables[0].Rows[0]["MessageAddId"].ToString()!="")
    				{
    					model.MessageAddId=int.Parse(ds.Tables[0].Rows[0]["MessageAddId"].ToString());
    				}
    				if(ds.Tables[0].Rows[0]["MessageToId"].ToString()!="")
    				{
    					model.MessageToId=int.Parse(ds.Tables[0].Rows[0]["MessageToId"].ToString());
    				}
    				if(ds.Tables[0].Rows[0]["MessageIsDisplay"].ToString()!="")
    				{
    					model.MessageIsDisplay=int.Parse(ds.Tables[0].Rows[0]["MessageIsDisplay"].ToString());
    				}
    				return model;
    			}
    			else
    			{
    			return null;
    			}
    		}
    
    		/// <summary>
    		/// 获得数据列表
    		/// </summary>
    		public DataSet GetList(string strWhere)
    		{
    			StringBuilder strSql=new StringBuilder();
    			strSql.Append("select MessageId,MessageContent,MessageAddTime,MessageAddId,MessageToId,MessageIsDisplay ");
    			strSql.Append(" FROM Message ");
    			if(strWhere.Trim()!="")
    			{
    				strSql.Append(" where "+strWhere);
    			}
    			return DbHelperSQL.Query(strSql.ToString());
    		}
    
    		/*
    		/// <summary>
    		/// 分页获取数据列表
    		/// </summary>
    		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
    		{
    			SqlParameter[] parameters = {
    					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
    					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
    					new SqlParameter("@PageSize", SqlDbType.Int),
    					new SqlParameter("@PageIndex", SqlDbType.Int),
    					new SqlParameter("@IsReCount", SqlDbType.Bit),
    					new SqlParameter("@OrderType", SqlDbType.Bit),
    					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
    					};
    			parameters[0].Value = "Message";
    			parameters[1].Value = "ID";
    			parameters[2].Value = PageSize;
    			parameters[3].Value = PageIndex;
    			parameters[4].Value = 0;
    			parameters[5].Value = 0;
    			parameters[6].Value = strWhere;	
    			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
    		}*/
    
    		#endregion  成员方法
    	}
    }
    
    
  • 相关阅读:
    制作软件说明书的图片编辑工具推荐PicPick
    浅谈配网供电可靠性及管理措施
    C#的winform中MDI 父窗体改变背景色
    Windows完成端口与Linux epoll技术简介
    django中的form表单
    调整图层初识3
    PS图层混合模式详解
    图层混合模式之正片叠底、滤色
    photoshop调整图层初识1
    调整图层初识2
  • 原文地址:https://www.cnblogs.com/lx1988729/p/3100851.html
Copyright © 2020-2023  润新知