Пример #1
0
 private void AddMetaAttribute(object value)
 {
     if (!_rows.Any(row => row.AttributeName.ToLower().Equals(value.ToString().ToLower())))
     {
         var newAttribute = new Attribute
         {
             AttributeName = value.ToString(),
             AttributeType = _metaAttType.ToString(),
             SchemaInfos   =
             {
                 new SchemaInfo
                 {
                     TaxonomyID  = Guid.Empty,
                     SchemaDatas =
                     {
                         new SchemaData
                         {
                             InSchema
                                 =
                                     true
                         }
                     }
                 }
             }
         };
         AryaTools.Instance.InstanceData.Dc.Attributes.InsertOnSubmit(newAttribute);
         _rows.Add(newAttribute);
         SetRowCount();
     }
     else
     {
         MessageBox.Show("This meta-attribute already exists.");
     }
 }
Пример #2
0
        public double?GetFillRate(TaxonomyInfo taxonomy, Attribute attribute, Filter filter)
        {
            var fillRateObject = FillRates.FirstOrDefault(fr => fr.Taxonomy.Equals(taxonomy));

            if (fillRateObject == null)
            {
                fillRateObject = new FillRate(taxonomy, null, null, FillRate.DataState.Active, DateTime.Now);
                FillRates.Add(fillRateObject);
                if (UseBackgroundWorker)
                {
                    EnqueWork(fillRateObject, attribute, filter);
                    return(double.MinValue);
                }
            }

            double?fillRateValue = fillRateObject.TryGetFillRate(attribute, filter);

            if (fillRateValue == null)
            {
                if (UseBackgroundWorker)
                {
                    EnqueWork(fillRateObject, attribute, filter);
                    return(double.MinValue);
                }
                fillRateValue = fillRateObject.FetchFillRate(attribute, filter);
            }

            if (double.IsNaN((double)fillRateValue))
            {
                return(null);
            }

            //return string.Format("{0:0.00}", fillRateValue);
            return(Math.Round((double)fillRateValue, 2));
        }
Пример #3
0
        private void Init()
        {
            txtAttributeNameFilter.TextAlignChanged -= FilterUpdated;

            PopulateFilterDropdown();
            LoadLists();
            lblStatus.Text = _queryDescription;

            txtAttributeNameFilter.TextAlignChanged += FilterUpdated;
            _currentLovAttribute = null;
        }
Пример #4
0
 private void EnqueWork(FillRate fillRate, Attribute attribute, Filter filter)
 {
     lock (CalculateFillRateQueue)
     {
         CalculateFillRateQueue.Enqueue(new FillRateWorkUnit(fillRate, attribute, filter));
         if (CalculateFillRateQueue.Count == 1)
         {
             Monitor.PulseAll(CalculateFillRateQueue);
         }
     }
 }
Пример #5
0
        private string GetValue(Attribute taxMetaAttribute, TaxonomyInfo taxonomy)
        {
            var taxMetaData = (from tmd in AryaTools.Instance.InstanceData.Dc.TaxonomyMetaDatas
                               where
                               tmd.TaxonomyMetaInfo.TaxonomyID.Equals(taxonomy.ID) &&
                               tmd.TaxonomyMetaInfo.MetaAttributeID.Equals(taxMetaAttribute.ID) &&
                               tmd.Active
                               select tmd).FirstOrDefault();

            return(taxMetaData == null ? string.Empty : taxMetaData.Value);
        }
Пример #6
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!!!
        }
Пример #7
0
 private void chkShowLovs_CheckedChanged(object sender, EventArgs e)
 {
     if (chkShowLovs.Checked)
     {
         if (_taxonomyNodes.Count > 1)
         {
             pnlLovOptions.Enabled = true;
         }
         TryLoadLovs();
     }
     else
     {
         _currentLovAttribute       = null;
         _dsListOfValues            = null;
         dgvListOfValues.DataSource = null;
         pnlLovOptions.Enabled      = false;
     }
 }
