Пример #1
0
        /// <summary>
        /// Constructor used for editing an existing format rule
        /// </summary>
        /// <param name="dashboardHelper">The dashboard helper to attach</param>
        public SimpleAssignDialog(DashboardHelper dashboardHelper, Rule_SimpleAssign assignRule)
        {
            InEditMode = true;
            this.dashboardHelper = dashboardHelper;
            this.AssignRule = assignRule;
            InitializeComponent();

            SimpleAssignType assignType = assignRule.AssignmentType;

            switch (assignType)
            {
                case SimpleAssignType.YearsElapsed:
                    cbxAssignmentType.SelectedIndex = 0;
                    break;
                case SimpleAssignType.MonthsElapsed:
                    cbxAssignmentType.SelectedIndex = 1;
                    break;
                case SimpleAssignType.DaysElapsed:
                    cbxAssignmentType.SelectedIndex = 2;
                    break;
                case SimpleAssignType.HoursElapsed:
                    cbxAssignmentType.SelectedIndex = 3;
                    break;
                case SimpleAssignType.MinutesElapsed:
                    cbxAssignmentType.SelectedIndex = 4;
                    break;
                case SimpleAssignType.Round:
                    cbxAssignmentType.SelectedIndex = 5;
                    break;
                case SimpleAssignType.TextToNumber:
                    cbxAssignmentType.SelectedIndex = 6;
                    break;
                case SimpleAssignType.StringLength:
                    cbxAssignmentType.SelectedIndex = 7;
                    break;
                case SimpleAssignType.FindText:
                    cbxAssignmentType.SelectedIndex = 8;
                    break;
                case SimpleAssignType.Substring:
                    cbxAssignmentType.SelectedIndex = 9;
                    break;
                case SimpleAssignType.Uppercase:
                    cbxAssignmentType.SelectedIndex = 10;
                    break;
                case SimpleAssignType.Lowercase:
                    cbxAssignmentType.SelectedIndex = 11;
                    break;
                case SimpleAssignType.AddDays:
                    cbxAssignmentType.SelectedIndex = 12;
                    break;
                case SimpleAssignType.DetermineNonExistantListValues:
                    cbxAssignmentType.SelectedIndex = 13;
                    break;
                case SimpleAssignType.CountCheckedCheckboxesInGroup:
                    cbxAssignmentType.SelectedIndex = 14;
                    break;
                case SimpleAssignType.CountYesMarkedYesNoFieldsInGroup:
                    cbxAssignmentType.SelectedIndex = 15;
                    break;
                case SimpleAssignType.DetermineCheckboxesCheckedInGroup:
                    cbxAssignmentType.SelectedIndex = 16;
                    break;
                case SimpleAssignType.DetermineYesMarkedYesNoFieldsInGroup:
                    cbxAssignmentType.SelectedIndex = 17;
                    break;
                case SimpleAssignType.CountNumericFieldsBetweenValuesInGroup:
                    cbxAssignmentType.SelectedIndex = 18;
                    break;
                case SimpleAssignType.CountNumericFieldsOutsideValuesInGroup:
                    cbxAssignmentType.SelectedIndex = 19;
                    break;
                case SimpleAssignType.FindSumNumericFieldsInGroup:
                    cbxAssignmentType.SelectedIndex = 20;
                    break;
                case SimpleAssignType.FindMeanNumericFieldsInGroup:
                    cbxAssignmentType.SelectedIndex = 21;
                    break;
                case SimpleAssignType.FindMaxNumericFieldsInGroup:
                    cbxAssignmentType.SelectedIndex = 22;
                    break;
                case SimpleAssignType.FindMinNumericFieldsInGroup:
                    cbxAssignmentType.SelectedIndex = 23;
                    break;
                case SimpleAssignType.CountFieldsWithMissingInGroup:
                    cbxAssignmentType.SelectedIndex = 24;
                    break;
                case SimpleAssignType.CountFieldsWithoutMissingInGroup:
                    cbxAssignmentType.SelectedIndex = 25;
                    break;
                case SimpleAssignType.DetermineFieldsWithMissingInGroup:
                    cbxAssignmentType.SelectedIndex = 26;
                    break;
                case SimpleAssignType.NumberToText:
                    cbxAssignmentType.SelectedIndex = 27;
                    break;
                case SimpleAssignType.StripDate:
                    cbxAssignmentType.SelectedIndex = 28;
                    break;
                case SimpleAssignType.TextToDate:
                    cbxAssignmentType.SelectedIndex = 29;
                    break;
            }

            FillSelectionComboBoxes();

            this.txtDestinationField.Text = AssignRule.DestinationColumnName;
            this.txtDestinationField.Enabled = false;
        }
