예제 #1
0
        private decimal[] GetComparerValue(AttributeColumn attCol)
        {
            if (_comparerCache.ContainsKey(attCol))
            {
                return(_comparerCache[attCol]);
            }

            var     majorRank = 0;
            decimal minorRank = 0;

            try
            {
                decimal navOrder, dispOrder;
                bool    inSchema;
                SchemaAttribute.GetAttributeOrders(attCol.Attribute, attCol.Taxonomy, out navOrder, out dispOrder,
                                                   out inSchema);

                if (navOrder > 0 && SortNavigationOrders)
                {
                    majorRank = 2;
                    minorRank = navOrder;
                }
                else if (dispOrder > 0 && SortDisplayOrders)
                {
                    majorRank = 3;
                    minorRank = dispOrder;
                }
                else if (attCol.Attribute.Type == AttributeTypeEnum.Global)
                {
                    majorRank = 0;
                    minorRank = 0;
                }
                else if (attCol.Attribute.Type == AttributeTypeEnum.Derived)
                {
                    majorRank = 1;
                    minorRank = 0;
                }
                else if (inSchema)
                {
                    majorRank = 4;
                    minorRank = 0;
                }
                else
                {
                    majorRank = 5;
                    minorRank = 0;
                }

                //if (!columnProperty.Visible || !AttributeHasValueInSkus(columnProperty.Attribute))
                //    majorRank += 10;
            }
            catch (Exception)
            {
            }

            var ranks = new[] { majorRank, minorRank };

            _comparerCache.Add(attCol, ranks);
            return(ranks);
        }
예제 #2
0
        private static object GetSortKey(TaxonomyInfo taxonomy, Attribute attribute, Field fieldName, Attribute metaAttribute, double defaultOrder)
        {
            if (fieldName == Field.MetaAttribute)
            {
                //return SchemaAttribute.GetValue(taxonomy, attribute, new SchemaAttribute
                return(SchemaAttribute.GetMetaAttributeValue(attribute, metaAttribute, taxonomy));
            }

            if (fieldName == Field.AttributeName)
            {
                return(attribute.AttributeName);
            }

            double navOrder  = defaultOrder;
            double dispOrder = defaultOrder;
            string dataType  = string.Empty;
            bool   inSchema  = false;

            try
            {
                var si = taxonomy.SchemaInfos.Where(a => a.Attribute == attribute).FirstOrDefault();
                var sd = si.SchemaDatas.Where(a => a.Active).FirstOrDefault();
                if (sd != null)
                {
                    navOrder  = (int)sd.NavigationOrder == 0 ? navOrder : (int)sd.NavigationOrder;
                    dispOrder = (int)sd.DisplayOrder == 0 ? dispOrder : (int)sd.DisplayOrder;
                    dataType  = sd.DataType;
                    inSchema  = sd.InSchema;
                }
            }
            catch
            {
            }

            switch (fieldName)
            {
            case Field.DisplayOrder:
                return(dispOrder);

            case Field.NavigationOrder:
                return(navOrder);

            case Field.DataType:
                return(dataType);

            case Field.InSchema:
                return(inSchema ? "Yes" : "No");
            }

            return(null); //Control should never get here!!!
        }
