using System;
using System.Data;
using System.Configuration;
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.Data.OleDb;
using System.Collections;
using System.Xml;
using System.Text;
public partial class _Default : System.Web.UI.Page 
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.RegisterStartupScript(Guid.NewGuid().ToString(), string.Format("<script>InitData('{0}');</script>", this.TextBox1.ClientID));
            this.Button1.Attributes.Add("onclick", "return checkValue();");
            ArrayList al = new ArrayList();
            al.Add("www.jy310.com");
            al.Add("www.16sb.cn");
            al.Add("www.13sb.cn");
            al.Add("www.csfwu.cn");
            al.Add("www.13dk.cn");
            Random rand1 = new Random(unchecked((int)DateTime.Now.Ticks));
            int s = rand1.Next(0, 4);
            string ss = al[s].ToString();
            Random rand = new Random(unchecked((int)DateTime.Now.Ticks));
            int p = rand.Next(1, 44);
            this.RegisterStartupScript(Guid.NewGuid().ToString(), string.Format("<script>getu(\"TuiGuang.aspx?url={0}&page={1}\",'{2}')</script>", ss, p, this.frameS.ClientID));
            //this.frameS.Attributes["src"] = "TuiGuang.aspx?url="+ss+"&page=" + p;

            
        }QueryXML();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Session["timeLimit"] != null)
        {
            DateTime aTime = (DateTime)Session["timeLimit"];
            if (aTime.AddSeconds(60) > DateTime.Now)
            {
                Page.ClientScript.RegisterStartupScript(typeof(string), "",string.Format( "<script>alert('{0}')</script>","您不能在60秒内连续提交网站"));
                return;
            }
        }
        if (!string.IsNullOrEmpty(this.TextBox1.Text.Trim()))
        {
            InsertXmlTop(this.TextBox1.Text.Trim());
            object o = WebClass.GetCache("QueryTop");
            Page.ClientScript.RegisterStartupScript(typeof(string), Guid.NewGuid().ToString(), "<script>getp(\"TuiGuang.aspx?url=" + this.TextBox1.Text.Trim() + "&page=1\");</script>");
            Session["timeLimit"] = DateTime.Now;
        }
        else
            Page.ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('请输入域名！');</script>");
    }

    void InsertXmlTop(string value)
    {
        try
        {
            string sql = string.Format("insert into topQuery(qurl,qtime,qip,qstatus) values('{0}','{1}','{2}',true)", value, DateTime.Now, WebClass.GetClientIP());
            SqlHelper.ExecuteSql(sql);
        }
        catch (Exception ex)
        {
            Response.Redirect("err.aspx?s=" + Server.HtmlEncode(ex.Message));
        }
    }
    void QueryXML()
    {
        OleDbDataReader reader = null;
        try
        {
            string sql = "select top 30 * from topQuery order by id desc ";
            reader = SqlHelper.ExecuteReader(sql, null);
            StringBuilder sb = new StringBuilder();
            while (reader.Read())
            {
                string url = reader["qurl"].ToString().Replace("http://", "");
                sb.AppendFormat("<li><a href='http://{0}' title='查询ip:{1}&nbsp;&nbsp;最近查询时间:{2}' target='_blank'>{0}</a>&nbsp;&nbsp;</li>", url, reader["qip"], (DateTime.Parse(reader["qtime"].ToString())).ToString("yyyy-MM-dd hh:mm:ss"));
            }
            // sb.Append("<a href='http://www.13sb.cn'  target='_blank'>www.13sb.cn</a>");
            this.ulTop.InnerHtml = sb.ToString();
        }
        catch (Exception ex) { Response.Redirect("err.aspx?s=" + Server.HtmlEncode(ex.Message)); }
        finally { if (reader != null){reader.Close(); reader = null;} }
    }
}
