Beispiel #1
0
        private void CatBreadCrumbDataBind(object sender, EventArgs e)
        {
            var lc = (Literal)sender;
            var container = (IDataItemContainer)lc.NamingContainer;
            try
            {
                var grpCatCtrl = new GrpCatController(Utils.GetCurrentCulture());

                lc.Visible = visibleStatus.DefaultIfEmpty(true).First();

                if (visibleStatus.DefaultIfEmpty(true).First())
                {

                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml("<root>" + lc.Text + "</root>");
                    var xmlNod = xmlDoc.SelectSingleNode("root/tag");

                    var catid = -1;
                    if (container.DataItem is NBrightInfo)
                    {
                        // Must be displaying a product or category with (NBrightInfo), so get categoryid
                        var objCInfo = (NBrightInfo) container.DataItem;
                        if (String.IsNullOrEmpty(objCInfo.TypeCode) || objCInfo.TypeCode == "PRD") // no type is list header, so use catid in url if there.
                        {
                            //Is product so get categoryid
                            var id = Convert.ToString(DataBinder.Eval(container.DataItem, "ItemId"));
                            var targetModuleKey = "";
                            if (xmlNod != null && xmlNod.Attributes != null && xmlNod.Attributes["targetmodulekey"] != null) targetModuleKey = xmlNod.Attributes["targetmodulekey"].InnerText;
                            var obj = grpCatCtrl.GetCurrentCategoryData(PortalSettings.Current.PortalId, lc.Page.Request, Convert.ToInt32(id), _settings, targetModuleKey);
                            if (obj != null) catid = obj.categoryid;
                        }
                        else if (objCInfo.TypeCode == "CATEGORYLANG") // no type is list header, so use catid in url if there.
                        {
                            catid = objCInfo.ParentItemId;

                        }
                        else
                        {
                            catid = objCInfo.ItemID;
                        }
                    }

                    if (container.DataItem is GroupCategoryData)
                    {
                        // GroupCategoryData class, so use categoryid
                        var id = Convert.ToString(DataBinder.Eval(container.DataItem, "categoryid"));
                        if (Utils.IsNumeric(id)) catid = Convert.ToInt32(id);
                    }

                    var intLength = 400;
                    var intShortLength = -1;
                    var isLink = false;
                    var separator = ">";
                    var aslist = false;

                    if (xmlNod != null && xmlNod.Attributes != null)
                    {
                        if (xmlNod.Attributes["length"] != null)
                        {
                            if (Utils.IsNumeric(xmlNod.Attributes["length"].InnerText))
                            {
                                intLength = Convert.ToInt32(xmlNod.Attributes["length"].InnerText);
                            }
                        }
                        if (xmlNod.Attributes["links"] != null) isLink = true;
                        if (xmlNod.Attributes["short"] != null)
                        {
                            if (Utils.IsNumeric(xmlNod.Attributes["short"].InnerText))
                            {
                                intShortLength = Convert.ToInt32(xmlNod.Attributes["short"].InnerText);
                            }
                        }
                        if (xmlNod.Attributes["separator"] != null) separator = xmlNod.Attributes["separator"].InnerText;
                        if (xmlNod.Attributes["aslist"] != null && xmlNod.Attributes["aslist"].InnerText.ToLower() == "true") aslist = true;
                    }

                    if (catid > 0) // check we have a catid
                    {
                        if (isLink)
                        {
                            var defTabId = PortalSettings.Current.ActiveTab.TabID;
                            if (_settings.ContainsKey("ddllisttabid") && Utils.IsNumeric(_settings["ddllisttabid"])) defTabId = Convert.ToInt32(_settings["ddllisttabid"]);
                            lc.Text = grpCatCtrl.GetBreadCrumbWithLinks(catid, defTabId, intShortLength, separator, aslist);
                        }
                        else
                        {
                            lc.Text = grpCatCtrl.GetBreadCrumb(catid, intShortLength, separator, aslist);
                        }

                        if ((lc.Text.Length > intLength) && (!aslist))
                        {
                            lc.Text = lc.Text.Substring(0, (intLength - 3)) + "...";
                        }
                    }
                }
            }
            catch (Exception)
            {
                lc.Text = "";
            }
        }