Пример #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ROYcms.Sys.Model.ROYcms_Messages GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,UserId,MessageType,State,Title,Contents,CreateTime from ROYcms_Messages ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            ROYcms.Sys.Model.ROYcms_Messages model = new ROYcms.Sys.Model.ROYcms_Messages();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserId"] != null && ds.Tables[0].Rows[0]["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MessageType"] != null && ds.Tables[0].Rows[0]["MessageType"].ToString() != "")
                {
                    model.MessageType = int.Parse(ds.Tables[0].Rows[0]["MessageType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["State"] != null && ds.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "")
                {
                    model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Contents"] != null && ds.Tables[0].Rows[0]["Contents"].ToString() != "")
                {
                    model.Contents = ds.Tables[0].Rows[0]["Contents"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CreateTime"] != null && ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ROYcms.Sys.Model.ROYcms_Messages model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ROYcms_Messages set ");
            strSql.Append("UserId=@UserId,");
            strSql.Append("MessageType=@MessageType,");
            strSql.Append("State=@State,");
            strSql.Append("Title=@Title,");
            strSql.Append("Contents=@Contents,");
            strSql.Append("CreateTime=@CreateTime");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",      SqlDbType.Int,          4),
                new SqlParameter("@MessageType", SqlDbType.Int,          4),
                new SqlParameter("@State",       SqlDbType.Int,          4),
                new SqlParameter("@Title",       SqlDbType.VarChar,    200),
                new SqlParameter("@Contents",    SqlDbType.VarChar,   2000),
                new SqlParameter("@CreateTime",  SqlDbType.DateTime),
                new SqlParameter("@Id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.MessageType;
            parameters[2].Value = model.State;
            parameters[3].Value = model.Title;
            parameters[4].Value = model.Contents;
            parameters[5].Value = model.CreateTime;
            parameters[6].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ROYcms.Sys.Model.ROYcms_Messages model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ROYcms_Messages(");
            strSql.Append("UserId,MessageType,State,Title,Contents,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("@UserId,@MessageType,@State,@Title,@Contents,@CreateTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",      SqlDbType.Int,        4),
                new SqlParameter("@MessageType", SqlDbType.Int,        4),
                new SqlParameter("@State",       SqlDbType.Int,        4),
                new SqlParameter("@Title",       SqlDbType.VarChar,  200),
                new SqlParameter("@Contents",    SqlDbType.VarChar, 2000),
                new SqlParameter("@CreateTime",  SqlDbType.DateTime)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.MessageType;
            parameters[2].Value = model.State;
            parameters[3].Value = model.Title;
            parameters[4].Value = model.Contents;
            parameters[5].Value = model.CreateTime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }