Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(HeqiaoDaoshiCore.Model.News model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update News set ");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("Title=@Title,");
            strSql.Append("NewsContent=@NewsContent,");
            strSql.Append("IsDelete=@IsDelete,");
            strSql.Append("ReleaseState=@ReleaseState");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CreateTime",   SqlDbType.DateTime),
                new SqlParameter("@Title",        SqlDbType.NVarChar,         50),
                new SqlParameter("@NewsContent",  SqlDbType.NVarChar,         -1),
                new SqlParameter("@IsDelete",     SqlDbType.Int,               4),
                new SqlParameter("@ReleaseState", SqlDbType.Int,               4),
                new SqlParameter("@ID",           SqlDbType.Int,               4),
                new SqlParameter("@NewsUUID",     SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = model.CreateTime;
            parameters[1].Value = model.Title;
            parameters[2].Value = model.NewsContent;
            parameters[3].Value = model.IsDelete;
            parameters[4].Value = model.ReleaseState;
            parameters[5].Value = model.ID;
            parameters[6].Value = model.NewsUUID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public HeqiaoDaoshiCore.Model.News DataRowToModel(DataRow row)
 {
     HeqiaoDaoshiCore.Model.News model = new HeqiaoDaoshiCore.Model.News();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
         {
             model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
         }
         if (row["NewsUUID"] != null && row["NewsUUID"].ToString() != "")
         {
             model.NewsUUID = new Guid(row["NewsUUID"].ToString());
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["NewsContent"] != null)
         {
             model.NewsContent = row["NewsContent"].ToString();
         }
         if (row["IsDelete"] != null && row["IsDelete"].ToString() != "")
         {
             model.IsDelete = int.Parse(row["IsDelete"].ToString());
         }
         if (row["ReleaseState"] != null && row["ReleaseState"].ToString() != "")
         {
             model.ReleaseState = int.Parse(row["ReleaseState"].ToString());
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(HeqiaoDaoshiCore.Model.News model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into News(");
            strSql.Append("CreateTime,NewsUUID,Title,NewsContent,IsDelete,ReleaseState)");
            strSql.Append(" values (");
            strSql.Append("@CreateTime,@NewsUUID,@Title,@NewsContent,@IsDelete,@ReleaseState)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CreateTime",   SqlDbType.DateTime),
                new SqlParameter("@NewsUUID",     SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@Title",        SqlDbType.NVarChar,         50),
                new SqlParameter("@NewsContent",  SqlDbType.NVarChar,         -1),
                new SqlParameter("@IsDelete",     SqlDbType.Int,               4),
                new SqlParameter("@ReleaseState", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CreateTime;
            parameters[1].Value = Guid.NewGuid();
            parameters[2].Value = model.Title;
            parameters[3].Value = model.NewsContent;
            parameters[4].Value = model.IsDelete;
            parameters[5].Value = model.ReleaseState;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HeqiaoDaoshiCore.Model.News GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,CreateTime,NewsUUID,Title,NewsContent,IsDelete,ReleaseState from News ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }