public static void AddRecord(string name, string url, string user, string pswd, string note) { SQLiteConnection conn = new SQLiteConnection(String.Format("Data Source={0};Version=3;", App.DB_PATH)); conn.Open(); using (DbCommand command = conn.CreateCommand()) { command.CommandText = "INSERT INTO services (name, url) VALUES(@Name, @URL)"; command.Parameters.Add(new SQLiteParameter("Name", name)); command.Parameters.Add(new SQLiteParameter("URL", url)); try { command.ExecuteNonQuery(); } catch (SQLiteException e) { throw new DBInsertServiceException(e.Message); } } using (DbCommand command = conn.CreateCommand()) { string secret = SecretHelper.Encrypt(pswd); if (String.IsNullOrWhiteSpace(note)) { note = null; } command.CommandText = "INSERT INTO keypairs (service, user, secret, note) " + "SELECT id, @Username, @Secret, @Note FROM services WHERE name LIKE @Name LIMIT 1"; command.Parameters.Add(new SQLiteParameter("Name", name)); command.Parameters.Add(new SQLiteParameter("Username", user)); command.Parameters.Add(new SQLiteParameter("Secret", secret)); command.Parameters.Add(new SQLiteParameter("Note", note)); try { command.ExecuteNonQuery(); } catch (SQLiteException e) { throw new DBInsertServiceException(e.Message); } } conn.Close(); }
private void clipFlow(bool reset) { this.clipState = reset? ClipState.INIT : (this.clipState <= ClipState.WAIT || this.clipState == ClipState.CLEANUP) ? this.clipState : // just keep holding Enum.GetValues(typeof(ClipState)).Cast <ClipState>().SkipWhile(e => e != this.clipState).Skip(1).FirstOrDefault(); if (null != LblURL.Background) { LblURL.Background = null; } if (null != LblUser.Background) { LblUser.Background = null; } if (null != LblPswd.Background) { LblPswd.Background = null; } switch (this.clipState) { case ClipState.URL: Clipboard.SetText(LblURL.Content.ToString()); LblURL.Background = Brushes.GreenYellow; LblCount.Content = "Copied!"; break; case ClipState.USER: Clipboard.SetText(LblUser.Content.ToString()); LblUser.Background = Brushes.GreenYellow; LblCount.Content = "Copied!!"; break; case ClipState.SECRET: string raw = SecretHelper.Decrypt(LblPswd.Content.ToString()); Clipboard.SetText(raw); LblPswd.Background = Brushes.OrangeRed; LblCount.Content = "Copied!!!"; break; case ClipState.CLEANUP: LblCount.Content = "Cleared!"; Clipboard.Clear(); return; } }