예제 #1
0
        private List <TModel> GetSource(IBaseManager <TModel> mgr)
        {
            // очищаем кэш
            mgr.ClearCache();

            if (InPropertyEditMode)
            {
                var values     = new List <TModel>();
                var filterList = FilterHelper.GetArrayFilterIn(typeof(TModel), (IEnumerable <object>)PropertyEditSource);
                foreach (var filter in filterList)
                {
                    values.AddRange(mgr.GetFiltered(filter).ToArray());
                }
                if (values.Count() != PropertyEditSource.Count())
                {
                    var diff =
                        PropertyEditSource.Where(
                            p =>
                            values.Cast <IKeyHandler>()
                            .FirstOrDefault(i => i.GetKey().Equals(((IKeyHandler)p).GetKey())) == null)
                        .ToList();
                    if (diff.Any())
                    {
                        throw new OperationException("Объекты были удалены: {0}",
                                                     string.Join(",", diff.Cast <IKeyHandler>().Select(i => i.GetKey())));
                    }
                }
                return(values);
            }

            // получаем данные
            var keyHandler = Source as IKeyHandler;

            if (keyHandler == null)
            {
                throw new DeveloperException("Source is not IKeyHandler.");
            }

            var result = mgr.Get(keyHandler.GetKey());

            return(new List <TModel>(new[] { result }));
            // обновляем все связанные списки
            //mgr.RiseManagerChanged();
        }
예제 #2
0
        public override ObservableCollection <DataField> GetDataFields(SettingDisplay displaySetting)
        {
            var fields = DataFieldHelper.Instance.GetDataFields(typeof(IWBPosInput), displaySetting);

            #region .  SKU filter  .
            var skuField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.SKUIDPropertyName));
            if (skuField != null)
            {
                skuField.LookupFilterExt = string.Empty;

                if (MandantId != null)
                {
                    skuField.LookupFilterExt = string.Format("mandantid = {0}", MandantId.Value);
                }

                if (!string.IsNullOrEmpty(Source.ArtCode))
                {
                    skuField.LookupFilterExt += string.IsNullOrEmpty(skuField.LookupFilterExt)
                        ? string.Format("upper(artcode_r)='{0}'", Source.ArtCode.ToUpper())
                        : string.Format(" and upper(artcode_r)='{0}'", Source.ArtCode.ToUpper());
                }
            }
            #endregion

            #region .  Factory filter  .
            var factoryField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.FACTORYID_RPropertyName));
            if (factoryField != null && MandantId != null)
            {
                factoryField.LookupFilterExt = string.Format("PartnerID_r = {0}", MandantId.Value);
            }
            #endregion

            #region .  TEType filter  .

            if (InPropertyEditMode)
            {
                var teTypeField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.TETypeCodePropertyName));
                var filter      = string.Format("1=1 or (TETYPECODE in (select TETYPECODE_R from wmssku2tte where wmssku2tte.SKUID_R in ({0}) group by TETYPECODE_R having count(*) = {1}))", string.Join(",", PropertyEditSource.Select(i => i.GetProperty(IWBPosInput.SKUIDPropertyName))), PropertyEditSource.Count());
                if (teTypeField != null)
                {
                    teTypeField.LookupFilterExt = string.IsNullOrEmpty(teTypeField.LookupFilterExt) ? filter : " and " + filter;
                }
            }

            #endregion

            // не даем редактировать, если SKU базовая
            var productCountField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.ProductCountPropertyName));
            if (productCountField != null)
            {
                productCountField.IsEnabled = InPropertyEditMode ? PropertyEditSource.FirstOrDefault(i => i.IsBaseSKU) == null : !Source.IsBaseSKU;
            }
            return(fields);
        }
예제 #3
0
        public override ObservableCollection <DataField> GetDataFields(SettingDisplay displaySetting)
        {
            var fields = DataFieldHelper.Instance.GetDataFields(typeof(IWBPosInput), displaySetting);

            #region .  SKU filter  .
            var skuField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.SKUIDPropertyName));
            if (skuField != null)
            {
                skuField.LookupFilterExt = string.Empty;

                if (MandantId != null)
                {
                    skuField.LookupFilterExt = string.Format("mandantid = {0}", MandantId.Value);
                }

                if (!string.IsNullOrEmpty(Source.ArtCode))
                {
                    skuField.LookupFilterExt += string.IsNullOrEmpty(skuField.LookupFilterExt)
                        ? string.Format("upper(artcode_r)='{0}'", Source.ArtCode.ToUpper())
                        : string.Format(" and upper(artcode_r)='{0}'", Source.ArtCode.ToUpper());
                }
            }
            #endregion

            #region .  Factory filter  .
            var factoryField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.FACTORYID_RPropertyName));
            if (factoryField != null && MandantId != null)
            {
                factoryField.LookupFilterExt = string.Format("PartnerID_r = {0}", MandantId.Value);
            }
            #endregion

            #region .  TEType filter  .

            if (InPropertyEditMode)
            {
                var teTypeField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.TETypeCodePropertyName));
                var filter      = string.Format("1=1 or (TETYPECODE in (select TETYPECODE_R from wmssku2tte where wmssku2tte.SKUID_R in ({0}) group by TETYPECODE_R having count(*) = {1}))", string.Join(",", PropertyEditSource.Select(i => i.GetProperty(IWBPosInput.SKUIDPropertyName))), PropertyEditSource.Count());
                if (teTypeField != null)
                {
                    teTypeField.LookupFilterExt = string.IsNullOrEmpty(teTypeField.LookupFilterExt) ? filter : " and " + filter;
                }
            }

            #endregion

            #region . TE visible .
            var teField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.IWBPosTEPropertyName));
            if (teField != null && !teField.Visible)
            {
                teField.Visible = true;
            }
            #endregion

            #region .  Place add .
            var placeField = new DataFieldWithDomain
            {
                Name        = "Place",
                Visible     = true,
                IsEnabled   = true,
                Caption     = "Место",
                FieldName   = "Place",
                BindingPath = "Place",
                FieldType   = typeof(EntityReference),
                Domain      = new EntityRefDomain
                {
                    EntityRefDescriptor = new EntityRefDescriptor
                    {
                        EntityType = Place.EntityType,
                        Fields     = new List <EntityRefFieldDescriptor>
                        {
                            new EntityRefFieldDescriptor {
                                Name = "PlaceCode"
                            },
                            new EntityRefFieldDescriptor {
                                Name = "PlaceName"
                            }
                        },
                        Format = "{{=it.PlaceName}}"
                    }
                },
                SourceName = "Place"
            };
            fields.Add(placeField);
            #endregion

            // не даем редактировать, если SKU базовая
            var productCountField = fields.FirstOrDefault(i => i.Name.EqIgnoreCase(IWBPosInput.ProductCountPropertyName));
            if (productCountField != null)
            {
                productCountField.IsEnabled = InPropertyEditMode ? PropertyEditSource.FirstOrDefault(i => i.IsBaseSKU) == null : !Source.IsBaseSKU;
            }

            //Формат полей
            if (DisplayFieldsFormat != null)
            {
                foreach (var item in fields.Where(p => !string.IsNullOrEmpty(p.Name) && DisplayFieldsFormat.ContainsKey(p.Name)))
                {
                    item.DisplayFormat = DisplayFieldsFormat[item.Name];
                }
            }

            return(fields);
        }