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;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;

public partial class admin_del : System.Web.UI.Page
{
    public int lid = 0;
    public string picture = string.Empty;
    public string pic = string.Empty;
    public string cpath = string.Empty;
    public int page = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["lid"] != null && Request.QueryString["pic"] != null)
        {
            lid = Convert.ToInt32(Request.QueryString["lid"].ToString());
            pic = Request.QueryString["pic"].ToString();
            page = Convert.ToInt32(Request.QueryString["page"]);
            if (!IsPostBack)
            {
                etw.etw_news lead = new etw.etw_news();
                lead.id = lid;
                lead.GetModel();
                picture = Encode(lead.picture);
            }
            delpic();
        }
    }
    public string Encode(string str)
    {
        str = str.Replace(pic+";", "");
        str = str.Replace(";"+pic , "");
        str = str.Replace(pic, "");
        return str;
    }
    private void delpic()
    {
        etw.etw_news lead = new etw.etw_news();
        lead.id = lid;
        lead.picture = picture;
        lead.Updatepic();
        if (File.Exists((System.Web.HttpContext.Current.Request.MapPath("../newsupfile/") + pic)))
        {
            File.Delete(System.Web.HttpContext.Current.Request.MapPath("../newsupfile/") + pic);
        }
        if (File.Exists((System.Web.HttpContext.Current.Request.MapPath("../newsupfile/s_") + pic)))
        {
            File.Delete(System.Web.HttpContext.Current.Request.MapPath("../newsupfile/s_") + pic);
        }

        Response.Write("<script type=text/javascript>alert('删除成功');window.location.href='" + "editnews.aspx?id=" + lid + "&page="+page+"';self.opener.location.reload();</script>");
    }
}