예제 #3
0
        //�Private�Methods�(7)�

        bool ChangeOrCreateEntities(
            List <EntityData> entityDatas, ICollection <Sku> blanks, Stack <EntityDataGridView.ChangeItem> undoHistory, bool createNewEntityDatas)
        {
            bool?copySchemati    = null;
            var  affectedTaxAtts = new DoubleKeyDictionary <TaxonomyInfo, Attribute, bool>();
            var  nodesToReorderAttributeRanksIn = new HashSet <TaxonomyInfo>();

            var changeId = Guid.NewGuid();

            //List<string> columnsToRefresh= new List<string>();

            if (OldValues.Att != null && !entityDatas.Any())
            {
                foreach (var sku in blanks)
                {
                    affectedTaxAtts[sku.Taxonomy, OldValues.Att] = true;
                }
            }

            // Update existing Entities
            //bool entityDataAddedToRefreshList = false;
            foreach (EntityData entityData in entityDatas)
            {
                var sku       = entityData.EntityInfo.Sku;
                var attribute = entityData.Attribute;

                if (AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKeys(attribute, sku))
                {
                    AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache[attribute].Remove(sku);
                }
                if (NewValues.Att != null)
                {
                    if (!AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKey(NewValues.Att))
                    {
                        AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.Add(NewValues.Att, sku, new List <EntityData>());
                    }
                    if (AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKeys(NewValues.Att, sku))
                    {
                        AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache[NewValues.Att].Remove(sku);
                    }
                }

                if (Delete && entityData.Active)
                {
                    entityData.Active        = false;
                    entityData.DeletedRemark = AryaTools.Instance.RemarkID;
                    if (undoHistory != null)
                    {
                        undoHistory.Push(new EntityDataGridView.ChangeItem(entityData, null, changeId));
                    }
                    continue;
                }

                //if (attribute.AttributeType != null && attribute.AttributeType.Equals(Attribute.AttributeTypeCalculated))
                //    return false;

                affectedTaxAtts[sku.Taxonomy, attribute] = true;

                // Make the existing EntityInfo Inactive
                if (RunTool != Tool.None)
                {
                    switch (RunTool)
                    {
                    case Tool.SliceInPlace:
                        SliceEntities(entityData, undoHistory, changeId, true);
                        break;

                    case Tool.SliceIntoNewAttributes:
                        SliceEntities(entityData, undoHistory, changeId, false);
                        break;

                    case Tool.ConvertToDecimal:
                        ConvertToDecimal(entityData, undoHistory, changeId);
                        break;

                    case Tool.ConvertToUom:
                        ConvertToUnitOfMeaure(entityData, undoHistory, changeId);
                        break;


                    case Tool.ExtractCountOfValues:
                    case Tool.ExtractMaximumValue:
                    case Tool.ExtractMinimumValue:
                        if (!_processedSkus.Contains(sku))
                        {
                            ExtractAggregate(sku, attribute.AttributeName, undoHistory, changeId);
                            _processedSkus.Add(sku);
                        }
                        break;
                    }
                    //This block must return right here.
                }

                else if (entityData.Active == false)
                {
                    entityData.Active = true;
                    entityData.Value  = NewValues.Val ?? entityData.Value;
                    entityData.Uom    = NewValues.FieldUomDelete ? null : NewValues.Uom ?? entityData.Uom;
                    entityData.Field1 = NewValues.Field1Delete ? null : NewValues.Field1 ?? entityData.Field1;
                    entityData.Field2 = NewValues.Field2Delete ? null : NewValues.Field2 ?? entityData.Field2;
                    entityData.Field3 = NewValues.Field3Delete ? null : NewValues.Field3 ?? entityData.Field3;

                    //Reserved for Base unit of measure and Status/PT Flag
                    //entityData.Field4 = NewValues.Field4Delete ? null : NewValues.Field4 ?? entityData.Field3;
                    //entityData.Field5 = NewValues.Field5Delete ? null : NewValues.Field5 ?? entityData.Field3;
                    LastEntityDataCreated = entityData;
                }
                else
                {
                    // Create a new entityData and add it to the entityInfo
                    entityData.Active = false;
                    var newEntityData = new EntityData
                    {
                        Attribute = NewValues.Att ?? attribute,
                        Value     = NewValues.Val ?? entityData.Value,
                        Uom       = NewValues.FieldUomDelete ? null : NewValues.Uom ?? entityData.Uom,
                        Field1    = NewValues.Field1Delete ? null : NewValues.Field1 ?? entityData.Field1,
                        Field2    = NewValues.Field2Delete ? null : NewValues.Field2 ?? entityData.Field2,
                        Field3    = NewValues.Field3Delete ? null : NewValues.Field3 ?? entityData.Field3,
                        Field4    = NewValues.Field4Delete ? null : NewValues.Field4 ?? entityData.Field4

                                    //Reserved for Base unit of measure and Status/PT Flag
                                    //Field4 = BaseUnitConvertion.GetBaseUnitValueAsString(NewValues.Val ?? entityData.Value, NewValues.Uom ?? entityData.Uom)  ,
                                    //Field5orStatus = NewValues.Field5 ?? entityData.Field5OrStatus
                    };

                    if (!entityData.Sku.Project.EntityField5IsStatus)
                    {
                        newEntityData.Field5 = NewValues.Field5 ?? entityData.Field5;
                    }

                    entityData.EntityInfo.EntityDatas.Add(newEntityData);
                    LastEntityDataCreated = newEntityData;

                    // Add these two to change history for Undo
                    if (undoHistory != null)
                    {
                        undoHistory.Push(new EntityDataGridView.ChangeItem(entityData, newEntityData, changeId));
                    }
                }
            }

            if (RunTool != Tool.None)
            {
                //This block must return right here.
                switch (RunTool)
                {
                case Tool.ConvertToDecimal:
                case Tool.SliceInPlace:
                    return(false);

                case Tool.ExtractCountOfValues:
                case Tool.ExtractMaximumValue:
                case Tool.ExtractMinimumValue:
                case Tool.SliceIntoNewAttributes:
                    return(true);
                }
            }

            if (NewValues.Att != null)
            {
                foreach (DoubleKeyPairValue <TaxonomyInfo, Attribute, bool> taxAtt in affectedTaxAtts)
                {
                    var taxonomy     = taxAtt.Key1;
                    var oldAttribute = taxAtt.Key2;

                    var oldIsMapped =
                        SchemaAttribute.GetValue(taxonomy, oldAttribute, SchemaAttribute.SchemaAttributeIsMapped) != null;
                    var newIsMapped =
                        SchemaAttribute.GetValue(taxonomy, NewValues.Att, SchemaAttribute.SchemaAttributeIsMapped) != null;

                    if (oldIsMapped && !newIsMapped)
                    {
                        copySchemati = CopySchemati(copySchemati);

                        if ((bool)copySchemati)
                        {
                            var newSchemaData =
                                taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(oldAttribute)).
                                SchemaData;
                            SchemaAttribute.SetValue(taxonomy, NewValues.Att, true, null, newSchemaData);

                            SchemaAttribute.SecondarySchemati.ForEach(
                                schematus =>
                            {
                                object newValue = SchemaAttribute.GetValue(taxonomy, oldAttribute, schematus);
                                if (newValue != null)
                                {
                                    SchemaAttribute.SetValue(taxonomy, NewValues.Att, true, schematus, newValue);
                                }
                            });
                            //SchemaAttribute.UnmapNodeAttribute(taxonomy, oldAttribute);
                        }
                    }

                    /*
                     * This part is obsolete unless required
                     */

                    //var oldTaxAtt =
                    //    taxonomy.TaxonomyAttributes.FirstOrDefault(
                    //        ta => ta.Attribute.Equals(oldAttribute) && (ta.DisplayOrder > 0 || ta.NavigationalOrder > 0));
                    //var newTaxAtt =
                    //    taxonomy.TaxonomyAttributes.FirstOrDefault(
                    //        ta =>
                    //        ta.Attribute.Equals(NewValues.Att) && (ta.DisplayOrder > 0 || ta.NavigationalOrder > 0));
                    //if (oldTaxAtt != null && newTaxAtt == null)
                    //{
                    //    moveAttributeRanks = MoveAttributeRanks(moveAttributeRanks);
                    //    if ((bool)(moveAttributeRanks))
                    //    {
                    //        taxonomy.InsertNavigationOrder(NewValues.Att, oldTaxAtt.NavigationalOrder, false);
                    //        taxonomy.InsertDisplayOrder(NewValues.Att, oldTaxAtt.DisplayOrder, false);
                    //        nodesToReorderAttributeRanksIn.Add(taxonomy);
                    //    }
                    //}
                }
            }

            //nodesToReorderAttributeRanksIn.ForEach(tax => tax.TryReorderAttributeOrders(true));

            if (!createNewEntityDatas || blanks.Count == 0)
            {
                return((copySchemati != null && (bool)copySchemati) || nodesToReorderAttributeRanksIn.Count > 0);
            }

            // Create new Entities
            Attribute att = NewValues.Att ??
                            (OldValues.Att ?? Attribute.GetAttributeFromName(OldValues.AttributeName, true));

            foreach (Sku sku in blanks)
            {
                if (!AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKey(att))
                {
                    AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.Add(att, sku, new List <EntityData>());
                }
                if (AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKeys(att, sku))
                {
                    AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache[att].Remove(sku);
                }

                var currentSku    = sku;
                var newEntityData = new EntityData
                {
                    Attribute = att,
                    Value     = NewValues.Val ?? string.Empty,
                    Uom       = NewValues.Uom,
                    Field1    = NewValues.Field1,
                    Field2    = NewValues.Field2,
                    Field3    = NewValues.Field3,
                    //Field4 = BaseUnitConvertion.GetBaseUnitValueAsString(NewValues.Val ?? string.Empty, NewValues.Uom)
                    //Field5orStatus = NewValues.Field5
                };
                currentSku.EntityInfos.Add(new EntityInfo {
                    EntityDatas = { newEntityData }
                });
                LastEntityDataCreated = newEntityData;

                // Add this to change history for Undo
                if (undoHistory != null)
                {
                    undoHistory.Push(new EntityDataGridView.ChangeItem(null, newEntityData, changeId));
                }
            }

            return(nodesToReorderAttributeRanksIn.Count > 0);
        }
