Exemplo n.º 1
0
        /// <summary>
        /// Gets the item from database.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="databaseName">Name of the database.</param>
        /// <returns></returns>
        public XPathNodeIterator GetItemFromDatabase(string path, string databaseName)
        {
            Database db = Factory.GetDatabase(databaseName);

            if (db != null)
            {
                Item itm = db.GetItem(path);
                if (itm != null)
                {
                    ItemNavigator navigator = Factory.CreateItemNavigator(itm);
                    if (navigator != null)
                    {
                        return(navigator.Select("."));
                    }
                }
            }

            XPathNavigator emptyNavigator = new XmlDocument().CreateNavigator();

            if (emptyNavigator != null)
            {
                return(emptyNavigator.Select("*"));
            }

            return(null);
        }
        private static void SetText(DataContext db, Type tableType, ItemNavigator itemNavigator)
        {
            ParameterExpression param  = Expression.Parameter(tableType, "c");
            Expression          right  = Expression.Constant(itemNavigator.ValueNullable.Value);
            Expression          left   = Expression.Property(param, tableType.GetProperty("id"));
            Expression          filter = Expression.Equal(left, right);
            Expression          pred   = Expression.Lambda(filter, param);

            ITable     table = db.GetTable(tableType);
            Expression expr  = Expression.Call(typeof(Queryable), "Where", new[] { tableType },
                                               Expression.Constant(table), pred);
            IQueryable  query      = table.AsQueryable().Provider.CreateQuery(expr);
            IEnumerator enumerator = query.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                itemNavigator.Text = "[запись не найдена]";
                return;
            }
            var obj = enumerator.Current;

            itemNavigator.Text = GetText(obj, itemNavigator.ColumnName);
            if (!string.IsNullOrEmpty(itemNavigator.AlternativeColumnName))
            {
                itemNavigator.AlternativeText = GetText(obj, itemNavigator.AlternativeColumnName);
            }
        }
        private static void AddParentNavigators(IDictionary <Type, ItemNavigator> navigators, XContainer doc, DataContext db, Type type, string removeInKey, MainPageUrlBuilder url, ref int order)
        {
            ItemNavigator navigator;

            if (!navigators.ContainsKey(type))
            {
                var element = doc.Element("data").Elements().FirstOrDefault(e => e.Attribute("TableType").Value == type.Name);
                if (element == null)
                {
                    throw new Exception("Не найдена таблица '" + type.Name + "' для построения связи (DataInformation_*).");
                }
                navigator = new ItemNavigator();
                navigators.Add(type, navigator);
                navigator.TableName             = element.Attribute("TableName").Value;
                navigator.TableType             = type;
                navigator.RecordCaption         = element.Attribute("RecordCaption").Value;
                navigator.TableCaption          = element.Attribute("Title").Value;
                navigator.ParentReferences      = element.Attribute("ParentReferences").Value;
                navigator.IsMain                = Convert.ToBoolean(element.Attribute("IsMain").Value);
                navigator.ColumnName            = element.Attribute("ColumnName").Value;
                navigator.AlternativeColumnName = element.Attribute("AlternativeColumnName").Value;
                SetUrls(removeInKey, navigator, url);
                if (navigator.ValueNullable.HasValue)
                {
                    SetText(db, type, navigator);
                }
            }
            else
            {
                navigator = navigators[type];
                if (string.IsNullOrEmpty(navigator.EditUrl) && !navigator.IsFiltered)
                {
                    SetUrls(removeInKey, navigator, url);
                    if (navigator.ValueNullable.HasValue)
                    {
                        SetText(db, type, navigator);
                    }
                }
            }
            navigator.OrderField = order++;
            if (!navigator.IsMain && !string.IsNullOrEmpty(navigator.ParentReferences))
            {
                foreach (var parent in navigator.ParentReferences.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var property = type.GetProperty(parent);
                    if (property != null && property.PropertyType != type)
                    {
                        AddParentNavigators(navigators, doc, db, property.PropertyType,
                                            removeInKey == null ? parent : removeInKey + "." + parent,
                                            url, ref order);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ListNodeIterator"/> class.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="reverseOrder">if set to <c>true</c> [reverse order].</param>
        private ListNodeIterator(List <Item> items, bool reverseOrder)
        {
            this.reverseOrder = reverseOrder;
            this.list         = new List <XPathNavigator>();
            foreach (Item item in items)
            {
                if (item == null)
                {
                    continue;
                }

                ItemNavigator nav = Factory.CreateItemNavigator(item);
                this.list.Add(nav.CreateNavigator());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets an XPathNodeIterator for a set of items.
        /// </summary>
        /// <param name="idlist">Pipe-separated string containing Sitecore Item IDs</param>
        /// <returns>An XPathNodeIterator for the Sitecore item</returns>
        public new XPathNodeIterator Items(string idlist)
        {
            var      items    = new List <XPathNavigator>();
            Database database = Sitecore.Context.Database;

            string[] ids = idlist.Trim(' ', '|').Split('|');
            foreach (string id in ids)
            {
                Item item = database.GetItem(id, Sitecore.Context.ContentLanguage);
                if (item != null)
                {
                    ItemNavigator nav = Factory.CreateItemNavigator(item);
                    items.Add(nav.CreateNavigator());
                }
            }

            return(new ListNodeIterator(items, false));
        }
        private Item findItemByXpathXMLQuery(Item item, string query)
        {
            try
            {
                ItemNavigator navigator = Sitecore.Configuration.Factory.CreateItemNavigator(item);
                if (navigator != null)
                {
                    System.Xml.XPath.XPathNodeIterator foundItemNavigator = navigator.Select(query);
                    if (foundItemNavigator != null && foundItemNavigator.MoveNext())
                    {
                        return(GetItem(foundItemNavigator));
                    }
                }
            }
            catch (Exception ex)
            {
//                return string.Format("<br>Exeption: {0} for query: {1} </br>", ex.ToString(), query);
            }
            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets an XPathNodeIterator for an item.
        /// </summary>
        /// <param name="id">
        /// Sitecore Item ID
        /// </param>
        /// <returns>
        /// An XPathNodeIterator for the Sitecore item
        /// </returns>
        public XPathNodeIterator Item(string id)
        {
            var      items    = new List <XPathNavigator>();
            Database database = Sitecore.Context.Database;

            if (string.IsNullOrEmpty(id))
            {
                return(new ListNodeIterator());
            }

            Item item = database.GetItem(id, Sitecore.Context.Language);

            if (item != null)
            {
                ItemNavigator nav = Factory.CreateItemNavigator(item);
                items.Add(nav.CreateNavigator());
            }

            return(new ListNodeIterator(items, false));
        }
Exemplo n.º 8
0
 private void BiNext_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     ItemNavigator.MoveNext();
 }
Exemplo n.º 9
0
 private void BiPrevious_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     ItemNavigator.MovePrevious();
 }
        private static void SetUrls(string removeInKey, ItemNavigator item, MainPageUrlBuilder url)
        {
            var builder = new MainPageUrlBuilder
            {
                UserControl   = item.TableName + "Edit",
                IsDataControl = true,
                IsRead        = true,
                Page          = url.Page,
                ShowHistory   = url.ShowHistory,
            };
            bool needLookLink = false;

            if (!string.IsNullOrEmpty(removeInKey))
            {
                string thisFilter = removeInKey + ".id";
                removeInKey += ".";
                var index = removeInKey.Length;
                foreach (var pair in url.QueryParameters)
                {
                    if (thisFilter.Equals(pair.Key, StringComparison.OrdinalIgnoreCase))
                    {
                        long value;
                        if (long.TryParse(pair.Value, out value))
                        {
                            item.ValueNullable = value;
                            builder.QueryParameters["ref" + item.TableName] = pair.Value;
                            needLookLink = true;
                        }
                    }
                    else if (pair.Key.StartsWith(removeInKey))
                    {
                        builder.QueryParameters[pair.Key.Substring(index)] = pair.Value;
                    }
                    else if (pair.Key.Equals("ref" + item.TableName))
                    {
                        long value;
                        if (long.TryParse(pair.Value, out value))
                        {
                            item.ValueNullable = value;
                        }
                        if (!string.IsNullOrEmpty(pair.Value))
                        {
                            needLookLink = true;
                            builder.QueryParameters[pair.Key] = pair.Value;
                        }
                    }
                    else if (!pair.Key.Contains('.'))
                    {
                        builder.QueryParameters[pair.Key] = pair.Value;
                    }
                }
            }
            foreach (var parameter in url.ControlFilterParameters)
            {
                //todo: надо както убирать фильтры дочерних журналов, при возврате вверх по ссылкам
//                if (item.TableName == parameter.Key)
//                    break;
                builder.ControlFilterParameters.Add(parameter);
            }
            if (needLookLink)
            {
                item.EditUrl = builder.CreateUrl();
            }
            builder.UserControl = item.TableName + "Journal";
            builder.IsRead      = false;
            item.IsFiltered     = builder.QueryParameters.Count > 0;
            item.JournalUrl     = builder.CreateUrl();
        }