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;

public partial class Tool_addLink : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnOK_ServerClick(object sender, EventArgs e)
    {
        string sname = this.sname.Text.Trim();
        string surl = this.surl.Text.Trim();
        string sdesc = this.sdesc.Text.Trim();
        string semail = this.semail.Text.Trim();
        if (string.IsNullOrEmpty(sname))
        {
            this.RegistScript("<script>alert('网站名称不能为空！');</script>"); return;
        }
        if (string.IsNullOrEmpty(surl))
        {
            this.RegistScript("<script>alert('网站URL不能为空！');</script>"); return;
        }
        if (string.IsNullOrEmpty(sdesc))
        {
            this.RegistScript("<script>alert('网站描述不能为空！');</script>"); return;
        }

        try
        {
            string s = string.Format("SELECT COUNT(ID) FROM LINKS WHERE SURL='{0}'",this.surl.Text.Trim());
            int sc = SqlHelper.ExecuteSql(s);
            if (sc > 0)
                this.RegistScript("<script>您的网站已申请，请勿重复申请，做好本站连接后点入即可显示</script>");
            else
            {
                surl = surl.Replace("http://","");
                string sql = string.Format("INSERT INTO LINKS(SNAME,SURL,SDESC,SEMAIL,sip,scount,soutcount,stime) values('{0}','{1}','{2}','{3}','{4}',{5},{6},'{7}')", sname, surl, sdesc, semail, WebClass.GetClientIP(), 0, 0, DateTime.Now);
                int k = SqlHelper.ExecuteSql(sql);
                if (k > 0)
                {
                    this.RegistScript("<script>alert('申请成功，请做好本站连接');location.href='link.aspx'</script>");
                }
                else

                    this.RegistScript("<script>alert('申请失败！请联系管理员');</script>");
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("err.aspx?s=" + Server.HtmlEncode(ex.Message));
        }
    }
    void RegistScript(string str)
    {
        Page.ClientScript.RegisterStartupScript(typeof(string), Guid.NewGuid().ToString(), str);
    }
}
