/// <summary> /// Called when toggle missing status button is pressed. Changes key missing status. /// </summary> protected void toggleMissingClicked(object o, EventArgs e) { int keyId = keyView.SelectedDbId; try { if (keyRegister.getKeyById(keyId).IsMissing) { keyRegister.setKeyToNotMissingById(keyId); } else { keyRegister.setKeyToMissingById(keyId); } } catch (KeyRegister.KeyIdNotFoundException) { return; } 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; } }