Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
        }