예제 #1
0
        /// <summary>
        /// Check for valid low or high value
        /// </summary>
        /// <param name="val"></param>
        /// <param name="colType"></param>
        /// <param name="r"></param>
        /// <param name="c"></param>
        /// <returns></returns>

        private bool IsValidValue(
            string val,
            MetaColumnType colType,
            int r,
            int c)
        {
            double d1;

            if (MetaColumn.IsNumericMetaColumnType(colType))
            {
                if (!double.TryParse(val, out d1))
                {
                    XtraMessageBox.Show("Invalid numeric value", UmlautMobius.String);
                    //RulesGrid.EditCell(r, c);
                    return(false);
                }
            }

            else if (colType == MetaColumnType.Date)
            {
                if (DateTimeMx.Normalize(val) == null)
                {
                    XtraMessageBox.Show("Invalid date", UmlautMobius.String);
                    //RulesGrid.EditCell(r, c);
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Convert a metacolumn type to the object type used to store it
        /// </summary>
        /// <param name="mc"></param>
        /// <returns></returns>

        public static Type MetaColumnTypeToClassType(
            MetaColumnType mcType)
        {
            if (mcType == MetaColumnType.Integer)
            {
                return(typeof(Int32));
            }
            else if (mcType == MetaColumnType.Number)
            {
                return(typeof(double));
            }
            else if (mcType == MetaColumnType.QualifiedNo)
            {
                return(typeof(QualifiedNumber));
            }
            else if (mcType == MetaColumnType.CompoundId)
            {
                return(typeof(CompoundId));
            }
            else if (mcType == MetaColumnType.String)
            {
                return(typeof(string));
            }
            else if (mcType == MetaColumnType.Date)
            {
                return(typeof(DateTime));
            }
            else if (mcType == MetaColumnType.Structure)
            {
                return(typeof(MoleculeMx));
            }
            return(typeof(string));            // map other types to string for now
        }
예제 #3
0
/// <summary>
/// Get a pair of MobiusDataType objects of the specified type that can be used
/// for comparison to the specified text value. This is useful for comparing
/// decimal numbers for equality.
/// </summary>
/// <param name="type"></param>
/// <param name="textValue"></param>
/// <param name="mdtLow"></param>
/// <param name="mdtHigh"></param>

        public static void GetFuzzyEqualityComparators(
            MetaColumnType type,
            string textValue,
            out MobiusDataType mdtLow,
            out MobiusDataType mdtHigh)
        {
            try
            {
                mdtLow  = MobiusDataType.New(type, textValue);
                mdtHigh = MobiusDataType.New(type, textValue);

                if (MetaColumn.IsDecimalMetaColumnType(type))
                {
                    double e = GetEpsilon(textValue);
                    mdtLow.NumericValue  -= e;
                    mdtHigh.NumericValue += e;
                }
            }
            catch (Exception ex)
            {
                mdtLow  = MobiusDataType.New(type);
                mdtHigh = MobiusDataType.New(type);
            }

            return;
        }
예제 #4
0
 /// <summary>Create instance of MetaTable column class</summary>
 /// <param name="tableType">Owner table type</param>
 /// <param name="columnType">Column type</param>
 /// <param name="columnName">Column name</param>
 /// <param name="columnIndex">Column index in table</param>
 public MetaColumn(Cor.MetaTableType tableType, MetaColumnType columnType, String columnName, UInt16 columnIndex)
 {
     this._tableType   = tableType;
     this._columnType  = columnType;
     this._columnName  = columnName;
     this._columnIndex = columnIndex;
 }
예제 #5
0
        /// <summary>
        /// Initialize internal match values for a list of rules single rule
        /// </summary>
        /// <param name="columnType"></param>

        public void InitializeInternalMatchValues(MetaColumnType columnType)
        {
            foreach (CondFormatRule rule in this)
            {
                rule.InitializeInternalMatchValues(columnType);
            }
            return;
        }
예제 #6
0
        /// <summary>
        /// Set derived values for a single calc function field
        /// </summary>
        /// <param name="sourceColumnType"></param>
        /// <param name="cfc"></param>
        void SetDerivedColumnValues(
            MetaColumnType sourceColumnType,
            CalcFieldColumn cfc)
        {
            cfc.FunctionEnum     = CalcFuncEnum.Unknown;
            cfc.ConstantDouble   = 0;
            cfc.ResultColumnType = MetaColumnType.Unknown;

            if (sourceColumnType == MetaColumnType.Unknown)
            {
                return;
            }

            if (!String.IsNullOrEmpty(cfc.Function))
            {
                cfc.FunctionEnum = ConvertCalcFuncStringToEnum(cfc.Function);
            }
            else
            {
                cfc.FunctionEnum = CalcFuncEnum.None;
            }

            double.TryParse(cfc.Constant, out cfc.ConstantDouble);

            // Get datatype after applying function

            cfc.ResultColumnType = sourceColumnType;
            if (sourceColumnType == MetaColumnType.Date)
            {
                if (cfc.FunctionEnum == CalcFuncEnum.DaysSince)
                {
                    cfc.ResultColumnType = MetaColumnType.Integer;
                }
                else if (cfc.FunctionEnum == CalcFuncEnum.None)
                {
                }
                else
                {
                    throw new Exception("Invalid function for field");
                }
            }

            else if (MetaColumn.IsNumericMetaColumnType(sourceColumnType))
            {
                if (cfc.FunctionEnum == CalcFuncEnum.DaysSince)
                {
                    throw new Exception("Invalid function for field");
                }
            }

            else
            {
                if (cfc.FunctionEnum != CalcFuncEnum.None)
                {
                    throw new Exception("Invalid function for field");
                }
            }
        }
예제 #7
0
/// <summary>
/// Set role and default grouping/summary type based on the metacolumn type
/// </summary>
/// <param name="role"></param>
/// <param name="mct"></param>

        public void SetDefaultTypeIfUndefined(
            MetaColumn mc,
            bool setIfAlreadyDefined = false)
        {
            MetaColumnType mct = mc.DataType;

            if (IsGroupingType)
            {
                if (mct == MetaColumnType.Date && GroupingType == GroupingTypeEnum.EqualValues)
                {
                    GroupingType = GroupingTypeEnum.Date;                     // fixup for date types
                }
                if (GroupingType == GroupingTypeEnum.Undefined || setIfAlreadyDefined)
                {
                    if (mct == MetaColumnType.Date)
                    {
                        GroupingType = GroupingTypeEnum.Date;
                    }

                    else
                    {
                        GroupingType = GroupingTypeEnum.EqualValues;
                    }
                }
            }

            else if (Role == AggregationRole.DataSummary)
            {
                if (SummaryType == SummaryTypeEnum.Undefined || setIfAlreadyDefined)
                {
                    if (MetaColumn.IsNumericMetaColumnType(mct))
                    {
                        if (mc.SinglePoint && mc.MultiPoint)
                        {
                            SummaryType = SummaryTypeEnum.ResultMean;
                        }

                        else if (mc.MultiPoint)
                        {
                            SummaryType = SummaryTypeEnum.GeometricMean;
                        }

                        else
                        {
                            SummaryType = SummaryTypeEnum.ArithmeticMean;
                        }
                    }

                    else
                    {
                        SummaryType = SummaryTypeEnum.Count;
                    }
                }
            }

            return;
        }
예제 #8
0
        public void Setup(ColumnInfo colInfo)
        {
            MobiusDataType mdtLow, mdtHigh;

            InSetup = true;

            ColInfo = colInfo;             // save ref to colInfo

            Stats = colInfo.Rfld.GetStats();
            ItemFilter.Properties.Minimum = 0;
            ItemFilter.Properties.Maximum = Stats.DistinctValueList.Count + 2 - 1;                // (All) on left, (Blanks) on right

            ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(ColInfo.Qc.SecondaryCriteria); // parse criteria

            ItemFilter.Value = 0;
            ValueLabel.Text  = "(All)";
            if (psc != null && psc.OpEnum == CompareOp.Eq && Stats.DistinctValueList.Count > 0)
            {
                MetaColumnType type    = ColInfo.Mc.DataType;
                MobiusDataType lowVal  = MobiusDataType.New(type, psc.Value);
                MobiusDataType highVal = MobiusDataType.New(type, psc.Value);

                if (MetaColumn.IsDecimalMetaColumnType(type))
                {                 // adjust decimal comparison values by an epsilon
                    double e = MobiusDataType.GetEpsilon(Stats.MaxValue.FormattedText);
                    lowVal.NumericValue  -= e;
                    highVal.NumericValue += e;
                }

                for (int i1 = 0; i1 < Stats.DistinctValueList.Count; i1++)
                {
                    MobiusDataType mdt  = Stats.DistinctValueList[i1];
                    string         fTxt = mdt.FormattedText;

                    if (Lex.Eq(psc.Value, fTxt) ||
                        (mdt.CompareTo(lowVal) >= 0 && mdt.CompareTo(highVal) <= 0))
                    {
                        ItemFilter.Value = i1 + 1;
                        ValueLabel.Text  = Stats.DistinctValueList[i1].FormattedText;
                        break;
                    }
                }
            }

            else if (psc != null && psc.OpEnum == CompareOp.IsNull)             // (Blanks)
            {
                ItemFilter.Value = Stats.DistinctValueList.Count + 1;
                ValueLabel.Text  = "(Blanks)";
            }

            ItemFilter.Focus();
            InSetup = false;
            return;
        }
예제 #9
0
        /// <summary>
        /// Edit conditional formatting
        /// </summary>
        /// <param name="qc"></param>
        /// <returns></returns>

        public static DialogResult Edit(
            QueryColumn qc)
        {
            MetaColumnType mcType = qc.MetaColumn.DataType;

            if (!CondFormat.CondFormattingAllowed(mcType))
            {
                ErrorMessageBox.Show(
                    "Conditional formatting isn't supported for the " + qc.ActiveLabel + " field.");
                return(DialogResult.Cancel);
            }

            CondFormat cf = qc.ActiveCondFormat;             // get current formatting

            if (cf == null)
            {
                cf = CreateAndInitializeCf(mcType);
            }
            QueryTable qt    = qc.QueryTable;
            Query      query = qt.Query;

            CondFormat cf2 = Edit(cf);

            if (cf2 == null)
            {
                return(DialogResult.Cancel);
            }

            if (cf2.Rules.Count == 0)             // all rules deleted
            {
                qc.CondFormat = null;
                return(DialogResult.OK);
            }

            qc.CondFormat = cf2;

            if (query != null && !String.IsNullOrEmpty(cf2.Name))             // update any other formatting that shares this name to use this object
            {
                foreach (QueryTable qt2 in query.Tables)
                {
                    foreach (QueryColumn qc2 in qt2.QueryColumns)
                    {
                        if (qc2.CondFormat != null && Lex.Eq(qc2.CondFormat.Name, cf2.Name))
                        {
                            qc2.CondFormat = cf2;
                        }
                    }
                }
            }

            return(DialogResult.OK);
        }
예제 #10
0
        internal static Int32 ToToken(MetaColumnType column, Int32 index)
        {
            if (index < 0)
            {
                throw new IndexOutOfRangeException(String.Format("Invalid coded token index ({0})", index));
            }
            //return -1;
            Int32 result = (Int32)column << 24 | index;

            /*MetaColumnType revColumn = (MetaColumnType)(result >> 24);
             * Int32 revIndex = result & (0xFFFFFF);*/
            return(result);
        }
예제 #11
0
		/// <summary>
		/// Fill the field grid with current mappings
		/// </summary>

		internal void UpdateFieldGridDataTable()
		{
			DataRow dr;
			DataColumn dc;
			MetaColumnType mcType = MetaColumnType.Unknown;

			bool excludeNoRoleColumns = false; // if true don't include columns that don't have a role from the initial template analysis file

			InSetup = true;

			DataTable dt = FieldDataTable;
			dt.Clear();

			if (CurrentMap != null)
				foreach (ColumnMapMsx cm in CurrentMap.ColumnMapList)
				{
					if (excludeNoRoleColumns && Lex.IsUndefined(cm.Role)) continue;

					dr = dt.NewRow();

					QueryColumn qc = cm.QueryColumn;

					if (qc != null) // column is mapped
					{
						dr["MobiusTableNameField"] = qc.QueryTable.ActiveLabel;
						dr["MobiusColNameField"] = qc.ActiveLabel;
						mcType = qc.MetaColumn.DataType;
					}

					else // no query column assigned, get type image from spotfire if including these
					{
						mcType = DataTableMapMsx.GetMatchingMobiusDataTypeFromSpotfireColumn(cm.SpotfireColumn);
					}

					int imgIdx = (int)MetaColumn.GetMetaColumnDataTypeImageIndex(mcType);
					if (mcType == MetaColumnType.CompoundId) imgIdx = (int)Bitmaps16x16Enum.Key;
					dr["DataTypeImageField"] = Bitmaps.Bitmaps16x16.Images[imgIdx];

					dr["SpotfireColNameField"] = cm.SpotfireColumnName;
					dr["OriginalSpotfireColNameField"] = cm.Role;

					dr["SelectedField"] = cm.Selected;

					dr["ColumnMapMsxRefField"] = cm; // store Field ref
					dt.Rows.Add(dr);
				}

			Changed = false;
			InSetup = false;
			return;
		}
예제 #12
0
        /// <summary>
        /// Set the column type for the source data
        /// </summary>

        public void SetupFormForColumnType(
            MetaColumnType mcType)
        {
            if (MetaColumn.AreCompatibleMetaColumnTypes(mcType, SourceColumnType))
            {
                return;
            }

            SourceColumnType = mcType;

            string[] funcs = null;
            string[] ops   = null;

            if (MetaColumn.IsNumericMetaColumnType(mcType))
            {
                funcs = CalcField.NumericFuncs;
                ops   = CalcField.NumericOps;
            }

            else if (mcType == MetaColumnType.Date)
            {
                funcs = CalcField.DateFuncs;
                ops   = CalcField.DateOps;
            }

            else if (mcType == MetaColumnType.Image)             // allow overlay of NGR CRC curves
            {
                funcs = CalcField.CrcOverlayFuncs;
                ops   = CalcField.CrcOverlayOps;
            }

            else
            {
                funcs = CalcField.NoFuncs;
                ops   = CalcField.NoOps;
            }

            foreach (CalcFieldColumnControl cfcc in CfColCtls)
            {
                cfcc.Function.Properties.Items.Clear();
                cfcc.Function.Properties.Items.AddRange(funcs);
                cfcc.Function.SelectedIndex = 0;
            }

            Operation.Properties.Items.Clear();
            Operation.Properties.Items.AddRange(ops);
            Operation.SelectedIndex = 0;

            return;
        }
예제 #13
0
        /// <summary>
        /// Return true if conditional formatting is allowed on the specified column
        /// </summary>
        /// <param name="qc"></param>
        /// <returns></returns>

        public static bool CondFormattingAllowed(
            MetaColumnType mcType)
        {
            if (mcType == MetaColumnType.Image ||
                mcType == MetaColumnType.Unknown)
            {
                return(false);
            }

            else
            {
                return(true);
            }
        }
예제 #14
0
/// <summary>
/// Check to see that columns are sortable
/// </summary>
/// <param name="sortColumns"></param>

        public void ValidateSortColumns(
            List <SortColumn> sortColumns)
        {
            for (int sci = 0; sci < sortColumns.Count; sci++)
            {             // be sure all columns are sortable
                QueryColumn    qc = sortColumns[sci].QueryColumn;
                MetaColumnType t  = qc.MetaColumn.DataType;
                if (t == MetaColumnType.Image || t == MetaColumnType.Structure)
                {
                    throw new Exception("Can't sort on column " + Lex.Dq(qc.MetaColumn.Label) +
                                        " because it is of type " + t.ToString());
                }
            }
            return;
        }
예제 #15
0
/// <summary>
/// Try to convert object to a MobiusDataType
/// </summary>
/// <param name="type"></param>
/// <param name="o"></param>
/// <param name="mdt"></param>
/// <returns></returns>

        public static bool TryConvertTo(
            MetaColumnType type,
            object o,
            out MobiusDataType mdt)
        {
            mdt = null;

            try
            {
                mdt = ConvertToMobiusDataType(type, o);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #16
0
        internal static MetaColumnType[] GetCodedTokenTypes(MetaColumnType column)
        {
            switch (column)
            {
            case MetaColumnType.TypeDefOrRef:
                return(new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.TypeRef, MetaColumnType.TypeSpec, });

            case MetaColumnType.HasConstant:
                return(new MetaColumnType[] { MetaColumnType.Field, MetaColumnType.Param, MetaColumnType.Property, });

            case MetaColumnType.HasCustomAttribute:
                return(new MetaColumnType[] { MetaColumnType.MethodDef, MetaColumnType.Field, MetaColumnType.TypeRef, MetaColumnType.TypeDef, MetaColumnType.Param, MetaColumnType.InterfaceImpl, MetaColumnType.MemberRef, MetaColumnType.Module, MetaColumnType.DeclSecurity, MetaColumnType.Property, MetaColumnType.Event, MetaColumnType.StandAloneSig, MetaColumnType.ModuleRef, MetaColumnType.TypeSpec, MetaColumnType.Assembly, MetaColumnType.AssemblyRef, MetaColumnType.File, MetaColumnType.ExportedType, MetaColumnType.ManifestResource, /*MetaColumnType.GenericParam, MetaColumnType.GenericParamConstraint, MetaColumnType.MethodSpec,*/ });

            case MetaColumnType.HasFieldMarshal:
                return(new MetaColumnType[] { MetaColumnType.Field, MetaColumnType.Param, });

            case MetaColumnType.HasDeclSecurity:
                return(new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.MethodDef, MetaColumnType.Assembly, });

            case MetaColumnType.MemberRefParent:
                return(new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.TypeRef, MetaColumnType.ModuleRef, MetaColumnType.MethodDef, MetaColumnType.TypeSpec, });

            case MetaColumnType.HasSemantic:
                return(new MetaColumnType[] { MetaColumnType.Event, MetaColumnType.Property, });

            case MetaColumnType.MethodDefOrRef:
                return(new MetaColumnType[] { MetaColumnType.MethodDef, MetaColumnType.MemberRef, });

            case MetaColumnType.MemberForwarded:
                return(new MetaColumnType[] { MetaColumnType.Field, MetaColumnType.MethodDef, });

            case MetaColumnType.Implementation:
                return(new MetaColumnType[] { MetaColumnType.File, MetaColumnType.AssemblyRef, MetaColumnType.ExportedType, });

            case MetaColumnType.CustomAttributeType:
                return(new MetaColumnType[] { MetaColumnType.TypeRef, MetaColumnType.TypeDef, MetaColumnType.MethodDef, MetaColumnType.MemberRef, MetaColumnType.UserString, });

            case MetaColumnType.ResolutionScope:
                return(new MetaColumnType[] { MetaColumnType.Module, MetaColumnType.ModuleRef, MetaColumnType.AssemblyRef, MetaColumnType.TypeRef, });

            case MetaColumnType.TypeOrMethodDef:
                return(new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.MethodDef, });

            default: throw new NotSupportedException();
            }
        }
예제 #17
0
        /// <summary>
        /// Copy CondFormat object onto the form
        /// </summary>
        /// <param name="cf"></param>

        public void CondFormatToForm(
            CondFormat cf)
        {
            ColumnType = cf.ColumnType;
            //ShowInHeaders = cf.ShowInHeaders;

            if (ColumnType == MetaColumnType.Structure)
            {
                Option1.Text    = "Highlight matching substructure";
                Option1.Visible = true;

                Option2.Text    = "Align to matching substructure query";
                Option2.Visible = true;

                Rules.Height = Option1.Top - Rules.Top - 8;
            }

            else
            {
                Option1.Visible = false;
                Option2.Visible = false;
                Rules.Height    = CfName.Top - Rules.Top - 8;
            }

            Option1.Checked = cf.Option1;
            Option2.Checked = cf.Option2;

            CfName.Text         = cf.Name;
            ColumnDataType.Text = cf.ColumnType.ToString();

            bool showFormatName = (!EditForUserObjectStorage);             // show either the Cf name or the Cf data type (for saved Cfs)

            CfNameLabel.Visible = CfName.Visible = CfNameLabel2.Visible = showFormatName;

            if (ColumnTypeLabel.Top != CfName.Top)
            {
                int dy = CfName.Top - ColumnTypeLabel.Top;
                ColumnDataType.Top  += dy;
                ColumnTypeLabel.Top += dy;
            }
            ColumnTypeLabel.Visible = ColumnDataType.Visible = !showFormatName;

            Rules.SetupControl(cf.ColumnType, cf.Rules);

            return;
        }
예제 #18
0
/// <summary>
/// Reset form for change in source column type if needed
/// </summary>
/// <param name="sourceColumnType"></param>

        public void SetSourceColumnType(
            int sourceColumnTypeInt)
        {
            MetaColumnType sourceColumnType = (MetaColumnType)sourceColumnTypeInt;

            SetupFormForColumnType(sourceColumnType);             // setup form
            CalcField.SourceColumnType = sourceColumnType;
            CalcField.SetDerivedValues();

            CondFormatRules rules = new CondFormatRules();

            CondFormatRulesCtl.SetupControl(CalcField.PreclassificationlResultType, rules.ColoringStyle);

            rules.Add(new CondFormatRule());             // include initial rule
            CondFormatRulesCtl.SetupControl(CalcField.PreclassificationlResultType, rules);
            return;
        }
예제 #19
0
        /// <summary>Получить размер колонки в таблице</summary>
        /// <param name="type">Тип колонки</param>
        /// <returns>Размер колонки</returns>
        internal UInt32 SizeOfColumn(MetaColumnType type)
        {
            switch (type)
            {
            case MetaColumnType.UInt16:
                return(2);

            case MetaColumnType.UInt32:
                return(4);

            case MetaColumnType.String:
                return(this.Root.StreamTableHeader.StringIndexSize);

            case MetaColumnType.Blob:
                return(this.Root.StreamTableHeader.BlobIndexSize);

            case MetaColumnType.Guid:
                return(this.Root.StreamTableHeader.GuidIndexSize);

            default:
                if (MetaColumn.IsColumnCellPointer(type))                       //Указатель на другую таблицу
                {
                    return((UInt32)(this.Root.GetRowsCount((Cor.MetaTableType)type) < 65536 ? 2 : 4));
                }

                //CodedToken
                MetaColumnType[] referredTypes = MetaTable.GetCodedTokenTypes(type);
                UInt32           maxRows       = 0;
                foreach (MetaColumnType referredType in referredTypes)
                {
                    if (referredType != MetaColumnType.UserString)                           //but what if there is a large user string table?
                    {
                        UInt32 rows = (UInt32)this.Root.GetRowsCount((Cor.MetaTableType)referredType);
                        if (maxRows < rows)
                        {
                            maxRows = rows;
                        }
                    }
                }
                maxRows = maxRows << MetaCellCodedToken.CodedTokenBits[referredTypes.Length];
                return((UInt32)(maxRows < 65536 ? 2 : 4));
            }
        }
예제 #20
0
        /// <summary>
        /// Initialize internal match values for a single rule
        /// </summary>
        /// <param name="columnType"></param>

        public void InitializeInternalMatchValues(MetaColumnType columnType)
        {
            OpCode = ConvertOpNameToCode(Op);

            bool calculateEpsilonFromCfValue = false;             // if true use cf value (note: may not be same number of decimals as output format)

            Epsilon = 0;

            if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value))
            {
                double.TryParse(Value, out ValueNumber);

                if (calculateEpsilonFromCfValue)
                {
                    Epsilon = MobiusDataType.GetEpsilon(Value);
                }

                else
                {
                    int decimals = 10;                     // use default epsilon value
                    Epsilon = MobiusDataType.GetEpsilon(decimals);
                }
            }

            else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value))
            {
                ValueNormalized = DateTimeMx.Normalize(Value);
            }

            if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value2))
            {
                double.TryParse(Value2, out Value2Number);
                double e2 = MobiusDataType.GetEpsilon(Value2);
                if (e2 < Epsilon)
                {
                    Epsilon = e2;
                }
            }
            else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value2))
            {
                Value2Normalized = DateTimeMx.Normalize(Value2);
            }
        }
