Esempio n. 1
0
        private void SetBooleanAssignmentValue(Rule_ConditionalAssign conditionalAssignRule)
        {
            this.txtAssignValue.Text = conditionalAssignRule.AssignValue.ToString();
            if (conditionalAssignRule.AssignValue.ToString().ToLowerInvariant() == "true")
            {
                this.cmbAssignValue.SelectedIndex = 0;
            }
            else if (conditionalAssignRule.AssignValue.ToString().ToLowerInvariant() == "false")
            {
                this.cmbAssignValue.SelectedIndex = 1;
            }

            if (conditionalAssignRule.UseElse == true)
            {
                this.checkboxUseElse.Checked = true;
                this.txtElseValue.Text       = conditionalAssignRule.ElseValue.ToString();
                if (conditionalAssignRule.ElseValue.ToString().ToLowerInvariant() == "true")
                {
                    this.cmbElseValue.SelectedIndex = 0;
                }
                else if (conditionalAssignRule.ElseValue.ToString().ToLowerInvariant() == "false")
                {
                    this.cmbElseValue.SelectedIndex = 1;
                }
            }
            else
            {
                this.checkboxUseElse.Checked    = false;
                this.txtElseValue.Text          = string.Empty;
                this.cmbElseValue.SelectedIndex = 0;
            }
        }
Esempio n. 2
0
        public ConditionalAssignDialog(DashboardHelper dashboardHelper, Rule_ConditionalAssign conditionalAssignRule)
        {
            InitializeComponent();
            this.dashboardHelper = dashboardHelper;
            this.DataFilters     = conditionalAssignRule.DataFilters;

            editMode = true;

            FillComboBoxes();

            this.txtDestinationField.Text    = conditionalAssignRule.DestinationColumnName;
            this.txtDestinationField.Enabled = false;

            SetAssignValue setAssignValue = new SetAssignValue(SetAssignmentValue);

            switch (conditionalAssignRule.DestinationColumnType)
            {
            case "System.SByte":
            case "System.Byte":
            case "System.Boolean":
                this.cbxFieldType.SelectedItem = "Yes/No";
                setAssignValue = new SetAssignValue(SetBooleanAssignmentValue);
                break;

            case "System.String":
                this.cbxFieldType.SelectedItem = "Text";
                break;

            case "System.Single":
            case "System.Double":
            case "System.Decimal":
            case "System.Int32":
            case "System.Int16":
                this.cbxFieldType.SelectedItem = "Numeric";
                break;
            }

            cbxFieldType.Enabled = false;

            this.txtAssignCondition.Text = DataFilters.GenerateReadableDataFilterString();

            //foreach (KeyValuePair<string, object> kvp in conditionalAssignRule.Conditions)
            //{
            //    this.txtAssignValue.Text = kvp.Value.ToString();
            //    break;
            //}

            setAssignValue(conditionalAssignRule);
        }
