Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Cms.Model.C_article_attach model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update C_article_attach set ");
            strSql.Append("article_id=@article_id,");
            strSql.Append("file_name=@file_name,");
            strSql.Append("file_path=@file_path,");
            strSql.Append("file_size=@file_size,");
            strSql.Append("file_ext=@file_ext,");
            strSql.Append("down_num=@down_num,");
            strSql.Append("point=@point,");
            strSql.Append("add_time=@add_time");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@article_id", SqlDbType.Int,         4),
                new SqlParameter("@file_name",  SqlDbType.NVarChar,  100),
                new SqlParameter("@file_path",  SqlDbType.NVarChar,  255),
                new SqlParameter("@file_size",  SqlDbType.Int,         4),
                new SqlParameter("@file_ext",   SqlDbType.NVarChar,   20),
                new SqlParameter("@down_num",   SqlDbType.Int,         4),
                new SqlParameter("@point",      SqlDbType.Int,         4),
                new SqlParameter("@add_time",   SqlDbType.DateTime),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.article_id;
            parameters[1].Value = model.file_name;
            parameters[2].Value = model.file_path;
            parameters[3].Value = model.file_size;
            parameters[4].Value = model.file_ext;
            parameters[5].Value = model.down_num;
            parameters[6].Value = model.point;
            parameters[7].Value = model.add_time;
            parameters[8].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Cms.Model.C_article_attach DataRowToModel(DataRow row)
 {
     Cms.Model.C_article_attach model = new Cms.Model.C_article_attach();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["article_id"] != null && row["article_id"].ToString() != "")
         {
             model.article_id = int.Parse(row["article_id"].ToString());
         }
         if (row["file_name"] != null)
         {
             model.file_name = row["file_name"].ToString();
         }
         if (row["file_path"] != null)
         {
             model.file_path = row["file_path"].ToString();
         }
         if (row["file_size"] != null && row["file_size"].ToString() != "")
         {
             model.file_size = int.Parse(row["file_size"].ToString());
         }
         if (row["file_ext"] != null)
         {
             model.file_ext = row["file_ext"].ToString();
         }
         if (row["down_num"] != null && row["down_num"].ToString() != "")
         {
             model.down_num = int.Parse(row["down_num"].ToString());
         }
         if (row["point"] != null && row["point"].ToString() != "")
         {
             model.point = int.Parse(row["point"].ToString());
         }
         if (row["add_time"] != null && row["add_time"].ToString() != "")
         {
             model.add_time = DateTime.Parse(row["add_time"].ToString());
         }
     }
     return(model);
 }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Cms.Model.C_article_attach model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into C_article_attach(");
            strSql.Append("article_id,file_name,file_path,file_size,file_ext,down_num,point,add_time)");
            strSql.Append(" values (");
            strSql.Append("@article_id,@file_name,@file_path,@file_size,@file_ext,@down_num,@point,@add_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@article_id", SqlDbType.Int,        4),
                new SqlParameter("@file_name",  SqlDbType.NVarChar, 100),
                new SqlParameter("@file_path",  SqlDbType.NVarChar, 255),
                new SqlParameter("@file_size",  SqlDbType.Int,        4),
                new SqlParameter("@file_ext",   SqlDbType.NVarChar,  20),
                new SqlParameter("@down_num",   SqlDbType.Int,        4),
                new SqlParameter("@point",      SqlDbType.Int,        4),
                new SqlParameter("@add_time",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.article_id;
            parameters[1].Value = model.file_name;
            parameters[2].Value = model.file_path;
            parameters[3].Value = model.file_size;
            parameters[4].Value = model.file_ext;
            parameters[5].Value = model.down_num;
            parameters[6].Value = model.point;
            parameters[7].Value = model.add_time;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cms.Model.C_article_attach GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,article_id,file_name,file_path,file_size,file_ext,down_num,point,add_time from C_article_attach ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

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