Esempio n. 1
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!");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// This method will set all of the Attributes within this Row to those in the provided one.
 /// </summary>
 /// <param name="poOriginal">The DataRow that we are copying all of the Attribute values from</param>
 /// <returns>None</returns>
 public void SetData(WonkaPrdGroupDataRow poOriginal)
 {
     foreach (int TmpAttrId in poOriginal.Keys)
     {
         this[TmpAttrId] = poOriginal[TmpAttrId];
     }
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// This method will update the contents of a row (at index 'pnRowIndex') with the values from the supplied DataRow.
        ///
        /// <param name="poNewDataRow">The DataRow that we are using to set the DataRow found at index 'pnRowIndex'</param>
        /// <returns>None</returns>
        /// </summary>
        public void UpdateRow(WonkaPrdGroupDataRow poNewDataRow, int pnRowIndex)
        {
            ValidateRowIndex(pnRowIndex);
            ValidateDataRow(poNewDataRow);

            DataRowVector[pnRowIndex] = poNewDataRow;
        }
Esempio n. 4
0
 /// <summary>
 /// This method will set all of the Attributes (for the target Field) within this Row to
 /// those in the provided one.
 /// </summary>
 /// <param name="poOriginal">The DataRow that we are copying all of the Attribute values from</param>
 /// <param name="poField">The subset of Attributes that we are targeting for the copy</param>
 /// <returns>None</returns>
 public void SetData(WonkaPrdGroupDataRow poOriginal, WonkaRefField poField)
 {
     foreach (int TmpAttrId in poField.AttrIds)
     {
         this[TmpAttrId] = poOriginal[TmpAttrId];
     }
 }
Esempio n. 5
0
        /// <summary>
        ///
        /// This method will append an empty DataRow to the list and then return it for usage to the caller
        /// (such as filling it with values).
        ///
        /// <returns>The new empty DataRow that has been inserted into the internal list</returns>
        /// </summary>
        public WonkaPrdGroupDataRow AppendRow()
        {
            WonkaPrdGroupDataRow NewDataRow = new WonkaPrdGroupDataRow(MasterGroup);

            DataRowVector.Add(NewDataRow);
            return(NewDataRow);
        }
Esempio n. 6
0
 public WonkaPrdGroupDataRow(WonkaPrdGroupDataRow poOriginalRow) : base(poOriginalRow)
 {
     this.GroupId     = poOriginalRow.GroupId;
     this.GroupName   = poOriginalRow.GroupName;
     this.AttrIds     = poOriginalRow.AttrIds;
     this.KeyAttrIds  = poOriginalRow.KeyAttrIds;
     this.MasterGroup = poOriginalRow.MasterGroup;
 }
Esempio n. 7
0
        /// <summary>
        ///
        /// This method provides a quick validation of the DataRow and indicates whether or not it belongs within this Group.
        ///
        /// <param name="poDataRow">The DataRow that we are validating for membership within this Group</param>
        /// <returns>Bool that indicates if the DataRow is acceptable</returns>
        /// </summary>
        public bool ValidateDataRow(WonkaPrdGroupDataRow poDataRow)
        {
            if ((MasterDataRow.MasterGroup.GroupId != poDataRow.MasterGroup.GroupId) || (poDataRow.MasterGroup.GroupId <= 0))
            {
                throw new Exception("ERROR!  Invalid Group ID (" + poDataRow.MasterGroup.GroupId + ").");
            }

            return(true);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public WonkaPrdGroup(WonkaRefGroup poRefGroup)
        {
            Modified = OldDataFound = ProperlySequenced = false;

            GroupId = poRefGroup.GroupId;

            DataRowVector = new List <WonkaPrdGroupDataRow>();
            MasterDataRow = new WonkaPrdGroupDataRow(poRefGroup);
            MasterGroup   = poRefGroup;
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// This method will merge the contents of ThatDataRow with the contents of this one, storing
        /// the results in here.
        ///
        /// NOTE: It will only accept actual values (i.e., not null and not empty) from ThatDataRow
        /// when it does the merge.
        ///
        /// </summary>
        /// <param name="ThatDataRow">The DataRow whose values are going to be merged into this DataRow</param>
        /// <returns>None</returns>
        public void Merge(WonkaPrdGroupDataRow ThatDataRow)
        {
            foreach (int TempAttrId in AttrIds)
            {
                string sThatValue = ThatDataRow[TempAttrId];

                if (!string.IsNullOrEmpty(sThatValue))
                {
                    this[TempAttrId] = ThatDataRow[TempAttrId];
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// This method will compare two DataRows to see if their Fields are equal.
        ///
        /// NOTE: Currently, it doesn't compare them exactly.  It just ensures that
        /// the contents of the Field in 'r1' are the same in 'r2', implying that
        /// the'r2' Field can be a superset of 'r1'.
        ///
        /// </summary>
        /// <param name="poThatDataRow">The data row that this one is being compared to</param>
        /// <returns>Bool that indicates whether or not the two DataRows are equal</returns>
        public bool Equals(WonkaPrdGroupDataRow poThatDataRow, WonkaRefField poField)
        {
            foreach (int nAttrId in poField.AttrIds)
            {
                if (this[nAttrId] != poThatDataRow[nAttrId])
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public bool MoveNext()
        {
            bool bResult = true;

            ++mnIndex;

            if (mnIndex < moGroup.DataRowVector.Count)
            {
                moCurrDataRow = moGroup.DataRowVector[mnIndex];
            }
            else
            {
                moCurrDataRow = null;
                bResult       = false;
            }

            return(bResult);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
 public WonkaPrdGroupDataRowKey(WonkaPrdGroupDataRow poParentDataRow)
 {
     this.ParentDataRow = poParentDataRow;
 }
Esempio n. 18
0
 /// <summary>
 ///
 /// This method will append the provided DataRow to the internal list.
 ///
 /// <param name="ProvidedDataRow">The DataRow that we will insert into our internal list (after it has been validated)</param>
 /// <returns>The provided DataRow that has been inserted into the internal list</returns>
 /// </summary>
 public WonkaPrdGroupDataRow AppendRow(WonkaPrdGroupDataRow ProvidedDataRow)
 {
     ValidateDataRow(ProvidedDataRow);
     DataRowVector.Add(ProvidedDataRow);
     return(ProvidedDataRow);
 }