Exemple #1
0
        private void SetAttributeName(string value)
        {
            if (Entities == null || (value == Attribute.AttributeName))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                MessageBox.Show(@"AttributeName cannot be renamed to blank");
                return;
            }

            if (Attribute.Type.ToString().Contains("Meta") || Attribute.Type == AttributeTypeEnum.Workflow)
            {
                MessageBox.Show(string.Format("{0} attributes cannot be renamed", Attribute.Type));
                return;
            }

            var oldAttribute = Attribute;
            var newAtt       = Attribute.GetAttributeFromName(value, true, Attribute.Type);

            if (newAtt.Type != oldAttribute.Type)
            {
                MessageBox.Show(string.Format("{0} attribute cannot be renamed to a {1} type.", Attribute.Type,
                                              newAtt.Type));
                return;
            }

            var waitkey = FrmWaitScreen.ShowMessage("Renaming attribute");

            UpdateDerivedAttributeExpressions(newAtt, oldAttribute);
            UpdateEntities(newAtt, waitkey);
            _schemaDatas = null; //Recompute the SchemaDatas!
            Attribute    = newAtt;

            AryaTools.Instance.SaveChangesIfNecessary(false, false);
            FrmWaitScreen.HideMessage(waitkey);
        }
Exemple #2
0
        public void UpsertValue(string attributeName, string value)
        {
            var        existingEds = GetValuesForAttribute(attributeName, false);
            EntityData ed          = null;

            if (existingEds.Count > 0)
            {
                if (existingEds.Count == 1 && existingEds[0].Value.Equals(value))
                {
                    return;
                }

                foreach (var existingEd in existingEds)
                {
                    ed        = existingEd;
                    ed.Active = false;
                }
            }

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            var newEd = new EntityData {
                Attribute = Attribute.GetAttributeFromName(attributeName, true), Value = value
            };

            if (ed != null)
            {
                ed.EntityInfo.EntityDatas.Add(newEd);
            }
            else
            {
                EntityInfos.Add(new EntityInfo {
                    EntityDatas = { newEd }
                });
            }
        }
Exemple #3
0
 public List <EntityData> GetValuesForAttribute(string attributeName, bool useCache = true, bool sortDesc = false)
 {
     return(string.IsNullOrEmpty(attributeName)
         ? new List <EntityData>()
         : GetValuesForAttribute(Attribute.GetAttributeFromName(attributeName, false), useCache, sortDesc));
 }
