public void PreAction(GXActionArgs arg) { //Entries are handled using actions. if (arg.Index == 1) { GXDLMSSpecialDay it = new GXDLMSSpecialDay(); GXDLMSSpecialDaysTableDlg dlg = new GXDLMSSpecialDaysTableDlg(it, false); OnSpecialDaysDlg(arg, dlg, it); } else if (arg.Index == 2) { GXDLMSSpecialDaysTableDlg dlg = new GXDLMSSpecialDaysTableDlg(null, true); OnSpecialDaysDlg(arg, dlg, null); } }
void OnSpecialDaysDlg(GXActionArgs arg, GXDLMSSpecialDaysTableDlg dlg, GXDLMSSpecialDay it) { if (InvokeRequired) { BeginInvoke(new SpecialDaysDlgEventHandler(OnSpecialDaysDlg), arg, dlg, it).AsyncWaitHandle.WaitOne(); } else { bool remove = false; ListViewItem li = null; if (it == null) { remove = true; GXDLMSSpecialDaysTable target = Target as GXDLMSSpecialDaysTable; if (SpecialDay.SelectedItems.Count != 1) { arg.Handled = true; return; } else { li = SpecialDay.SelectedItems[0]; dlg.Item = it = (GXDLMSSpecialDay)li.Tag; } } if (dlg.ShowDialog(this) == DialogResult.OK) { GXDLMSSpecialDaysTable target = Target as GXDLMSSpecialDaysTable; if (!remove) { li = SpecialDay.Items.Add(it.Index.ToString()); li.SubItems.Add(it.Date.ToString()); li.SubItems.Add(it.DayId.ToString()); li.Tag = it; arg.Value = target.Insert(arg.Client, it); } else { arg.Value = target.Delete(arg.Client, it); li.Remove(); } } else { arg.Handled = true; } } }