Пример #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtDestinationField.Text))
            {
                MsgBox.ShowError(SimpleAssignmentStrings.ERROR_DESTINATION_FIELD_MISSING);
                this.DialogResult = DialogResult.None;
                return;
            }

            if (cbxAssignmentType.SelectedIndex < 0)
            {
                MsgBox.ShowError(SimpleAssignmentStrings.ERROR_TYPE_MISSING);
                this.DialogResult = DialogResult.None;
                return;
            }

            if (
                (cbxParam1.Visible == true && string.IsNullOrEmpty(cbxParam1.Text))
                || (cbxParam2.Visible == true && string.IsNullOrEmpty(cbxParam2.Text))
                || (cbxParam3.Visible == true && string.IsNullOrEmpty(cbxParam3.Text))
                )
            {
                MsgBox.ShowError(SimpleAssignmentStrings.ERROR_PARAMS_BLANK);
                this.DialogResult = DialogResult.None;
                return;
            }

            bool overwritesPermanentField = false;
            if (this.AssignRule != null)
            {
                overwritesPermanentField = this.AssignRule.OverwritesPermanentField;
            }

            if (!editMode)
            {
                ColumnDataType columnDataType = ColumnDataType.Boolean | ColumnDataType.Numeric | ColumnDataType.Text;

                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(SimpleAssignmentStrings.ERROR_FIELD_ALREADY_EXISTS_WITH_RECODED_DATA);
                            this.DialogResult = DialogResult.None;
                            return;
                        }
                    }
                }

                foreach (string s in dashboardHelper.GetFieldsAsList(columnDataType))
                {
                    if (txtDestinationField.Text.ToLower().Equals(s.ToLower()))
                    {
                        System.Windows.Forms.DialogResult result = MsgBox.ShowQuestion(SimpleAssignmentStrings.OVERWRITE_FIELD_DATA);
                        if (result != System.Windows.Forms.DialogResult.Yes && result != System.Windows.Forms.DialogResult.OK)
                        {
                            this.DialogResult = DialogResult.None;
                            return;
                        }
                        else
                        {
                            overwritesPermanentField = true;
                        }
                    }
                }
            }

            string friendlyLabel = "Assign " + txtDestinationField.Text;

            string param1 = cbxParam1.Text.ToString();
            string param2 = cbxParam2.Text.ToString();
            string param3 = cbxParam3.Text.ToString();

            List<string> parameters = new List<string>();
            parameters.Add(param1);
            if (!string.IsNullOrEmpty(param2)) { parameters.Add(param2); }
            if (!string.IsNullOrEmpty(param3)) { parameters.Add(param3); }
            SimpleAssignType assignmentType = SimpleAssignType.YearsElapsed;

            //switch (cbxAssignmentType.SelectedItem.ToString())
            switch (cbxAssignmentType.SelectedIndex)
            {
                case 0: //"Difference in years":
                    friendlyLabel = friendlyLabel + " the difference in years between " + param1 + " and " + param2;
                    assignmentType = SimpleAssignType.YearsElapsed;
                    break;
                case 1: //"Difference in months":
                    friendlyLabel = friendlyLabel + " the difference in months between " + param1 + " and " + param2;
                    assignmentType = SimpleAssignType.MonthsElapsed;
                    break;
                case 2: //"Difference in days":
                    friendlyLabel = friendlyLabel + " the difference in days between " + param1 + " and " + param2;
                    assignmentType = SimpleAssignType.DaysElapsed;
                    break;
                case 3: //"Difference in hours":
                    friendlyLabel = friendlyLabel + " the difference in hours between " + param1 + " and " + param2;
                    assignmentType = SimpleAssignType.HoursElapsed;
                    break;
                case 4: //"Difference in minutes":
                    friendlyLabel = friendlyLabel + " the difference in minutes between " + param1 + " and " + param2;
                    assignmentType = SimpleAssignType.MinutesElapsed;
                    break;
                case 5: //"Round a number":
                    friendlyLabel = friendlyLabel + " the rounded value of " + param1;
                    if (!string.IsNullOrEmpty(param2))
                    {
                        friendlyLabel = friendlyLabel + " to " + param2 + " decimal place(s)";
                    }
                    assignmentType = SimpleAssignType.Round;
                    break;
                case 6: //"Convert text data to numeric data":
                    friendlyLabel = friendlyLabel + " the numeric representation of " + param1;
                    assignmentType = SimpleAssignType.TextToNumber;
                    break;
                case 7: //"Find the length of text data":
                    friendlyLabel = friendlyLabel + " the length of the text contained in " + param1;
                    assignmentType = SimpleAssignType.StringLength;
                    break;
                case 8: //"Find the location of text data":
                    friendlyLabel = friendlyLabel + " the starting location of the text " + param2 + " contained in " + param1;
                    assignmentType = SimpleAssignType.FindText;
                    break;
                case 9: //"Substring":
                    friendlyLabel = friendlyLabel + " the portion of the text contained in " + param1 + " starting at position " + param2 + " and continuing for " + param3 + " characters";
                    assignmentType = SimpleAssignType.Substring;
                    break;

                // New ones added after 7.0.9.48
                case 10: //"Convert text characters to uppercase":
                    friendlyLabel = friendlyLabel + " the upper case equivalent of " + param1;
                    assignmentType = SimpleAssignType.Uppercase;
                    break;
                case 11: //"Convert text characters to lower":
                    friendlyLabel = friendlyLabel + " the lower case equivalent of " + param1;
                    assignmentType = SimpleAssignType.Lowercase;
                    break;

                // New ones added after 7.0.9.51
                case 12: //"Add days to a date field":
                    friendlyLabel = friendlyLabel + " the date value in " + param1 + " and add " + param2 + " days";
                    assignmentType = SimpleAssignType.AddDays;
                    break;
                case 13: //"Determine if a drop-down list field contains a value not present in its code table":
                    friendlyLabel = friendlyLabel + " a Yes if the value in " + param1 + " appears in its corresponding code table";
                    assignmentType = SimpleAssignType.DetermineNonExistantListValues;
                    break;
                case 14: //"Count the number of checked checkboxes in a group":
                    friendlyLabel = friendlyLabel + " the number of checked checkboxes in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.CountCheckedCheckboxesInGroup;
                    break;
                case 15: //"Count the number of Yes-marked Yes/No fields in a group":
                    friendlyLabel = friendlyLabel + " the number of Yes-marked Yes/No fields in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.CountYesMarkedYesNoFieldsInGroup;
                    break;
                case 16: //"Determine if more than N checkboxes are checked in a group":
                    friendlyLabel = friendlyLabel + " a Yes if more than " + param2 + " checkboxes are checked in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.DetermineCheckboxesCheckedInGroup;
                    break;
                case 17: //"Determine if more than N Yes/No fields are marked Yes in a group":
                    friendlyLabel = friendlyLabel + " a Yes if more than " + param2 + " Yes/No fields are marked Yes in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.DetermineYesMarkedYesNoFieldsInGroup;
                    break;
                case 18: //"Count the number of numeric fields with values between X and Y in a group":
                    friendlyLabel = friendlyLabel + " the number of numeric fields with values between (inclusive) " + param2 + " and " + param3 + " in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.CountNumericFieldsBetweenValuesInGroup;
                    break;
                case 19: //"Count the number of numeric fields with values outside X and Y in a group":
                    friendlyLabel = friendlyLabel + " the number of numeric fields with values outside " + param2 + " and " + param3 + " in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.CountNumericFieldsOutsideValuesInGroup;
                    break;
                case 20: //"Find the sum of all numeric fields in a group":
                    friendlyLabel = friendlyLabel + " the sum of all numeric fields in " + param1 + " (group field).";
                    if (param2 == dashboardHelper.Config.Settings.RepresentationOfYes) friendlyLabel = friendlyLabel + " Include Yes/No fields.";
                    else friendlyLabel = friendlyLabel + " Do not include Yes/No fields.";
                    if (param3 == dashboardHelper.Config.Settings.RepresentationOfYes) friendlyLabel = friendlyLabel + " Include Comment Legal fields.";
                    else friendlyLabel = friendlyLabel + " Do not include Comment Legal fields.";
                    assignmentType = SimpleAssignType.FindSumNumericFieldsInGroup;
                    break;
                case 21: //"Find the mean of all numeric fields in a group":
                    friendlyLabel = friendlyLabel + " the mean of all numeric fields in " + param1 + " (group field).";
                    if (param2 == dashboardHelper.Config.Settings.RepresentationOfYes) friendlyLabel = friendlyLabel + " Include Yes/No fields.";
                    else friendlyLabel = friendlyLabel + " Do not include Yes/No fields.";
                    if (param3 == dashboardHelper.Config.Settings.RepresentationOfYes) friendlyLabel = friendlyLabel + " Include Comment Legal fields.";
                    else friendlyLabel = friendlyLabel + " Do not include Comment Legal fields.";
                    assignmentType = SimpleAssignType.FindMeanNumericFieldsInGroup;
                    break;
                case 22: //"Find the maximum value of all numeric fields in a group":
                    friendlyLabel = friendlyLabel + " the maximum numeric value in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.FindMaxNumericFieldsInGroup;
                    break;
                case 23: //"Find the minimum value of all numeric fields in a group":
                    friendlyLabel = friendlyLabel + " the minimum numeric value in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.FindMinNumericFieldsInGroup;
                    break;
                case 24: //"Count the number of fields with missing values in a group":
                    friendlyLabel = friendlyLabel + " the number of fields with missing values in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.CountFieldsWithMissingInGroup;
                    break;
                case 25: //"Count the number of fields without missing values in a group":
                    friendlyLabel = friendlyLabel + " the number of fields without missing values in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.CountFieldsWithoutMissingInGroup;
                    break;
                case 26: //"Determine if more than N fields have missing values in a group":
                    friendlyLabel = friendlyLabel + " a Yes if more than " + param2 + " fields are missing in " + param1 + " (group field)";
                    assignmentType = SimpleAssignType.DetermineFieldsWithMissingInGroup;
                    break;
                case 27: //"Convert numeric data to text data":
                    friendlyLabel = friendlyLabel + " the text representation of " + param1;
                    assignmentType = SimpleAssignType.NumberToText;
                    break;
                case 28: //"Strip date":
                    friendlyLabel = friendlyLabel + " the date component of " + param1;
                    assignmentType = SimpleAssignType.StripDate;
                    break;
                case 29: //"Convert text data to date data":
                    friendlyLabel = friendlyLabel + " the date representation of " + param1;
                    assignmentType = SimpleAssignType.TextToDate;
                    break;
            }

            AssignRule = new Rule_SimpleAssign(this.dashboardHelper, friendlyLabel, txtDestinationField.Text, assignmentType, parameters);
            AssignRule.OverwritesPermanentField = overwritesPermanentField;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }