示例#1
0
        private void dgvAllAttributes_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            if (e.Value == null)
            {
                return;
            }

            var value = e.Value.ToString();

            if (string.IsNullOrWhiteSpace(value) ||
                string.Equals(value, Resources.NewAttributeName, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            switch (dgvAttributes.Columns[e.ColumnIndex].HeaderText)
            {
            case ColumnAttributeName:
                if (e.RowIndex == _visibleAttributes.Count)
                {
                    var existingAttribute = Attribute.GetAttributeFromName(value, false);
                    if (existingAttribute != null)
                    {
                        MessageBox.Show(@"Attribute already exists!");
                    }
                    else
                    {
                        var newAttribute = Attribute.GetAttributeFromName(value, true);
                        _allAttributes.Add(newAttribute);
                        _visibleAttributes.Add(newAttribute);
                        dgvAttributes.RowCount++;
                    }
                }
                else
                {
                    if (!_visibleAttributes[e.RowIndex].AttributeName.ToLower().Equals(value.ToLower()))
                    {
                        MessageBox.Show(@"Only Capitalization can be fixed in the Attribute Farm");
                    }
                    else
                    {
                        _visibleAttributes[e.RowIndex].AttributeName = value;
                    }
                }
                break;

            case ColumnAttributeType:
                if (e.RowIndex < _visibleAttributes.Count)
                {
                    int rowIndex = e.RowIndex;
                    UpdateAttributeType(_visibleAttributes[rowIndex], value);
                }
                break;

            case ColumnAttributeGroup:
                if (e.RowIndex < _visibleAttributes.Count)
                {
                    int rowIndex = e.RowIndex;
                    UpdateAttributeGroup(_visibleAttributes[rowIndex], value);
                }
                break;
            }
            AryaTools.Instance.SaveChangesIfNecessary(false, false);
        }
示例#2
0
            private void CalculateValue(IEnumerable <Token> existingTokens)
            {
                var token = _expression;

                if (tokenType == TokenType.Attribute || tokenType == TokenType.AttributeValueOnly)
                {
                    var entities =
                        _sku.EntityInfos.SelectMany(ei => ei.EntityDatas.Where(ed => ed.Active))
                        .Where(
                            ed =>
                            ed.Attribute.AttributeName != null &&
                            ed.Attribute.AttributeName.Equals(token, StringComparison.OrdinalIgnoreCase))
                        .OrderBy(ed => ed.Value)
                        .ToList();

                    if (entities.Count == 0)
                    {
                        var attribute = Attribute.GetAttributeFromName(token, false);
                        if (attribute != null && attribute.AttributeType == AttributeTypeEnum.Derived.ToString())
                        {
                            entities = new List <EntityData>
                            {
                                new TaxAttValueCalculator(_sku)
                                .ProcessCalculatedAttribute(attribute, _sku.Taxonomy)
                            };
                        }
                    }

                    if (entities.Count == 0)
                    {
                        return;
                    }

                    if (entities.Count == 1)
                    {
                        var ed = entities[0];
                        _value = ed.Value ?? string.Empty;
                        if (tokenType == TokenType.Attribute && !string.IsNullOrEmpty(ed.Uom))
                        {
                            Value += ed.Uom;
                        }
                        Uom = ed.Uom;
                        return;
                    }

                    var value   = string.Empty;
                    var allUoms = new HashSet <string>();
                    foreach (var entityData in entities)
                    {
                        value += (string.IsNullOrEmpty(value) ? string.Empty : ", ") + entityData.Value;
                        allUoms.Add(entityData.Uom);
                        if (!string.IsNullOrEmpty(entityData.Uom))
                        {
                            if (tokenType == TokenType.Attribute)
                            {
                                value += entityData.Uom;
                            }
                        }
                    }

                    Value = value;

                    if (allUoms.Count == 1)
                    {
                        Uom = allUoms.First();
                    }

                    return;
                }

                if (tokenType == TokenType.Uom)
                {
                    var allUomValues =
                        _sku.EntityInfos.SelectMany(ei => ei.EntityDatas.Where(ed => ed.Active))
                        .Where(
                            ed =>
                            ed.Attribute.AttributeName != null &&
                            ed.Attribute.AttributeName.Equals(token, StringComparison.OrdinalIgnoreCase))
                        .Select(p => p.Uom)
                        .Distinct()
                        .ToList();

                    Value = allUomValues.Count == 1 ? allUomValues[0] : string.Empty;
                    return;
                }

                if (tokenType == TokenType.Constant)
                {
                    Value = token.Substring(1, token.Length - 2).Replace("\"\"", "\"");
                    return;
                }

                if (tokenType == TokenType.Special)
                {
                    if (token.Equals(NewTaxonomyExpression))
                    {
                        var tax = _sku.Taxonomy;
                        Value = tax != null?tax.ToString() : string.Empty;

                        return;
                    }

                    if (token.Equals(OldTaxonomyExpression))
                    {
                        Value = _sku.OldTaxonomy;
                        return;
                    }

                    if (token.Equals(UomExpression))
                    {
                        var allUoms =
                            existingTokens.Where(
                                p =>
                                p._id != _id && p.CurrentTokenType == TokenType.Attribute &&
                                !string.IsNullOrEmpty(p.Value)).Select(p => p.Uom).Distinct().ToList();
                        Value = allUoms.Count == 1 ? allUoms[0] : null;
                        return;
                    }

                    if (token.Equals(NodeNameExpression))
                    {
                        var tax = _sku.Taxonomy;
                        Value = tax != null ? tax.TaxonomyData.NodeName : string.Empty;
                    }
                }
            }