示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public RecodeDialog(DashboardHelper dashboardHelper, Rule_Recode rule)
        {
            this.dashboardHelper = dashboardHelper;
            this.editMode = true;
            InitializeComponent();

            FillComboBoxes();

            this.txtDestinationField.Text = rule.DestinationColumnName;
            this.cbxSourceField.SelectedItem = rule.SourceColumnName;
            this.checkboxMaintainSortOrder.Checked = rule.ShouldMaintainSortOrder;
            this.checkboxUseWildcards.Checked = rule.ShouldUseWildcards;
            this.txtElseValue.Text = rule.ElseValue;

            // TODO: Find better way to do this
            switch (rule.DestinationColumnType)
            {
                case "System.SByte":
                case "System.Byte":
                case "System.Boolean":
                    this.cbxFieldType.SelectedItem = "Yes/No";
                    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;
            }

            this.cbxFieldType.Enabled = false;

            if (rule.RecodeInputTable.Columns.Count == 3)
            {
                rule.RecodeInputTable.Columns[0].ColumnName = COL_FROM;
                rule.RecodeInputTable.Columns[1].ColumnName = COL_TO;
                rule.RecodeInputTable.Columns[2].ColumnName = COL_REPRESENTATION;
            }
            else if (rule.RecodeInputTable.Columns.Count == 2)
            {
                rule.RecodeInputTable.Columns[0].ColumnName = COL_FROM;
                rule.RecodeInputTable.Columns[1].ColumnName = COL_REPRESENTATION;
            }

            this.dataGridViewRecode.DataSource = rule.RecodeInputTable;
        }
示例#2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtDestinationField.Text))
            {
                MsgBox.ShowError("Destination field is blank.");
                this.DialogResult = DialogResult.None;
                return;
            }

            if (cbxFieldType.SelectedIndex == 1 && cbxFieldType.Text == "Numeric")
            {
                foreach (DataRow row in RecodeTable.Rows)
                {
                    string textValue = row["Representation"].ToString();
                    double value;
                    bool success = double.TryParse(textValue, out value);
                    if (!success && !string.IsNullOrEmpty(textValue))
                    {
                        MsgBox.ShowError("The destination field type has been defined as numeric, but the destination values are not valid numbers.");
                        this.DialogResult = DialogResult.None;
                        return;
                    }
                }
            }

            if (!editMode)
            {
                ColumnDataType columnDataType = ColumnDataType.Boolean | ColumnDataType.Numeric | ColumnDataType.Text;
                foreach (string s in dashboardHelper.GetFieldsAsList(columnDataType))
                {
                    if (txtDestinationField.Text.ToLower().Equals(s.ToLower()))
                    {
                        MsgBox.ShowError("Destination field name already exists as a column in this data set. Please use another name.");
                        this.DialogResult = DialogResult.None;
                        return;
                    }
                }

                foreach (IDashboardRule rule in dashboardHelper.Rules)
                {
                    if (rule is DataAssignmentRule)
                    {
                        DataAssignmentRule assignmentRule = rule as DataAssignmentRule;
                        if (txtDestinationField.Text.ToLower().Equals(assignmentRule.DestinationColumnName.ToLower()))
                        {
                            MsgBox.ShowError("Destination field name already exists as a defined field with recoded values. Please use another field name.");
                            this.DialogResult = DialogResult.None;
                            return;
                        }
                    }
                }
            }

            string friendlyRule = "Recode the values in " + sourceColumnName + " to " + txtDestinationField.Text + "";
            string sourceColumnType = dashboardHelper.GetColumnType(sourceColumnName);
            RecodeRule = new Rule_Recode(this.DashboardHelper, friendlyRule, sourceColumnName, sourceColumnType, txtDestinationField.Text, DestinationFieldType, RecodeTable, txtElseValue.Text, checkboxMaintainSortOrder.Checked, checkboxUseWildcards.Checked);
        }