// passing public void AddNewPassword() { // 表单验证 if (string.IsNullOrEmpty(TagNameAdded)) { WindowToolTip = "Please choose or add a tag for the password"; return; } if (string.IsNullOrEmpty(PasswordForm.Title)) { WindowToolTip = "Please fill the title"; return; } if (string.IsNullOrEmpty(PasswordForm.Password)) { WindowToolTip = "Please enter the password!"; } if (!PasswordForm.Website.StartsWith("https://")) { PasswordForm.Website = "https://" + PasswordForm.Website; } if (DbHelper.IfTagedPasswordListContain(TagList, TagNameAdded)) { // 如果该 tag 在列表中已存在 int tagId = DbHelper.GetTagId(TagNameAdded); // 保留明文密码 string password = PasswordForm.Password; string encryptedPassword = Encryptor.AESEncrypt(PasswordForm.Password, KeyPassword); PasswordForm.TagId = tagId; PasswordForm.Avatar = AvatarDictionary.GetAvatarPath(PasswordForm.Title); PasswordForm.Password = encryptedPassword; DbHelper.InsertPasswordItem(PasswordForm); // 处理好后将密码明文添加进TagList PasswordForm.Password = password; AddPasswordToTagList(PasswordForm, TagNameAdded); } else { // tag 不存在, 将新来的 tag 入表 // 插入新 tag 返回 tag Id int tagId = DbHelper.InsertTagName(TagNameAdded); // 重复,待优化 string password = PasswordForm.Password; string encryptedPassword = Encryptor.AESEncrypt(PasswordForm.Password, KeyPassword); PasswordForm.TagId = tagId; PasswordForm.Avatar = AvatarDictionary.GetAvatarPath(PasswordForm.Title); PasswordForm.Password = encryptedPassword; DbHelper.InsertPasswordItem(PasswordForm); // 处理好后将密码明文添加进TagList PasswordForm.Password = password; AddPasswordToTagList(PasswordForm, TagNameAdded); } UpdateTagList(); PasswordForm.Clean(); Switcher.AddNewPassword(); }