MainWindowViewModel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Avalonia.Controls;
  2. using AvaloniaApplication5.Models;
  3. //using AvaloniaApplication5.Models;
  4. using AvaloniaApplication5.Views;
  5. using Microsoft.EntityFrameworkCore;
  6. using ReactiveUI;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Tmds.DBus.Protocol;
  10. namespace AvaloniaApplication5.ViewModels
  11. {
  12. public class MainWindowViewModel : ViewModelBase
  13. {
  14. static _1234Context DBConnect = new _1234Context();
  15. private UserControl uc = new PageLogin();
  16. public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
  17. #region VMLogin
  18. PageLoginViewModel pageLoginVM = new PageLoginViewModel();
  19. public PageLoginViewModel PageLoginVM { get => pageLoginVM; set => pageLoginVM = value; }
  20. public void LoadPageList()
  21. {
  22. Logintable? currentUser = DBConnect.Logintables.FirstOrDefault(x => x.Login == PageLoginVM.Login && x.Password == PageLoginVM.Password);
  23. if (currentUser != null)
  24. {
  25. switch (currentUser.IdRole)
  26. {
  27. case 1:
  28. UC = new PageUserList();
  29. break;
  30. case 2:
  31. PageUCabinetVM = new PageUserCabinetViewModel(DBConnect, currentUser.Id);
  32. UC = new PageUserCabinet();
  33. break;
  34. }
  35. }
  36. else PageLoginVM.Message = "Пользователь отсутствует в системе, либо указанные данные введены неверно";
  37. }
  38. #endregion
  39. #region VMUserCabinet
  40. private PageUserCabinetViewModel pageUCabinetVM;
  41. public PageUserCabinetViewModel PageUCabinetVM { get => pageUCabinetVM; set => pageUCabinetVM = value; }
  42. #endregion
  43. #region VMadmin
  44. private PageUserListViewModel pageUserListViewVM = new PageUserListViewModel(DBConnect);
  45. public PageUserListViewModel PageUserListViewVM { get => pageUserListViewVM; set => pageUserListViewVM = value; }
  46. UserControl ucAdmin;
  47. public UserControl UCAdmin
  48. {
  49. get => ucAdmin;
  50. set => this.RaiseAndSetIfChanged(ref ucAdmin, value);
  51. }
  52. public void EditUser(int id)
  53. {
  54. PageUCabinetVM = id == 0 ? new PageUserCabinetViewModel(DBConnect) : new PageUserCabinetViewModel(DBConnect, id);
  55. UCAdmin = new PageUserCabinet();
  56. }
  57. #endregion
  58. }
  59. }