예제 #1
0
        void lbListOfCodes_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                frmSingleInputBox fGetCode      = new frmSingleInputBox("Please enter the code", ref sEngine);
                string            sOriginalCode = lbListOfCodes.Items[lbListOfCodes.SelectedIndex].ToString();
                string            sNewCode      = "";
                string            sDesc         = "";
                fGetCode.tbResponse.Text = lbListOfCodes.Items[lbListOfCodes.SelectedIndex].ToString();
                fGetCode.ShowDialog();
                if (fGetCode.Response != "$NONE")
                {
                    sNewCode = fGetCode.Response;
                    frmSingleInputBox fGetDesc = new frmSingleInputBox("Please enter the description", ref sEngine);
                    fGetDesc.tbResponse.Text = lbListOfCategories.Items[lbListOfCodes.SelectedIndex].ToString().TrimStart(' ');
                    fGetDesc.ShowDialog();
                    if (fGetDesc.Response != "$NONE")
                    {
                        sDesc = fGetDesc.Response;
                        sEngine.EditCategoryDetails(sOriginalCode, sNewCode, sDesc);
                        ListAllCategories();
                        lbListOfCodes.SelectedIndex = 0;
                        for (int i = 0; i < lbListOfCodes.Items.Count; i++)
                        {
                            if (lbListOfCodes.Items[i].ToString() == fGetCode.Response)
                            {
                                lbListOfCodes.SelectedIndex = i;
                            }
                        }
                    }
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            else if (e.KeyCode == Keys.Insert)
            {
                frmSingleInputBox fGetCode = new frmSingleInputBox("Enter the code for the new category:", ref sEngine);
                fGetCode.ShowDialog();
                if (fGetCode.Response != "$NONE")
                {
                    frmSingleInputBox fGetDesc = new frmSingleInputBox("Enter the description for the new category:", ref sEngine);
                    fGetDesc.ShowDialog();
                    if (fGetDesc.Response != "$NONE")
                    {
                        sEngine.AddCategory(fGetCode.Response, fGetDesc.Response);
                        ListAllCategories();
                        lbListOfCodes.SelectedIndex = 0;

                        for (int i = 0; i < lbListOfCodes.Items.Count; i++)
                        {
                            if (lbListOfCodes.Items[i].ToString() == fGetCode.Response)
                            {
                                lbListOfCodes.SelectedIndex = i;
                            }
                        }
                    }
                }
            }
        }