Пример #8
0
        public static IEnumerable <string> GetLovs(Attribute attribute, TaxonomyInfo taxonomy, Sku sku = null)
        {
            if (attribute == null || taxonomy == null)
            {
                return(null);
            }

            IEnumerable <string> lov;
            var node = taxonomy;

            do
            {
                lov  = GetLovsForNode(attribute, node, sku);
                node = node.TaxonomyData.ParentTaxonomyInfo;
            } while (lov == null && node != null);

            return(lov);
        }
Пример #9
0
        // Public Methods (2) 

        public double FetchFillRate(Attribute attribute, Filter filter)
        {
            if (_fillRateValues.ContainsKeys(attribute, filter))
            {
                return(_fillRateValues[attribute, filter]);
            }
            try
            {
                var skus           = FilteredSkus(filter).ToList();
                var totalSkuCount  = skus.Count;
                var filterSkuCount =
                    GetEntities(skus).Where(ed => ed.Attribute.Equals(attribute)).Select(ed => ed.EntityInfo.SkuID).
                    Distinct().Count();
                var value = (100.0 * filterSkuCount / totalSkuCount);
                _fillRateValues.Add(attribute, filter, value);

                return(value);
            }
            catch (Exception)
            {
                return(double.NaN);
            }
        }
Пример #10
0
 public FillRateWorkUnit(FillRate fillRate, Attribute attribute, Filter filter)
 {
     FillRateUnit  = fillRate;
     AttributeUnit = attribute;
     FilterUnit    = filter;
 }
Пример #11
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);
        }
Пример #12
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));
                }
            }
        }
Пример #13
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));
            }
        }
Пример #14
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);
        }
Пример #15
0
 private void rbInschemaLovs_CheckedChanged(object sender, EventArgs e)
 {
     _currentLovAttribute = null;
     TryLoadLovs();
 }
Пример #16
0
 private IQueryable <EntityInfo> GetEntities(IQueryable <EntityInfo> entities, Attribute att)
 {
     return(from ei in entities
            from ed in ei.EntityDatas
            where ed.Active && ed.AttributeID == att.ID
            select ed.EntityInfo);
 }
Пример #17
0
        private static IEnumerable <string> GetLovsForNode(Attribute attribute, TaxonomyInfo taxonomy, Sku sku = null)
        {
            if (attribute == null || taxonomy == null)
            {
                return(null);
            }

            var si = taxonomy.SchemaInfos.FirstOrDefault(s => s.Attribute == attribute);

            if (si == null)
            {
                return(null);
            }

            var lovs = si.ListOfValues.Where(a => a.Active).ToList();

            if (lovs.Count == 0)
            {
                return(null);
            }

            if (sku == null)
            {
                return(lovs.Select(a => a.Value).Distinct());
            }

            //Get LOVs where parent Value is null
            var defaultLov =
                lovs.Where(a => a.ParentValue == null || a.ParentValue == "Ø").Select(v => v.Value).Distinct().ToList();

            // Combinations:
            // value: parentValue == x:null -- NA
            // value: parentValue == x:y --- if x is the cell value then y must be the parentValue -- check first
            // value: parentValue == x:* --- there must exist a parent value for cell value x -- check second
            // value: parentValue == x:Ø --- cell Value must be x when parentValue does not exist -- check third
            // value: parentValue == *:y --- Any/other cell value must have parentValue y  -- check fourth
            // value: parentValue == *:Ø --- No parent should exist for any/other value -- fifth check
            // value: parentValue == *:* --- all the values must have parent value -- sixth check
            // value: parentValue == Ø:y --- Does not make sense ..

            var parentEntities = GetParentAttributeValues(si, sku);

            if (parentEntities == null) //No Dependencies
            {
                return(defaultLov);
            }

            IEnumerable <string> parentAttributeValues = parentEntities.Select(v => v.Value).ToList();

            if (parentAttributeValues.Count() == 0)
            {
                return(defaultLov);
            }

            var allowedLovs =
                lovs.Where(a => a.ParentValue == "✽" || parentAttributeValues.Contains(a.ParentValue))
                .Select(v => v.Value)
                .Distinct()
                .ToList();

            if (allowedLovs.Contains("Ø"))
            {
                return(new List <string>());
            }

            if (allowedLovs.Count == 0 || allowedLovs.Contains("✽"))
            {
                return(null);
            }

            return(allowedLovs);
        }
