예제 #1
0
파일: Ad.cs 프로젝트: thinhtp/liteweb.info
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            CustomPage page = this.Page as CustomPage;

            string ids = "";

            if (page != null)
            {
                if (page.PageContext[cte.AdsContext] != null)
                {
                    ids = page.PageContext[cte.AdsContext].ToString();
                }
                else
                {
                    page.AddContext(cte.AdsContext, "", false);
                }
            }

            _ad = _aMgr.GetAd(Zone, Keywords, ids);
            if (_ad == null)
            {
                return;
            }

            AdsView ad = _ad;

            if (page != null)
            {
                page.AddContext(cte.AdsContext, string.Format("{0},{1}", page.PageContext[cte.AdsContext], ad.AdId), true);
            }

            switch (_type)
            {
            case AdRenderType.Image:
                if (string.IsNullOrEmpty(ad.Image))
                {
                    goto default;
                }
                if (string.IsNullOrEmpty(ad.URL))
                {
                    _render = string.Format("<img src=\"{0}\" alt=\"{1}\" />",
                                            ad.Image,
                                            ad.Description
                                            );
                }
                else
                {
                    _render = string.Format("<a href=\"{0}\" title=\"{1}\"{3}><img src=\"{2}\" alt=\"{1}\" /></a>",
                                            ad.URL,
                                            ad.Description,
                                            ad.Image,
                                            ad.NewWindow != null && ad.NewWindow.Value ? " target=\"_blank\"" : ""
                                            );
                }
                break;

            case AdRenderType.Html:
                if (string.IsNullOrEmpty(ad.HtmlCode))
                {
                    goto default;
                }

                _render = ad.HtmlCode;
                break;

            case AdRenderType.Name:
            default:
                _render = string.Format("<a href=\"{0}\" title=\"{1}\">{1}</a>",
                                        ad.URL, ad.Description);
                break;
            }

            base.DataBind();
        }