/// <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 = SFUtils.DelLastChar(idList.ToString(), ","); StringBuilder strSql = new StringBuilder(); strSql.Append("select id,thumb_path,original_path from " + databaseprefix + "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 " + databaseprefix + "article_albums where id=" + dr["id"].ToString()); //ɾ³ýÊý¾Ý¿â if (rows > 0) { SFUtils.DeleteFile(dr["thumb_path"].ToString()); //ɾ³ýËõÂÔͼ SFUtils.DeleteFile(dr["original_path"].ToString()); //ɾ³ýÔͼ } } }
/// <summary> /// 查找不存在的图片并删除已删除的图片及数据 /// </summary> public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.article_images_size> models, int category_id) { StringBuilder idList = new StringBuilder(); if (models != null) { foreach (Model.article_images_size modelt in models) { if (modelt.id > 0) { idList.Append(modelt.id + ","); } } } string id_list = SFUtils.DelLastChar(idList.ToString(), ","); StringBuilder strSql = new StringBuilder(); strSql.Append("select id,height,width,category_id from " + databaseprefix + "article_images_size where category_id=" + category_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) { DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "article_images_size where id=" + dr["id"].ToString()); //删除数据库 } }