/// <summary> /// 获得数据列表 /// </summary> public List <Model.contents.article_attach> GetList(int article_id) { List <Model.contents.article_attach> modelList = new List <Model.contents.article_attach>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select id,article_id,file_name,file_path,file_size,file_ext,down_num,point,add_time "); strSql.Append(" FROM " + databaseprefix + "article_attach "); strSql.Append(" where article_id=" + article_id); DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0]; int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.contents.article_attach model; for (int n = 0; n < rowsCount; n++) { model = new Model.contents.article_attach(); if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "") { model.id = int.Parse(dt.Rows[n]["id"].ToString()); } if (dt.Rows[n]["article_id"] != null && dt.Rows[n]["article_id"].ToString() != "") { model.article_id = int.Parse(dt.Rows[n]["article_id"].ToString()); } if (dt.Rows[n]["file_name"] != null && dt.Rows[n]["file_name"].ToString() != "") { model.file_name = dt.Rows[n]["file_name"].ToString(); } if (dt.Rows[n]["file_path"] != null && dt.Rows[n]["file_path"].ToString() != "") { model.file_path = dt.Rows[n]["file_path"].ToString(); } if (dt.Rows[n]["file_ext"] != null && dt.Rows[n]["file_ext"].ToString() != "") { model.file_ext = dt.Rows[n]["file_ext"].ToString(); } if (dt.Rows[n]["file_size"] != null && dt.Rows[n]["file_size"].ToString() != "") { model.file_size = int.Parse(dt.Rows[n]["file_size"].ToString()); } if (dt.Rows[n]["down_num"] != null && dt.Rows[n]["down_num"].ToString() != "") { model.down_num = int.Parse(dt.Rows[n]["down_num"].ToString()); } if (dt.Rows[n]["point"] != null && dt.Rows[n]["point"].ToString() != "") { model.point = int.Parse(dt.Rows[n]["point"].ToString()); } if (dt.Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(dt.Rows[0]["add_time"].ToString()); } modelList.Add(model); } } return(modelList); }
//删除更新的旧文件 public void DeleteFile(int id, string filePath) { Model.contents.article_attach model = GetModel(id); if (model != null && model.file_path != filePath) { Utils.DeleteFile(model.file_path); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.contents.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 " + databaseprefix + "article_attach "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.contents.article_attach model = new Model.contents.article_attach(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["article_id"].ToString() != "") { model.article_id = int.Parse(ds.Tables[0].Rows[0]["article_id"].ToString()); } model.file_name = ds.Tables[0].Rows[0]["file_name"].ToString(); model.file_path = ds.Tables[0].Rows[0]["file_path"].ToString(); if (ds.Tables[0].Rows[0]["file_size"].ToString() != "") { model.file_size = int.Parse(ds.Tables[0].Rows[0]["file_size"].ToString()); } model.file_ext = ds.Tables[0].Rows[0]["file_ext"].ToString(); if (ds.Tables[0].Rows[0]["down_num"].ToString() != "") { model.down_num = int.Parse(ds.Tables[0].Rows[0]["down_num"].ToString()); } if (ds.Tables[0].Rows[0]["point"].ToString() != "") { model.point = int.Parse(ds.Tables[0].Rows[0]["point"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } return(model); } else { return(null); } }