Пример #18
0
        public static Attribute GetAttributeFromName(string attributeName, bool createIfNotFound,
                                                     Framework.Data.AryaDb.AttributeTypeEnum attributeType =
                                                     Framework.Data.AryaDb.AttributeTypeEnum.NonMeta)
        {
            // select cache to use
            Dictionary <string, Attribute> attributeCache;

            switch (attributeType)
            {
            case Framework.Data.AryaDb.AttributeTypeEnum.SchemaMeta:
            {
                attributeCache = SchemaMetaAttributeCache;
                break;
            }

            case Framework.Data.AryaDb.AttributeTypeEnum.SchemaMetaMeta:
            {
                attributeCache = SchemaMetaMetaAttributeCache;
                break;
            }

            case Framework.Data.AryaDb.AttributeTypeEnum.TaxonomyMeta:
            {
                attributeCache = TaxonomyMetaAttributeCache;
                break;
            }

            case Framework.Data.AryaDb.AttributeTypeEnum.TaxonomyMetaMeta:
            {
                attributeCache = TaxonomyMetaMetaAttributeCache;
                break;
            }

            case Framework.Data.AryaDb.AttributeTypeEnum.Workflow:
            {
                attributeCache = WorkflowAttributeCache;
                break;
            }

            default:     //Sku, Global, Derived, Flag
            {
                attributeCache = NonMetaAttributeCache;
                break;
            }
            }

            // format attribute name
            attributeName = attributeName.Trim();
            var lowerAttributeName = attributeName.ToLower();

            // try to find attribute in cache and make sure it is correct
            if (attributeCache.ContainsKey(lowerAttributeName))
            {
                var attribute = attributeCache[lowerAttributeName];
                if (attribute != null && !attribute.AttributeName.ToLower().Equals(lowerAttributeName))
                {
                    attributeCache.Remove(lowerAttributeName);
                }
                else
                {
                    return(attribute);
                }
            }

            // if attribute is not cached, try to find it in the whole attribute file
            Attribute newAttribute = null;
            var       attQuery     = from attribute in AryaTools.Instance.InstanceData.Dc.Attributes
                                     where
                                     attribute.AttributeName.Equals(lowerAttributeName) &&
                                     attribute.ProjectID == AryaTools.Instance.InstanceData.CurrentProject.ID
                                     select attribute;

            attQuery = attributeType == Framework.Data.AryaDb.AttributeTypeEnum.NonMeta
                ? attQuery.Where(
                attr => Framework.Data.AryaDb.Attribute.NonMetaAttributeTypes.Contains(attr.AttributeType))
                : attQuery.Where(attr => attr.AttributeType == attributeType.ToString());

            var att = attQuery.FirstOrDefault();

            // if found, return it
            if (att != null)
            {
                newAttribute = att;
            }
            // if not found and creation is requested, create it
            else if (createIfNotFound)
            {
                newAttribute = new Attribute
                {
                    AttributeName = attributeName,
                    AttributeType =
                        (attributeType
                         == Framework.Data.AryaDb.AttributeTypeEnum.NonMeta
                                           ? Framework.Data.AryaDb.AttributeTypeEnum.Sku
                                           : attributeType).ToString()
                };
                AryaTools.Instance.InstanceData.CurrentProject.Attributes.Add(newAttribute);
            }

            // if attribute exists, try to add it to the appropriate cache
            if (newAttribute != null)
            {
                if (!attributeCache.Keys.Contains(lowerAttributeName))
                {
                    attributeCache.Add(lowerAttributeName, newAttribute);
                }
            }

            return(newAttribute);
        }
