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 webXabara_ads_ad : System.Web.UI.Page
{
    admin a = new admin();
    classify c = new classify();
    sqlServer sql = new sqlServer();
    javasrcipt js = new javasrcipt();

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

        c.bindingDropDownList("all", true, 0, "ads", adClass);

        long cid = xabara.isNum(Request.QueryString["cid"]);
        long w = xabara.isNum(Request.QueryString["w"]);
        long h = xabara.isNum(Request.QueryString["h"]);

        string jsCode = string.Empty;

        if (cid > 0)
        {
            DataTable dt = sql.getDataTable("select fnID,TreeName from NewsTree where tid=" + cid.ToString());
            if (dt.Rows.Count > 0)
            {
                string name = dt.Rows[0]["TreeName"].ToString().Trim();
                adName.Text = name + "<br />";
                if (name.IndexOf("_") > 0)
                {
                    jsCode = "<script src=\"http://" + Request.Url.Host + "/js/ad.aspx?id=" + dt.Rows[0]["fnID"].ToString().Trim() + "\" type=\"text/javascript\"></script>";
                }
                else
                {
                    js.div(false, "操作提示", "text", "分类 <span style='color:red;'>" + name + "</span> 命名不正确，如 首页顶部_468X60？", 400, 0, "", "");
                }
            }
            dt.Dispose();
        }
        else
        {
            if (w > 0 && h > 0)
            {
                adName.Text = "尺寸 " + w.ToString() + "X" + h.ToString() + " 全站随机广告：<br />";
                jsCode = "<script src=\"http://" + Request.Url.Host + "/js/ad.aspx?w=" + w.ToString() + "&h=" + h.ToString() + "\" type=\"text/javascript\"></script>";
            }
            else
            {
                js.div(false, "操作提示", "text", "<b>目前提供以下方式获取：</b><br />1. 通过固定广告位置随机显示<br />2. 通过广告高度和宽度使全站的同尺寸随机显示，如 468X60", 450, 0, "", "");
            }
        }

        if (!string.IsNullOrEmpty(jsCode as string))
        {
            ad.Text = jsCode;

            js.writeEnd(jsCode);
        }
    }

    protected void jsCode_Click(object sender, EventArgs e)
    {
        Response.Redirect("ad.aspx?cid=" + adClass.Text + "&w=" + adW.Text + "&h=" + adH.Text, true);
    }
}