Ejemplo n.º 1
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            // add data to new rule add to  list
            // add new rule to listbox item source   kk
            //  add column to Allcolumns

            List <ListBoxItemSource> TempList = applicationViewModel.ListOfRules.Where(t => t.DestinationColumn.ToLower() == txtDestinationField.Text.ToLower()).ToList();

            if (TempList.Count > 0 && !editMode)
            {
                MessageBox.Show("Variable name already exists.");
                return;
            }


            EwavRule_ExpressionAssign ea = new EwavRule_ExpressionAssign();

            ea.Expression = txtExpression.Text;

            if (((EwavColumn)cbxDataType.SelectedItem).SqlDataTypeAsString.ToString() == "Text")
            {
                ea.DataType = "System.String";
            }
            else if (((EwavColumn)cbxDataType.SelectedItem).SqlDataTypeAsString.ToString() == "Numeric")
            {
                ea.DataType = "System.Decimal";
            }

            //   "System.String";
            ea.FriendlyRule          = string.Format("Assign {0} the expression: {1}", txtDestinationField.Text, txtExpression.Text);
            ea.DestinationColumnName = txtDestinationField.Text;
            ea.VaraiableName         = txtDestinationField.Text;

            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 == ea.VaraiableName)
                    {
                        MessageBox.Show("Rule Name already exists. Select another name.");
                        return;
                    }
                }
            }

            for (int i = 0; i < rules.Count; i++)
            {
                if (ea.DestinationColumnName == rules[i].VaraiableName)
                {
                    rules.RemoveAt(i);
                    applicationViewModel.ListOfRules.RemoveAt(i);
                    break;
                }
            }

            //EwavRule_ExpressionAssign ea = new EwavRule_ExpressionAssign();
            //ea.Expression = txtExpression.Text;

            //ea.DataType = "System.String";
            //ea.FriendlyRule = "Assign " + txtDestinationField.Text + " the expression: " + txtExpression.Text;
            //ea.DestinationColumnName = txtDestinationField.Text;

            applicationViewModel.InvokePreColumnChangedEvent();



            //   applicationViewModel.EwavDefinedVariables.Add(ea);

            ListBoxItemSource listBoxItem = new ListBoxItemSource();

            listBoxItem.RuleString        = ea.FriendlyRule;
            listBoxItem.NewColumn         = txtDestinationField.Text;
            listBoxItem.AssignExpression  = txtExpression.Text;
            listBoxItem.DataType          = ((EwavColumn)cbxDataType.SelectedItem).SqlDataTypeAsString.ToString();
            listBoxItem.DestinationColumn = txtDestinationField.Text;
            listBoxItem.SourceColumn      = null;
            listBoxItem.RuleType          = EwavRuleType.Assign;

            ea.VaraiableDataType = ((EwavColumn)cbxDataType.SelectedItem).SqlDataTypeAsString.ToString();

            listBoxItem.Rule = ea;
            EwavColumn newColumn = new EwavColumn();

            newColumn.Name = txtDestinationField.Text;
            newColumn.SqlDataTypeAsString = ((EwavColumn)cbxDataType.SelectedItem).SqlDataTypeAsString;
            newColumn.NoCamelName         = txtDestinationField.Text;
            newColumn.IsUserDefined       = true;

            if (editMode == false)
            {
                applicationViewModel.EwavSelectedDatasource.AllColumns.Add(newColumn);
            }

            applicationViewModel.ListOfRules.Add(listBoxItem);

            List <EwavRule_Base> tempList = applicationViewModel.EwavDefinedVariables;

            tempList.Add(ea);

            applicationViewModel.EwavDefinedVariables = tempList;

            this.DialogResult = true;
        }
Ejemplo n.º 2
0
        /// <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("<", "&lt;").Replace(">", "&gt;")));
                        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("<", "&lt;").Replace(">", "&gt;")));
                        }
                        recodeTableRowElement.Add(new XElement("recodeTableData", dtb[i].col3.Replace("<", "&lt;").Replace(">", "&gt;")));
                        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);
        }
Ejemplo n.º 3
0
        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("&lt;", "<").Replace("&gt;", ">");
                                        row.col3 = list[1].Value.ToString().Replace("&lt;", "<").Replace("&gt;", ">");
                                    }
                                    else
                                    {
                                        row.col1 = list[0].Value.ToString().Replace("&lt;", "<").Replace("&gt;", ">");
                                        row.col2 = list[1].Value.ToString().Replace("&lt;", "<").Replace("&gt;", ">");
                                        row.col3 = list[2].Value.ToString().Replace("&lt;", "<").Replace("&gt;", ">");
                                    }
                                    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);
        }