private void CreateInputVariableList()
        {
            Dictionary <string, string> inputVariableList = new Dictionary <string, string>();

            if (cbxField.SelectedIndex > -1 && !string.IsNullOrEmpty(cbxField.SelectedItem.ToString()))
            {
                GadgetOptions.MainVariableName = cbxField.SelectedItem.ToString();
            }
            else
            {
                return;
            }

            //if (cbxFieldStrata.SelectedIndex > -1 && !string.IsNullOrEmpty(cbxFieldStrata.SelectedItem.ToString()))
            //{
            //    inputVariableList.Add("stratavar", cbxFieldStrata.SelectedItem.ToString());
            //}

            if (checkboxSortHighLow.IsChecked == true)
            {
                inputVariableList.Add("sort", "highlow");
                GadgetOptions.ShouldSortHighToLow = true;
            }
            else
            {
                GadgetOptions.ShouldSortHighToLow = false;
            }

            if (checkboxShowDenominator.IsChecked == true)
            {
                inputVariableList.Add("denom", "true");
            }
            else
            {
                inputVariableList.Add("denom", "false");
            }

            GadgetOptions.ShouldIncludeMissing = false;

            if (DataFilters != null && DataFilters.Count > 0)
            {
                GadgetOptions.CustomFilter = DataFilters.GenerateDataFilterString(false);
            }
            else
            {
                GadgetOptions.CustomFilter = string.Empty;
            }

            if (cmbCombineMode.SelectedIndex >= 0)
            {
                inputVariableList.Add("combinemode", cmbCombineMode.SelectedIndex.ToString());
            }

            inputVariableList.Add("truevalue", txtTrueValue.Text);

            GadgetOptions.InputVariableList = inputVariableList;
        }
        public override void SetupRule(DataTable table)
        {
            string destinationColumnType = this.DestinationColumnType;

            DataColumn dc = new DataColumn(destinationColumnName);

            if (!table.Columns.Contains(dc.ColumnName))
            {
                switch (destinationColumnType)
                {
                case "System.Boolean":
                    dc = new DataColumn(this.DestinationColumnName, typeof(bool));
                    break;

                case "System.Byte":
                case "System.SByte":
                    dc = new DataColumn(this.DestinationColumnName, typeof(byte));
                    break;

                case "System.Single":
                case "System.Double":
                    dc = new DataColumn(this.DestinationColumnName, typeof(double));
                    break;

                case "System.Decimal":
                    dc = new DataColumn(this.DestinationColumnName, typeof(decimal));
                    break;

                case "System.String":
                default:
                    dc = new DataColumn(this.DestinationColumnName, typeof(string));
                    break;
                }

                try
                {
                    table.Columns.Add(dc);
                }
                catch (ArgumentException)
                {
                    dc = new DataColumn(DestinationColumnName);
                    table.Columns.Add(dc);
                }
            }
            else
            {
                dc = table.Columns[dc.ColumnName];
            }


            dvAssign = new DataView(table, DataFilters.GenerateDataFilterString(), string.Empty, DataViewRowState.CurrentRows);

            //foreach (KeyValuePair<string, object> kvp in this.conditions)
            //{
            //    dvAssign = new DataView(table, kvp.Key, string.Empty, DataViewRowState.CurrentRows);

            //    assignValue = kvp.Value;
            //    // currently, we're supporting only one condition.
            //    // This KVP list may be useful later on if ELSE-IF is
            //    // added as a feature. For now, just kill the loop.
            //    break;
            //}
        }
Exemple #3
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;
        }