예제 #1
0
        /// <summary>
        /// Met à jour les données d'une fiche d'authentification.
        /// </summary>
        /// <param name="_authenCardData">Liste de données d'une fiche d'authentification</param>
        /// <returns>Boolean : True -> Données mise à jour. False -> Valeur null.</returns>
        public static bool UpdateAuthenCardData(List <string> _authenCardData)
        {
            try
            {
                bool success = false;

                using (SqlConnection connectionSQL = new SqlConnection(Data_VaultDatabase.Default.VaultDatabaseConnectionString))
                {
                    connectionSQL.Open();

                    string queryUpdate_1     = "UPDATE [tbl_authenCard] SET [authenCardName]=@authenCardName, [authenCardShortcut]=@authenCardShortcut, [authenCardUsername]=@authenCardUsername,";
                    string queryUpdate_2     = " [authenCardPassword]=@authenCardPassword, [authenCardComplexity]=@authenCardComplexity, [authenCardScrNote]=@authenCardScrNote, ";
                    string queryUpdate_3     = "[authenCardBookmark]=@authenCardBookmark, [authenCardChangeDate]=@authenCardChangeDate, [idCategory]=@idCategory";
                    string queryUpdate_4     = " WHERE [idVault]=@idVault AND [idAuthenCard]=@idAuthenCard;";
                    string queryUpdate_Final = queryUpdate_1 + queryUpdate_2 + queryUpdate_3 + queryUpdate_4;

                    using (SqlCommand commandSQL = new SqlCommand(queryUpdate_Final, connectionSQL))
                    {
                        const int     NUMBER_LINE_ASSIGNS = 1;
                        List <string> authenCardData      = _authenCardData;
                        string        categoryID          = VaultDatabase.GetCategoryID(authenCardData[8]);

                        byte[] cipheredACardUsername = Convert.FromBase64String(authenCardData[2]);
                        byte[] cipheredACardPassword = Convert.FromBase64String(authenCardData[3]);
                        byte[] cipheredACardScrNote  = Convert.FromBase64String(authenCardData[5]);

                        // Ajoute une valeur à l'endroit spécifié dans la commande SQL.
                        commandSQL.Parameters.AddWithValue("@authenCardName", authenCardData[0]);
                        commandSQL.Parameters.AddWithValue("@authenCardShortcut", authenCardData[1]);
                        commandSQL.Parameters.AddWithValue("@authenCardUsername", cipheredACardUsername);
                        commandSQL.Parameters.AddWithValue("@authenCardPassword", cipheredACardPassword);
                        commandSQL.Parameters.AddWithValue("@authenCardComplexity", authenCardData[4]);
                        commandSQL.Parameters.AddWithValue("@authenCardScrNote", cipheredACardScrNote);
                        commandSQL.Parameters.AddWithValue("@authenCardBookmark", authenCardData[6]);
                        commandSQL.Parameters.AddWithValue("@authenCardChangeDate", authenCardData[7]);
                        commandSQL.Parameters.AddWithValue("@idVault", VaultID);
                        commandSQL.Parameters.AddWithValue("@idCategory", categoryID);
                        commandSQL.Parameters.AddWithValue("@idAuthenCard", authenCardData[9]);

                        // Exécute la commande SQL.
                        success = (commandSQL.ExecuteNonQuery() == NUMBER_LINE_ASSIGNS);
                    }
                }

                return(success);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show(Data_VaultDatabase.Default.UpdateAuthenCardData);
                return(false);
            }
        }
        /// <summary>
        /// Met à jour les données d'une note sécurisée.
        /// </summary>
        /// <param name="_authenCardData">Liste de données d'une fiche d'authentification</param>
        /// <returns>Boolean : True -> Données mise à jour. False -> Valeur null.</returns>
        public static bool UpdateScrNoteData(List <string> _scrNoteData)
        {
            try
            {
                bool success = false;

                using (SqlConnection connectionSQL = new SqlConnection(Data_VaultDatabase.Default.VaultDatabaseConnectionString))
                {
                    connectionSQL.Open();

                    string queryUpdate_1     = "UPDATE [tbl_scrNote] SET [scrNoteName]=@scrNoteName, [scrNoteContent]=@scrNoteContent,";
                    string queryupdate_2     = " [scrNoteBookmark]=@scrNoteBookmark, [scrNoteChangeDate]=@scrNoteChangeDate, [idCategory]=@idCategory";
                    string queryUpdate_3     = "  WHERE [idVault]=@idVault AND [idScrNote]=@idScrNote;";
                    string queryUpdate_Final = queryUpdate_1 + queryupdate_2 + queryUpdate_3;

                    using (SqlCommand commandSQL = new SqlCommand(queryUpdate_Final, connectionSQL))
                    {
                        const int     NUMBER_LINE_ASSIGNS = 1;
                        List <string> scrNoteData         = _scrNoteData;
                        string        categoryID          = VaultDatabase.GetCategoryID(scrNoteData[4]);

                        byte[] cipheredScrNoteContent = Convert.FromBase64String(scrNoteData[1]);

                        // Ajoute une valeur à l'endroit spécifié dans la commande SQL.
                        commandSQL.Parameters.AddWithValue("@scrNoteName", scrNoteData[0]);
                        commandSQL.Parameters.AddWithValue("@scrNoteContent", cipheredScrNoteContent);
                        commandSQL.Parameters.AddWithValue("@scrNoteBookmark", scrNoteData[2]);
                        commandSQL.Parameters.AddWithValue("@scrNoteChangeDate", scrNoteData[3]);
                        commandSQL.Parameters.AddWithValue("@idVault", VaultID);
                        commandSQL.Parameters.AddWithValue("@idCategory", categoryID);
                        commandSQL.Parameters.AddWithValue("@idScrNote", scrNoteData[5]);

                        // Exécute la commande SQL.
                        success = (commandSQL.ExecuteNonQuery() == NUMBER_LINE_ASSIGNS);
                    }
                }

                return(success);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show(Data_VaultDatabase.Default.UpdateScrNoteData);
                return(false);
            }
        }