Exemple #1
0
        /// <summary>
        /// Clone cf
        /// </summary>
        /// <returns></returns>

        public CondFormat Clone()
        {
            string     serializedForm = this.Serialize();
            CondFormat clone          = CondFormat.Deserialize(serializedForm);

            return(clone);
        }
Exemple #2
0
        /// <summary>
        /// Lookup predefined conditional formatting by name
        /// </summary>
        /// <param name="cfName"></param>
        /// <returns></returns>

        public static CondFormat GetPredefined(string cfName)
        {
            CondFormat cf = null;

            cfName = cfName.ToUpper();

            if (Lex.Eq(cfName, "Activity Class Conditional Formatting") || Lex.Eq(cfName, "ActivityClassCondFormat"))             // special internal format
            {
                cf = UnpivotedAssayResult.BuildActivityClassCondFormat();
                return(cf);
            }

            else if (Lex.Eq(cfName, "Activity Bin Conditional Formatting") || Lex.Eq(cfName, "ActivityBinCondFormat"))             // special internal format
            {
                cf = UnpivotedAssayResult.BuildActivityBinCondFormat();
                return(cf);
            }

            else if (Lex.StartsWith(cfName, "CONDFORMAT_"))
            {
                if (PredefinedDict == null)                 // need to build?
                {
                    if (InterfaceRefs.IUserObjectTree == null)
                    {
                        return(null);
                    }
                    List <UserObject> uoList = InterfaceRefs.IUserObjectTree.GetUserObjectsByType(UserObjectType.CondFormat);
                    if (uoList == null)
                    {
                        return(null);
                    }

                    PredefinedDict = new Dictionary <string, string>();
                    foreach (UserObject uo0 in uoList)
                    {
                        PredefinedDict[uo0.InternalName.ToUpper()] = uo0.Content;
                    }
                }

                if (!PredefinedDict.ContainsKey(cfName))
                {
                    return(null);
                }

                cf = CondFormat.Deserialize(PredefinedDict[cfName]);
                return(cf);
            }

            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Deserialize CalcField from an XmlTextReader
        /// </summary>
        /// <param name="tr"></param>
        /// <returns></returns>

        public static CalcField Deserialize(
            XmlTextReader tr)
        {
            string     mtName, mcName, txt, errMsg = "";
            MetaTable  mt;
            MetaColumn mc;

            CalcField cf = new CalcField();

            XmlUtil.GetStringAttribute(tr, "Name", ref cf.UserObject.Name);

            txt = tr.GetAttribute("CalcType");
            EnumUtil.TryParse(txt, out cf.CalcType);
            if (cf.CalcType != CalcTypeEnum.Basic && cf.CalcType != CalcTypeEnum.Advanced)
            {
                cf.CalcType = CalcTypeEnum.Basic;                 // default to basic type
            }
            txt = tr.GetAttribute("SourceColumnType");
            if (txt != null)
            {
                cf.SourceColumnType = MetaColumn.ParseMetaColumnTypeString(txt);
            }

            txt = tr.GetAttribute("PreclassificationlResultType");
            if (txt != null)
            {
                cf.PreclassificationlResultType = MetaColumn.ParseMetaColumnTypeString(txt);
            }

            for (int ci = 1; ; ci++)             // get the set of columns
            {
                mtName = tr.GetAttribute("Table" + ci);
                if (String.IsNullOrEmpty(mtName))
                {
                    //if (ci == 1) continue; // first col may be undefined
                    //else
                    if (ci > 1)
                    {
                        break;                             // if beyond the first then col then all done
                    }
                }

                if (ci > cf.CfCols.Count)
                {
                    cf.CfCols.Add(new CalcFieldColumn());
                }
                CalcFieldColumn cfc = cf.CfCols[ci - 1];

                mt = MetaTableCollection.Get(mtName);
                if (mt != null)
                {
                    mcName = tr.GetAttribute("Column" + ci);
                    if (mcName != null)
                    {
                        cfc.MetaColumn = mt.GetMetaColumnByName(mcName);
                        if (cfc.MetaColumn == null)
                        {
                            errMsg += "Unable to find column: " + mcName + " in data table " + mt.Label + "(" + mt.Name + ")\r\n";
                        }
                    }
                }

                else if (ci != 1)
                {
                    errMsg += "Unable to find data table: " + mtName + "\r\n";
                }

                txt = tr.GetAttribute("Function" + ci);
                if (txt != null)
                {
                    cfc.Function = txt;
                }

                txt = tr.GetAttribute("Constant" + ci);
                if (txt != null)
                {
                    cfc.Constant = txt;
                }
            }

            txt = tr.GetAttribute("Operation");
            if (txt != null)
            {
                cf.Operation = txt;
            }

            XmlUtil.GetStringAttribute(tr, "AdvancedExpr", ref cf.AdvancedExpr);
            XmlUtil.GetStringAttribute(tr, "OuterJoinRoot", ref cf.OuterJoinRoot);

            XmlUtil.GetStringAttribute(tr, "ColumnLabel", ref cf.ColumnLabel);
            XmlUtil.GetStringAttribute(tr, "Description", ref cf.Description);
            XmlUtil.GetStringAttribute(tr, "Prompt", ref cf.Prompt);


            if (!tr.IsEmptyElement)
            {
                tr.Read();
                tr.MoveToContent();
                if (Lex.Eq(tr.Name, "CondFormat"))                 // and cond format
                {
                    if (!tr.IsEmptyElement)
                    {
                        cf.Classification = CondFormat.Deserialize(tr);
                    }
                    tr.Read();                     // get next element
                    tr.MoveToContent();
                }

                if (!Lex.Eq(tr.Name, "CalcField") || tr.NodeType != XmlNodeType.EndElement)
                {
                    throw new Exception("CalcField.Deserialize - Expected CalcField end element");
                }
            }

            cf.SetDerivedValues();

            return(cf);
        }