Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.News.InternalMessage GetModel(int ID, int msg_to)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,senderUserType,sendId,sender,receiverType,receiverId,receiver,msgtitle,msgContent,addtime,isRead,readTime from msg ");
            strSql.Append(" where ID=@ID and msg_to=@msg_to");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",     SqlDbType.Int, 4),
                new SqlParameter("@msg_to", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;
            parameters[1].Value = msg_to;

            Model.News.InternalMessage model = new Model.News.InternalMessage();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.News.InternalMessage model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update msg set ");
            strSql.Append("senderUserType=@senderUserType,");
            strSql.Append("sendId=@sendId,");
            strSql.Append("sender=@sender,");
            strSql.Append("receiverType=@receiverType,");
            strSql.Append("receiverId=@receiverId,");
            strSql.Append("receiver=@receiver,");
            strSql.Append("msgtitle=@msgtitle,");
            strSql.Append("msgContent=@msgContent,");
            strSql.Append("addtime=@addtime,");
            strSql.Append("isRead=@isRead,");
            strSql.Append("readTime=@readTime");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@senderUserType", SqlDbType.TinyInt,      1),
                new SqlParameter("@sendId",         SqlDbType.Int,          4),
                new SqlParameter("@sender",         SqlDbType.NVarChar,    50),
                new SqlParameter("@receiverType",   SqlDbType.TinyInt,      1),
                new SqlParameter("@receiverId",     SqlDbType.Int,          4),
                new SqlParameter("@receiver",       SqlDbType.NVarChar,    50),
                new SqlParameter("@msgtitle",       SqlDbType.NVarChar,    50),
                new SqlParameter("@msgContent",     SqlDbType.NVarChar,  2000),
                new SqlParameter("@addtime",        SqlDbType.DateTime),
                new SqlParameter("@isRead",         SqlDbType.Bit,          1),
                new SqlParameter("@readTime",       SqlDbType.DateTime),
                new SqlParameter("@ID",             SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.senderUserType;
            parameters[1].Value  = model.sendId;
            parameters[2].Value  = model.sender;
            parameters[3].Value  = model.receiverType;
            parameters[4].Value  = model.receiverId;
            parameters[5].Value  = model.receiver;
            parameters[6].Value  = model.msgtitle;
            parameters[7].Value  = model.msgContent;
            parameters[8].Value  = model.addtime;
            parameters[9].Value  = model.isRead;
            parameters[10].Value = model.readTime;
            parameters[11].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public static bool Update(Model.News.InternalMessage model)
 {
     try
     {
         return(dal.Update(model));
     }
     catch (Exception exception)
     {
         ExceptionHandler.HandleException(exception);
         return(false);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public static int Add(Model.News.InternalMessage model)
 {
     try
     {
         return(dal.Add(model));
     }
     catch (Exception exception)
     {
         ExceptionHandler.HandleException(exception);
         return(0);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.News.InternalMessage model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into msg(");
            strSql.Append("senderUserType,sendId,sender,receiverType,receiverId,receiver,msgtitle,msgContent,addtime,isRead,readTime)");
            strSql.Append(" values (");
            strSql.Append("@senderUserType,@sendId,@sender,@receiverType,@receiverId,@receiver,@msgtitle,@msgContent,@addtime,@isRead,@readTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@senderUserType", SqlDbType.TinyInt,      1),
                new SqlParameter("@sendId",         SqlDbType.Int,          4),
                new SqlParameter("@sender",         SqlDbType.NVarChar,    50),
                new SqlParameter("@receiverType",   SqlDbType.TinyInt,      1),
                new SqlParameter("@receiverId",     SqlDbType.Int,          4),
                new SqlParameter("@receiver",       SqlDbType.NVarChar,    50),
                new SqlParameter("@msgtitle",       SqlDbType.NVarChar,    50),
                new SqlParameter("@msgContent",     SqlDbType.NVarChar,  2000),
                new SqlParameter("@addtime",        SqlDbType.DateTime),
                new SqlParameter("@isRead",         SqlDbType.Bit,          1),
                new SqlParameter("@readTime",       SqlDbType.DateTime)
            };
            parameters[0].Value  = model.senderUserType;
            parameters[1].Value  = model.sendId;
            parameters[2].Value  = model.sender;
            parameters[3].Value  = model.receiverType;
            parameters[4].Value  = model.receiverId;
            parameters[5].Value  = model.receiver;
            parameters[6].Value  = model.msgtitle;
            parameters[7].Value  = model.msgContent;
            parameters[8].Value  = model.addtime;
            parameters[9].Value  = model.isRead;
            parameters[10].Value = model.readTime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.News.InternalMessage DataRowToModel(DataRow row)
 {
     Model.News.InternalMessage model = new Model.News.InternalMessage();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["senderUserType"] != null && row["senderUserType"].ToString() != "")
         {
             model.senderUserType = byte.Parse(row["senderUserType"].ToString());
         }
         if (row["sendId"] != null && row["sendId"].ToString() != "")
         {
             model.sendId = int.Parse(row["sendId"].ToString());
         }
         if (row["sender"] != null)
         {
             model.sender = row["sender"].ToString();
         }
         if (row["receiverType"] != null && row["receiverType"].ToString() != "")
         {
             model.receiverType = byte.Parse(row["receiverType"].ToString());
         }
         if (row["receiverId"] != null && row["receiverId"].ToString() != "")
         {
             model.receiverId = int.Parse(row["receiverId"].ToString());
         }
         if (row["receiver"] != null)
         {
             model.receiver = row["receiver"].ToString();
         }
         if (row["msgtitle"] != null)
         {
             model.msgtitle = row["msgtitle"].ToString();
         }
         if (row["msgContent"] != null)
         {
             model.msgContent = row["msgContent"].ToString();
         }
         if (row["addtime"] != null && row["addtime"].ToString() != "")
         {
             model.addtime = DateTime.Parse(row["addtime"].ToString());
         }
         if (row["isRead"] != null && row["isRead"].ToString() != "")
         {
             if ((row["isRead"].ToString() == "1") || (row["isRead"].ToString().ToLower() == "true"))
             {
                 model.isRead = true;
             }
             else
             {
                 model.isRead = false;
             }
         }
         if (row["readTime"] != null && row["readTime"].ToString() != "")
         {
             model.readTime = DateTime.Parse(row["readTime"].ToString());
         }
     }
     return(model);
 }