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);
        }
        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 SetBooleanAssignmentValue(Rule_ConditionalAssign conditionalAssignRule)
        {
            this.txtAssignValue.Text = conditionalAssignRule.AssignValue.ToString();
            if (conditionalAssignRule.AssignValue.ToString().ToLower() == "true")
                this.cmbAssignValue.SelectedIndex = 0;
            else if (conditionalAssignRule.AssignValue.ToString().ToLower() == "false")
                this.cmbAssignValue.SelectedIndex = 1;

            if (conditionalAssignRule.UseElse == true)
            {
                this.checkboxUseElse.Checked = true;
                this.txtElseValue.Text = conditionalAssignRule.ElseValue.ToString();
                if (conditionalAssignRule.ElseValue.ToString().ToLower() == "true")
                    this.cmbElseValue.SelectedIndex = 0;
                else if (conditionalAssignRule.ElseValue.ToString().ToLower() == "false")
                    this.cmbElseValue.SelectedIndex = 1;
            }
            else
            {
                this.checkboxUseElse.Checked = false;
                this.txtElseValue.Text = string.Empty;
                this.cmbElseValue.SelectedIndex = 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;
        }