public void DeleteDecoder() { if (grdModuleView.SelectedRowsCount <= 0) { MessageBox.Show("You must select the control device you want to delete.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!(grdModuleView.GetRow(grdModuleView.GetSelectedRows()[0]) is AccessoryDecoder decoder)) { return; } if (MessageBox.Show("Are you sure you want to delete the module " + decoder.Name + " and all its related data and configurations?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No) { return; } try { AccessoryDecoder.Delete(decoder.ID); // Also remove the module in current project OTCContext.Project.AccessoryDecoders.Remove(decoder); this.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CmdDecoderDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (tabDecoder.SelectedTabPage == tabDecoderAcc) { if (!(this.GetSelectedResource() is AccessoryDecoder accDecoder)) { return; } if (MessageBox.Show("Are you sure you want to remove the selected decoder?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { AccessoryDecoder.Delete(accDecoder); this.ListAccessoryDecoders(); } } else { if (!(this.GetSelectedResource() is FeedbackEncoder fbEncoder)) { return; } if (MessageBox.Show("Are you sure you want to remove the selected decoder?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { FeedbackEncoder.Delete(fbEncoder); this.ListFeedbackEncoders(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal void DeleteItem() { if (tlsDecoders.Selection.Count <= 0) { MessageBox.Show("No items selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TreeListNode node = tlsDecoders.Selection[0]; if (node == null) { return; } try { if (node.Tag is AccessoryDecoder) { AccessoryDecoder decoder = node.Tag as AccessoryDecoder; if (decoder == null) { return; } if (MessageBox.Show("Are you sure you want to delete the accessory decoder " + decoder.Name + "?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { AccessoryDecoder.Delete(decoder); this.RefreshTreeList(); } } else if (node.Tag is FeedbackEncoder) { FeedbackEncoder encoder = node.Tag as FeedbackEncoder; if (encoder == null) { return; } if (MessageBox.Show("Are you sure you want to delete the feedback encoder " + encoder.Name + "?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { FeedbackEncoder.Delete(encoder); this.RefreshTreeList(); } } else if (node.Tag is Module) { Module module = node.Tag as Module; if (module == null) { return; } if (MessageBox.Show("Are you sure you want to remove the layout module " + module.Name + "?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Module.Delete(module); this.RefreshTreeList(); } } } catch (Exception ex) { MessageBox.Show(Logger.LogError(this, ex), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }