Ejemplo n.º 1
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];
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// This method will return the sought ProductField of this Product, if one is already present.
        /// If it is not present, it will create one by default and return it after inserting into
        /// our collection.
        ///
        /// <param name="poField">The Field representing the ProductField that we want to retrieve</param>
        /// <returns>The ProductField that we want to retrieve from this Product</returns>
        /// </summary>
        public WonkaProductField GetProductField(WonkaRefField poField)
        {
            WonkaProductField SoughtField = null;

            if (ProductFieldIndex.Keys.Contains(poField.FieldId))
            {
                SoughtField = ProductFieldIndex[poField.FieldId];
            }
            else if (WonkaRefEnvironment.GetInstance().DoesFieldExist(poField.FieldId))
            {
                ProductFieldIndex[poField.FieldId] = new WonkaProductField();

                SoughtField = ProductFieldIndex[poField.FieldId];

                SoughtField.ProductId = this.ProductId;
                SoughtField.FieldId   = poField.FieldId;
                SoughtField.LockCd    = "N";

                SoughtField.LastTouchedSourceId =
                    (this.OwnerSourceIds != null) && (this.OwnerSourceIds.Count > 0) ? this.OwnerSourceIds.ElementAt(0) : 0;
            }
            else
            {
                throw new Exception("ERROR!  WonkaProduct::getProductField(const WonkaRefField&) : " +
                                    "Requested field does not exist: (" + poField.FieldName + ").");
            }

            return(SoughtField);
        }
Ejemplo n.º 3
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.º 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.
        ///
        /// 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.º 5
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.º 6
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);
        }
