public override void Run() { ItemForm form = new ItemForm(item); IItemRepository itemDao = new NHibernateItemRepository(); IUnitRepository unitDao = new NHibernateUnitRepository(); IVendorRepository vendorDao = new NHibernateVendorRepository(); form.UnitsList += delegate { form.Units = unitDao.FindActive(); }; form.VendorsList += delegate { form.Vendors = vendorDao.FindActive(); }; form.ItemSave += delegate(object sender, ItemEventArgs e) { itemDao.SaveOrUpdate(e.Item); form.Close(); }; WorkbenchSingleton.AddChild(form, "Edit Item"); }
private void Edit_KeyDown(object sender, KeyEventArgs e) { if (ShowFilter) { if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) { if (!FilterItemForm.Visible) { ShowDropDownFilter(); } int cnt = filterForm.ListBox.Items.Count; int idx = filterForm.ListBox.SelectedIndex; if (cnt > 0) { if (e.KeyCode == Keys.Down) { if (idx < cnt - 1) { filterForm.ListBox.SelectedIndex++; } } if (e.KeyCode == Keys.Up) { if (idx > 0) { filterForm.ListBox.SelectedIndex--; } } } } else if (e.KeyCode == Keys.Escape) { FilterItemForm.Close(); } else if (e.KeyCode == Keys.Return) { if (FilterItemForm.Visible) { int cnt = filterForm.ListBox.Items.Count; int idx = filterForm.ListBox.SelectedIndex; if (cnt > 0 && idx >= 0 && idx < cnt) { SelectTextChange = true; filterSelectedItem = filterList[idx]; filterSelectedValue = GetItemValue(filterSelectedItem); Text = GetItemText(filterSelectedItem).ToString(); edit.SelectionStart = Text.Length; SelectedValueChanged?.Invoke(this, EventArgs.Empty); SelectTextChange = false; } FilterItemForm.Close(); } else { ShowDropDownFilter(); } } else { base.OnKeyDown(e); } } else { if (e.KeyCode == Keys.Enter) { ShowDropDown(); } else if (e.KeyCode == Keys.Escape) { ItemForm.Close(); } else { base.OnKeyDown(e); } } }