private void ConditionControlDeleted(object sender, EventArgs e) { SmsConditionControl control = (SmsConditionControl)sender; EventCondition cond = control.EventCondition; if (cond.ItemId > 0 && MessageBox.Show("Do you really want to delete event condition?", "Deleting confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { //если информация о состоянии сохранена в БД //и получен положительный ответ на ее удаление try { GlobalObjects.CasEnvironment.NewKeeper.Delete(cond); Event.EventConditions.Remove(cond); } catch (Exception ex) { Program.Provider.Logger.Log("Error while removing data", ex); } flowLayoutPanelConditions.Controls.Remove(control); control.Deleted -= ConditionControlDeleted; control.Dispose(); } else if (cond.ItemId <= 0) { flowLayoutPanelConditions.Controls.Remove(control); control.Deleted -= ConditionControlDeleted; control.Dispose(); } }
private void LinkLabelAddNewConditionLinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (Event == null) { return; } SmsConditionControl performance = new SmsConditionControl(new EventCondition { ParentId = Event.ItemId }); performance.Deleted += ConditionControlDeleted; if (flowLayoutPanelConditions.Controls.Count > 1) { performance.ShowHeaders = false; } flowLayoutPanelConditions.Controls.Remove(panelAddCondition); flowLayoutPanelConditions.Controls.Add(performance); flowLayoutPanelConditions.Controls.Add(panelAddCondition); performance.Focus(); }
/// <summary> /// Обновляет значения полей /// </summary> public override void FillControls() { BeginUpdate(); dictionaryComboEventType.SelectedIndexChanged -= LookupComboboxEventTypeSelectedIndexChanged; dictionaryComboEventClass.SelectedIndexChanged -= DictionaryComboEventClassSelectedIndexChanged; dictionaryComboBoxCategory.SelectedIndexChanged -= DictionaryComboBoxCategorySelectedIndexChanged; comboBoxIncident.Items.Clear(); foreach (IncidentType o in IncidentType.Items) { comboBoxIncident.Items.Add(o); } dictionaryComboEventClass.Type = typeof(EventClass); dictionaryComboBoxCategory.Type = typeof(EventCategory); dictionaryComboEventType.Type = typeof(SmsEventType); dictionaryComboEventType.ScreenControl = new EventTypesListScreen(Event); foreach (Control c in flowLayoutPanelConditions.Controls) { if (c != panelAddCondition) { c.Dispose(); } } flowLayoutPanelConditions.Controls.Clear(); if (Event != null) { dictionaryComboEventType.SelectedItem = Event.EventType; dictionaryComboBoxCategory.SelectedItem = Event.EventCategory; dictionaryComboEventClass.SelectedItem = Event.EventClass; comboBoxIncident.SelectedItem = Event.IncidentType; dateTimePickerEventDate.Value = Event.RecordDate; textBoxDescription.Text = Event.Description; textBoxRemarks.Text = Event.Remarks; foreach (EventCondition condition in Event.EventConditions) { SmsConditionControl newControl = new SmsConditionControl(condition); newControl.Deleted += ConditionControlDeleted; if (flowLayoutPanelConditions.Controls.Count >= 1) { newControl.ShowHeaders = false; } flowLayoutPanelConditions.Controls.Add(newControl); } } flowLayoutPanelConditions.Controls.Add(panelAddCondition); SetExtendableControlCaption(); SetRiskIndex(); dictionaryComboEventType.SelectedIndexChanged += LookupComboboxEventTypeSelectedIndexChanged; dictionaryComboEventClass.SelectedIndexChanged += DictionaryComboEventClassSelectedIndexChanged; dictionaryComboBoxCategory.SelectedIndexChanged += DictionaryComboBoxCategorySelectedIndexChanged; EndUpdate(); }