EscribePassword/Passwords.cs

65 lines
1.9 KiB
C#
Raw Permalink Normal View History

using CommunityToolkit.Mvvm.ComponentModel;
2024-06-17 04:40:34 -03:00
using System.Text.Json.Serialization;
namespace EscribePassword
{
public partial class Passwords : ObservableObject
{
[ObservableProperty]
private string usuario;
[ObservableProperty]
private string password;
[ObservableProperty]
private string categoria;
2024-06-17 04:40:34 -03:00
public static List<Passwords> ConvertArrayToPasswordsList(string[,] tableArray)
{
var passwordsList = new List<Passwords>();
for (int i = 0; i < tableArray.GetLength(0); i++)
{
var passwords = new Passwords();
if (tableArray.GetLength(1) >= 1)
passwords.Categoria = tableArray[i, 0];
if (tableArray.GetLength(1) >= 2)
passwords.Usuario = tableArray[i, 1];
if (tableArray.GetLength(1) >= 3)
passwords.Password = tableArray[i, 2];
passwordsList.Add(passwords);
}
return passwordsList;
}
public static string[,] ConvertPasswordsListToArray(List<Passwords> passwordsList)
{
if (passwordsList == null || passwordsList.Count == 0)
return new string[0, 0];
int rows = passwordsList.Count;
int columns = 3; // Asumimos que siempre hay tres columnas: Usuario, Password, Categoria
string[,] tableArray = new string[rows + 1, columns];
// Fill header
tableArray[0, 0] = "Class";
tableArray[0, 1] = "User";
tableArray[0, 2] = "Password";
// Fill data
for (int i = 0; i < rows; i++)
{
2024-06-17 04:40:34 -03:00
tableArray[i + 1, 0] = passwordsList[i].Categoria;
tableArray[i + 1, 1] = passwordsList[i].Usuario;
tableArray[i + 1, 2] = passwordsList[i].Password;
}
return tableArray;
}
}
}