Пример #19
0
        private void TryLoadLovs()
        {
            if (!ShowLovs || dgvAttributes.CurrentCell == null)
            {
                return;
            }

            var currentAttribute = ((AttributeColumn)dgvAttributes.CurrentCell.OwningRow.DataBoundItem).Attribute;

            if (currentAttribute == null || (_currentLovAttribute != null && _currentLovAttribute == currentAttribute))
            {
                return;
            }

            _currentLovAttribute = currentAttribute;

            var waitKey =
                FrmWaitScreen.ShowMessage(string.Format("Generating List of Values for {0}",
                                                        currentAttribute.AttributeName));

            if (rbAllLovs.Checked)
            {
                // this query must go ToList(), otherwise the results are not case sensitive.
                var loadQuery = (from ei in _entities
                                 join ed in AryaTools.Instance.InstanceData.Dc.EntityDatas on ei.ID equals ed.EntityID
                                 where ed.AttributeID == currentAttribute.ID && ed.Active
                                 select ed).ToList();

                var temp = (from ed in loadQuery
                            group ed by new { ed.Value, ed.Uom }
                            into grp
                            orderby grp.Key.Value
                            select new Lov(grp.Key.Value, grp.Key.Uom, grp.Select(ed => ed.EntityInfo)));

                _dsListOfValues = temp.ToList();

                dgvListOfValues.DataSource = _dsListOfValues;
            }

            else if (rbInschemaLovs.Checked)
            {
                var inSchemaTaxonomies =
                    _dsAttributes.First(ac => ac.Attribute.Equals(currentAttribute))
                    ._schemaDatas.Where(sd => sd.InSchema)
                    .Select(sd => sd.SchemaInfo.TaxonomyID)
                    .ToList();
                // this query must go ToList(), otherwise the results are not case sensitive.
                var loadQuery = (from ei in _entities
                                 join ed in AryaTools.Instance.InstanceData.Dc.EntityDatas on ei.ID equals ed.EntityID
                                 join si in AryaTools.Instance.InstanceData.Dc.SkuInfos on ei.SkuID equals si.SkuID
                                 where
                                 ed.AttributeID == currentAttribute.ID && ed.Active && si.Active &&
                                 inSchemaTaxonomies.Contains(si.TaxonomyID)
                                 select ed).ToList();

                var temp = (from ed in loadQuery
                            group ed by new { ed.Value, ed.Uom }
                            into grp
                            orderby grp.Key.Value
                            select new Lov(grp.Key.Value, grp.Key.Uom, grp.Select(ed => ed.EntityInfo)));

                _dsListOfValues = temp.ToList();

                dgvListOfValues.DataSource = _dsListOfValues;
            }

            FrmWaitScreen.HideMessage(waitKey);
        }
