using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class etwuser_delete_news : System.Web.UI.Page
{
    public int id = 0;
    public int page = 0;
    public string picture = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookEtwuser"] == null)
        {
            Response.Redirect("../index.aspx");
        }
        if (Request.QueryString["id"] != null)
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
            page = Convert.ToInt32(Request.QueryString["page"]);
            etw.etw_news lead = new etw.etw_news();
            lead.id = id;
            Deletepic(id);
            lead.Delete();
            Fun.JsAlerT("删除成功！", "newslist.aspx?page=" + page); 
        }
    }
    public void Deletepic(int id)
    {
        DataSet dsd = DbHelperSQL.Query("select picture from etw_news where id=" + id + "");
        if (dsd.Tables[0].Rows.Count>0)
        {
            picture = dsd.Tables[0].Rows[0]["picture"].ToString();
            string[] result = picture.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s in result)
            {
                if (s != "" && s != null)
                {
                    if (File.Exists((System.Web.HttpContext.Current.Request.MapPath("../newsupfile/") + s)))
                    {
                        File.Delete(System.Web.HttpContext.Current.Request.MapPath("../newsupfile/") + s);
                    }
                    if (File.Exists((System.Web.HttpContext.Current.Request.MapPath("../newsupfile/s_") + s)))
                    {
                        File.Delete(System.Web.HttpContext.Current.Request.MapPath("../newsupfile/s_") + s);
                    }
                }
            }
        }
    }
}