예제 #4
0
        private void WriteTaxonomyToFile(TaxonomyInfo taxonomy, int taxonomyMaxDepth)
        {
            var ignoreT1taxonomy = taxonomy.ToString();

            if (IgnoreT1Taxonomy)
            {
                ignoreT1taxonomy = taxonomy.ToString().Substring(taxonomy.ToString().IndexOf('>') + 1);
            }

            if (string.IsNullOrEmpty(taxonomy.ToString()))
            {
                return;
            }

            if (_processedTaxonomies.Contains(taxonomy))
            {
                return;
            }
            _processedTaxonomies.Add(taxonomy);

            if (!LeafNodesOnly || taxonomy.HasSkus || ExportAllSchemaNodes)
            {
                StatusMessage = string.Format("{1}{0}Reading Node", Environment.NewLine, taxonomy);

                List <Attribute> atts;

                if (ExportSuperSchema && !taxonomy.IsLeafNode)
                {
                    var schemaInfos = new List <SchemaInfo>();
                    schemaInfos.AddRange(taxonomy.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());
                    if (ExportSuperSchema)
                    {
                        foreach (var leaf in taxonomy.AllLeafChildren)
                        {
                            schemaInfos.AddRange(
                                leaf.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());
                        }
                    }
                    var schemaAttributes =
                        schemaInfos.Where(p => p.SchemaData.InSchema)
                        .Select(p => new { p.Attribute, p.SchemaData })
                        .ToList();

                    atts = (from att in schemaAttributes
                            group att by att.Attribute
                            into grp
                            let minRank = grp.Min(p => GetRank(p.SchemaData, SortOrder.OrderbyDisplayNavigation))
                                          orderby minRank
                                          select grp.Key).Distinct().ToList();
                }
                else
                {
                    atts = (from si in AryaTools.Instance.InstanceData.Dc.SchemaInfos
                            where si.TaxonomyID == taxonomy.ID
                            let sd = si.SchemaDatas.FirstOrDefault(sd => sd.Active)
                                     where sd != null
                                     let inSchema = sd.InSchema
                                                    where inSchema
                                                    let navRank = sd == null || sd.NavigationOrder == 0 ? decimal.MaxValue : sd.NavigationOrder
                                                                  let dispRank = sd == null || sd.DisplayOrder == 0 ? decimal.MaxValue : sd.DisplayOrder
                                                                                 orderby navRank, dispRank
                            select si.Attribute).ToList();

                    var currentTaxonomyString = ignoreT1taxonomy;

                    var possibleMissingAttributes = (from si in AryaTools.Instance.InstanceData.Dc.SchemaInfos
                                                     where si.TaxonomyID == taxonomy.ID
                                                     let sd = si.SchemaDatas.FirstOrDefault(sd => sd.Active)
                                                              where sd != null && !sd.InSchema && (sd.NavigationOrder > 0 || sd.DisplayOrder > 0)
                                                              select si.Attribute.AttributeName).ToList()
                                                    .Select(p => currentTaxonomyString + "\t" + p)
                                                    .ToList();

                    _possibleMissingInSchemaAttributes.AddRange(possibleMissingAttributes);
                }

                var isLeafNode = taxonomy.IsLeafNode;

                //if a node has no schema, just skip it.
                if ((atts.Count == 0 && ExportAllSchemaNodes) || (LeafNodesOnly && isLeafNode == false))
                {
                    StatusMessage = string.Format("{1}{0}, Fetching Child Nodes", Environment.NewLine, taxonomy);
                    var taxonomies =
                        taxonomy.ChildTaxonomyDatas.Where(td => td.Active)
                        .Select(td => td.TaxonomyInfo)
                        .OrderBy(tax => tax.ToString());

                    foreach (var tax in taxonomies)
                    {
                        WriteTaxonomyToFile(tax, taxonomyMaxDepth);
                    }
                    CurrentProgress++;
                    return;
                }

                var taxonomyString = ignoreT1taxonomy;
                var taxParts       = ignoreT1taxonomy.Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None);
                var taxonomyParts  = new string[taxonomyMaxDepth];

                _taxFile.Write("{1}{0}", _delimiter, taxonomyString);
                for (var i = 0; i < taxonomyMaxDepth; i++)
                {
                    taxonomyParts[i] = i < taxParts.Length ? taxParts[i].Trim() : string.Empty;
                    _taxFile.Write(taxonomyParts[i] + "\t");
                }

                // write to taxonomy file
                // _taxFile.WriteLine("{9}{0}{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}", _delimiter, taxonomyString);

                WriteTaxMetaValue(taxonomy);

                _schemaFile.WriteLine("{1}{0}", _delimiter, taxonomyString);
                foreach (var attribute in atts)
                {
                    _schemaFile.Write("{1}{0}", _delimiter, taxonomyString);
                    for (var i = 0; i < taxonomyMaxDepth; i++)
                    {
                        taxonomyParts[i] = i < taxParts.Length ? taxParts[i].Trim() : string.Empty;
                        _schemaFile.Write(taxonomyParts[i] + "\t");
                    }

                    _schemaFile.Write("{1}{0}{2}", _delimiter,
                                      (taxonomy.NodeType == "Derived") ? "Cross List" : TaxonomyInfo.NodeTypeRegular, attribute);

                    foreach (var schematus in _allSchemati)
                    {
                        object value = null;

                        if (schematus.AttributeType == SchemaAttribute.SchemaAttributeType.FillRate)
                        {
                            if (_fillRates.Count > 0)
                            {
                                var data =
                                    _fillRates.FirstOrDefault(
                                        p =>
                                        p.Item1 == schematus.FillRateSchemaAttribute.GetFilterName() &&
                                        p.Item2 == taxonomy.ID && p.Item3 == attribute.ID);

                                value = data == null ? "0" : data.Item4.ToString(CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                value = SchemaAttribute.GetValue(taxonomy, attribute, schematus);
                            }
                        }
                        else
                        {
                            if (ExportSuperSchema && !isLeafNode)
                            {
                                if (schematus.AttributeType == SchemaAttribute.SchemaAttributeType.Meta)
                                {
                                    if (schematus.MetaSchemaAttribute.AttributeName.Equals("Sample Values",
                                                                                           StringComparison.OrdinalIgnoreCase) &&
                                        schematus.MetaSchemaAttribute.AttributeName.Equals("Restricted UOM",
                                                                                           StringComparison.OrdinalIgnoreCase))
                                    {
                                        value = string.Empty;
                                    }
                                }
                                else
                                {
                                    var allChildren = taxonomy.AllLeafChildren.ToList();
                                    allChildren.Add(taxonomy);

                                    var attribute2 = attribute;
                                    var schematus1 = schematus;
                                    var bestValue  = (from child in allChildren
                                                      let childValue = SchemaAttribute.GetValue(child, attribute2, schematus1)
                                                                       where childValue != null
                                                                       group child by childValue
                                                                       into grp
                                                                       orderby grp.Count() descending
                                                                       select grp.Key).FirstOrDefault();

                                    value = bestValue;
                                }
                            }
                            else
                            {
                                value = SchemaAttribute.GetValue(taxonomy, attribute, schematus);
                            }
                        }

                        value = value ?? string.Empty;

                        if ((schematus.PrimarySchemaAttribute == "Navigation Order" ||
                             schematus.PrimarySchemaAttribute == "Display Order"))
                        {
                            decimal result;
                            if (Decimal.TryParse(value.ToString(), out result) && result > 0)
                            {
                                value = string.Format("{0:0.##}", value);
                            }
                        }
                        else if (schematus.AttributeType == SchemaAttribute.SchemaAttributeType.Meta &&
                                 schematus.MetaSchemaAttribute.AttributeName == Resources.SchemaEnrichmentImageAttributeName &&
                                 !String.IsNullOrEmpty(value.ToString()))
                        {
                            using (var dc = new AryaDbDataContext(AryaTools.Instance.InstanceData.CurrentProject.ID, AryaTools.Instance.InstanceData.CurrentUser.ID))
                            {
                                var imageMgr = new ImageManager(dc, AryaTools.Instance.InstanceData.CurrentProject.ID)
                                {
                                    RemoteImageGuid = value.ToString()
                                };
                                if (DownloadAssets)
                                {
                                    imageMgr.LocalDirectory = _downloadDir.ToString();
                                    imageMgr.DownloadImage(taxonomy.ID, attribute.ID);
                                    value = imageMgr.LocalImageName;
                                }
                                else
                                {
                                    value = imageMgr.RemoteImageUrl;
                                }
                            }
                        }

                        var value2 = value.ToString();

                        if (value2.Length > 0)
                        {
                            _schemaFile.Write(_delimiter
                                              + value2.Replace("\n", string.Empty).Replace("\r", string.Empty));
                        }
                        else
                        {
                            _schemaFile.Write(_delimiter + value2);
                        }
                    }
                    _schemaFile.WriteLine();

                    var schemaData =
                        attribute.SchemaInfos.Where(p => p.TaxonomyID == taxonomy.ID && p.SchemaData != null)
                        .Select(p => p.SchemaData)
                        .FirstOrDefault();

                    if (schemaData != null)
                    {
                        var attribute1 = attribute;

                        foreach (var lov in schemaData.SchemaInfo.ListOfValues.Where(lov => lov.Active))
                        {
                            for (var j = 0; j < taxonomyMaxDepth; j++)
                            {
                                taxonomyParts[j] = j < taxParts.Length ? taxParts[j].Trim() : string.Empty;
                                _lovFile.Write(taxonomyParts[j] + "\t");
                            }
                            //_lovFile.WriteLine(
                            //    "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}{0}{11}{0}{12}{0}{13}",
                            //    _delimiter, taxParts[0], taxParts[1], taxParts[2], taxParts[3], taxParts[4], taxParts[5],
                            //    taxParts[6], taxParts[7], (taxonomy.NodeType == "Derived") ? "Cross List" : TaxonomyInfo.NodeTypeRegular,
                            //    attribute1.AttributeName,
                            //    schemaData.NavigationOrder == 0
                            //        ? string.Empty
                            //        : string.Format("{0:0.##}", schemaData.NavigationOrder),
                            //    schemaData.DisplayOrder == 0
                            //        ? string.Empty
                            //        : string.Format("{0:0.##}", schemaData.DisplayOrder), lov.Value);

                            _lovFile.Write("{1}{0}{2}{0}{3}{0}{4}{0}{5}", _delimiter,
                                           (taxonomy.NodeType == "Derived") ? "Cross List" : TaxonomyInfo.NodeTypeRegular,
                                           attribute1.AttributeName,
                                           schemaData.NavigationOrder == 0
                                    ? string.Empty
                                    : string.Format("{0:0.##}", schemaData.NavigationOrder),
                                           schemaData.DisplayOrder == 0
                                    ? string.Empty
                                    : string.Format("{0:0.##}", schemaData.DisplayOrder), lov.Value);

                            if (ExportEnrichments)
                            {
                                using (
                                    var dc =
                                        new AryaDbDataContext(AryaTools.Instance.InstanceData.CurrentProject.ID,
                                                              AryaTools.Instance.InstanceData.CurrentUser.ID))
                                {
                                    var imageMgr = new ImageManager(dc, AryaTools.Instance.InstanceData.CurrentProject.ID)
                                    {
                                        ImageSku = dc.Skus.FirstOrDefault(s => s.ItemID == lov.EnrichmentImage)
                                    };
                                    string lovImage;
                                    if (DownloadAssets)
                                    {
                                        imageMgr.LocalDirectory = _downloadDir.ToString();
                                        imageMgr.DownloadImage(taxonomy.ID, attribute.ID, lov.ID);
                                        lovImage = imageMgr.LocalImageName;
                                    }
                                    else
                                    {
                                        lovImage = imageMgr.RemoteImageUrl;
                                    }

                                    _lovFile.Write("{0}{1}{0}{2}", _delimiter, lovImage, lov.EnrichmentCopy);
                                }
                            }

                            _lovFile.WriteLine();
                        }
                    }
                }
            }

            StatusMessage = string.Format("{1}{0}, Fetching Child Nodes", Environment.NewLine, taxonomy);
            var taxs =
                taxonomy.ChildTaxonomyDatas.Where(td => td.Active)
                .Select(td => td.TaxonomyInfo)
                .OrderBy(tax => tax.ToString());

            foreach (var tax in taxs)
            {
                WriteTaxonomyToFile(tax, taxonomyMaxDepth);
            }
            CurrentProgress++;
        }
