Ejemplo n.º 1
0
        /// <summary>
        ///
        /// This method will iterate through a list of Products and apply the default value to every instance
        /// of an empty Attribute (i.e., in every DataRow of its Group).
        ///
        /// <param name="poProducts">The product list that we are iterating through</param>
        /// <param name="poDefaultValues">The default values for Attributes</param>
        /// <returns>None</returns>
        /// </summary>
        public static void ApplyDefaults(List <WonkaProduct> poProducts, Dictionary <int, string> poDefaultValues)
        {
            foreach (WonkaProduct TempProduct in poProducts)
            {
                var iDefaultValEnumerator = poDefaultValues.GetEnumerator();
                while (iDefaultValEnumerator.MoveNext())
                {
                    int    nDefaultAttrId    = iDefaultValEnumerator.Current.Key;
                    string sDefaultAttrValue = iDefaultValEnumerator.Current.Value;

                    WonkaRefAttr TempAttr = WonkaRefEnvironment.GetInstance().GetAttributeByAttrId(nDefaultAttrId);

                    WonkaPrdGroup TargetGroup = TempProduct.GetProductGroup(TempAttr.GroupId);

                    foreach (WonkaPrdGroupDataRow TempDataRow in TargetGroup)
                    {
                        string sTempValue = TempDataRow[TempAttr.AttrId];

                        if (String.IsNullOrEmpty(sTempValue))
                        {
                            TempDataRow.SetData(TempAttr.AttrId, sDefaultAttrValue);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// This method will merge the contents of this Group with the one provided.
        ///
        /// NOTE: A true merge happens only between two instances of a group with one row.  The functionality
        /// to merge other groups has not yet been truly implemented.
        ///
        /// <param name="ThatProductGroup">The Group that should merge with this one</param>
        /// <returns>None</returns>
        /// </summary>
        public void Merge(WonkaPrdGroup ThatProductGroup)
        {
            if (this.MasterGroup.GroupId == ThatProductGroup.MasterGroup.GroupId)
            {
                if ((this.GetRowCount() == 1) && (ThatProductGroup.GetRowCount() == 1))
                {
                    if (ThatProductGroup.GetRowCount() > 0)
                    {
                        if (this.GetRowCount() <= 0)
                        {
                            AppendRow();
                        }

                        WonkaPrdGroupDataRow ThisRow = this.DataRowVector[0];
                        WonkaPrdGroupDataRow ThatRow = ThatProductGroup.DataRowVector[0];

                        ThisRow.Merge(ThatRow);
                    }
                }
                else if (ThatProductGroup.GetRowCount() > 0)
                {
                    this.SetData(ThatProductGroup);
                }
            }
            else
            {
                throw new Exception("ERROR!  Attempting to merge two Groups of different sizes!");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// This method will provide the ProductGroup inside this Product, if one has already
        /// been instantiated with values.  If not, it will create a new empty one and place it
        /// inside the collection.
        ///
        /// <param name="pnGroupId">The ID of the Group that we are interested in retrieving</param>
        /// <returns>The ProductGroup that we want to retrieve from this Product</returns>
        /// </summary>
        public WonkaPrdGroup GetProductGroup(int pnGroupId)
        {
            WonkaPrdGroup SoughtGroup = null;

            if (HasProductGroup(pnGroupId))
            {
                SoughtGroup = this.ProductGroups[pnGroupId];
            }
            else
            {
                if (WonkaRefEnvironment.GetInstance().DoesGroupExist(pnGroupId))
                {
                    this.ProductGroups[pnGroupId] =
                        new WonkaPrdGroup(WonkaRefEnvironment.GetInstance().GetGroupByGroupId(pnGroupId));

                    return(this.ProductGroups[pnGroupId]);
                }
                else
                {
                    throw new Exception("ERROR!  Requested Group ID (" + pnGroupId + ") does not exist.");
                }
            }

            return(SoughtGroup);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// This method will compare two Groups to see if they are equal, but it will
        /// only compare those Attributes mentioned in the target Field.
        ///
        /// <param name="poThatGroup">The group being compared against (usually representing old data from persistence/storage)</param>
        /// <param name="poTargetField">The Field that has the Attribute list of interest</param>
        /// <returns>Bool that indicates whether or not the two Groups are equal</returns>
        /// </summary>
        public bool Equals(WonkaPrdGroup poThatGroup, WonkaRefField poTargetField)
        {
            Dictionary <int, string> ThisGroupAttrValues = new Dictionary <int, string>();
            Dictionary <int, string> ThatGroupAttrValues = new Dictionary <int, string>();

            return(Equals(poThatGroup, poTargetField, ThisGroupAttrValues, ThatGroupAttrValues));
        }
Ejemplo n.º 5
0
        public WonkaPrdGroup(WonkaPrdGroup poOriginalGroup) : this(poOriginalGroup.MasterGroup)
        {
            this.DataRowVector.AddRange(poOriginalGroup.DataRowVector);

            this.Modified          = poOriginalGroup.Modified;
            this.OldDataFound      = poOriginalGroup.OldDataFound;
            this.ProperlySequenced = poOriginalGroup.ProperlySequenced;
        }
Ejemplo n.º 6
0
        public WonkaPrdGroupEnumerator(WonkaPrdGroup poGroup)
        {
            if (poGroup == null)
            {
                throw new Exception("ERROR!  Group provided is null.");
            }

            moGroup = poGroup;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// This method will replace the contents of its current DataRows with the contents of the provided Group.
        ///
        /// <param name="poOriginalCopy">The Group from which we are going to copy the DataRows</param>
        /// <returns>None</returns>
        /// </summary>
        public void SetData(WonkaPrdGroup poOriginalCopy)
        {
            this.DeleteRows();

            foreach (WonkaPrdGroupDataRow ThatDataRow in poOriginalCopy.DataRowVector)
            {
                AppendRow(new WonkaPrdGroupDataRow(ThatDataRow));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// This method will compare two Groups to see if they are equal, but it will
        /// only compare those Attributes mentioned in the target Field.
        ///
        /// NOTE: The auditing containers 'poThisAttrValues' and 'poThatAttrValues' will only
        /// work correctly with a group that only has one row.
        ///
        /// <param name="poThatGroup">The group being compared against (usually representing old data from the persistence/storage)</param>
        /// <param name="poTargetField">The Field that has the Attribute list of interest</param>
        /// <param name="poThisAttrValues">Storage for the values different from "this" group</param>
        /// <param name="poThatAttrValues">Storage for the values different from "that" group</param>
        /// <returns>Bool that indicates whether or not the two Groups are equal</returns>
        /// </summary>
        public bool Equals(WonkaPrdGroup poThatGroup,
                           WonkaRefField poTargetField,
                           Dictionary <int, string> poThisAttrValues,
                           Dictionary <int, string> poThatAttrValues)
        {
            HashSet <int> IgnoreAttrIds = new HashSet <int>();

            return(Equals(poThatGroup, poTargetField, IgnoreAttrIds, poThisAttrValues, poThatAttrValues));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// This method will update the contents of a row (at index 'pnRowIndex') with the values from the supplied DataRow
        /// (via matching on the key), but only for the Attributes of a given Field.  In addition, if any Attribute inside
        /// the updated Field has an associated AttrModDt, we will set that Attribute with the timestamp of CurrTimeStamp.
        ///
        /// NOTE: This code assumes that only 1 AttrModDt will be updated per call of updateField(...)
        ///
        /// <param name="poThatGroup">The Group that we are using to update this one</param>
        /// <param name="poTargetField">The Field that possesses the Attribute list of interest</param>
        /// <param name="psCurrTimeStamp">The current Timestamp that we will use to set any associated AttrModDdt</param>
        /// <returns>The AttrID of the AttrModDt which has been updated with the CurrTimeStamp</returns>
        /// </summary>
        public int UpdateField(WonkaPrdGroup poThatGroup, WonkaRefField poTargetField, string psCurrTimeStamp = null)
        {
            int nUpdatedModDtAttrId = 0;

            HashSet <int> FieldAttrIds = WonkaRefEnvironment.GetInstance().GetAttrIdsByFieldId(poTargetField.FieldId);

            string sTimeStamp = (!String.IsNullOrEmpty(psCurrTimeStamp)) ? psCurrTimeStamp : DateTime.Now.ToString("yyyyMMddHHmmss");

            foreach (WonkaPrdGroupDataRow ThatRow in poThatGroup)
            {
                WonkaPrdGroupDataRow ThisRow =
                    (this.GetRowIndex(ThatRow.GetKey()) >= 0) ? this.GetRow(ThatRow.GetKey()) : AppendRow();

                foreach (int nTempAttrId in FieldAttrIds)
                {
                    string sThatValue = ThatRow[nTempAttrId];

                    if (!String.IsNullOrEmpty(sThatValue))
                    {
                        WonkaRefAttr TempAttr = WonkaRefEnvironment.GetInstance().GetAttributeByAttrId(nTempAttrId);

                        ThisRow[nTempAttrId] = sThatValue;

                        if (TempAttr.AttrModDtFlag)
                        {
                            try
                            {
                                WonkaRefAttr TempAttrModDt =
                                    WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(TempAttr.AttrModDt);

                                string sThatAttrModDtValue = ThatRow[TempAttrModDt.AttrId];

                                // NOTE: We will only use the CurrentTimestamp if there isn't already a timestamp value
                                //       in the provided DataRow of ThatGroup
                                if (String.IsNullOrEmpty(sThatAttrModDtValue))
                                {
                                    ThisRow[TempAttrModDt.AttrId] = sTimeStamp;

                                    if (nUpdatedModDtAttrId == 0)
                                    {
                                        nUpdatedModDtAttrId = TempAttrModDt.AttrId;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("ERROR!  Cannot set the ATTR_MOD_DT sibling (" + TempAttr.AttrModDt +
                                                    ") for ATTRIBUTE (" + TempAttr.AttrName + ").");
                            }
                        }
                    }
                }
            }

            return(nUpdatedModDtAttrId);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// This method will update a particular ProductGroup of this Product with the one provided.
        ///
        /// <param name="poThatProductGroup">The ProductGroup from which we will copy our sought data</param>
        /// <param name="pbMergeFlag">Indicator of whether the provided data should completely overlay or merge with the contents of this ProductGroup</param>
        /// <returns>None</returns>
        /// </summary>
        public void Update(WonkaPrdGroup poThatProductGroup, bool pbMergeFlag)
        {
            WonkaPrdGroup ThisPrdGroup = this.GetProductGroup(poThatProductGroup.GroupId);

            if (pbMergeFlag)
            {
                ThisPrdGroup.Merge(poThatProductGroup);
            }
            else
            {
                ThisPrdGroup = poThatProductGroup;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// This method will compare two Groups to see if they are equal, but it will
        /// only compare those Attributes mentioned in the target Field.
        ///
        /// NOTE: The auditing containers 'poThisAttrValues' and 'poThatAttrValues' will only
        /// work correctly with a group that only has one row.
        ///
        /// <param name="poThatGroup">The group being compared against (usually representing old data from the DB)</param>
        /// <param name="poTargetField">The Field that has the Attribute list of interest</param>
        /// <param name="poIgnoreAttrIds">The list of Attributes that should be ignored when comparisons are done</param>
        /// <param name="poThisAttrValues">Storage for the values different from "this" group</param>
        /// <param name="poThatAttrValues">Storage for the values different from "that" group</param>
        /// <returns>Bool that indicates whether or not the two Groups are equal</returns>
        /// </summary>
        public bool Equals(WonkaPrdGroup poThatGroup,
                           WonkaRefField poTargetField,
                           HashSet <int> poIgnoreAttrIds,
                           Dictionary <int, string> poNewAttrValues,
                           Dictionary <int, string> poOldAttrValues)
        {
            bool bResult = true;

            foreach (WonkaPrdGroupDataRow ThisRow in this.DataRowVector)
            {
                int nThatRowIndex = poThatGroup.GetRowIndex(ThisRow.GetKey());

                if (nThatRowIndex != -1)
                {
                    WonkaPrdGroupDataRow ThatRow = poThatGroup[nThatRowIndex];

                    HashSet <int> FieldAttrIds =
                        WonkaRefEnvironment.GetInstance().GetAttrIdsByFieldId(poTargetField.FieldId);

                    foreach (int nAttrId in FieldAttrIds)
                    {
                        WonkaRefAttr TempAttr = WonkaRefEnvironment.GetInstance().GetAttributeByAttrId(nAttrId);

                        if (poIgnoreAttrIds.Contains(nAttrId))
                        {
                            continue;
                        }

                        if (poTargetField.MergeNullAttrFlag || !String.IsNullOrEmpty(ThisRow[nAttrId]))
                        {
                            string sThisValue = ThisRow[nAttrId];
                            string sThatValue = ThatRow[nAttrId];

                            if (sThisValue != sThatValue)
                            {
                                // NOTE: Need to record these values, maybe for auditing
                                if (TempAttr.IsAudited)
                                {
                                    poNewAttrValues[TempAttr.AttrId] = sThisValue;
                                    poOldAttrValues[TempAttr.AttrId] = sThatValue;
                                }

                                bResult = Compare(TempAttr, sThisValue, sThatValue);
                            }
                        }
                    }
                }
            }

            return(bResult);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// This method will seek the primary row (i.e., usually the first row) of a ProductGroup and then
        /// return the value for the Attribute in that row.  If the ProductGroup is sequenced, we will
        /// look for the row with the 'group_seq' equal to 1; if it's not, we will just take the first row.
        ///
        /// <param name="pnGroupId">The ID of the Group that we are interested in</param>
        /// <param name="pnAttrId">The ID of the Attribute that we are interested in</param>
        /// <returns>The value of the Attribute for the Group's primary row</returns>
        /// </summary>
        public string GetPrimaryAttributeData(int pnGroupId, int pnAttrId)
        {
            string sAttrValue = null;

            WonkaPrdGroup TargetGroup = this.GetProductGroup(pnGroupId);

            if (TargetGroup.DataRowVector.Count > 0)
            {
                if (TargetGroup.MasterGroup.IsSequenced)
                {
                    int nSeqAttrId =
                        WonkaRefEnvironment.GetInstance().GetGroupSeqAttrId(pnGroupId);

                    WonkaPrdGroupDataRow TargetDataRow = null;

                    if (TargetGroup.DataRowVector.Any(x => x.ContainsKey(nSeqAttrId) && x[nSeqAttrId] == "1"))
                    {
                        TargetDataRow = TargetGroup.DataRowVector.Where(x => x.ContainsKey(nSeqAttrId) && x[nSeqAttrId] == "1").FirstOrDefault();
                    }
                    else
                    {
                        TargetDataRow = TargetGroup[0];
                    }

                    if (TargetDataRow.ContainsKey(pnAttrId))
                    {
                        sAttrValue = TargetDataRow[pnAttrId];
                    }
                }
                else
                {
                    WonkaPrdGroupDataRow TargetDataRow = TargetGroup[0];

                    if (TargetDataRow.ContainsKey(pnAttrId))
                    {
                        sAttrValue = TargetDataRow[pnAttrId];
                    }
                }
            }

            return(sAttrValue);
        }
Ejemplo n.º 13
0
        /// <summary>
        ///
        /// This method will compare two Groups to see if they are equal. It will compare
        /// them by finding a corresponding DataRow within ThisGroup and ThatGroup, based
        /// on the key.
        ///
        /// NOTE: This Group (i.e., the left-hand data row) usually represents incoming/new data
        ///
        /// NOTE: Currently, it doesn't compare them exactly.  It just ensures that
        /// the contents of 'r1' are the same in 'r2', implying that 'r2' can be a
        /// superset of 'r1'.
        ///
        /// <param name="ThatGroup">The right-hand data row (usually representing old data from persistence/storage)</param>
        /// <returns>Bool that indicates whether or not the two Groups are equal</returns>
        public bool Equals(WonkaPrdGroup poThatGroup)
        {
            foreach (WonkaPrdGroupDataRow ThisRow in this)
            {
                int nThatRowIndex = poThatGroup.GetRowIndex(ThisRow.GetKey());

                if (nThatRowIndex != -1)
                {
                    if (ThisRow != poThatGroup.GetRow(nThatRowIndex))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
        /// <summary>
        ///
        /// This method will assign the Attribute values for a new DataRow
        /// created for their respective Group.
        ///
        /// <param name="poProduct">The Product that we are assigning these Attribute values</param>
        /// <param name="poAttrValues">The Attribute values that we are going to set inside the provided Product</param>
        /// <returns>None</returns>
        /// </summary>
        public static void PopulateProductGroup(WonkaProduct poProduct, int pnGroupId, Dictionary <int, string> poAttrValues)
        {
            WonkaPrdGroup        TempPrdGroup = poProduct.ProductGroups[pnGroupId];
            WonkaPrdGroupDataRow TempDataRow  = TempPrdGroup.AppendRow();

            var iAttrValueEnum = poAttrValues.GetEnumerator();

            while (iAttrValueEnum.MoveNext())
            {
                int    nAttrId    = iAttrValueEnum.Current.Key;
                string sAttrValue = iAttrValueEnum.Current.Value;

                WonkaRefAttr TempAttribute = WonkaRefEnvironment.GetInstance().GetAttributeByAttrId(nAttrId);

                if (TempAttribute.GroupId != pnGroupId)
                {
                    continue;
                }

                TempDataRow.SetData(nAttrId, sAttrValue);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///
        /// This method will assign the Attribute values specifically to the first DataRow
        /// of their respective Group.
        ///
        /// NOTE: This method will nullify Attributes only for the first DataRow of the Group.
        ///
        /// <param name="poProduct">The Product that we are assigning these Attribute values</param>
        /// <param name="poAttrValues">The Attribute values that we are going to set inside the provided Product</param>
        /// <returns>None</returns>
        /// </summary>
        public static void PopulateProduct(WonkaProduct poProduct, Dictionary <int, string> poAttrValues)
        {
            var iAttrValueEnum = poAttrValues.GetEnumerator();

            while (iAttrValueEnum.MoveNext())
            {
                int    nAttrId    = iAttrValueEnum.Current.Key;
                string sAttrValue = iAttrValueEnum.Current.Value;

                WonkaRefAttr  TempAttribute = WonkaRefEnvironment.GetInstance().GetAttributeByAttrId(nAttrId);
                WonkaPrdGroup TempPrdGroup  = poProduct.ProductGroups[TempAttribute.GroupId];

                if (TempPrdGroup.GetRowCount() <= 0)
                {
                    TempPrdGroup.AppendRow();
                }

                WonkaPrdGroupDataRow GrpDataRow = TempPrdGroup.GetRow(0);

                GrpDataRow.SetData(nAttrId, sAttrValue);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// This method will iterate through all of the data in the contained groups and detect whether
        /// any of them are not valid according to the designated type for that Attribute.
        ///
        /// <param name="poErrors">The list to which we will add any errors concerning the validation of types</param>
        /// <returns>Indicates whether or not there any errors with validating types</returns>
        /// </summary>
        public bool ValidateTypes(List <WonkaProductError> poErrors)
        {
            WonkaRefEnvironment RefEnv = WonkaRefEnvironment.GetInstance();

            bool bResult = true;

            foreach (int nGrpId in this.ProductGroups.Keys)
            {
                WonkaPrdGroup TempGroup = ProductGroups[nGrpId];

                foreach (WonkaPrdGroupDataRow TempDataRow in TempGroup)
                {
                    foreach (int nAttrId in TempDataRow.Keys)
                    {
                        string sAttrValue = TempDataRow[nAttrId];

                        if (!String.IsNullOrEmpty(sAttrValue))
                        {
                            WonkaRefAttr TempAttr = RefEnv.GetAttributeByAttrId(nAttrId);

                            if (TempAttr.IsDecimal)
                            {
                                try
                                {
                                    Decimal dValue = Convert.ToDecimal(sAttrValue);
                                }
                                catch (Exception ex)
                                {
                                    poErrors.Add(new WonkaProductError()
                                    {
                                        AttrName     = TempAttr.AttrName,
                                        ErrorMessage = "ERROR!  Value(" + sAttrValue + ") is not a valid decimal!"
                                    });
                                }
                            }
                            else if (TempAttr.IsNumeric)
                            {
                                try
                                {
                                    long nValue = Convert.ToInt64(sAttrValue);
                                }
                                catch (Exception ex)
                                {
                                    poErrors.Add(new WonkaProductError()
                                    {
                                        AttrName     = TempAttr.AttrName,
                                        ErrorMessage = "ERROR!  Value(" + sAttrValue + ") is not a valid number!"
                                    });
                                }
                            }
                            else if (TempAttr.IsDate)
                            {
                                try
                                {
                                    DateTime dtValue = DateTime.Parse(sAttrValue);
                                }
                                catch (Exception ex)
                                {
                                    poErrors.Add(new WonkaProductError()
                                    {
                                        AttrName     = TempAttr.AttrName,
                                        ErrorMessage = "ERROR!  Value(" + sAttrValue + ") is not a valid date!"
                                    });
                                }
                            }
                        }
                    }
                }
            }

            return(bResult);
        }