Ejemplo n.º 1
0
        /// <summary>
        /// Convert a basic calc field to an advanced one
        /// </summary>
        /// <returns></returns>

        public string ConvertBasicToAdvanced()
        {
            string expr = "", expr1 = "", expr2 = "", tableAlias = "";

            CalcField cf = this;
            string    op = GetOperator();

            //CalcOpEnum coe = CalcField.ConvertCalcOpStringToEnum(ref operation);

            foreach (CalcFieldColumn cfc in CfCols)
            {
                if (cfc.MetaColumn == null)
                {
                    continue;
                }
                expr1 = BuildColumnExpr(cfc, tableAlias);

                if (cfc.Constant != "")
                {
                    expr1 = "(" + expr1 + ")";
                }

                if (expr == "")
                {
                    expr = expr1;
                }
                else if (cf.Operation != "")
                {
                    expr += " " + op + " " + expr1;
                }
            }

            return(expr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clone the CalcField
        /// </summary>
        /// <returns></returns>

        public CalcField Clone()
        {
            string    content = Serialize();
            CalcField copy    = Deserialize(content);

            return(copy);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get operator for advanced form of calc field
        /// </summary>
        /// <returns></returns>

        public string GetOperator()
        {
            string op;

            CalcField cf = this;

            if (cf.OpEnum == CalcOpEnum.Overlay)
            {
                op = "|| ' " + OverlayOp + " ' ||";                 // build sql form
            }
            else if (Lex.IsDefined(cf.Operation))
            {
                op = cf.Operation.Substring(0, 1);
            }

            else
            {
                op = "/";              // default
            }
            return(op);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deserialize calculated field
        /// </summary>
        /// <param name="serializedForm"></param>
        /// <returns></returns>

        public static CalcField Deserialize(
            string serializedForm)
        {
            if (Lex.Contains(serializedForm, "<CalcField"))
            {
                XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

                XmlTextReader tr = mstr.Reader;
                tr.Read();                 // get CalcField element
                tr.MoveToContent();
                if (!Lex.Eq(tr.Name, "CalcField"))
                {
                    throw new Exception("CalcField.Deserialize - \"CalcField\" element not found");
                }

                CalcField cf = Deserialize(mstr.Reader);
                mstr.Close();
                return(cf);
            }

            return(DeserializeOld(serializedForm));            // must be old form
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Parse serialized form of calculated field
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>

        public static CalcField DeserializeOld(
            string content)
        {
            MetaTable mt, mt2;
            string    mtName;

            CalcField       cf = new CalcField();
            CalcFieldColumn c1 = cf.Column1;
            CalcFieldColumn c2 = cf.Column2;

            string[] sa = content.Split('\t');

            cf.CalcType = CalcTypeEnum.Basic;             // assume basic type

            if (sa[0] != "")
            {
                mt = MetaTableCollection.GetWithException(sa[0]);
                if (mt.SummarizedExists && !mt.UseSummarizedData)
                {                 // use summarized form if exists
                    mtName = mt.Name + MetaTable.SummarySuffix;
                    mt2    = MetaTableCollection.Get(mtName);
                    if (mt2 != null && mt2.GetMetaColumnByName(sa[1]) != null)
                    {
                        mt = mt2;
                    }
                }

                c1.MetaColumn = mt.GetMetaColumnByNameWithException(sa[1]);
                if (c1.MetaColumn == null)
                {
                    return(null);
                }
                c1.Function = sa[2];
                c1.Constant = sa[3];

                cf.Operation = sa[4];
            }

            if (sa.Length <= 5 ||             // old form with only first field defined
                (sa.Length == 6 && String.IsNullOrEmpty(sa[5])))
            {
                cf.SetDerivedValues();
                return(cf);
            }

            if (sa[6] != "")
            {
                mt = MetaTableCollection.GetWithException(sa[5]);
                if (mt == null)
                {
                    return(null);
                }

                if (mt.SummarizedExists && !mt.UseSummarizedData)
                {                 // use summarized form if exists
                    mtName = mt.Name + MetaTable.SummarySuffix;
                    mt2    = MetaTableCollection.Get(mtName);
                    if (mt2 != null && mt2.GetMetaColumnByName(sa[6]) != null)
                    {
                        mt = mt2;
                    }
                }

                c2.MetaColumn = mt.GetMetaColumnByNameWithException(sa[6]);
                if (c2.MetaColumn == null)
                {
                    return(null);
                }
                c2.Function = sa[7];
                c2.Constant = sa[8];
            }

            if (sa.Length >= 13)             // get other values if new form
            {
                EnumUtil.TryParse(sa[9], out cf.CalcType);
                cf.AdvancedExpr = sa[10];
                string obsoleteIncludedQueryXml = sa[11];                 // obsolete cf.IncludedQueryXml
                cf.Description = sa[12];
            }

            cf.SetDerivedValues();

            return(cf);
        }
Ejemplo n.º 6
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);
        }