/// <summary> /// Serialize from form into cf object & then into string /// </summary> /// <returns></returns> public CondFormat FormToCondFormat() { CondFormat cf = new CondFormat(); cf.ColumnType = ColumnType; //cf.ShowInHeaders = ShowInHeaders; cf.Name = CfName.Text; cf.ColumnType = MetaColumn.ParseMetaColumnTypeString(ColumnDataType.Text); cf.Option1 = Option1.Checked; cf.Option2 = Option2.Checked; cf.Rules = Rules.GetRules(); return(cf); }
/// <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); }
/// <summary> /// Get other values from calc field form checking for errors /// </summary> /// <returns></returns> bool GetCalcFieldForm() { List <MetaColumn> mcList; CalcField cf = CalcField; CalcFieldColumn cfc = null; if (cf.CalcType == CalcTypeEnum.Basic) // basic CF { cf.Operation = Operation.Text; cf.CfCols.Clear(); // update foreach (CalcFieldColumnControl cfcc in CfColCtls) { if (cfcc.FieldSelectorControl.MetaColumn == null) { continue; } cfc = new CalcFieldColumn(); cfc.MetaColumn = cfcc.FieldSelectorControl.MetaColumn; cfc.Function = cfcc.Function.Text; cfc.Constant = cfcc.Constant.Text; cf.CfCols.Add(cfc); } } else // advanced CF { cf.AdvancedExpr = ParseAdvancedExpr(AdvancedExpr.Text, out mcList); // Get preclassification result type string txt = ResultDataType.Text; if (Lex.IsDefined(txt)) { cf.PreclassificationlResultType = MetaColumn.ParseMetaColumnTypeString(txt); } else { cf.PreclassificationlResultType = MetaColumnType.Number; } // Get anchor table for joins cf.CfCols.Clear(); foreach (MetaColumn mc0 in mcList) { cfc = new CalcFieldColumn(); cfc.MetaColumn = mc0; cf.CfCols.Add(cfc); } cf.OuterJoinRoot = ""; txt = JoinAnchorComboBox.Text; if (Lex.Eq(txt, "(None)")) { txt = ""; } if (Lex.IsDefined(txt)) { for (int ci = 0; ci < cf.CfCols.Count; ci++) { cfc = cf.CfCols[ci]; if (Lex.Eq(txt, cfc.MetaColumn.MetaTable.Label)) { cf.OuterJoinRoot = cfc.MetaColumn.MetaTable.Name; break; } } } } cf.Description = Description.Text; CondFormatRules rules = CondFormatRulesCtl.GetRules(); if (rules.Count == 0) { cf.Classification = null; } else { cf.Classification = new CondFormat(); cf.Classification.Rules = rules; } try { cf.SetDerivedValuesWithException(); } // set derived values checking for errors catch (Exception ex) { MessageBoxMx.ShowError(ex.Message); return(false); } return(true); }