예제 #21
0
        public static CondFormat CreateAndInitializeCf(
            MetaColumnType mcType)
        {
            CondFormat cf = null;

            if (MetaColumn.IsNumericMetaColumnType(mcType) ||
                mcType == MetaColumnType.String ||
                mcType == MetaColumnType.Date)
            {
                cf = CondFormat.BuildDefaultConditionalFormatting();
            }

            else
            {
                cf = new CondFormat();
                cf.Rules.Add(new CondFormatRule());                 // initial rule
            }

            cf.ColumnType = mcType;             // be sure type is set
            return(cf);
        }
예제 #22
0
        /// <summary>
        /// Create a new conditional format user object
        /// </summary>
        /// <returns></returns>

        public static CondFormat CreateNewUserObject()
        {
            MetaColumnType mcType = MetaColumnType.Number;
            CondFormat     cf     = CreateAndInitializeCf(mcType);

            string     title = "New Conditional Format";
            CondFormat cf2   = Edit(cf, true, title);

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

            UserObject uo = new UserObject(UserObjectType.CondFormat);

            //  Predefined cond formats by default are owned by a single owner and stored in a single folder

            uo.Owner        = SS.I.UserName;
            uo.ParentFolder = CondFormat.PredefinedCondFormatFolderName;
            uo.AccessLevel  = UserObjectAccess.ACL;
            uo.ACL          = AccessControlList.GetAdministratorGroupRwPublicReadAcl(SS.I.UserName);

            uo = UserObjectSaveDialog.Show("Save As", uo);
            if (uo == null)
            {
                return(null);
            }

            uo.Content = cf2.Serialize();
            UserObjectDao.Write(uo, uo.Id);

            MessageBoxMx.Show("Conditional format " + uo.Name + " saved (" + uo.InternalName + ")");             // show internal name so it may be referenced in a MetaColumn definition

            if (MainMenuControl != null)
            {
                MainMenuControl.UpdateMruList(uo.InternalName);
            }

            return(cf);
        }
