/// <summary> /// 查找不存在的文件并删除已删除的附件及数据 /// </summary> public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.download_attach> models, int article_id) { StringBuilder idList = new StringBuilder(); if (models != null) { foreach (Model.download_attach modelt in models) { if (modelt.id > 0) { idList.Append(modelt.id + ","); } } } string id_list = HotoUtils.DelLastChar(idList.ToString(), ","); StringBuilder strSql = new StringBuilder(); strSql.Append("select id,file_path from dt_download_attach where article_id=" + article_id); if (!string.IsNullOrEmpty(id_list)) { strSql.Append(" and id not in(" + id_list + ")"); } DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString()); foreach (DataRow dr in ds.Tables[0].Rows) { int rows = DbHelperSQL.ExecuteSql(conn, trans, "delete from dt_download_attach where id=" + dr["id"].ToString()); //删除数据库 if (rows > 0) { HotoUtils.DeleteFile(dr["file_path"].ToString()); //删除文件 } } }
/// <summary> /// ²éÕÒ²»´æÔÚµÄͼƬ²¢É¾³ýÒÑɾ³ýµÄͼƬ¼°Êý¾Ý /// </summary> public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.article_albums> models, int article_id) { StringBuilder idList = new StringBuilder(); if (models != null) { foreach (Model.article_albums modelt in models) { if (modelt.id > 0) { idList.Append(modelt.id + ","); } } } string id_list = HotoUtils.DelLastChar(idList.ToString(), ","); StringBuilder strSql = new StringBuilder(); strSql.Append("select id,big_img,small_img from dt_article_albums where article_id=" + article_id); if (!string.IsNullOrEmpty(id_list)) { strSql.Append(" and id not in(" + id_list + ")"); } DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString()); foreach (DataRow dr in ds.Tables[0].Rows) { int rows = DbHelperSQL.ExecuteSql(conn, trans, "delete from dt_article_albums where id=" + dr["id"].ToString()); //ɾ³ýÊý¾Ý¿â if (rows > 0) { HotoUtils.DeleteFile(dr["big_img"].ToString()); //ɾ³ýÔͼ HotoUtils.DeleteFile(dr["small_img"].ToString()); //ɾ³ýËõÂÔͼ } } }
//删除更新的旧文件 public void DeleteFile(int id, string filePath) { Model.download_attach model = GetModel(id); if (model != null && model.file_path != filePath) { HotoUtils.DeleteFile(model.file_path); } }
/// <summary> /// 删除附件文件 /// </summary> public void DeleteFile(List <Model.download_attach> models) { if (models != null) { foreach (Model.download_attach modelt in models) { HotoUtils.DeleteFile(modelt.file_path); } } }
/// <summary> /// ɾ³ýÏà²áͼƬ /// </summary> public void DeleteFile(List <Model.article_albums> models) { if (models != null) { foreach (Model.article_albums modelt in models) { HotoUtils.DeleteFile(modelt.big_img); HotoUtils.DeleteFile(modelt.small_img); } } }