using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using xabaraCOM;

public partial class inClude_ueditor_net_img : System.Web.UI.Page
{
    admin a = new admin();
    sqlServer sql = new sqlServer();
    fileDocument f = new fileDocument();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check("");

        if (!IsPostBack)
        {
            //预览图
            string indexPic = Request.QueryString["session"];
            if (!string.IsNullOrEmpty(indexPic as string))
            {
                Session.Add("upPreFile", indexPic);
                //缩略图
                f.MakeThumbnail(indexPic, 300, 0, "W");
                f.MakeThumbnail(indexPic, 400, 0, "W");
                f.MakeThumbnail(indexPic, 500, 0, "W");
            }
            
            string session = string.Empty;
            if (!string.IsNullOrEmpty(Session["upPreFile"] as string))
            {
                session = Session["upPreFile"].ToString().Trim();
            }

            string strSql = "select Fid,fileName from upFileName where fileFlag='Img' and fileID='" + Session["upFileID"].ToString() + "' order by Fid ASC ";
            //Response.Write(strSql);
            //Response.End();
            DataTable dt = sql.getDataTable(strSql);
            if (dt.Rows.Count > 0)
            {
                imgHtm.Text = "<table cellspacing=\"8\" cellpadding=\"8\" border=\"0\" align=\"left\">";

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string select = string.Empty;
                    string fileName = dt.Rows[i]["fileName"].ToString().Trim();
                    if (fileName == session)
                    {
                        select = " checked=\"checked\"";
                    }

                    if ((i + 1) % 4 == 1)
                    {
                        imgHtm.Text += "<tr>";
                    }

                    imgHtm.Text += " <td valign=\"bottom\"><ul><li><img src=\"" + f.filePath(fileName + ".300.jpg") + "\" style=\"width:136px; vertical-align:middle;\" /></li><li><input name=\"checkList\" type=\"radio\" " + select + " value=\"" + fileName + "\" />&nbsp;&nbsp;<a href=\"img.aspx?del=" + fileName + "\">删除</a>&nbsp;&nbsp;<a href=\"imgTxt.aspx?id=" + dt.Rows[i]["fid"].ToString().Trim() + "\">修改</a></li></ul></td>";
                    if ((i + 1) % 4 == 0)
                    {
                        imgHtm.Text += "<tr>";
                    }
                }
            }
            else
            {
                imgHtm.Text = "<div style=\"padding:20px;\">暂无预览图，此项设置用于首页或子栏目图文新闻缩略图读取时使用！<br /><br />如通过 <span style=\"color:#333;\">本地上传</span> 已上传相关图片的还无显示，请点击 <a href=\"img.aspx\" style=\"font-weight:bold; font-size:14px;\">刷新一下</a> 试一试！</div>";
            }

            dt.Dispose();

            //删除图片
            string delID = Request.QueryString["del"];
            if (!string.IsNullOrEmpty(delID as string))
            {
                if (delID.Trim().Equals(Session["upPreFile"].ToString().Trim()))
                {
                    Response.Write("<script type=\"text/javascript\">{window.alert(\"不能删除已选预览图，请上传一张新图片后再操作！\");}</script>");
                }
                else
                {
                    f.del(delID);
                    sql.del("upFileName", "fileName", delID.ToString(), "", false, "");
                    Response.Redirect("img.aspx", true);
                }
            }
        }
    }
}