/// <summary> /// Called when remove key button is pressed. Handles key removal. /// </summary> protected void removeKeyClicked(object o, EventArgs e) { int dbId = keyView.SelectedDbId; Key key; // If getKeyById throws KeyIdNotFoundException nothing is selected. try { key = keyRegister.getKeyById(dbId); } catch (KeyRegister.KeyIdNotFoundException) { return; } bool doRemove = showConfirmationDialog("Do you really want to delete key with identifier '" + key.Identifier + "'?"); if (doRemove) { try { keyRegister.deleteKeyById(dbId); } catch (KeyRegister.DependencyException ex) { showInfoDialog(ex.Message); } doUpdates(); } }
///////////////////// // Other Methods // ///////////////////// /// <summary> /// Runs specified command with specified arguments /// </summary> public void runCommand(string[] argv) { string command = argv [0]; List <string> args = new List <string> (argv); args.RemoveAt(0); int dbId; switch (command) { //////////////////// // Key operations // //////////////////// case "listkeys": listKeys(); break; case "keydetails": if (int.TryParse(args[0], out dbId)) { getKeyDetails(dbId); } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "addkey": addKey(args); break; case "editkey": if (int.TryParse(args [0], out dbId)) { args.RemoveAt(0); editKey(dbId, args); } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "setkeymissing": if (int.TryParse(args [0], out dbId)) { try { keyRegister.setKeyToMissingById(dbId); } catch (KeyRegister.KeyIdNotFoundException e) { Console.WriteLine(e.Message); } } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "removekey": if (int.TryParse(args [0], out dbId)) { try { keyRegister.deleteKeyById(dbId); } catch (KeyRegister.KeyIdNotFoundException e) { Console.WriteLine(e.Message); } } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "loankey": case "addloan": if (int.TryParse(args [0], out dbId)) { args.RemoveAt(0); addLoanToKey(dbId, args); } else { Console.WriteLine("Provided id not parsable as integer!"); } break; ///////////////////// // Loan operations // ///////////////////// case "listloans": listLoans(); break; case "loandetails": if (int.TryParse(args[0], out dbId)) { getLoanDetails(dbId); } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "editloan": if (int.TryParse(args[0], out dbId)) { args.RemoveAt(0); editLoan(dbId, args); } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "returnloan": if (int.TryParse(args[0], out dbId)) { args.RemoveAt(0); setLoanReturned(dbId); } else { Console.WriteLine("Provided id not parsable as integer!"); } break; case "help": Console.WriteLine(usage + "\n" + helpString); break; default: Console.WriteLine("Unknown command"); break; } }