123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using LoginGenerator.Models;
- using ReactiveUI;
- namespace LoginGenerator.ViewModels
- {
- public class DataOutputViewModel : ReactiveObject
- {
- public string[] AllData;
- private List<Users>? users;
- public List<Users>? Userss { get => users; set => this.RaiseAndSetIfChanged(ref users, value); }
- public string[] OneUser;
- public Users u;
- public DataOutputViewModel()
- {
- Userss = new List<Users>();
- FillingUsersList();
- Sort = new List<string>() { "Äàòà ïî óáûâàíèþ", "Äàòà ïî âîçðàñòàíèþ" };
- SelectedSort = Sort[0];
- }
- public void FillingUsersList()
- {
- if (!File.Exists(FilePath.PATH))
- {
- var file = File.Create(FilePath.PATH);
- file.Close();
- }
- AllData = File.ReadAllLines(FilePath.PATH);
- List<Users>? newUsers = new List<Users>();
- foreach (string user in AllData)
- {
- if (!string.IsNullOrEmpty(user))
- {
- u = new Users();
- OneUser = user.Split(' ');
- u.Surname = OneUser[0].ToString();
- u.Name = OneUser[1].ToString();
- u.Patronymic = OneUser[2].ToString();
- u.Login = OneUser[3].ToString();
- u.Password = OneUser[4].ToString();
- u.DateReg = Convert.ToDateTime(OneUser[5]);
- newUsers.Add(u);
- }
- }
- Userss = newUsers;
- }
- private string? _findPass;
- public string? FindPass
- {
- get => _findPass;
- set
- {
- _findPass = value;
- Filter();
- }
- }
- private string? _findLogin;
- public string? FindLogin
- {
- get => _findLogin;
- set
- {
- _findLogin = value;
- Filter();
- }
- }
- private string? _findFio;
- public string? FindFio
- {
- get => _findFio;
- set
- {
- _findFio = value;
- Filter();
- }
- }
- private static List<string>? _sort;
- public static List<string>? Sort { get => _sort; set => _sort = value; }
- private string? _selectedSort;
- public string? SelectedSort
- {
- get
- {
- return _selectedSort;
- }
- set
- {
- _selectedSort = value;
- Filter();
- }
- }
- public void Filter()
- {
- FillingUsersList();
- switch (SelectedSort)
- {
- case "Äàòà ïî óáûâàíèþ":
- Userss = Userss.OrderByDescending(x => x.DateReg).ToList();
- break;
- case "Äàòà ïî âîçðàñòàíèþ":
- Userss = Userss.OrderBy(x => x.DateReg).ToList();
- break;
- }
- if (FindFio != null && FindFio != "")
- {
- Userss = Userss.Where(x => x.Name.ToUpper().Contains(FindFio.ToString().ToUpper()) || x.Surname.ToUpper().Contains(FindFio.ToString().ToUpper()) ||
- x.Patronymic.ToUpper().Contains(FindFio.ToString().ToUpper())).ToList();
- }
- if (FindLogin != null && FindLogin != "")
- {
- Userss = Userss.Where(x => x.Login.Contains(FindLogin.ToString())).ToList();
- }
- if (FindPass != null && FindPass != "")
- {
- Userss = Userss.Where(x => x.Password.Contains(FindPass.ToString())).ToList();
- }
- }
- }
- }
|