Example #1
0
        public static byte[] GetFile(string uri, Page page)
        {
            var url = new MainPageUrlBuilder(uri);

            if (!url.IsDownload)
            {
                throw new ArgumentException("is incorrect url");
            }
            var type        = BuildManager.GetType(url.QueryParameters["ManagerType"], false, true);
            var fileManager = (IFileManager2)Activator.CreateInstance(type);

            if (!fileManager.CheckPermit(page))
            {
                return(null);
            }
            return(fileManager.GetFile(Convert.ToInt64(url.QueryParameters["ID"]), url.QueryParameters["fieldName"]));
        }
 public static IDictionary <Type, ItemNavigator> GetItemNavigators(MainPageUrlBuilder UrlBuilder, Type type, Type dataContextType)
 {
     return(GetItemNavigators(UrlBuilder, type, dataContextType, ""));
 }
 public static IEnumerable <ItemNavigator> GetItems(MainPageUrlBuilder UrlBuilder, Type type, Type dataContextType)
 {
     return(GetItemNavigators(UrlBuilder, type, dataContextType).Values.Where(p => p.ValueNullable.HasValue).OrderByDescending(p => p.OrderField).ToArray());
 }
        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();
        }
        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);
                    }
                }
            }
        }
        private static void AddParentNavigators(IDictionary <Type, ItemNavigator> navigators, Type type, MainPageUrlBuilder url, Type dataContextType, string projectName)
        {
            var doc     = GetDocumnet(projectName);
            var db      = (DataContext)Activator.CreateInstance(dataContextType);
            int order   = 1;
            var element = doc.Element("data").Elements().FirstOrDefault(e => e.Attribute("TableType").Value == type.Name);

            if (element == null)
            {
                throw new Exception("Не найдена таблица '" + type.Name + "' для построения связи (DataInformation_*).");
            }
            var parentReferences = element.Attribute("ParentReferences").Value;
            var isMain           = Convert.ToBoolean(element.Attribute("IsMain").Value);

            if (!isMain && !string.IsNullOrEmpty(parentReferences))
            {
                foreach (var parent in parentReferences.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var property = type.GetProperty(parent);
                    if (property != null)
                    {
                        AddParentNavigators(navigators, doc, db, property.PropertyType, parent, url, ref order);
                        if (property.PropertyType == type)
                        {
                            navigators[type].Visible = /*url.ShowHistory &&*/ !string.IsNullOrEmpty(navigators[type].EditUrl);
                        }
                    }
                }
            }
        }