private void butDuplicate_Click(object sender, EventArgs e) { if (gridCustom.GetSelectedIndex() == -1) { MsgBox.Show(this, "Please select an custom alert category from the list first."); return; } List <AlertCategory> listNewAlertCategories = _listInternalAlertCategory.Select(x => x.Copy()).ToList(); AlertCategory alertCat = _listCustomAlertCategory[gridCustom.GetSelectedIndex()].Copy(); alertCat.Description += Lan.g(this, "(Copy)"); listNewAlertCategories.Add(alertCat); //alertCat.AlertCategoryNum reflects the original pre-copied PK. After sync this will be a new PK for the new row. List <AlertCategoryLink> listAlertCategoryType = AlertCategoryLinks.GetForCategory(alertCat.AlertCategoryNum); if (AlertCategories.Sync(listNewAlertCategories, _listInternalAlertCategory)) { //At this point alertCat has a new PK, so we need to update and insert our new copied alertCategoryLinks listAlertCategoryType.ForEach(x => { x.AlertCategoryNum = alertCat.AlertCategoryNum; AlertCategoryLinks.Insert(x); }); DataValid.SetInvalid(InvalidType.AlertCategories, InvalidType.AlertCategoryLinks); FillGrids(selectedCustomKey: alertCat.AlertCategoryNum); } }
private void butDelete_Click(object sender, EventArgs e) { if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Are you sure you would like to delete this?")) { return; } AlertCategoryLinks.DeleteForCategory(_categoryCur.AlertCategoryNum); AlertCategories.Delete(_categoryCur.AlertCategoryNum); DataValid.SetInvalid(InvalidType.AlertCategories, InvalidType.AlertCategories); DialogResult = DialogResult.OK; }
private void FormAlertCategoryEdit_Load(object sender, EventArgs e) { textDesc.Text = _categoryCur.Description; listShownAlertTypes = Enum.GetValues(typeof(AlertType)).OfType <AlertType>().ToList(); listShownAlertTypes.RemoveAll(x => !PrefC.IsODHQ && x.IsODHQ()); if (_categoryCur.IsHQCategory) { textDesc.Enabled = false; butDelete.Enabled = false; butOK.Enabled = false; } listOldAlertCategoryLinks = AlertCategoryLinks.GetForCategory(_categoryCur.AlertCategoryNum); InitAlertTypeSelections(); }
private void InsertCopyAlertCategory(AlertCategory alertCat) { alertCat.IsHQCategory = false; alertCat.Description += Lan.g(this, "(Copy)"); //alertCat.AlertCategoryNum reflects the original pre-copied PK. After Insert this will be a new PK for the new row. List <AlertCategoryLink> listAlertCategoryType = AlertCategoryLinks.GetForCategory(alertCat.AlertCategoryNum); alertCat.AlertCategoryNum = AlertCategories.Insert(alertCat); //At this point alertCat has a new PK, so we need to update and insert our new copied alertCategoryLinks listAlertCategoryType.ForEach(x => { x.AlertCategoryNum = alertCat.AlertCategoryNum; AlertCategoryLinks.Insert(x); }); DataValid.SetInvalid(InvalidType.AlertCategories, InvalidType.AlertCategoryLinks); FillGrids(); }
private void butOK_Click(object sender, EventArgs e) { _categoryCur.Description = textDesc.Text; List <AlertType> listSelectedTypes = listBoxAlertTypes.SelectedIndices .OfType <int>() .Select(x => (AlertType)listShownAlertTypes[x]) .ToList(); List <AlertCategoryLink> listNewAlertCategoryType = listOldAlertCategoryLinks.Select(x => x.Copy()).ToList(); listNewAlertCategoryType.RemoveAll(x => !listSelectedTypes.Contains(x.AlertType)); //Remove unselected AlertTypes foreach (AlertType type in listSelectedTypes) { if (!listOldAlertCategoryLinks.Exists(x => x.AlertType == type)) //Add newly selected AlertTypes. { listNewAlertCategoryType.Add(new AlertCategoryLink(_categoryCur.AlertCategoryNum, type)); } } AlertCategoryLinks.Sync(listNewAlertCategoryType, listOldAlertCategoryLinks); AlertCategories.Update(_categoryCur); DataValid.SetInvalid(InvalidType.AlertCategoryLinks, InvalidType.AlertCategories); DialogResult = DialogResult.OK; }