예제 #5
0
        public static string SetValue(TaxonomyInfo taxonomy, Attribute attribute, bool autoMapSchema,
                                      SchemaAttribute schematus, object value, bool suppressAutoMapMessage = false)
        {
            var schemaInfo    = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(attribute));
            var newSchemaInfo = false;

            if (schemaInfo == null)
            {
                if (suppressAutoMapMessage)
                {
                    return(null);
                }
                if (!autoMapSchema &&
                    MessageBox.Show(
                        String.Format("Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?", attribute,
                                      taxonomy.TaxonomyData.NodeName), @"Add to Schema", MessageBoxButtons.YesNo)
                    == DialogResult.No)
                {
                    return(null);
                }
                schemaInfo = new SchemaInfo {
                    Attribute = attribute
                };
                taxonomy.SchemaInfos.Add(schemaInfo);
                newSchemaInfo = true;
            }

            if (schematus == null)
            {
                //Create/Update Schema Info only
                var currentSchemaData = schemaInfo.SchemaData;
                var newSchemaData     = new SchemaData();
                if (value != null && value is SchemaData)
                {
                    var fromSchemaData = (SchemaData)value;
                    if (currentSchemaData != null && currentSchemaData.Equals(fromSchemaData))
                    {
                        return(null);
                    }

                    newSchemaData.DataType        = fromSchemaData.DataType;
                    newSchemaData.DisplayOrder    = fromSchemaData.DisplayOrder;
                    newSchemaData.NavigationOrder = fromSchemaData.NavigationOrder;
                    newSchemaData.InSchema        = fromSchemaData.InSchema;
                }

                if (currentSchemaData != null)
                {
                    currentSchemaData.Active = false;
                }
                schemaInfo.SchemaDatas.Add(newSchemaData);
                return(null);
            }

            var activeSd = schemaInfo.SchemaData;

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                var reallyNewSd  = false;
                var reorderRanks = false;

                SchemaData newSchemaData;
                if (activeSd == null)
                {
                    reallyNewSd   = true;
                    newSchemaData = new SchemaData();
                }
                else
                {
                    //activeSd.DeletedBy = AryaTools.Instance.InstanceData.CurrentUser.ID;
                    activeSd.DeletedByUser = AryaTools.Instance.InstanceData.CurrentUser;
                    //fixes Object not found error
                    activeSd.DeletedOn = DateTime.Now;
                    newSchemaData      = new SchemaData
                    {
                        DataType        = activeSd.DataType,
                        InSchema        = activeSd.InSchema,
                        NavigationOrder = activeSd.NavigationOrder,
                        DisplayOrder    = activeSd.DisplayOrder
                    };
                }

                var propertyName = schematus.PrimarySchemaAttribute.Replace(" ", String.Empty);

                var valueProperty = newSchemaData.GetType().GetProperty(propertyName);
                var propertyType  = valueProperty.PropertyType;

                if (propertyType == typeof(string))
                {
                    var stringValue = value ?? String.Empty;
                    if (propertyName == "DataType")
                    {
                        stringValue = ValidateDataType(stringValue);
                    }

                    if (!(valueProperty.GetValue(newSchemaData, null) ?? String.Empty).Equals(stringValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, stringValue.ToString(), null);
                    }
                }
                else if (propertyType == typeof(bool))
                {
                    var    boolValue = value ?? false;
                    string firstCharacter;
                    try
                    {
                        firstCharacter = boolValue.ToString().Substring(0, 1).ToLower();
                    }
                    catch (Exception)
                    {
                        firstCharacter = "f";
                    }

                    var newValue = firstCharacter.Equals("t") || firstCharacter.Equals("y") ||
                                   firstCharacter.Equals("1");

                    if (!((bool)valueProperty.GetValue(newSchemaData, null)).Equals(newValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, newValue, null);
                    }
                }
                else if (propertyType == typeof(decimal))
                {
                    var     decimalValue = value ?? 0.0;
                    decimal newDecimalValue;
                    if (Decimal.TryParse(decimalValue.ToString(), out newDecimalValue))
                    {
                        if (!((decimal)valueProperty.GetValue(newSchemaData, null)).Equals(newDecimalValue))
                        {
                            reallyNewSd = true;
                            valueProperty.SetValue(newSchemaData, newDecimalValue, null);
                            reorderRanks = SchemaDataGridView.AutoOrderRanks;
                        }
                    }
                    else
                    {
                        return(String.Format("Invalid value [{0}] for [{1}] - [{2}].{3}Expected a decimal value.",
                                             decimalValue, taxonomy.NodeName, attribute, Environment.NewLine));
                    }
                }
                else
                {
                    return(String.Format("Unknown data type for value [{0}] for [{1}] - [{2}]",
                                         value ?? String.Empty, taxonomy.NodeName, attribute));
                }

                if (reallyNewSd)
                {
                    if (activeSd != null)
                    {
                        activeSd.Active = false;
                    }
                    schemaInfo.SchemaDatas.Add(newSchemaData);

                    if (reorderRanks)
                    {
                        AutoOrderRanks(newSchemaData.SchemaInfo.TaxonomyInfo, newSchemaData);
                    }
                }

                return(null);

            case SchemaAttributeType.Meta:
                var reallyNewSmd = false;

                if (schematus.DataType == typeof(bool))
                {
                    value = value.ToString().StartsWith("y", StringComparison.OrdinalIgnoreCase) ? "Yes" : "No";
                }
                //First check if there is an active SchemaData
                if (activeSd == null)
                {
                    if (suppressAutoMapMessage)
                    {
                        return(null);
                    }

                    if (!newSchemaInfo && !autoMapSchema &&
                        MessageBox.Show(
                            String.Format("Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?",
                                          attribute, taxonomy.TaxonomyData.NodeName), "Add to Schema", MessageBoxButtons.YesNo)
                        == DialogResult.No)
                    {
                        return(null);
                    }

                    schemaInfo.SchemaDatas.Add(new SchemaData());
                    reallyNewSmd = true;
                }

                var activeSmi =
                    (from mi in schemaInfo.SchemaMetaInfos
                     where mi.Attribute.Equals(schematus.MetaSchemaAttribute)
                     select mi).FirstOrDefault();

                if (activeSmi == null)
                {
                    activeSmi = new SchemaMetaInfo {
                        Attribute = schematus.MetaSchemaAttribute
                    };
                    schemaInfo.SchemaMetaInfos.Add(activeSmi);
                    reallyNewSmd = true;
                }

                var activeSmd = activeSmi.SchemaMetaData;

                if (activeSmd == null)
                {
                    reallyNewSmd = true;
                }
                else if (value == null || !activeSmd.Value.Equals(value))
                {
                    reallyNewSmd     = true;
                    activeSmd.Active = false;
                }

                if (reallyNewSmd && value != null && !String.IsNullOrEmpty(value.ToString()))
                {
                    activeSmi.SchemaMetaDatas.Add(new SchemaMetaData {
                        Value = value.ToString()
                    });
                    SchemaDataGridView.UpdateAutoCompleteSource(schematus.MetaSchemaAttribute, value.ToString());
                }

                return(null);

            default:
                return("Unknown Meta-attribute Type! Weird!!!");
            }
        }