Пример #20
0
        public void FillTaxonomyAttributesCacheForImagingGapFill(TaxonomyInfo rootTaxonomy)
        {
            var allChilds = rootTaxonomy.AllLeafChildren.ToList();

            //include the root
            allChilds.Add(rootTaxonomy);

            var maxAttrCount = _currentDb.ExecuteQuery <int>(@"SELECT MAX(A.CT) AS MaxAttrCount
                    FROM 
                    (
	                    SELECT TaxonomyID,COUNT(DISTINCT AttributeName)AS  CT
	                    FROM SchemaAttributes 
	                    WHERE InSchema = 1
	                    AND T2 = 'Representational'
	                    AND T3 = 'Skus'
	                    AND (DisplayOrder <= 49 AND DisplayOrder >= 1)
	                    GROUP BY TaxonomyID 
                    ) A").Single();

            //Data Combination
            var dCSchema =
                allChilds.SelectMany(
                    child =>
                    child.SchemaInfos.Where(
                        si =>
                        si.SchemaDatas.Any(sd => sd.Active && sd.InSchema) &&
                        si.Attribute.AttributeName == "Data Combination")).FirstOrDefault();

            var dCSchemaAttribute = dCSchema == null
                ? new Attribute {
                AttributeName = "Data Combination"
            }
                : dCSchema.Attribute;

            var blankAttribute = new Attribute {
                AttributeName = string.Empty
            };

            foreach (var child in allChilds)
            {
                if (_taxonomyAttributesCache.ContainsKey(child.ID))
                {
                    continue;
                }

                var atts =
                    child.SchemaInfos.Where(p => p.SchemaData != null && p.SchemaData.InSchema)
                    .Select(p => new { p.Attribute, p.SchemaData })
                    .ToList();

                var attributes = (from att in atts
                                  let rank = GetRank(att.SchemaData, OrderAttributesBy)
                                             orderby rank, att.Attribute.AttributeName
                                  select
                                  new Tuple <Attribute, decimal, decimal>(att.Attribute,
                                                                          att.SchemaData == null ? 0 : att.SchemaData.NavigationOrder,
                                                                          att.SchemaData == null ? 0 : att.SchemaData.DisplayOrder)).ToList();

                var finalList = new List <Tuple <Attribute, decimal, decimal> >();

                var lessThan50DisplayAttributes = attributes.Where(p => p.Item3 < 50);

                //add all the left attributes
                finalList.AddRange(lessThan50DisplayAttributes);

                if (finalList.Count != maxAttrCount)
                {
                    var misCount = maxAttrCount - finalList.Count;
                    finalList.AddRange(
                        Enumerable.Repeat(new Tuple <Attribute, decimal, decimal>(blankAttribute, 0, int.MaxValue),
                                          misCount));
                }

                //add DC attribute
                finalList.Add(new Tuple <Attribute, decimal, decimal>(dCSchemaAttribute, 0, int.MaxValue));

                finalList.AddRange(attributes.Where(p => p.Item3 > 50));
                _taxonomyAttributesCache.Add(child.ID, finalList);
            }
        }
Пример #21
0
 public double?TryGetFillRate(Attribute attribute, Filter filter)
 {
     return(_fillRateValues.ContainsKeys(attribute, filter) ? (double?)_fillRateValues[attribute, filter] : null);
 }
Пример #22
0
        private object GetValue(Attribute colItem, Attribute rowItem)
        {
            // return headers if on the edges of the grid
            if (colItem == null)
            {
                return(rowItem);
            }
            if (rowItem == null)
            {
                return(colItem);
            }

            object returnVal = null;
            var    attName   = colItem.AttributeName;

            switch (attName)
            {
            case DisplayOrder:
            {
                var si = rowItem.SchemaInfos.FirstOrDefault(s => s.TaxonomyID.Equals(Guid.Empty));
                returnVal = si == null ? null : (object)si.SchemaData.DisplayOrder;
                break;
            }

            case Active:
            {
                var si = rowItem.SchemaInfos.FirstOrDefault(s => s.TaxonomyID.Equals(Guid.Empty));
                returnVal = si == null ? null : (object)si.SchemaData.InSchema;
                break;
            }

            case ListOfValues:
            {
                var schemaInfo = rowItem.SchemaInfos.FirstOrDefault(s => s.TaxonomyID.Equals(Guid.Empty));
                if (schemaInfo != null)
                {
                    var listOfValues = schemaInfo.ListOfValues.Where(lov => lov.Active).Select(lov => lov).ToList();
                    if (listOfValues.Any())
                    {
                        var listSep =
                            AryaTools.Instance.InstanceData.CurrentProject.ProjectPreferences.ListSeparator
                            ?? "; ";
                        returnVal =
                            listOfValues.OrderBy(val => val.DisplayOrder)
                            .ThenBy(val => val.Value)
                            .Select(val => val.Value)
                            .Aggregate((current, lov) => current + listSep + lov);
                    }
                }
                break;
            }

            default:
            {
                // get intersection of row and column attributes
                var ami = rowItem.AttributeMetaInfos.FirstOrDefault(a => a.MetaAttribute == colItem);
                if (ami != null)
                {
                    // get associated data, if it exists
                    var amd = ami.AttributeMetaDatas.FirstOrDefault(a => a.Active);
                    if (amd != null)
                    {
                        returnVal = amd.Value;
                    }
                }
                break;
            }
            }

            return(returnVal);
        }