예제 #1
0
        private static DacInfo ReadProperties(string dacName)
        {
            if (string.IsNullOrEmpty(dacName))
            {
                return(null);
            }

            lock (_dacMap.SyncRoot)
            {
                var res = _dacMap[dacName] as DacInfo;
                if (res == null)
                {
                    PXFieldState[] fieldStates = null;
                    var            dac         = BuildManager.GetType(dacName, false);
                    if (dac != null)
                    {
                        var graph = new PXGraph();
                        fieldStates = PXFieldState.GetFields(graph, new Type[] { dac }, false);
                    }
                    res = DacInfo.Create(dacName, fieldStates);
                    _dacMap.Add(dacName, res);
                }
                return(res);
            }
        }
예제 #2
0
        public static List <CacheEntityItem> TemplateEntity(PXGraph graph, string parent, PXSiteMap.ScreenInfo _info)
        {
            List <CacheEntityItem> ret = new List <CacheEntityItem>();

            if (parent == null)
            {
                int i = 0;
                if (_info.GraphName != null)
                {
                    foreach (Data.Description.PXViewDescription viewdescr in _info.Containers.Values)
                    {
                        CacheEntityItem item = new CacheEntityItem();
                        item.Key    = viewdescr.ViewName;
                        item.SubKey = viewdescr.ViewName;
                        item.Path   = null;
                        item.Name   = viewdescr.DisplayName;
                        item.Number = i++;
                        item.Icon   = Sprite.Main.GetFullUrl(Sprite.Main.Box);
                        ret.Add(item);
                    }
                }
            }
            else
            {
                string[] viewname = null;
                _info.Views.TryGetValue(parent, out viewname);
                if (viewname != null)
                {
                    int f         = 0;
                    var tempgraph = (PXGraph)PXGraph.CreateInstance(GraphHelper.GetType(_info.GraphName));
                    if (!tempgraph.Views.ContainsKey(parent))
                    {
                        return(null);
                    }

                    foreach (PXFieldState field in PXFieldState.GetFields(graph, tempgraph.Views[parent].BqlSelect.GetTables(), false))
                    {
                        CacheEntityItem item = new CacheEntityItem();
                        item.Key    = parent + "." + field.Name;
                        item.SubKey = field.Name;
                        item.Path   = "((" +
                                      (string.IsNullOrEmpty(parent)
                                                                                                        ? field.Name
                                                                                                        : parent + "." + field.Name) + "))";
                        item.Name   = field.DisplayName;
                        item.Number = f++;
                        item.Icon   = Sprite.Main.GetFullUrl(Sprite.Main.BoxIn);
                        ret.Add(item);
                    }
                }
            }
            return(ret);
        }
        protected virtual void BoxScreenConfiguration_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            var screenConfig = e.Row as BoxScreenConfiguration;

            if (!string.IsNullOrEmpty(screenConfig.ScreenID))
            {
                string graphTypeName = PXPageIndexingService.GetGraphTypeByScreenID(screenConfig.ScreenID);
                if (string.IsNullOrEmpty(graphTypeName))
                {
                    throw new PXException(Messages.PrimaryGraphForScreenIDNotFound, screenConfig.ScreenID);
                }
                Type graphType = PXBuildManager.GetType(graphTypeName, true);
                var  graph     = PXGraph.CreateInstance(graphType);

                string primaryViewName = PXPageIndexingService.GetPrimaryView(graphTypeName);
                PXView view            = graph.Views[primaryViewName];

                //Construct ddl values and displayed values, specifying field name for duplicates
                var fieldsArray  = PXFieldState.GetFields(graph, view.BqlSelect.GetTables(), true);
                var displayNames = fieldsArray.GroupBy(fa => fa.DisplayName).ToDictionary(k => k.Key, v => v.ToList());
                var labels       = new List <string>();
                var values       = new List <string>();
                foreach (var displayName in displayNames)
                {
                    if (displayName.Value.Count > 1)
                    {
                        foreach (var displayNameField in displayName.Value)
                        {
                            labels.Add($"{displayName.Key} ({displayNameField.Name})");
                            values.Add(displayNameField.Name);
                        }
                    }
                    else
                    {
                        labels.Add(displayName.Key);
                        values.Add(displayName.Value.FirstOrDefault()?.Name);
                    }
                }

                PXStringListAttribute.SetList <BoxScreenGroupingFields.fieldName>(Fields.Cache, null, values.ToArray(), labels.ToArray());
            }
        }
        private void ReadProperties()
        {
            _propertyNames  = new string[0];
            _propertyLabels = new string[0];
            _propertyStates = new PXFieldState[0];
            _numFields.Clear();
            _dateFields.Clear();
            _stringFields.Clear();

            var fieldStates =
                PXFieldState.GetFields(this, new[] { typeof(Contact) }, false)
                .Where(s => s.Name.EndsWith("_Attributes") || !s.Name.Contains('_')).ToList();

            fieldStates.AddRange(PXFieldState.GetFields(this, new[] { typeof(Address) }, false)
                                 .Where(state => !state.Name.Contains('_') && !fieldStates.Exists(e => e.Name == state.Name || e.DisplayName == state.DisplayName))
                                 .Select(state => PXFieldState.CreateInstance(state, null, null, null, null, null, null, null, typeof(Address).Name + "__" + state.Name, null, null, null, PXErrorLevel.Undefined, null, null, null, PXUIVisibility.Undefined, null, null, null)));

            var properties = new List <PXFieldState>();

            foreach (var state in fieldStates)
            {
                string fieldName = state.Name.Replace(typeof(Address).Name + "__", string.Empty);

                if (fieldName.EndsWith("_Attributes") ||
                    (state.Visibility != PXUIVisibility.Invisible &&
                     state.Visible && !string.IsNullOrEmpty(state.DisplayName) &&
                     !fieldName.Contains('_') &&
                     !properties.Exists(item => item.Name == fieldName || item.DisplayName == state.DisplayName)))
                {
                    properties.Add(state);

                    if (!string.IsNullOrEmpty(state.ViewName) && !Views.ContainsKey(state.ViewName))
                    {
                        Views.Add(state.ViewName, this.FilteredItems.View);
                    }
                    switch (Type.GetTypeCode(state.DataType))
                    {
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                    case TypeCode.UInt64:
                    case TypeCode.Single:
                    case TypeCode.Double:
                    case TypeCode.Decimal:
                        _numFields.Add(state.Name);
                        break;

                    case TypeCode.DateTime:
                        _dateFields.Add(state.Name);
                        break;

                    case TypeCode.String:
                    case TypeCode.Char:
                        _stringFields.Add(state.Name);
                        break;
                    }
                }
            }
            _propertyNames  = new string[properties.Count];
            _propertyLabels = new string[properties.Count];
            _propertyStates = new PXFieldState[properties.Count];
            //properties.Sort((fs1, fs2) => String.Compare(String.Concat(fs1.DisplayName, "$", fs1.Name), String.Concat(fs2.DisplayName, "$", fs2.Name)));
            for (int i = 0; i < properties.Count; i++)
            {
                PXFieldState state = properties[i];
                _propertyNames[i]  = state.Name;
                _propertyLabels[i] = state.DisplayName;
                _propertyStates[i] = state;
            }

            MakeEqualLabelsDistinct();
        }