/// <summary> /// Constructor used for editing an existing format rule /// </summary> public FormatDialog(DashboardHelper dashboardHelper, Rule_Format formatRule) { InEditMode = true; this.dashboardHelper = dashboardHelper; this.formatRule = formatRule; InitializeComponent(); FillSelectionComboboxes(); this.txtDestinationField.Text = formatRule.DestinationColumnName; this.txtDestinationField.Enabled = false; this.cbxFieldName.Enabled = false; }
private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtDestinationField.Text)) { MsgBox.ShowError("Destination field is blank."); this.DialogResult = DialogResult.None; return; } else if (cbxFormatOptions.SelectedIndex < 0) { MsgBox.ShowError("No format options selected."); this.DialogResult = DialogResult.None; return; } if (!editMode) { foreach (string s in dashboardHelper.GetFieldsAsList()) { if (txtDestinationField.Text.ToLowerInvariant().Equals(s.ToLowerInvariant())) { 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.ToLowerInvariant().Equals(assignmentRule.DestinationColumnName.ToLowerInvariant())) { MsgBox.ShowError("Destination field name already exists as a defined field with recoded values. Please use another field name."); this.DialogResult = DialogResult.None; return; } } } } FormatRule = new Rule_Format(this.dashboardHelper, "Format the display of " + cbxFieldName.SelectedItem.ToString() + " to show " + cbxFormatOptions.SelectedItem.ToString() + " and place the formatted values in " + txtDestinationField.Text, cbxFieldName.SelectedItem.ToString(), txtDestinationField.Text, cbxFormatOptions.SelectedItem.ToString(), GetFormatType()); this.DialogResult = DialogResult.OK; this.Close(); }
private void cbxFormatOptions_SelectedIndexChanged(object sender, EventArgs e) { if (cbxFormatOptions.SelectedIndex >= 0) { FormatTypes type = GetFormatType(); if (type != FormatTypes.EpiWeek) { Rule_Format tempFormatRule = new Rule_Format(dashboardHelper, "temp", "temp", "temp", "temp", type); string formatString = tempFormatRule.GetFormatString(); txtPreview.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, formatString, DateTime.Now); } else { StatisticsRepository.EpiWeek epiWeek = new StatisticsRepository.EpiWeek(); txtPreview.Text = epiWeek.GetEpiWeek(DateTime.Now).ToString().Trim(); } } }
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()); } } } } }