Esempio n. 3
0
        private void SetAssignmentValue(Rule_ConditionalAssign conditionalAssignRule)
        {
            this.txtAssignValue.Text = conditionalAssignRule.AssignValue.ToString();

            if (conditionalAssignRule.UseElse == true)
            {
                this.checkboxUseElse.Checked = true;
                this.txtElseValue.Text       = conditionalAssignRule.ElseValue.ToString();
            }
            else
            {
                this.checkboxUseElse.Checked = false;
                this.txtElseValue.Text       = string.Empty;
            }
        }
        private void btnEditRule_Click(object sender, RoutedEventArgs e)
        {
            if (lbxRules.SelectedItems != null && lbxRules.SelectedItems.Count == 1)
            {
                Rule_Recode            recodeRule            = null;
                Rule_Format            formatRule            = null;
                Rule_ExpressionAssign  expressionAssignRule  = null;
                Rule_SimpleAssign      simpleAssignRule      = null;
                Rule_ConditionalAssign conditionalAssignRule = null;
                Rule_VariableGroup     variableGroupRule     = null;

                foreach (IDashboardRule rule in dashboardHelper.Rules)
                {
                    if (rule.FriendlyRule.Equals(lbxRules.SelectedItem.ToString()))
                    {
                        if (rule is Rule_Recode)
                        {
                            recodeRule = rule as Rule_Recode;
                            break;
                        }
                        else if (rule is Rule_Format)
                        {
                            formatRule = rule as Rule_Format;
                            break;
                        }
                        else if (rule is Rule_ExpressionAssign)
                        {
                            expressionAssignRule = rule as Rule_ExpressionAssign;
                            break;
                        }
                        else if (rule is Rule_SimpleAssign)
                        {
                            simpleAssignRule = rule as Rule_SimpleAssign;
                            break;
                        }
                        else if (rule is Rule_ConditionalAssign)
                        {
                            conditionalAssignRule = rule as Rule_ConditionalAssign;
                            break;
                        }
                        else if (rule is Rule_VariableGroup)
                        {
                            variableGroupRule = rule as Rule_VariableGroup;
                            break;
                        }
                    }
                }

                System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.None;

                if (recodeRule != null)
                {
                    EpiDashboard.Dialogs.RecodeDialog recodeDialog = new EpiDashboard.Dialogs.RecodeDialog(this.dashboardHelper, recodeRule);
                    result = recodeDialog.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        dashboardHelper.UpdateRule(recodeRule, recodeDialog.RecodeRule);
                        UpdateRules();
                        if (UserVariableChanged != null)
                        {
                            UserVariableChanged(this, new EventArgs());
                        }
                    }
                }
                else if (formatRule != null)
                {
                    EpiDashboard.Dialogs.FormatDialog formatDialog = new EpiDashboard.Dialogs.FormatDialog(this.dashboardHelper, formatRule);
                    result = formatDialog.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        dashboardHelper.UpdateRule(formatRule, formatDialog.FormatRule);
                        UpdateRules();
                        if (UserVariableChanged != null)
                        {
                            UserVariableChanged(this, new EventArgs());
                        }
                    }
                }
                else if (expressionAssignRule != null)
                {
                    EpiDashboard.Dialogs.ExpressionAssignDialog assignDialog = new EpiDashboard.Dialogs.ExpressionAssignDialog(this.dashboardHelper, expressionAssignRule);
                    result = assignDialog.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        dashboardHelper.UpdateRule(expressionAssignRule, assignDialog.AssignRule);
                        UpdateRules();
                        if (UserVariableChanged != null)
                        {
                            UserVariableChanged(this, new EventArgs());
                        }
                    }
                }
                else if (simpleAssignRule != null)
                {
                    EpiDashboard.Dialogs.SimpleAssignDialog assignDialog = new EpiDashboard.Dialogs.SimpleAssignDialog(this.dashboardHelper, simpleAssignRule);
                    result = assignDialog.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        dashboardHelper.UpdateRule(simpleAssignRule, assignDialog.AssignRule);
                        UpdateRules();
                        if (UserVariableChanged != null)
                        {
                            UserVariableChanged(this, new EventArgs());
                        }
                    }
                }
                else if (conditionalAssignRule != null)
                {
                    EpiDashboard.Dialogs.ConditionalAssignDialog assignDialog = new EpiDashboard.Dialogs.ConditionalAssignDialog(this.dashboardHelper, conditionalAssignRule);
                    result = assignDialog.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        dashboardHelper.UpdateRule(conditionalAssignRule, assignDialog.AssignRule);
                        UpdateRules();
                        if (UserVariableChanged != null)
                        {
                            UserVariableChanged(this, new EventArgs());
                        }
                    }
                }
                else if (variableGroupRule != null)
                {
                    EpiDashboard.Dialogs.CreateGroupDialog groupDialog = new EpiDashboard.Dialogs.CreateGroupDialog(this.dashboardHelper, variableGroupRule);
                    result = groupDialog.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        dashboardHelper.UpdateRule(variableGroupRule, groupDialog.Group);
                        UpdateRules();
                        if (UserVariableChanged != null)
                        {
                            UserVariableChanged(this, new EventArgs());
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string destinationColumnType = "System.String";

            object elseValue   = this.txtElseValue.Text;
            object assignValue = this.txtAssignValue.Text;

            switch (cbxFieldType.SelectedItem.ToString())
            {
            case "Yes/No":
                destinationColumnType = "System.Boolean";
                if (cmbAssignValue.SelectedIndex == 0)
                {
                    assignValue = true;
                }
                else if (cmbAssignValue.SelectedIndex == 1)
                {
                    assignValue = false;
                }

                if (cmbElseValue.SelectedIndex == 0)
                {
                    elseValue = true;
                }
                else if (cmbElseValue.SelectedIndex == 1)
                {
                    elseValue = false;
                }

                break;

            case "Text":
                destinationColumnType = "System.String";
                elseValue             = this.txtElseValue.Text;
                assignValue           = this.txtAssignValue.Text;
                break;

            case "Numeric":
                destinationColumnType = "System.Decimal";
                decimal decElse;
                decimal decAssign;
                bool    success1 = Decimal.TryParse(this.txtElseValue.Text, out decElse);
                if (success1)
                {
                    elseValue = decElse;
                }
                bool success2 = Decimal.TryParse(this.txtAssignValue.Text, out decAssign);
                if (success2)
                {
                    assignValue = decAssign;
                }

                if ((!success1 && checkboxUseElse.Checked) || !success2)
                {
                    Epi.Windows.MsgBox.ShowError(DashboardSharedStrings.ERROR_CANNOT_CONDITIONAL_ASSIGN_INVALID_INPUT);
                    this.DialogResult = DialogResult.None;
                    return;
                }
                break;
            }

            if (!editMode && this.dashboardHelper.TableColumnNames.ContainsKey(txtDestinationField.Text))
            {
                string columnType = dashboardHelper.GetColumnType(txtDestinationField.Text);

                if (columnType != destinationColumnType)
                {
                    Epi.Windows.MsgBox.ShowError(string.Format(DashboardSharedStrings.ERROR_CANNOT_CONDITIONAL_ASSIGN_TYPE_MISMATCH, columnType, destinationColumnType));
                    this.DialogResult = DialogResult.None;
                    return;
                }
            }

            string sentencePart = txtAssignCondition.Text;

            if (sentencePart.Length > 0)
            {
                sentencePart = " when " + "t" + txtAssignCondition.Text.Remove(0, 1);
            }

            string conditionText = "Assign " + txtDestinationField.Text + " the value " + assignValue + sentencePart;

            if (!checkboxUseElse.Checked)
            {
                elseValue = null;
            }
            else
            {
                conditionText = conditionText + ". Otherwise, assign " + txtDestinationField.Text + " the value " + elseValue + ".";
            }

            assignRule             = new Rule_ConditionalAssign(this.dashboardHelper, conditionText, txtDestinationField.Text, destinationColumnType, assignValue, elseValue, DataFilters.GenerateDataFilterString());
            assignRule.DataFilters = this.DataFilters;
        }