Ejemplo n.º 7
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.º 8
0
        /// <summary>
        ///
        /// This method will detect if this Data Row is null (i.e., empty with no values present)
        /// with respect to those Attributes in the indicated Field.
        ///
        /// </summary>
        /// <param name="poField">The Field whose Attributes are being inspected</param>
        /// <returns>Bool whether the row is empty (i.e., null) in terms of the Attributes for the Field</returns>
        public bool IsNull(WonkaRefField poField)
        {
            foreach (int nAttrId in poField.AttrIds)
            {
                string sValue = this[nAttrId];

                if (sValue.Length > 0)
                {
                    return(false);
                }
            }

            return(true);
        }
        public List <WonkaRefField> GetFieldCache()
        {
            List <WonkaRefField> FieldCache      = new List <WonkaRefField>();
            XmlSerializer        FieldSerializer = new XmlSerializer(typeof(WonkaRefField));

            XmlNodeList FieldNodeList = moXmlDoc.GetElementsByTagName("Field");

            foreach (XmlNode FieldNode in FieldNodeList)
            {
                WonkaRefField TempField = (WonkaRefField)FieldSerializer.Deserialize(new StringReader(FieldNode.OuterXml));

                FieldCache.Add(TempField);
            }

            return(FieldCache);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// This method will detect if all DataRows contained in this Group are considered 'null' (i.e., empty of values),
        /// but only for those Attributes mentioned within the target Field.
        ///
        /// <param name="poField">The target Field with the list of Attributes on which we are focused</param>
        /// <param name="pbIgnoreDeletedRows">Indicates whether or not Marked-as-Delete rows should be ignored</param>
        /// <returns>Bool that indicates if there are any rows present inside the Group that are not null</returns>
        ///
        /// </summary>
        public bool IsNull(WonkaRefField poField, bool pbIgnoreDeletedRows = true)
        {
            bool bResult = true;

            if (GetRowCount() == 0)
            {
                return(bResult);
            }

            int           nGrpSeqAttrId = -1;
            HashSet <int> FieldAttrIds  = WonkaRefEnvironment.GetInstance().GetAttrIdsByFieldId(poField.FieldId);

            if (this.MasterGroup.IsSequenced)
            {
                nGrpSeqAttrId = WonkaRefEnvironment.GetInstance().GetGroupSeqAttrId(MasterGroup.GroupId);
            }

            foreach (WonkaPrdGroupDataRow TempDataRow in DataRowVector)
            {
                if (pbIgnoreDeletedRows)
                {
                    if ((nGrpSeqAttrId >= 0) && (TempDataRow[nGrpSeqAttrId] == "0"))
                    {
                        continue;
                    }
                }

                foreach (int nAttrId in FieldAttrIds)
                {
                    string sTempValue = TempDataRow[nAttrId];
                    if (!String.IsNullOrEmpty(sTempValue))
                    {
                        return(false);
                    }
                }
            }

            return(bResult);
        }
Ejemplo n.º 11
0
 public void AddField(WonkaRefField poNewField)
 {
     FieldCollection.Add(poNewField);
 }
Ejemplo n.º 12
0
 /// <summary>
 ///
 /// This method will detect whether or not this Product already has an instance of the identified
 /// ProductField
 ///
 /// <param name="poField">The Field indicating the ProductField that we are interested in</param>
 /// <returns>Indicator of whether or not an instance of that ProductField has been created within this Product</returns>
 /// </summary>
 public bool HasProductField(WonkaRefField poField)
 {
     return(this.ProductFieldIndex.Keys.Contains(poField.FieldId));
 }
Ejemplo n.º 13
0
        public IMetadataRetrievable ImportSource(string psDatabaseTable, ObjectContext poDbContext)
        {
            WonkaBreImportSource NewImportSource = new WonkaBreImportSource();
            HashSet <string>     KeyColNames     = new HashSet <string>();

            if (!String.IsNullOrEmpty(psDatabaseTable) && (poDbContext != null))
            {
                if (moCachedImports.ContainsKey(psDatabaseTable))
                {
                    return(moCachedImports[psDatabaseTable]);
                }

                var tables =
                    poDbContext.MetadataWorkspace.GetItems(DataSpace.CSpace).Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType);

                foreach (var TmpTable in tables)
                {
                    EntityType TmpEntityType = (EntityType)TmpTable;

                    if (TmpEntityType.Name == psDatabaseTable)
                    {
                        var KeyCols = TmpEntityType.KeyMembers;
                        foreach (var KeyCol in KeyCols)
                        {
                            KeyColNames.Add(KeyCol.Name);
                        }

                        break;
                    }
                }

                var columns =
                    from meta in poDbContext.MetadataWorkspace.GetItems(DataSpace.CSpace).Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                    from p in (meta as EntityType).Properties.Where(p => p.DeclaringType.Name == psDatabaseTable)
                    select new
                {
                    colName   = p.Name,
                    colType   = p.TypeUsage.EdmType,
                    doc       = p.Documentation,
                    maxLength = p.MaxLength,
                    precision = p.Precision,
                    scale     = p.Scale,
                    defValue  = p.DefaultValue,
                    props     = p.MetadataProperties
                };

                foreach (var TmpCol in columns)
                {
                    string sTmpColName = TmpCol.colName;
                    var    Props       = TmpCol.props;

                    WonkaRefAttr TmpWonkaAttr = new WonkaRefAttr();

                    TmpWonkaAttr.AttrId   = GenerateNewAttrId();
                    TmpWonkaAttr.AttrName = sTmpColName;
                    TmpWonkaAttr.ColName  = sTmpColName;
                    TmpWonkaAttr.TabName  = psDatabaseTable;

                    TmpWonkaAttr.DefaultValue = Convert.ToString(TmpCol.defValue);
                    TmpWonkaAttr.Description  = (TmpCol.doc != null) ? TmpCol.doc.LongDescription : "";

                    TmpWonkaAttr.IsDate    = IsTypeDate(TmpCol.colType);
                    TmpWonkaAttr.IsNumeric = IsTypeNumeric(TmpCol.colType);
                    TmpWonkaAttr.IsDecimal = IsTypeDecimal(TmpCol.colType);

                    if (TmpWonkaAttr.IsNumeric || TmpWonkaAttr.IsDecimal)
                    {
                        TmpWonkaAttr.Precision = (int)((TmpCol.precision != null) ? TmpCol.precision : 0);
                        TmpWonkaAttr.Scale     = (int)((TmpCol.scale != null) ? TmpCol.scale : 0);
                    }

                    TmpWonkaAttr.MaxLength = (TmpCol.maxLength != null) ? (int)TmpCol.maxLength : 0;

                    TmpWonkaAttr.FieldId   = TmpWonkaAttr.AttrId + 1000;
                    TmpWonkaAttr.GroupId   = CONST_DEFAULT_GROUP_ID;
                    TmpWonkaAttr.IsAudited = true;

                    TmpWonkaAttr.IsKey = KeyColNames.Contains(TmpWonkaAttr.AttrName);

                    NewImportSource.AddAttribute(TmpWonkaAttr);
                }

                if (NewImportSource.GetAttrCache().Count <= 0)
                {
                    throw new WonkaBreException(0, 0, "ERROR!  Could not import the schema because the Reader's field count was zero.");
                }

                WonkaRefGroup NewImportGroup = new WonkaRefGroup();

                NewImportGroup.GroupId        = CONST_DEFAULT_GROUP_ID;
                NewImportGroup.GroupName      = psDatabaseTable;
                NewImportGroup.KeyTabCols     = KeyColNames;
                NewImportGroup.ProductTabName = psDatabaseTable;
                NewImportSource.AddGroup(NewImportGroup);

                WonkaRefSource GuestSource = new WonkaRefSource();

                GuestSource.SourceId   = 1;
                GuestSource.SourceName = "Guest";
                GuestSource.Status     = "Active";
                NewImportSource.AddSource(GuestSource);

                foreach (WonkaRefAttr TempAttr in NewImportSource.GetAttrCache())
                {
                    WonkaRefField NewImportField = new WonkaRefField();

                    NewImportField.FieldId     = TempAttr.FieldId;
                    NewImportField.FieldName   = TempAttr.AttrName;
                    NewImportField.Description = TempAttr.Description;
                    NewImportField.GroupId     = CONST_DEFAULT_GROUP_ID;
                    NewImportField.DisplayName = TempAttr.AttrName;
                    NewImportField.AttrIds.Add(TempAttr.AttrId);
                    NewImportSource.AddField(NewImportField);

                    WonkaRefSourceField NewImportSrcFld = new WonkaRefSourceField();

                    NewImportSrcFld.SourceFieldId = 10000 + NewImportField.FieldId;
                    NewImportSrcFld.SourceId      = 1;
                    NewImportSrcFld.FieldId       = NewImportField.FieldId;
                    NewImportSrcFld.SecurityLevel = CONST_SEC_LEVEL_READ;
                    NewImportSource.AddSourceField(NewImportSrcFld);
                }
            }
            else
            {
                throw new WonkaBreException(0, 0, "ERROR!  Could not import the schema for the database table.");
            }

            PopulateDefaults();

            return(NewImportSource);
        }