예제 #23
0
/// <summary>
/// Try to create the specifed MobiusDataType from a text string
/// </summary>
/// <param name="type"></param>
/// <param name="textValue"></param>
/// <param name="mdt"></param>
/// <returns></returns>

        public static bool TryParse(
            MetaColumnType type,
            string textValue,
            out MobiusDataType mdt)
        {
            try
            {
                mdt = New(type, textValue);
                if (mdt != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                mdt = null;
                return(false);
            }
        }
예제 #24
0
        /// <summary>
        /// Convert object to a MobiusDataType
        /// </summary>
        /// <param name="o"></param>
        /// <param name="type"></param>
        /// <returns></returns>

        public static MobiusDataType ConvertToMobiusDataType(
            MetaColumnType type,
            Object o)
        {
            switch (type)
            {
            case MetaColumnType.Integer:
            case MetaColumnType.Number:
            case MetaColumnType.DictionaryId:
                return(NumberMx.ConvertTo(o));

            case MetaColumnType.QualifiedNo:
                return(QualifiedNumber.ConvertTo(o));

            case MetaColumnType.String:
            case MetaColumnType.MolFormula:
            case MetaColumnType.Hyperlink:
            case MetaColumnType.Html:
            case MetaColumnType.Binary:
                return(StringMx.ConvertTo(o));

            case MetaColumnType.Date:
                return(DateTimeMx.ConvertTo(o));

            case MetaColumnType.CompoundId:
                return(CompoundId.ConvertTo(o));

            case MetaColumnType.Structure:
                return(MoleculeMx.ConvertTo(o));

            case MetaColumnType.Image:
                return(ImageMx.ConvertTo(o));                        // assume text is dblink

            default:
                throw new Exception("Unrecognized data type: " + type);
            }
        }
예제 #25
0
        /// <summary>
        /// Set values derived from primary values
        /// </summary>

        public void SetDerivedValuesWithException()
        {
            MetaColumnType firstColumnType = MetaColumnType.Unknown;
            MetaColumnType column2Type     = MetaColumnType.Unknown;

            List <MetaColumn> inputMetaColumns = GetInputMetaColumnList();

            if (SourceColumnType == MetaColumnType.Unknown)
            {
                SourceColumnType = MetaColumnType.Number;                 // default type
            }
            if (CalcType == CalcTypeEnum.Basic)
            {
                if (MetaColumn1 != null)
                {
                    SourceColumnType = MetaColumn1.DataType;
                }

                if (!String.IsNullOrEmpty(Operation))
                {
                    OpEnum = ConvertCalcOpStringToEnum(ref Operation);
                }
                else
                {
                    OpEnum = CalcOpEnum.None;
                }

                for (int ci = 0; ci < CfCols.Count; ci++)
                {
                    CalcFieldColumn cfc = CfCols[ci];
                    SetDerivedColumnValues(SourceColumnType, cfc);                     // set the result type for the col

                    if (ci == 0)
                    {
                        firstColumnType = cfc.ResultColumnType;
                    }
                    else if (ci == 1)
                    {
                        column2Type = cfc.ResultColumnType;
                    }

                    if (ci > 0 && cfc.MetaColumn != null &&
                        MetaColumn1 != null && OpEnum != CalcOpEnum.None)
                    {                     // be sure column types are compatible if binary op
                        if (!MetaColumn.AreCompatibleMetaColumnTypes(Column1.ResultColumnType, cfc.ResultColumnType))
                        {
                            throw new Exception("Incompatible column types");
                        }

                        if (MetaColumn.IsNumericMetaColumnType(MetaColumn1.DataType))
                        {
                        }                                                                                         // all operations allowed

                        else if (MetaColumn1.DataType == MetaColumnType.Date)
                        {
                            if (OpEnum != CalcOpEnum.Sub)
                            {
                                throw new Exception("Invalid date operation");
                            }
                        }

                        else if (MetaColumn1.DataType == MetaColumnType.Image)
                        {
                            if (OpEnum != CalcOpEnum.Overlay)
                            {
                                throw new Exception("Invalid Curve/Image operation");
                            }
                        }

                        else
                        {
                            throw new Exception("Invalid operation");
                        }
                    }
                }

                // Determine the result type from the source column types, functions, operations and mapping

                PreclassificationlResultType = MetaColumnType.Unknown;

                // Set result type before any classification is applied

                if (firstColumnType == MetaColumnType.Integer &&                 // see if integer type output
                    (column2Type == MetaColumnType.Integer || OpEnum == CalcOpEnum.None) &&
                    (OpEnum == CalcOpEnum.None || OpEnum == CalcOpEnum.Add || OpEnum == CalcOpEnum.Sub))
                {
                    PreclassificationlResultType = MetaColumnType.Integer;
                }

                else if (MetaColumn.IsNumericMetaColumnType(firstColumnType))
                {
                    PreclassificationlResultType = MetaColumnType.Number;
                }

                else if (firstColumnType == MetaColumnType.Date)
                {
                    if (Column1.FunctionEnum == CalcFuncEnum.None && OpEnum == CalcOpEnum.None)
                    {
                        PreclassificationlResultType = MetaColumnType.Date;
                    }
                    else
                    {
                        PreclassificationlResultType = MetaColumnType.Integer;                      // either days elapsed or difference in date
                    }
                }

                else
                {
                    PreclassificationlResultType = firstColumnType;
                }

                if (Classification != null)                 // set the type info for the classification
                {
                    Classification.ColumnType = PreclassificationlResultType;
                }
            }

            else if (CalcType == CalcTypeEnum.Advanced)             // user defines result type via input
            {
                if (PreclassificationlResultType == MetaColumnType.Unknown)
                {
                    PreclassificationlResultType = MetaColumnType.Number;                     // default to number
                }
            }

            // Set final result type

            FinalResultType = PreclassificationlResultType;             // default type without classification

            if (IsClassificationDefined)
            {                                             // if mapping to class then class names determine the type
                FinalResultType = MetaColumnType.Integer; // start assuming integer type

                foreach (CondFormatRule rule in Classification.Rules)
                {
                    if (Lex.IsInteger(rule.Name))
                    {
                        continue;
                    }

                    else if (Lex.IsDouble(rule.Name))
                    {
                        FinalResultType = MetaColumnType.Number;
                    }

                    else
                    {
                        FinalResultType = MetaColumnType.String;
                        break;
                    }
                }
            }

            return;
        }
예제 #26
0
/// <summary>
/// Format a hyperlink for a metacolumn where details are available
/// </summary>
/// <param name="qc"></param>
/// <param name="mdt"></param>
/// <returns></returns>

        public static string FormatDetailsAvailableHyperlink(
            QueryColumn qc,
            MobiusDataType mdt)
        {
            string hyperlink, uri = "";
            int    drilldownLevel = 1;

            if (qc == null || qc.MetaColumn == null || qc.MetaColumn.MetaTable == null)
            {
                return("");
            }

            MetaColumn     mc     = qc.MetaColumn;
            MetaTable      mt     = mc.MetaTable;
            MetaColumnType mcType = mc.DataType;

            MetaBrokerType mbt = qc.MetaColumn.MetaTable.MetaBrokerType;

            // Annotation table broker

            if (mbt == MetaBrokerType.Annotation)
            {
                return(mdt.Hyperlink);                // just return already formatted hyperlink value
            }

// Target-Assay broker

            else if (mbt == MetaBrokerType.TargetAssay)
            {
                if (Lex.Eq(qc.MetaColumn.Name, "assy_nm"))
                {
                    if (mdt.DbLink != "")
                    {
                        string[] sa     = mdt.DbLink.Split(',');
                        string   mtName = sa[0].Trim() + "_" + sa[1].Trim();
                        uri = "http://Mobius/command?" +
                              "ClickFunction ShowTableDescription " + mtName;
                    }
                }

                else if (qc.MetaColumn.DetailsAvailable)
                {
                    if (Lex.Eq(qc.MetaColumn.MetaTable.Name, MultiDbAssayDataNames.CombinedNonSumTableName))
                    {
                        drilldownLevel = 2;                         // level 2 goes from unsummarized unpivoted to warehouse details
                    }
                    else
                    {
                        drilldownLevel = 1;                      // level 1 goes from summarized to unsummarized (UNPIVOTED_ASSAY_RESULTS)
                    }
                    uri = "http://Mobius/command?" +
                          "ClickFunction DisplayDrilldownDetail " +
                          qc.MetaColumn.MetaTable.Name + " " + qc.MetaColumn.Name +
                          " " + drilldownLevel + " " + Lex.AddSingleQuotes(mdt.DbLink);
                }
            }

// Pivot broker

            else if (mbt == MetaBrokerType.Pivot)
            {
                string[] sa = mdt.DbLink.Split(',');
                if (sa.Length < 2 || sa[1] == "")
                {
                    return("");
                }
                uri = sa[1];
                if (uri.ToLower().StartsWith("www."))
                {
                    uri = "http://" + uri;                                                   // fix shortcut for proper linking
                }
            }

// All other broker types

            else
            {
                int nValue = -1;
                if (mdt is QualifiedNumber)
                {
                    nValue = ((QualifiedNumber)mdt).NValue;
                }
                if ((qc.QueryTable.MetaTable.UseSummarizedData && nValue >= 0) || // link if there is a non-null n-value associated with number
                    qc.MetaColumn.DetailsAvailable)                               // or we explicitly know that details are available
                {
                    uri = "http://Mobius/command?" +
                          "ClickFunction DisplayDrilldownDetail " +
                          qc.QueryTable.MetaTable.Name + " " + qc.MetaColumn.Name +
                          (qc.QueryTable.MetaTable.UseSummarizedData ? " 1 " : " 2 ") + Lex.AddSingleQuotes(mdt.DbLink);
                }
            }

            return(uri);
        }
예제 #27
0
        /// <summary>Получить описатель таблицы</summary>
        /// <param name="table">Таблица для получения колонок</param>
        /// <exception cref="T:NotSupportedException">Unknown table</exception>
        /// <exception cref="T:InvalidOperationException">Column names not equal column types</exception>
        /// <returns>Массив колонок в таблице</returns>
        private static MetaColumn[] GetTableDescription(Cor.MetaTableType table)
        {
            MetaColumnType[] columnType;
            String[]         columnName;
            switch (table)
            {
            case Cor.MetaTableType.Module:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Guid, MetaColumnType.Guid, MetaColumnType.Guid, };
                columnName = new String[] { "Generation", "Name", "Mvid", "EncId", "EncBaseId", };
                break;

            case Cor.MetaTableType.TypeRef:
                columnType = new MetaColumnType[] { MetaColumnType.ResolutionScope, MetaColumnType.String, MetaColumnType.String, };
                columnName = new String[] { "ResolutionScope", "TypeName", "TypeNamespace" };
                break;

            case Cor.MetaTableType.TypeDef:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.String, MetaColumnType.TypeDefOrRef, MetaColumnType.Field, MetaColumnType.MethodDef, };
                columnName = new String[] { "Flags", "TypeName", "TypeNamespace", "Extends", "FieldList", "MethodList", };
                break;

            case Cor.MetaTableType.FieldPtr:
                columnType = new MetaColumnType[] { MetaColumnType.Field, };
                columnName = new String[] { "Field" };
                break;

            case Cor.MetaTableType.Field:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Blob, };
                columnName = new String[] { "Flags", "Name", "Signature", };
                break;

            case Cor.MetaTableType.MethodPtr:
                columnType = new MetaColumnType[] { MetaColumnType.MethodDef, };
                columnName = new String[] { "Method", };
                break;

            case Cor.MetaTableType.MethodDef:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Blob, MetaColumnType.Param, };
                columnName = new String[] { "RVA", "ImplFlags", "Flags", "Name", "Signature", "ParamList", };
                break;

            case Cor.MetaTableType.ParamPtr:
                columnType = new MetaColumnType[] { MetaColumnType.Param, };
                columnName = new String[] { "Param", };
                break;

            case Cor.MetaTableType.Param:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.String, };
                columnName = new String[] { "Flags", "Sequence", "Name", };
                break;

            case Cor.MetaTableType.InterfaceImpl:
                columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.TypeDefOrRef, };
                columnName = new String[] { "Class", "Interface", };
                break;

            case Cor.MetaTableType.MemberRef:
                columnType = new MetaColumnType[] { MetaColumnType.MemberRefParent, MetaColumnType.String, MetaColumnType.Blob, };
                columnName = new String[] { "Class", "Name", "Signature", };
                break;

            case Cor.MetaTableType.Constant:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.HasConstant, MetaColumnType.Blob, };
                columnName = new String[] { "Type", "Parent", "Value", };
                break;

            case Cor.MetaTableType.CustomAttribute:
                columnType = new MetaColumnType[] { MetaColumnType.HasCustomAttribute, MetaColumnType.CustomAttributeType, MetaColumnType.Blob, };
                columnName = new String[] { "Parent", "Type", "Value", };
                break;

            case Cor.MetaTableType.FieldMarshal:
                columnType = new MetaColumnType[] { MetaColumnType.HasFieldMarshal, MetaColumnType.Blob, };
                columnName = new String[] { "Parent", "Native", };
                break;

            case Cor.MetaTableType.DeclSecurity:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.HasDeclSecurity, MetaColumnType.Blob, };
                columnName = new String[] { "Action", "Parent", "PermissionSet", };
                break;

            case Cor.MetaTableType.ClassLayout:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt32, MetaColumnType.TypeDef, };
                columnName = new String[] { "PackingSize", "ClassSize", "Parent", };
                break;

            case Cor.MetaTableType.FieldLayout:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.Field, };
                columnName = new String[] { "Offset", "Field", };
                break;

            case Cor.MetaTableType.StandAloneSig:
                columnType = new MetaColumnType[] { MetaColumnType.Blob, };
                columnName = new String[] { "Signature", };
                break;

            case Cor.MetaTableType.EventMap:
                columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.Event, };
                columnName = new String[] { "Parent", "EventList", };
                break;

            case Cor.MetaTableType.EventPtr:
                columnType = new MetaColumnType[] { MetaColumnType.Event, };
                columnName = new String[] { "Event", };
                break;

            case Cor.MetaTableType.Event:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.TypeDefOrRef, };
                columnName = new String[] { "EventFlags", "Name", "EventType", };
                break;

            case Cor.MetaTableType.PropertyMap:
                columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.Property, };
                columnName = new String[] { "Parent", "PropertyList", };
                break;

            case Cor.MetaTableType.PropertyPtr:
                columnType = new MetaColumnType[] { MetaColumnType.Property, };
                columnName = new String[] { "Property", };
                break;

            case Cor.MetaTableType.Property:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Blob, };
                columnName = new String[] { "Flags", "Name", "Type", };
                break;

            case Cor.MetaTableType.MethodSemantics:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.MethodDef, MetaColumnType.HasSemantic, };
                columnName = new String[] { "Semantic", "Method", "Association", };
                break;

            case Cor.MetaTableType.MethodImpl:
                columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.MethodDefOrRef, MetaColumnType.MethodDefOrRef, };
                columnName = new String[] { "Class", "MethodBody", "MethodDeclaration", };
                break;

            case Cor.MetaTableType.ModuleRef:
                columnType = new MetaColumnType[] { MetaColumnType.String, };
                columnName = new String[] { "Name", };
                break;

            case Cor.MetaTableType.TypeSpec:
                columnType = new MetaColumnType[] { MetaColumnType.Blob, };
                columnName = new String[] { "Signature", };
                break;

            case Cor.MetaTableType.ImplMap:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.MemberForwarded, MetaColumnType.String, MetaColumnType.ModuleRef, };
                columnName = new String[] { "MappingFlags", "MemberForwarded", "ImportName", "ImportScope", };
                break;

            case Cor.MetaTableType.FieldRVA:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.Field, };
                columnName = new String[] { "RVA", "Field", };
                break;

            case Cor.MetaTableType.ENCLog:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, };
                columnName = new String[] { "Token", "FuncCode", };
                break;

            case Cor.MetaTableType.ENCMap:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, };
                columnName = new String[] { "Token", };
                break;

            case Cor.MetaTableType.Assembly:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt32, MetaColumnType.Blob, MetaColumnType.String, MetaColumnType.String, };
                columnName = new String[] { "HashAlgId", "MajorVersion", "MinorVersion", "BuildNumber", "RevisionNumber", "Flags", "PublicKey", "Name", "Locale", };
                break;

            case Cor.MetaTableType.AssemblyProcessor:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, };
                columnName = new String[] { "Processor", };
                break;

            case Cor.MetaTableType.AssemblyOS:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.UInt32, };
                columnName = new String[] { "OSPlatformId", "OSMajorVersion", "OSMinorVersion", };
                break;

            case Cor.MetaTableType.AssemblyRef:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt32, MetaColumnType.Blob, MetaColumnType.String, MetaColumnType.String, MetaColumnType.Blob, };
                columnName = new String[] { "MajorVersion", "MinorVersion", "BuildNumber", "RevisionNumber", "Flags", "PublicKeyOrToken", "Name", "Locale", "HashValue", };
                break;

            case Cor.MetaTableType.AssemblyRefProcessor:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.AssemblyRef, };
                columnName = new String[] { "Processor", "AssemblyRef", };
                break;

            case Cor.MetaTableType.AssemblyRefOS:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.AssemblyRef, };
                columnName = new String[] { "OSPlatformId", "OSMajorVersion", "OSMinorVersion", "AssemblyRef", };
                break;

            case Cor.MetaTableType.File:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.Blob, };
                columnName = new String[] { "Flags", "Name", "HashValue", };
                break;

            case Cor.MetaTableType.ExportedType:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.String, MetaColumnType.Implementation, };
                columnName = new String[] { "Flags", "TypeDefId", "TypeName", "TypeNamespace", "Implementation", };
                break;

            case Cor.MetaTableType.ManifestResource:
                columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.Implementation, };
                columnName = new String[] { "Offset", "Flags", "Name", "Implementation", };
                break;

            case Cor.MetaTableType.NestedClass:
                columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.TypeDef, };
                columnName = new String[] { "NestedClass", "EnclosingClass", };
                break;

            case Cor.MetaTableType.GenericParam:
                columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.TypeOrMethodDef, MetaColumnType.String, };
                columnName = new String[] { "Number", "Flags", "Owner", "Name", };
                break;

            case Cor.MetaTableType.MethodSpec:
                columnType = new MetaColumnType[] { MetaColumnType.MethodDefOrRef, MetaColumnType.Blob, };
                columnName = new String[] { "Method", "Instantiation", };
                break;

            case Cor.MetaTableType.GenericParamConstraint:
                columnType = new MetaColumnType[] { MetaColumnType.GenericParam, MetaColumnType.TypeDefOrRef, };
                columnName = new String[] { "Owner", "Constraint", };
                break;

            default: throw new NotSupportedException();
            }

            if (columnType.Length != columnName.Length)
            {
                throw new InvalidOperationException("Length of column type and names must be equal");
            }

            MetaColumn[] result = new MetaColumn[columnType.Length];
            for (UInt16 loop = 0; loop < result.Length; loop++)
            {
                result[loop] = new MetaColumn(table, columnType[loop], columnName[loop], loop);
            }

            return(result);
        }