예제 #6
0
        public static object GetValue(TaxonomyInfo taxonomy, Attribute attribute, SchemaAttribute schematus)
        {
            if (taxonomy == null && attribute == null)
            {
                return(schematus);
            }

            if (taxonomy == null)
            {
                return(attribute);
            }

            if (attribute == null)
            {
                return(taxonomy);
            }

            var schemaInfo =
                taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute != null && si.Attribute.Equals(attribute));

            if (schematus == null || schemaInfo == null)
            {
                return(null);
            }

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                var activeSchemaData = schemaInfo.SchemaDatas.FirstOrDefault(sd => sd.Active);
                if (activeSchemaData == null)
                {
                    return(null);
                }

                var valueProperty =
                    activeSchemaData.GetType()
                    .GetProperty(schematus.PrimarySchemaAttribute.Replace(" ", String.Empty));
                return(valueProperty.GetValue(activeSchemaData, null));

            case SchemaAttributeType.Meta:
                var metaSchemaData = (from mi in schemaInfo.SchemaMetaInfos
                                      where mi.Attribute.Equals(schematus.MetaSchemaAttribute) && mi.SchemaMetaData != null
                                      select mi.SchemaMetaData).FirstOrDefault();
                if (schematus.MetaSchemaAttribute.AttributeName == Framework.Properties.Resources.SchemaEnrichmentImageAttributeName)
                {
                    if (metaSchemaData == null || string.IsNullOrEmpty(metaSchemaData.Value))
                    {
                        return(metaSchemaData);
                    }

                    Guid guidValue;
                    var  isGuid = Guid.TryParse(metaSchemaData.Value, out guidValue);
                    return(isGuid ? GetImageName(taxonomy, new Guid(metaSchemaData.Value)) : metaSchemaData.Value);
                    //AryaTools.Instance.InstanceData.Dc.Skus.First(sk => sk.ID.ToString() == metaSchemaData.ToString()).EntityInfos.Where(ei => ei.EntityDatas.Where(ed => ed.Attribute.AttributeName == "Image FileName"));
                    //Sku imageSku = taxonomy.SkuInfos.FirstOrDefault(si => si.Sku.SkuType == Framework.Data.AryaDb.Sku.ItemType.EnrichmentImage.ToString()).Sku;
                }

                return(metaSchemaData);

            case SchemaAttributeType.Special:
                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusIsMapped))
                {
                    var activeSd = schemaInfo.SchemaDatas.FirstOrDefault(sd => sd.Active);
                    if (activeSd != null)
                    {
                        return("x");
                    }
                }

                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusAttributeType))
                {
                    if (attribute.AttributeType == "Sku")
                    {
                        return("Product");
                    }
                    return(attribute.Type);
                }


                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusListOfValues))
                {
                    var listOfValues = schemaInfo.ListOfValues.Where(lov => lov.Active).Select(lov => lov).ToList();
                    if (listOfValues.Any())
                    {
                        var listSep =
                            AryaTools.Instance.InstanceData.CurrentProject.ProjectPreferences.ListSeparator
                            ?? "; ";
                        return
                            (listOfValues.OrderBy(val => val.DisplayOrder)
                             .ThenBy(val => val.Value)
                             .Select(val => val.Value)
                             .Aggregate((current, lov) => current + listSep + lov));
                    }
                    return(null);
                }
                return(null);

            case SchemaAttributeType.FillRate:
                var fillRate = AryaTools.Instance.AllFillRates.GetFillRate(taxonomy, attribute,
                                                                           schematus.FillRateSchemaAttribute);
                if (fillRate == Double.MinValue)
                {
                    SchemaDataGridView.RefreshGridView = true;
                    return("Calculating...");
                }

                return(fillRate);

            default:
                return(null);
            }
        }