示例#1
0
        private void ItemsListControl_ItemDataBound(object sender, RadListViewItemEventArgs e)
        {
            if (e.Item.ItemType != RadListViewItemType.DataItem && e.Item.ItemType != RadListViewItemType.AlternatingItem)
            {
                return;
            }

            RealEstateItem item = ((RadListViewDataItem)e.Item).DataItem as RealEstateItem;

            if (item == null)
            {
                return;
            }

            System.Web.UI.WebControls.Image photo = (System.Web.UI.WebControls.Image)e.Item.FindControl("Photo");

            if (isThumbView)
            {
                photo.ImageUrl = item.GetPhotoUrl(SinglePhotoType.ThumbnailListPhoto);
            }
            else
            {
                photo.ImageUrl = item.GetPhotoUrl(SinglePhotoType.FlowListPhoto);
            }

            RadListView FeaturesList = (RadListView)e.Item.FindControl("FeaturesList");

            FeaturesList.ItemDataBound += new EventHandler <RadListViewItemEventArgs>(FeaturesList_ItemDataBound);
            FeaturesList.DataSource     = item.GetTaxons <FlatTaxon>(TaxonType.Features);
            FeaturesList.DataBind();
        }
        private void SlidesList_ItemDataBound(object sender, RadListViewItemEventArgs e)
        {
            if (e.Item.ItemType != RadListViewItemType.DataItem && e.Item.ItemType != RadListViewItemType.AlternatingItem)
            {
                return;
            }

            RadListViewDataItem dataItem = (RadListViewDataItem)e.Item;
            RealEstateItem      item     = (RealEstateItem)dataItem.DataItem;

            string sliderPhotoUrl     = item.GetPhotoUrl(SinglePhotoType.SliderPhoto);
            string sliderThumbnailUrl = item.GetPhotoUrl(SinglePhotoType.SliderThumbnail);

            if (sliderPhotoUrl.IsNullOrEmpty() || sliderThumbnailUrl.IsNullOrEmpty())
            {
                e.Item.Visible = false;
                return;
            }

            bool   isForSale      = item.IsForSale();
            string detailsPageUrl = this.GetDetailsPageUrl(isForSale);

            HyperLink hlDetails = (HyperLink)e.Item.FindControl("hlDetails");

            hlDetails.NavigateUrl = detailsPageUrl + this.RealEstateManager.GetItemUrl(item);

            Image imgSlider = (Image)e.Item.FindControl("imgSlider");

            imgSlider.AlternateText = item.Title;
            imgSlider.ImageUrl      = sliderPhotoUrl;

            Literal ltrAddress = (Literal)e.Item.FindControl("ltrAddress");

            ltrAddress.Text = item.Address;

            Literal ltrPrice = (Literal)e.Item.FindControl("ltrPrice");

            ltrPrice.Text = item.Price.ToString("n2");

            RadListView featuresList = (RadListView)e.Item.FindControl("FeaturesList");

            featuresList.ItemDataBound += new EventHandler <RadListViewItemEventArgs>(FeaturesList_ItemDataBound);
            featuresList.DataSource     = item.GetTaxons <FlatTaxon>(TaxonType.Features);
            featuresList.DataBind();
        }
        /// <summary>
        /// Handles the ItemDataBound event of the DetailsView control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Web.UI.RadListViewItemEventArgs"/> instance containing the event data.</param>
        private void DetailsView_ItemDataBound(object sender, RadListViewItemEventArgs e)
        {
            if (e.Item.ItemType != RadListViewItemType.DataItem && e.Item.ItemType != RadListViewItemType.AlternatingItem)
            {
                return;
            }

            RealEstateItem item = ((RadListViewDataItem)e.Item).DataItem as RealEstateItem;

            if (item == null)
            {
                return;
            }

            #region Contact Our Agent
            RadTabStrip  tabStrip           = (RadTabStrip)e.Item.FindControl("tabStrip");
            RadMultiPage multiPage          = (RadMultiPage)e.Item.FindControl("multiPage");
            RadTab       tabContactOurAgent = tabStrip.Tabs[5];

            if (tabContactOurAgent != null && !item.AgentId.Equals(Guid.Empty))
            {
                AgentItem agent = this.AgentsManager.GetAgent(item.AgentId);
                if (agent != null)
                {
                    tabContactOurAgent.NavigateUrl = AGENTS_PAGE + this.AgentsManager.GetItemUrl(agent);
                }
                else
                {
                    tabContactOurAgent.Visible     = false;
                    multiPage.PageViews[5].Visible = false;
                }
            }
            else
            {
                tabContactOurAgent.Visible     = false;
                multiPage.PageViews[5].Visible = false;
            }
            #endregion

            RadListView  rlvOverview       = (RadListView)e.Item.FindControl("rlvOverview");
            List <Photo> overviewTabPhotos = item.GetPhotos(MultiplePhotoType.OverviewTabPhoto);
            rlvOverview.DataSource = overviewTabPhotos;
            rlvOverview.DataBind();
            tabStrip.Tabs[0].Visible       = (overviewTabPhotos.Count > 0);
            multiPage.PageViews[0].Visible = tabStrip.Tabs[0].Visible;

            RadListView  rlvPhotos       = (RadListView)e.Item.FindControl("rlvPhotos");
            List <Photo> photosTabPhotos = item.GetPhotos(MultiplePhotoType.PhotosTabPhoto);
            rlvPhotos.DataSource = photosTabPhotos;
            rlvPhotos.DataBind();
            tabStrip.Tabs[1].Visible       = (photosTabPhotos.Count > 0);
            multiPage.PageViews[1].Visible = tabStrip.Tabs[1].Visible;

            RadListView  rlvPanaromicView       = (RadListView)e.Item.FindControl("rlvPanaromicView");
            List <Photo> panaromicViewTabPhotos = item.GetPhotos(MultiplePhotoType.PanaromicViewTabPhoto);
            rlvPanaromicView.DataSource = panaromicViewTabPhotos;
            rlvPanaromicView.DataBind();
            tabStrip.Tabs[2].Visible       = (panaromicViewTabPhotos.Count > 0);
            multiPage.PageViews[2].Visible = tabStrip.Tabs[2].Visible;

            RadListView  rlvFloorPlan       = (RadListView)e.Item.FindControl("rlvFloorPlan");
            List <Photo> floorPlanTabPhotos = item.GetPhotos(MultiplePhotoType.FloorPlanTabPhoto);
            rlvFloorPlan.DataSource = floorPlanTabPhotos;
            rlvFloorPlan.DataBind();
            tabStrip.Tabs[3].Visible       = (floorPlanTabPhotos.Count > 0);
            multiPage.PageViews[3].Visible = tabStrip.Tabs[3].Visible;

            if (item.Latitude <= 0 || item.Longitude <= 0)
            {
                tabStrip.Tabs[4].Visible       = false;
                multiPage.PageViews[4].Visible = false;
            }

            for (int i = 0; i < tabStrip.Tabs.Count; i++)
            {
                if (tabStrip.Tabs[i].Visible)
                {
                    tabStrip.SelectedIndex  = i;
                    multiPage.SelectedIndex = i;

                    this.Page.ClientScript.RegisterClientScriptBlock(
                        this.GetType(), "initialTabStripId",
                        string.Format("var initialTabStripId = '{0}';", multiPage.PageViews[i].ClientID), true);

                    break;
                }
            }

            Panel pnlPrice = (Panel)e.Item.FindControl("pnlPrice");
            pnlPrice.Controls.Clear();
            pnlPrice.Controls.Add(new Literal()
            {
                Text = item.Price.ToString("n2")
            });

            if (!item.Description.Value.IsNullOrEmpty())
            {
                PlaceHolder phDescription = (PlaceHolder)e.Item.FindControl("phDescription");
                phDescription.Visible = true;
            }

            #region Location
            FlatTaxon locationTaxon = item.GetTaxon <FlatTaxon>(TaxonType.Locations);
            if (locationTaxon != null)
            {
                Literal ltrLocation = (Literal)e.Item.FindControl("ltrLocation");

                ltrLocation.Text = locationTaxon.Title;
            }
            #endregion

            #region Item Type
            FlatTaxon itemTypeTaxon = item.GetTaxon <FlatTaxon>(TaxonType.Types);
            if (itemTypeTaxon != null)
            {
                PlaceHolder phItemType  = (PlaceHolder)e.Item.FindControl("phItemType");
                Literal     ltrItemType = (Literal)e.Item.FindControl("ltrItemType");

                ltrItemType.Text   = itemTypeTaxon.Title;
                phItemType.Visible = true;
            }
            #endregion

            #region Housing
            if (!item.Housing.IsNullOrEmpty())
            {
                PlaceHolder phHousing  = (PlaceHolder)e.Item.FindControl("phHousing");
                Literal     ltrHousing = (Literal)e.Item.FindControl("ltrHousing");
                ltrHousing.Text   = string.Format("{0} m<sup>2</sup>", item.Housing);
                phHousing.Visible = true;
            }
            #endregion

            #region Rooms
            if (!item.NumberOfRooms.IsNullOrEmpty())
            {
                PlaceHolder phRooms  = (PlaceHolder)e.Item.FindControl("phRooms");
                Literal     ltrRooms = (Literal)e.Item.FindControl("ltrRooms");
                ltrRooms.Text   = item.NumberOfRooms;
                phRooms.Visible = true;
            }
            #endregion

            #region Floors
            if (!item.NumberOfFloors.IsNullOrEmpty())
            {
                PlaceHolder phFloors  = (PlaceHolder)e.Item.FindControl("phFloors");
                Literal     ltrFloors = (Literal)e.Item.FindControl("ltrFloors");
                ltrFloors.Text   = item.NumberOfFloors;
                phFloors.Visible = true;
            }
            #endregion

            #region Built
            if (!item.YearBuilt.IsNullOrEmpty())
            {
                PlaceHolder phBuilt  = (PlaceHolder)e.Item.FindControl("phBuilt");
                Literal     ltrBuilt = (Literal)e.Item.FindControl("ltrBuilt");
                ltrBuilt.Text   = item.YearBuilt;
                phBuilt.Visible = true;
            }
            #endregion

            #region Payment
            if (item.Payment > 0)
            {
                PlaceHolder phPayment  = (PlaceHolder)e.Item.FindControl("phPayment");
                Literal     ltrPayment = (Literal)e.Item.FindControl("ltrPayment");
                ltrPayment.Text   = item.Payment.ToString("n2");
                phPayment.Visible = true;
            }
            #endregion

            #region MonthlyRate
            if (item.MonthlyRate > 0)
            {
                PlaceHolder phMonthlyRate  = (PlaceHolder)e.Item.FindControl("phMonthlyRate");
                Literal     ltrMonthlyRate = (Literal)e.Item.FindControl("ltrMonthlyRate");
                ltrMonthlyRate.Text   = item.MonthlyRate.ToString("n2");
                phMonthlyRate.Visible = true;
            }
            #endregion

            #region Net
            if (item.Net > 0)
            {
                PlaceHolder phNet  = (PlaceHolder)e.Item.FindControl("phNet");
                Literal     ltrNet = (Literal)e.Item.FindControl("ltrNet");
                ltrNet.Text   = item.Net.ToString("n2");
                phNet.Visible = true;
            }
            #endregion

            #region PriceSquareMeter
            if (item.PriceSquareMeter > 0)
            {
                PlaceHolder phPriceSquareMeter  = (PlaceHolder)e.Item.FindControl("phPriceSquareMeter");
                Literal     ltrPriceSquareMeter = (Literal)e.Item.FindControl("ltrPriceSquareMeter");
                ltrPriceSquareMeter.Text   = item.PriceSquareMeter.ToString("n2");
                phPriceSquareMeter.Visible = true;
            }
            #endregion

            RadListView FeaturesList = (RadListView)e.Item.FindControl("FeaturesList");
            FeaturesList.ItemDataBound += new EventHandler <RadListViewItemEventArgs>(FeaturesList_ItemDataBound);
            FeaturesList.DataSource     = item.GetTaxons <FlatTaxon>(TaxonType.Features);
            FeaturesList.DataBind();

            RadListView RoomsList = (RadListView)e.Item.FindControl("RoomsList");
            RoomsList.ItemDataBound += new EventHandler <RadListViewItemEventArgs>(RoomsList_ItemDataBound);
            RoomsList.DataSource     = item.GetTaxons <FlatTaxon>(TaxonType.Rooms);
            RoomsList.DataBind();

            #region Agent
            if (!item.AgentId.Equals(Guid.Empty))
            {
                AgentItem agent = this.AgentsManager.GetAgent(item.AgentId);

                if (agent != null)
                {
                    PlaceHolder phAgent = (PlaceHolder)e.Item.FindControl("phAgent");
                    phAgent.Visible = true;

                    Literal ltrAgentName = (Literal)e.Item.FindControl("ltrAgentName");
                    ltrAgentName.Text = agent.Title;


                    #region Address
                    if (!agent.Address.IsNullOrEmpty())
                    {
                        PlaceHolder phAgentAddress  = (PlaceHolder)e.Item.FindControl("phAgentAddress");
                        Literal     ltrAgentAddress = (Literal)e.Item.FindControl("ltrAgentAddress");
                        ltrAgentAddress.Text   = agent.Address;
                        phAgentAddress.Visible = true;
                    }
                    #endregion

                    #region PhoneNumber
                    if (!agent.PhoneNumber.IsNullOrEmpty())
                    {
                        PlaceHolder phAgentPhoneNumber  = (PlaceHolder)e.Item.FindControl("phAgentPhoneNumber");
                        Literal     ltrAgentPhoneNumber = (Literal)e.Item.FindControl("ltrAgentPhoneNumber");
                        ltrAgentPhoneNumber.Text   = agent.PhoneNumber;
                        phAgentPhoneNumber.Visible = true;
                    }
                    #endregion


                    #region Email
                    if (!agent.Email.IsNullOrEmpty())
                    {
                        PlaceHolder phAgentEmail = (PlaceHolder)e.Item.FindControl("phAgentEmail");
                        HyperLink   hlAgentEmail = (HyperLink)e.Item.FindControl("hlAgentEmail");
                        hlAgentEmail.Text        = agent.Email;
                        hlAgentEmail.NavigateUrl = tabContactOurAgent.NavigateUrl;
                        phAgentEmail.Visible     = true;
                    }
                    #endregion
                }
            }
            #endregion
        }