/// <summary> /// Retrieves a set of FieldData rows in the Fields data table in the Header Data Set object linked to the DataAccess class that are contained /// in the structure/union specified in the function's StructName parameter. Each field in a structure/union will be keyed by the name of the /// structure/union concatenated with the index of the field. /// </summary> /// <param name="strStructName"></param> /// <returns></returns> public CHeaderDataSet.tblFieldsRow[] GetStructFields(string strStructName) { try { CHeaderDataSet.tblStructuresRow rowStruct = GetStruct(strStructName); if (rowStruct == null) { return(null); } CHeaderDataSet.tblFieldsRow[] rowFields = new CHeaderDataSet.tblFieldsRow[rowStruct.FieldCount]; for (int iFieldIndex = 0; iFieldIndex < rowFields.Length; iFieldIndex++) { rowFields[iFieldIndex] = FieldsTable.FindByFieldKey(rowStruct.StructName + "_" + iFieldIndex.ToString()); }//next iFieldIndex return(rowFields); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in GetStructFields function of DataAccess class."); return(null); } }
/// <summary> /// Queries the data type associated with the field with the specified field name passed to the function. The linked data type record will be returned /// by the function. Depending on what type of data type is associated with the field, will determine whether a structure data row, typedef data row /// or primitive data object is returned by the function. Primtive data types will not be stored in the Header Data Set and will have its data returned /// from the Global Primitive data object. /// </summary> /// <param name="strFieldKey"></param> /// <returns></returns> public object QueryFieldTypeDataByName(string strFieldName) { try { CHeaderDataSet.tblFieldsRow rowField = FieldsTable.Where(f => f.FieldName == strFieldName).FirstOrDefault(); if (rowField == null) { return(null); } return(QueryFieldTypeDataByKey(rowField.FieldKey)); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryFieldTypeDataByName function of DataAccess class."); return(null); } }
/// <summary> /// Queries the data type associated with the field with the specified key passed to the function. The linked data type record will be returned /// by the function. Depending on what type of data type is associated with the field, will determine whether a structure data row, typedef data row /// or primitive data object is returned by the function. Primtive data types will not be stored in the Header Data Set and will have its data returned /// from the Global Primitive data object. /// </summary> /// <param name="strFieldKey"></param> /// <returns></returns> public object QueryFieldTypeDataByKey(string strFieldKey) { try { CHeaderDataSet.tblFieldsRow rowField = FieldsTable.FindByFieldKey(strFieldKey); if (rowField == null) { return(null); } switch ((FieldTypeEnum)rowField.FieldType) { case FieldTypeEnum.Primitive: case FieldTypeEnum.Enum: case FieldTypeEnum.Pointer: object[] aryPrimTypeData = new object[] { rowField.FieldTypeName, DataAccess.PrimDataTypes[rowField.FieldTypeName] }; return(aryPrimTypeData); case FieldTypeEnum.TypeDef: CHeaderDataSet.tblTypeDefsRow rowTypeDef = TypeDefsTable.FindByTypeDefName(rowField.FieldTypeName); return(rowTypeDef); case FieldTypeEnum.Structure: CHeaderDataSet.tblStructuresRow rowStruct = StructuresTable.FindByStructName(rowField.FieldTypeName); return(rowStruct); } ; return(null); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in QueryFieldTypeDataByKey function of DataAccess class."); return(null); } }
/// <summary> /// Adds a set of rows to the Fields data table in the Header Data Set object linked to the DataAccess class using the data contained in the /// list of FieldData objects passed to the function. The FieldData object will contain all the required information needed to create a field record /// in the Fields table. /// </summary> /// <param name="lstFields"></param> /// <returns></returns> public bool AddFieldRows(List <FieldData> lstFields) { try { CHeaderDataSet.tblFieldsRow rowField = null; foreach (FieldData fdField in lstFields) { rowField = FieldsTable.NewtblFieldsRow(); rowField.FieldKey = fdField.FieldKey; rowField.FieldName = fdField.FieldName; rowField.ParentName = fdField.ParentName; rowField.FieldIndex = fdField.FieldIndex; rowField.FieldType = (int)fdField.FieldType; rowField.FieldTypeName = fdField.FieldTypeName; rowField.Elements = fdField.Elements; rowField.DataSize = fdField.DataSize; if (fdField.Bits > 0) { rowField.FieldName += "<bit: " + fdField.Bits.ToString() + ">"; } rowField.FieldByteOffset = fdField.FieldByteOffset; FieldsTable.AddtblFieldsRow(rowField); }//next fdField return(true); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in AddFieldRows function of DataAccess class."); return(false); } }