Exemple #4
0
        public bool Execute(TaxonomyInfo currentTaxonomy, Stack <EntityDataGridView.ChangeItem> undoHistory, bool createNewEntityDatas)
        {
            bool refreshColumns = false;

            if (!HasChange())
            {
                return(false);
            }

            //Rename an attribute to change case
            if (!string.IsNullOrEmpty(OldValues.AttributeName) && !string.IsNullOrEmpty(NewValues.AttributeName) &&
                OldValues.AttributeName.ToLower().Equals(NewValues.AttributeName.ToLower()) &&
                !OldValues.AttributeName.Equals(NewValues.AttributeName))
            {
                if (
                    MessageBox.Show(@"This will rename the attribute globally (for the entire project). Are you sure?",
                                    @"Global Attribute Rename", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    OldValues.Att.AttributeName = NewValues.AttributeName;
                    //if (string.IsNullOrEmpty(NewValues.Val) && string.IsNullOrEmpty(NewValues.Uom) &&
                    //    string.IsNullOrEmpty(NewValues.Field1) && string.IsNullOrEmpty(NewValues.Field2) &&
                    //    string.IsNullOrEmpty(NewValues.Field3) && string.IsNullOrEmpty(NewValues.Field4) &&
                    //    string.IsNullOrEmpty(NewValues.Field5))
                    //    return true;
                }
                else
                {
                    return(false);
                }
            }

            List <Sku> blanks = GetBlanks();

            if (NewValues.Tax != null)
            {
                // Taxonomy Change
                bool moveBlanks = false;
                if (blanks.Count > 0)
                {
                    moveBlanks =
                        MessageBox.Show(
                            string.Format(
                                "There are {0} blank values in the current selection. Would you like to move SKUs associated with blanks?",
                                blanks.Count),
                            @"Move blanks?",
                            MessageBoxButtons.YesNo) == DialogResult.Yes;
                }

                ChangeTaxonomy(currentTaxonomy, moveBlanks, undoHistory);
            }
            else
            {
                //Items to change
                List <EntityData> entityDatas = GetEntityDatas();

                Attribute newAttribute = NewValues.Att;
                if (newAttribute == null)
                {
                    if (NewValues.AttributeName != null)
                    {
                        newAttribute  = Attribute.GetAttributeFromName(NewValues.AttributeName, true);
                        NewValues.Att = newAttribute;
                    }
                    //else
                    //    return false;
                }

                //if (entityDatas.Count + blanks.Count == _totalSkuCount && currentTaxonomy != null && _oldValues.Att != null)
                //{
                //    TaxonomyAttribute oldTaxAtt =
                //        _oldValues.Att.TaxonomyAttributes.Where(ta => ta.TaxonomyInfo.Equals(currentTaxonomy)).
                //            FirstOrDefault();
                //    if (oldTaxAtt != null && !_oldValues.Att.Equals(newAttribute) &&
                //        (oldTaxAtt.NavigationalOrder > 0 || oldTaxAtt.DisplayOrder > 0))
                //    {
                //        currentTaxonomy.InsertDisplayOrder(newAttribute, oldTaxAtt.DisplayOrder, false);
                //        currentTaxonomy.InsertNavigationOrder(newAttribute, oldTaxAtt.NavigationalOrder, false);
                //        oldTaxAtt.DisplayOrder = 0;
                //        oldTaxAtt.NavigationalOrder = 0;
                //        refreshColumns = true;
                //    }
                //}

                refreshColumns = ChangeOrCreateEntities(entityDatas, blanks, undoHistory, createNewEntityDatas);
            }

            return(refreshColumns);
        }
Exemple #5
0
        private void SliceEntities(EntityData entityData, Stack <EntityDataGridView.ChangeItem> undoHistory, Guid changeId, bool sliceInPlace)
        {
            var parts = entityData.Value.Split(new[] { SliceDelimiter }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length <= 1)
            {
                return;
            }

            var       currentSku       = entityData.EntityInfo.Sku;
            Attribute currentAttribute = entityData.Attribute;

            if (sliceInPlace)
            {
                entityData.Active = false;

                if (!AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKey(currentAttribute))
                {
                    AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.Add(currentAttribute, currentSku, new List <EntityData>());
                }
                if (AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache.ContainsKeys(currentAttribute, currentSku))
                {
                    AryaTools.Instance.InstanceData.Dc.SkuAttributeValueCache[currentAttribute].Remove(currentSku);
                }
            }

            var oldEntityInfo = entityData.EntityInfo;

            if (undoHistory != null)
            {
                undoHistory.Push(new EntityDataGridView.ChangeItem(entityData, null, changeId));
            }

            for (int i = 0; i < parts.Length; i++)
            {
                var       slice     = parts[i];
                Attribute attribute = sliceInPlace
                                          ? currentAttribute
                                          : Attribute.GetAttributeFromName(
                    string.Format(
                        "{0} - Part {1}", currentAttribute.AttributeName, (i + 1)),
                    true);
                if (!sliceInPlace)
                {
                    NewAttributeNames.Add(attribute.AttributeName);

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

                var newEntityData = new EntityData
                {
                    Attribute = attribute,
                    Value     = slice.Trim(),
                    Uom       = entityData.Uom,
                    Field1    = entityData.Field1,
                    Field2    = entityData.Field2,
                    Field3    = entityData.Field3
                                //Field4 = BaseUnitConvertion.GetBaseUnitValueAsString(slice.Trim(), entityData.Uom)
                                //Field5orStatus = entityData.Field5OrStatus
                };

                //preserve the first link
                if (i == 0)
                {
                    oldEntityInfo.EntityDatas.Add(newEntityData);
                }
                else
                {
                    currentSku.EntityInfos.Add(new EntityInfo {
                        EntityDatas = { newEntityData }
                    });
                }

                LastEntityDataCreated = newEntityData;

                if (undoHistory != null)
                {
                    undoHistory.Push(new EntityDataGridView.ChangeItem(null, newEntityData, changeId));
                }
            }
        }
Exemple #6
0
        private void ExtractAggregate(Sku sku, string attributeName, Stack <EntityDataGridView.ChangeItem> undoHistory, Guid changeId)
        {
            var values = sku.GetValuesForAttribute(attributeName);

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

            EntityData entityData             = null;
            var        newValue               = string.Empty;
            var        newAttributeNamePrefix = string.Empty;

            switch (RunTool)
            {
            case Tool.ExtractMinimumValue:
                newAttributeNamePrefix = "Minimum ";
                entityData             = values.OrderBy(val => val.Value, new CompareForAlphaNumericSort()).First();
                break;

            case Tool.ExtractMaximumValue:
                newAttributeNamePrefix = "Maximum ";
                entityData             = values.OrderByDescending(val => val.Value, new CompareForAlphaNumericSort()).First();
                break;

            case Tool.ExtractCountOfValues:
                newAttributeNamePrefix = "No of ";
                newValue = values.Count.ToString();
                break;
            }

            var newAttribute = Attribute.GetAttributeFromName(string.Format("{0}{1}", newAttributeNamePrefix, attributeName), true);

            NewAttributeNames.Add(newAttribute.AttributeName);

            EntityData newEntityData;

            if (entityData != null)
            {
                newEntityData = new EntityData
                {
                    Attribute = newAttribute,
                    Value     = entityData.Value,
                    Uom       = entityData.Uom,
                    Field1    = entityData.Field1,
                    Field2    = entityData.Field2,
                    Field3    = entityData.Field3
                                //Field4 = BaseUnitConvertion.GetBaseUnitValueAsString(entityData.Value, entityData.Uom)
                }
            }
            ;
            else
            {
                newEntityData = new EntityData {
                    Attribute = newAttribute, Value = newValue
                }
            };

            var currentValue = sku.GetValuesForAttribute(newAttribute.AttributeName).FirstOrDefault();

            if (currentValue != null)
            {
                currentValue.EntityInfo.EntityDatas.Add(newEntityData);
                currentValue.Active = false;
            }
            else
            {
                sku.EntityInfos.Add(new EntityInfo {
                    EntityDatas = { newEntityData }
                });
            }

            LastEntityDataCreated = newEntityData;

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

            // Add this to change history for Undo
            if (undoHistory != null)
            {
                undoHistory.Push(new EntityDataGridView.ChangeItem(currentValue ?? null, newEntityData, changeId));
            }
        }
Exemple #7
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);
        }