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.Text;
using System.IO;
using xl_utils;
using xl_data;

/* This page add by Firgray.XL (Friday,February 06,2009) */
public partial class SYSadmin_Products_newpicslist : System.Web.UI.Page
{
    // Methods
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Fetch.Get("id");
        string pid = Fetch.Get("pid");
        string _content = null;
        if (Fetch.Get("action") == "delpics" && pid != string.Empty)
        {
            string _picpath = new Connection().GetScalar("Select P_Path From News_Pics Where P_Id = " + pid);
            if (File.Exists(Fetch.MapPath("../../" + _picpath)))
            {
                File.Delete(Fetch.MapPath("../../" + _picpath));
            }
            new Connection().ExecSql("Delete From News_Pics Where P_Id = " + pid);
            if (id.CompareTo(pid) == 0)
            {
                id = id.Replace(pid, "");
            }
            else if (id.IndexOf(pid) < pid.Length)
            {
                id = id.Replace(pid + ",", "");
            }
            else if (id.IndexOf(pid) >= pid.Length && id.IndexOf(pid) < (id.Length - pid.Length))
            {
                id = id.Replace(pid, "").Replace(",,", ",");
            }
            else if (id.IndexOf(pid) >= (id.Length - pid.Length))
            {
                id = id.Replace("," + pid, "");
            }
            _content += "\r\n<script type=\"text/javascript\">";
            _content += "\r\n<!--";
            if (id == "")
            {
                _content += "\r\n\tparent.$(\"news_pics\").value = '';";
                _content += "\r\n\tparent.$(\"picslist\").style.display = 'none';";
            }
            else
            {
                _content += "\r\n\tparent.$(\"news_pics\").value = '" + id + "';";
                _content += "\r\n\tparent.$(\"picslist\").style.display = 'block';";
                _content += "\r\n\tparent.$(\"picslist\").src = 'newpicslist.aspx?id=" + id + "';";
            }
            _content += "\r\n//-->";
            _content += "\r\n</script>";
        }
        else
        {
            DataTable dataTable = new Connection().GetDataTable("Select * From News_Pics Where P_Id In (" + id + ")");
            int iCount = dataTable.Rows.Count;
            if (iCount > 0)
            {
                for (int i = 0; i < iCount; i++)
                {
                    string _picnote = Text.Left(dataTable.Rows[i]["P_Description"].ToString(), 8, false);
                    _content += string.Concat(new object[] { "<div style='float:left;text-align:center'>\r\n<img src='../../", dataTable.Rows[i]["P_Path"].ToString(), "' class='showpic' alt='", dataTable.Rows[i]["P_Description"].ToString(), "' /><br />", _picnote, " <a onclick='if(confirm())' href='?action=delpics&id=", id, "&pid=", dataTable.Rows[i]["P_Id"].ToString(), "' style='color:red;font-weight:700' title='删除这张图片'>×</a>\r\n</div>" });
                }
            }
            else
            {
                _content += "\r\n<script type=\"text/javascript\">";
                _content += "\r\n<!--";
                _content += "\r\n\tparent.$(\"picslist\").style.display = 'none';";
                _content += "\r\n//-->";
                _content += "\r\n</script>";
            }
            dataTable.Dispose();
        }
        this.picslist.InnerHtml = _content;
    }
}
