Esempio n. 1
0
        void lbKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && lbCode.SelectedIndex >= 0)
            {
                Commissioner = lbCode.Items[((ListBox)sender).SelectedIndex].ToString();
                this.Close();
            }
            else if (e.KeyCode == Keys.Insert)
            {
                frmAddCommPerson facp = new frmAddCommPerson(ref sEngine);
                facp.ShowDialog();

                lbCode.Items.Clear();
                lbName.Items.Clear();
                string[] sCodes = sEngine.GetListOfCommissioners();
                for (int i = 0; i < sCodes.Length; i++)
                {
                    lbCode.Items.Add(sCodes[i]);
                    lbName.Items.Add(sEngine.GetCommissionerName(sCodes[i]));
                }

                if (lbCode.Items.Count > 0)
                {
                    lbCode.SelectedIndex = 0;
                }
            }
            else if (e.KeyCode == Keys.Delete && e.Shift)
            {
                // The user wants to delete the commissioner

                // First, check that there are no items in COMMITEM which use this commissioner

                if (!sEngine.CheckIfCommissionerIsUsed(lbCode.Items[lbCode.SelectedIndex].ToString()) || e.Control)
                {
                    sEngine.DeleteCommissioner(lbCode.Items[lbCode.SelectedIndex].ToString());
                    MessageBox.Show("Commissioner Deleted");
                    LoadCommissioners();
                }
                else
                {
                    MessageBox.Show("You can't delete this commissioner, as they are in use on a product. Use Ctrl+Shift+Delete if you are certain that it doesn't matter");
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }