public GroupVariable(bool editMode, ListBoxItemSource selectedItem = null) { SelectedItem = selectedItem; this.editMode = editMode; ClientCommon.Common cmnClass = new ClientCommon.Common(); InitializeComponent(); FillListBox(); if (editMode) { EwavRule_GroupVariable rule = (EwavRule_GroupVariable)selectedItem.Rule; txtDestinationField.Text = rule.VaraiableName; txtDestinationField.IsEnabled = false; foreach (var item in rule.Items) { //cbxField.SelectedIndex = cmnClass.FindIndexToSelect(cmnClass.GetItemsSource(GetFieldPrimaryDataType), child.Value.ToString().Replace("<", "<")); //int index = -1; //lbxFieldName.ItemsSource lbxFieldName.SelectedItems.Add(cmnClass.FindEwavColumn(item.VarName, ReadColumns())); } } }
/// <summary> /// Serializes the rules /// </summary> /// <param name="rule"></param> /// <returns></returns> public static XElement Serialize(this EwavRule_Base rule) { XElement element = null; if (rule is EwavRule_Format) { EwavRule_Format ruleFormat = (EwavRule_Format)rule; element = new XElement("rule", new XAttribute("type", "Rule_Format"), new XElement("friendlyRule", ruleFormat.FriendlyLabel), new XElement("sourceColumnName", ruleFormat.CbxFieldName), new XElement("destinationColumnName", ruleFormat.TxtDestinationField), new XElement("formatString", ruleFormat.CbxFormatOptions), new XElement("formatType", ruleFormat.FormatTypes), new XElement("variableDataType", ruleFormat.VaraiableDataType)); } else if (rule is EwavRule_ExpressionAssign) { EwavRule_ExpressionAssign ruleAssign = (EwavRule_ExpressionAssign)rule; element = new XElement("rule", new XAttribute("type", "Rule_ExpressionAssign"), new XElement("friendlyRule", ruleAssign.FriendlyRule), new XElement("expression", ruleAssign.Expression), new XElement("destinationColumnName", ruleAssign.DestinationColumnName), new XElement("destinationColumnType", ruleAssign.DataType), new XElement("variableDataType", ruleAssign.VaraiableDataType)); } else if (rule is EwavRule_ConditionalAssign) { EwavRule_ConditionalAssign ruleCondAssign = (EwavRule_ConditionalAssign)rule; element = new XElement("rule", new XAttribute("type", "Rule_ConditionalAssign"), new XElement("friendlyRule", ruleCondAssign.FriendlyRule.VarName), new XElement("destinationColumnName", ruleCondAssign.TxtDestination), new XElement("destinationColumnType", ruleCondAssign.DestinationColumnType), new XElement("assignValue", ruleCondAssign.AssignValue), new XElement("elseValue", ruleCondAssign.ElseValue), new XElement("cbxFieldType", ruleCondAssign.CbxFieldType), new XElement("variableDataType", ruleCondAssign.VaraiableDataType)); ruleCondAssign.ConditionsList.Serialize(element); } else if (rule is EwavRule_GroupVariable) { EwavRule_GroupVariable ruleGroupVar = (EwavRule_GroupVariable)rule; element = new XElement("rule", new XAttribute("type", "Rule_GroupVariable"), new XElement("friendlyLabel", ruleGroupVar.FriendlyLabel), new XElement("destinationColumnName", ruleGroupVar.VaraiableName), //new XElement("destinationColumnType", ruleGroupVar.VaraiableDataType), new XElement("variableDataType", ruleGroupVar.VaraiableDataType)); XElement items = new XElement("Columns"); for (int i = 0; i < ruleGroupVar.Items.Count; i++) { items.Add(new XElement("column", ruleGroupVar.Items[i].VarName)); } element.Add(items); } else if (rule is EwavRule_Recode) { EwavRule_Recode ruleRecode = (EwavRule_Recode)rule; element = new XElement("rule", new XAttribute("type", "Rule_Recode"), new XElement("friendlyRule", ruleRecode.Friendlyrule), new XElement("sourceColumnName", ruleRecode.SourceColumnName), new XElement("sourceColumnType", ruleRecode.SourceColumnType), new XElement("destinationColumnName", ruleRecode.TxtDestinationField), new XElement("destinationColumnType", ruleRecode.DestinationFieldType), //new XElement("tableColumns",(List<EwavRuleRecodeDataRow>)dataGridViewRecode.ItemsSource.Count.ToString() ), new XElement("elseValue", ruleRecode.TxtElseValue), new XElement("shouldUseWildcards", ruleRecode.CheckboxUseWildcardsIndicator), new XElement("shouldMaintainSortOrder", ruleRecode.CheckboxMaintainSortOrderIndicator), new XElement("variableDataType", ruleRecode.VaraiableDataType)); List <EwavRuleRecodeDataRow> dtb = ruleRecode.RecodeTable; XElement recodeTableElement = new XElement("recodeTable"); XElement recodeTableRowElement = null; for (int i = 0; i < dtb.Count; i++) { if (dtb[i].col1.Length > 0 && dtb[i].col1.Length > 0 && dtb[i].col1.Length > 0) { recodeTableRowElement = new XElement("recodeTableRow"); recodeTableRowElement.Add(new XElement("recodeTableData", dtb[i].col1.Replace("<", "<").Replace(">", ">"))); if (dtb[i].col2 == null) { recodeTableRowElement.Add(new XElement("recodeTableData", null)); } else if (dtb[i].col2.Length > 0) { recodeTableRowElement.Add(new XElement("recodeTableData", dtb[i].col2.Replace("<", "<").Replace(">", ">"))); } recodeTableRowElement.Add(new XElement("recodeTableData", dtb[i].col3.Replace("<", "<").Replace(">", ">"))); recodeTableElement.Add(recodeTableRowElement); } } element.Add(recodeTableElement); } else if (rule is EwavRule_SimpleAssignment) { EwavRule_SimpleAssignment ruleSimple = (EwavRule_SimpleAssignment)rule; element = new XElement("rule", new XAttribute("type", "Rule_SimpleAssign"), new XElement("friendlyRule", ruleSimple.FriendlyLabel), new XElement("assignmentType", ruleSimple.AssignmentType), new XElement("destinationColumnName", ruleSimple.TxtDestinationField), new XElement("variableDataType", ruleSimple.VaraiableDataType)); XElement paramsList = new XElement("parametersList"); for (int i = 0; i < ruleSimple.Parameters.Count; i++) { paramsList.Add(new XElement("parameter", ruleSimple.Parameters[i].VarName)); } element.Add(paramsList); } return(element); }
private void OKButton_Click(object sender, RoutedEventArgs e) { EwavRule_GroupVariable rule = new EwavRule_GroupVariable(); if (txtDestinationField.Text.Trim().Length == 0) { MessageBox.Show("Group Field Name must be entered."); return; } if (lbxFieldName.SelectedItems.Count == 0) { MessageBox.Show("Select items to include in the group."); return; } List <MyString> lbxItems = new List <MyString>(); StringBuilder listOfColumnNamesSelected = new StringBuilder(); foreach (var item in lbxFieldName.SelectedItems) { MyString itemValue = new MyString(); itemValue.VarName = ((EwavColumn)item).Name.ToString(); lbxItems.Add(itemValue); listOfColumnNamesSelected.Append(itemValue.VarName + ","); } string friendlyLabel = "Create a variable group called " + txtDestinationField.Text + " and include: " + listOfColumnNamesSelected.ToString().Substring(0, listOfColumnNamesSelected.ToString().Length - 1); rule.Items = lbxItems; rule.VaraiableName = txtDestinationField.Text; rule.VaraiableDataType = ColumnDataType.GroupVariable.ToString(); rule.FriendlyLabel = friendlyLabel; ListBoxItemSource listBoxItem = new ListBoxItemSource(); listBoxItem.RuleString = friendlyLabel; //listBoxItem.SourceColumn = sourceColumn.Name; listBoxItem.DestinationColumn = txtDestinationField.Text; listBoxItem.NewColumn = txtDestinationField.Text; listBoxItem.RuleType = EwavRuleType.GroupVariable; listBoxItem.SourceColumn = null; listBoxItem.Rule = rule; EwavColumn newcolumn = new EwavColumn(); newcolumn.Name = txtDestinationField.Text; newcolumn.SqlDataTypeAsString = ColumnDataType.GroupVariable; newcolumn.NoCamelName = txtDestinationField.Text; newcolumn.IsUserDefined = true; applicationViewModel.InvokePreColumnChangedEvent(); List <EwavRule_Base> rules = new List <EwavRule_Base>(); rules = applicationViewModel.EwavDefinedVariables; //Shows the error message if name already exists. if (!editMode) { for (int i = 0; i < applicationViewModel.EwavDefinedVariables.Count; i++) { if (applicationViewModel.EwavDefinedVariables[i].VaraiableName == rule.VaraiableName) { MessageBox.Show("Rule Name already exists. Select another name."); return; } } } for (int i = 0; i < rules.Count; i++) { if (rule.VaraiableName == rules[i].VaraiableName) { rules.RemoveAt(i); applicationViewModel.ListOfRules.RemoveAt(i); break; } } if (!editMode) { applicationViewModel.EwavSelectedDatasource.AllColumns.Add(newcolumn); } applicationViewModel.ListOfRules.Add(listBoxItem); List <EwavRule_Base> listOfRules = new List <EwavRule_Base>(); listOfRules = applicationViewModel.EwavDefinedVariables; listOfRules.Add(rule); applicationViewModel.EwavDefinedVariables = listOfRules; this.DialogResult = true; }
public List <EwavRule_Base> ConvertXMLToDefinedVariables(XDocument doc) { List <EwavRule_Base> EwavDefinedVariables = new List <EwavRule_Base>(); foreach (var item in doc.Descendants("Rules").Descendants()) { if (item.Name.ToString().ToLower() == "rule") { try { //Type gadgetType = Type.GetType(item.Attribute("type").Value); // item.Attributes["gadgetType"].Value); //EwavRule_Base rule = null; EwavRule_Base baseRule = null; switch (item.Attribute("type").Value.ToLower()) { case "rule_format": EwavRule_Format rule = new EwavRule_Format(); rule.FriendlyLabel = item.Element("friendlyRule").Value.ToString(); rule.CbxFieldName = item.Element("sourceColumnName").Value.ToString(); rule.TxtDestinationField = item.Element("destinationColumnName").Value.ToString(); rule.CbxFormatOptions = item.Element("formatString").Value.ToString(); rule.FormatTypes = (Ewav.Web.EpiDashboard.Rules.FormatTypes)Enum.Parse(typeof(Ewav.Web.EpiDashboard.Rules.FormatTypes), item.Element("formatType").Value.ToString(), true); rule.VaraiableDataType = item.Element("variableDataType").Value.ToString(); baseRule = rule; baseRule.VaraiableName = rule.TxtDestinationField; break; case "rule_expressionassign": EwavRule_ExpressionAssign ruleAssign = new EwavRule_ExpressionAssign(); ruleAssign.FriendlyRule = item.Element("friendlyRule").Value.ToString(); ruleAssign.Expression = item.Element("expression").Value.ToString(); ruleAssign.DestinationColumnName = item.Element("destinationColumnName").Value.ToString(); ruleAssign.DataType = item.Element("destinationColumnType").Value.ToString(); ruleAssign.VaraiableDataType = item.Element("variableDataType").Value.ToString(); baseRule = ruleAssign; baseRule.VaraiableName = ruleAssign.DestinationColumnName; break; case "rule_groupvariable": EwavRule_GroupVariable ruleGroupVar = new EwavRule_GroupVariable(); ruleGroupVar.FriendlyLabel = item.Element("friendlyLabel").Value.ToString(); ruleGroupVar.VaraiableName = item.Element("destinationColumnName").Value.ToString(); ruleGroupVar.VaraiableDataType = item.Element("variableDataType").Value.ToString(); List <MyString> columnList = new List <MyString>(); foreach (var column in item.Descendants("column")) { MyString colVal = new MyString(); colVal.VarName = column.Value.ToString(); columnList.Add(colVal); } ruleGroupVar.Items = columnList; baseRule = ruleGroupVar; baseRule.VaraiableName = ruleGroupVar.VaraiableName; break; case "rule_conditionalassign": EwavRule_ConditionalAssign ruleCondAssign = new EwavRule_ConditionalAssign(); MyString myString = new MyString(); myString.VarName = item.Element("friendlyRule").Value.ToString(); ruleCondAssign.FriendlyRule = myString; ruleCondAssign.TxtDestination = item.Element("destinationColumnName").Value.ToString(); ruleCondAssign.DestinationColumnType = item.Element("destinationColumnType").Value.ToString(); ruleCondAssign.AssignValue = item.Element("assignValue").Value.ToString(); ruleCondAssign.ElseValue = item.Element("elseValue").Value.ToString(); ruleCondAssign.VaraiableDataType = item.Element("variableDataType").Value.ToString(); if (item.Element("cbxFieldType") != null) { ruleCondAssign.CbxFieldType = (cbxFieldTypeEnum)Enum.Parse(typeof(cbxFieldTypeEnum), item.Element("cbxFieldType").Value.ToString(), false); } ruleCondAssign.ConditionsList = new List <EwavDataFilterCondition>(); //ruleCondAssign.ConditionsList = foreach (var condition in item.Descendants("EwavDataFilterCondition").OrderBy(x => (int)x.Attribute("order"))) { EwavDataFilterCondition df = new EwavDataFilterCondition(); if (condition.Attribute("friendlyOperand") != null) { df.FriendlyOperand = ToMyString(condition.Attribute("friendlyOperand").Value); } if (condition.Attribute("friendlyValue") != null) { df.FriendlyValue = ToMyString(condition.Attribute("friendlyValue").Value); } if (condition.Attribute("fieldName") != null) { df.FieldName = ToMyString(condition.Attribute("fieldName").Value); } if (condition.Attribute("joinType") != null) { df.JoinType = ToMyString(condition.Attribute("joinType").Value); } if (condition.Attribute("friendLowValue") != null && condition.Attribute("friendLowValue").Value != "null") { df.FriendLowValue = ToMyString(condition.Attribute("friendLowValue").Value); } if (condition.Attribute("friendHighValue") != null && condition.Attribute("friendHighValue").Value != "null") { df.FriendHighValue = ToMyString(condition.Attribute("friendHighValue").Value); } ruleCondAssign.ConditionsList.Add(df); } baseRule = ruleCondAssign; baseRule.VaraiableName = ruleCondAssign.TxtDestination; break; case "rule_simpleassign": EwavRule_SimpleAssignment ruleSimple = new EwavRule_SimpleAssignment(); ruleSimple.FriendlyLabel = item.Element("friendlyRule").Value.ToString(); ruleSimple.AssignmentType = (Ewav.Web.EpiDashboard.Rules.SimpleAssignType)Enum.Parse(typeof(Ewav.Web.EpiDashboard.Rules.SimpleAssignType), item.Element("assignmentType").Value.ToString(), true); ruleSimple.TxtDestinationField = item.Element("destinationColumnName").Value.ToString(); ruleSimple.Parameters = new List <MyString>(); ruleSimple.VaraiableDataType = item.Element("variableDataType").Value.ToString(); foreach (var item1 in item.Element("parametersList").Descendants()) { MyString mys = new MyString(); mys.VarName = item1.Value; ruleSimple.Parameters.Add(mys); } baseRule = ruleSimple; baseRule.VaraiableName = ruleSimple.TxtDestinationField; break; case "rule_recode": EwavRule_Recode ruleRecode = new EwavRule_Recode(); ruleRecode.Friendlyrule = item.Element("friendlyRule").Value.ToString(); ruleRecode.SourceColumnName = item.Element("sourceColumnName").Value.ToString(); ruleRecode.SourceColumnType = item.Element("sourceColumnType").Value.ToString(); ruleRecode.TxtDestinationField = item.Element("destinationColumnName").Value.ToString(); ruleRecode.DestinationFieldType = (DashboardVariableType)Enum.Parse(typeof(DashboardVariableType), item.Element("destinationColumnType").Value.ToString(), true); ruleRecode.TxtElseValue = item.Element("elseValue").Value.ToString(); ruleRecode.CheckboxUseWildcardsIndicator = bool.Parse(item.Element("shouldUseWildcards").Value.ToString()); ruleRecode.CheckboxMaintainSortOrderIndicator = bool.Parse(item.Element("shouldMaintainSortOrder").Value.ToString()); ruleRecode.VaraiableName = item.Element("destinationColumnName").Value.ToString(); ruleRecode.VaraiableDataType = item.Element("variableDataType").Value.ToString(); //ruleRecode.VaraiableDataType = item.Element("variableDataType").Value.ToString(); List <EwavRuleRecodeDataRow> rows = new List <EwavRuleRecodeDataRow>(); foreach (var item2 in item.Descendants("recodeTable")) { var itemmm = item2; foreach (var item3 in item2.Elements("recodeTableRow")) { EwavRuleRecodeDataRow row = new EwavRuleRecodeDataRow(); IEnumerable <XElement> enumerableList = item3.Elements("recodeTableData"); List <XElement> list = enumerableList.ToList(); if (list.Count == 2) { row.col1 = list[0].Value.ToString().Replace("<", "<").Replace(">", ">"); row.col3 = list[1].Value.ToString().Replace("<", "<").Replace(">", ">"); } else { row.col1 = list[0].Value.ToString().Replace("<", "<").Replace(">", ">"); row.col2 = list[1].Value.ToString().Replace("<", "<").Replace(">", ">"); row.col3 = list[2].Value.ToString().Replace("<", "<").Replace(">", ">"); } rows.Add(row); } } ruleRecode.RecodeTable = rows; baseRule = ruleRecode; baseRule.VaraiableName = ruleRecode.TxtDestinationField; break; default: throw new Exception("This Rule doesn't exists."); } //newColumn.SqlDataTypeAsString = (ColumnDataType)Enum.Parse(typeof(ColumnDataType), item.Element("variableDataType").Value.ToString(), false); EwavDefinedVariables.Add(baseRule); } catch (Exception ex) { //Epi.Windows.MsgBox.ShowError(DashboardSharedStrings.GADGET_LOAD_ERROR); throw new Exception("Exception occured deserializing Rules." + ex.Message); //return; } } } return(EwavDefinedVariables); }