private void mnuNewVariableGroupRule_Click(object sender, RoutedEventArgs e)
        {
            EpiDashboard.Dialogs.CreateGroupDialog groupDialog = new EpiDashboard.Dialogs.CreateGroupDialog(this.dashboardHelper);
            System.Windows.Forms.DialogResult      result      = groupDialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                // Add to the list of format rules
                dashboardHelper.AddRule(groupDialog.Group);

                // Update the UI listbox
                UpdateRules();
                if (UserVariableChanged != null)
                {
                    UserVariableChanged(this, new EventArgs());
                }
            }
        }
        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());
                        }
                    }
                }
            }
        }
        private void mnuNewVariableGroupRule_Click(object sender, RoutedEventArgs e)
        {
            EpiDashboard.Dialogs.CreateGroupDialog groupDialog = new EpiDashboard.Dialogs.CreateGroupDialog(this.dashboardHelper);
            System.Windows.Forms.DialogResult result = groupDialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                // Add to the list of format rules
                dashboardHelper.AddRule(groupDialog.Group);

                // Update the UI listbox
                UpdateRules();
                if (UserVariableChanged != null)
                {
                    UserVariableChanged(this, new EventArgs());
                }
            }
        }
        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());
                        }
                    }
                }
            }
        }