예제 #28
0
        /// <summary>
        /// Create a Mobius data type based on the supplied MetaColumn type and an initial value
        /// </summary>
        /// <param name="type">MobiusDataType</param>
        /// <param name="o">Object to convert to type</param>
        /// <returns>MobiusDataType object</returns>

        //MobiusDataType lowVal = MobiusDataType.New(qc.MetaColumn.DataType, psc.Value);
        //MobiusDataType highVal = MobiusDataType.New(qc.MetaColumn.DataType, psc.Value2);

        public static MobiusDataType New(
            MetaColumnType type,
            object o)
        {
            if (o == null || o is DBNull)
            {
                return(null);
            }

            else if (o is MobiusDataType)
            {
                return((MobiusDataType)o);                                      // if already a MobiusDataType just return existing object
            }
// Create based on string object

            else if (o is string)
            {
                string textValue = o as string;
                switch (type)
                {
                case MetaColumnType.Integer:
                case MetaColumnType.Number:
                    return(new NumberMx(textValue));

                case MetaColumnType.QualifiedNo:
                    return(new QualifiedNumber(textValue));

                case MetaColumnType.String:
                    return(new StringMx(textValue));

                case MetaColumnType.Date:
                    return(new DateTimeMx(textValue));

                case MetaColumnType.Binary:
                    return(new StringMx(textValue));

                case MetaColumnType.CompoundId:
                    return(new CompoundId(textValue));

                case MetaColumnType.Structure:
                    return(new MoleculeMx(textValue));

                case MetaColumnType.Image:
                    return(new ImageMx(textValue));                            // assume text is dblink

                case MetaColumnType.MolFormula:
                    return(new StringMx(textValue));

                case MetaColumnType.DictionaryId:
                    return(new NumberMx(textValue));

                case MetaColumnType.Hyperlink:
                    return(new StringMx(textValue));

                case MetaColumnType.Html:
                    return(new StringMx(textValue));

                default:
                    break;
                }
            }

// Numeric input object

            else if (o is byte || o is sbyte ||
                     o is Int16 || o is Int32 || o is Int64 ||
                     o is float || o is double || o is decimal)
            {
                double d = Convert.ToDouble(o);                 // convert to double first

                if (type == MetaColumnType.Integer)
                {
                    return(new NumberMx(d));
                }

                else if (type == MetaColumnType.Number)
                {
                    return(new NumberMx(d));
                }

                else if (type == MetaColumnType.QualifiedNo)
                {
                    return(new QualifiedNumber(d));
                }

                else if (type == MetaColumnType.String)
                {
                    return(new StringMx(o.ToString()));
                }

                else if (type == MetaColumnType.Image)
                {
                    return(new ImageMx(o.ToString()));                    // assume number is dblink
                }
            }

// Date object

            else if (type == MetaColumnType.Date && o is DateTime)
            {
                return(new DateTimeMx((DateTime)o));
            }

// Image object

            else if (type == MetaColumnType.Image && o is Bitmap)
            {
                return(new ImageMx((Bitmap)o));
            }

// Can't handle

            throw new Exception("Unrecognized data type: " + o.GetType());
        }
예제 #29
0
        /////////////////////////////////////////////////////////////////
        //////////////////////////// Methods ////////////////////////////
        /////////////////////////////////////////////////////////////////

/// <summary>
/// Create a Mobius data type based on the supplied MetaColumn type
/// </summary>
/// <param name="type"></param>
/// <returns></returns>

        public static MobiusDataType New(
            MetaColumnType type)
        {
            MobiusDataType o;

            if (type == MetaColumnType.Integer)
            {
                o = new NumberMx();
            }
            else if (type == MetaColumnType.Number)
            {
                o = new NumberMx();
            }
            else if (type == MetaColumnType.QualifiedNo)
            {
                o = new QualifiedNumber();
            }
            else if (type == MetaColumnType.String)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.Date)
            {
                o = new DateTimeMx();
            }
            else if (type == MetaColumnType.Binary)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.CompoundId)
            {
                o = new CompoundId();
            }
            else if (type == MetaColumnType.Structure)
            {
                o = new MoleculeMx();
            }
            else if (type == MetaColumnType.MolFormula)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.Image)
            {
                o = new ImageMx();
            }
            else if (type == MetaColumnType.DictionaryId)
            {
                o = new NumberMx();
            }
            else if (type == MetaColumnType.Hyperlink)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.Html)
            {
                o = new StringMx();
            }
            else
            {
                throw new Exception("Unrecognized data type: " + type);
            }

            return(o);
        }
예제 #30
0
 /// <summary>Coded token column</summary>
 /// <param name="type">MetaData column type</param>
 /// <returns>This column contains coded token</returns>
 public static Boolean IsColumnCodedToken(MetaColumnType type)
 {
     return((Int32)type >= (Int32)MetaColumnType.TypeDefOrRef && (Int32)type < (Int32)MetaColumnType.UInt16);
 }