コード例 #1
0
    protected void genCode(object sender, EventArgs e)
    {
        if (ddlsite.SelectedIndex == 0)
        {
            this.lbltest.Text = "<b>请先选择网站!</b><br />";
            this.txtgcode.Text = "";
            return;
        }
        validateMember userobj = MasterPageOpration.getMasterControl(this.Page.Master, "Muser");

        //生成广告代码
        string ad = hidadid.Value;
        string adhost=hidadhost.Value;
        string site = ddlsite.SelectedValue;// userobj.siteid;
        string uname=userobj.suser.userid.ToString();
        int adtype = 0;
        int paytype = 0;
        try  //假如不带参数过来,int.Parse会抛错,正好利用它判断是否正常访问本页
        {
            adtype = int.Parse(hidadtype.Value);
            paytype = int.Parse(hidpaytype.Value);
        }
        catch (Exception)
        {
            Response.Redirect("/member/default.aspx");
        }

        Uri thisurl = Request.Url;
        //thisurl = thisurl.Remove(thisurl.IndexOf('?'));
        string port = thisurl.Port == 80 ? "" : (":" + thisurl.Port.ToString());
        string url = "http://" + thisurl.Host + port + "/click/click.aspx";
        string urlparams = "?shopid=" + adhost + "&adid=" + ad + "&siteid=" + site + "&userid=" + uname + "&paytype=" + paytype;
        url += urlparams;

        string url_ctr = "http://" + thisurl.Host + port + "/click/";

        wgiAdUnionSystem.BLL.wgi_adv bll = new wgi_adv();
        wgiAdUnionSystem.Model.wgi_adv model = bll.GetModel(int.Parse(ad));
        string adcont = model.advcont;

        //计费模式
        switch (paytype)
        {
            case 1:
                //广告类型
                switch (adtype)
                {
                    case 1:
                        url += "&adtype=1";
                        //预览
                        this.lbltest.Text = "<a href=\"" + url + "&preview=1" + "\" target=\"_blank\">" + adcont + "</a>";
                        url = "<a href=\""+url+"\" target=\"_blank\">"+adcont+"</a>";
                        break;
                    case 2:
                        url += "&adtype=2";
                        //取出图片预设宽高
                        string w = model.advwidth.ToString();
                        string h = model.advheight.ToString();
                        //预览
                        this.lbltest.Text = "<a href=\"" + url + "&preview=1" + "\" target=\"_blank\"><img src=\"" + adcont + "\" alt=\"\" style=\"border:none; width:"+w+"px; height:"+h+"px\" /></a>";
                        url = "<a href=\"" + url + "\" target=\"_blank\"><img src=\"" + adcont + "\" alt=\"\" style=\"border:none; width:" + w + "px; height:" + h + "px\" /></a>";
                        break;
                    case 3:
                        break;
                    default:
                        break;
                }
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
            default:
                break;
        }
        //接上统计露出数字串
        url += "<img src='http://" + thisurl.Host + port + "/click/showCtr.aspx" + urlparams + "&adtype=" + adtype + "' alt='' style='display:none;' />";
        this.txtgcode.Text = url;
    }