VWMain.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Data.Entity;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Runtime.CompilerServices;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using Rkis29.Model;
  17. using Rkis29.View;
  18. namespace Rkis29.ViewModel
  19. {
  20. public class VWMain : INotifyPropertyChanged
  21. {
  22. public event PropertyChangedEventHandler PropertyChanged;
  23. public void OnPropertyChanged([CallerMemberName] string prop = "")
  24. {
  25. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
  26. }
  27. public void DataGoM(DataGrid d)
  28. {
  29. List<Model.Task> t = ModelPublic.GetContext().Task.Where(w => w.AcceptedTaskId == Users.Id && w.StatusTaskId != 3).ToList();
  30. d.ItemsSource = t;
  31. }
  32. private string _Profil;
  33. public string LbProfil { get { return _Profil; } set { _Profil = value; OnPropertyChanged(); } }
  34. public void SaveFIO()
  35. {
  36. var p = ModelPublic.GetContext().Person.FirstOrDefault(f => f.Id == Users.Id);
  37. _Profil = p.SurnameP + " " + p.NameP + " " + p.PatronomycP;
  38. }
  39. private RelayCommand _dataGo;
  40. public RelayCommand DataGo
  41. {
  42. get
  43. {
  44. return _dataGo ?? new RelayCommand(obj =>
  45. {
  46. var Grid = (DataGrid)obj;
  47. DataGoM(Grid);
  48. SaveFIO();
  49. OnPropertyChanged();
  50. });
  51. }
  52. }
  53. public static void Status(int IdTask, int Status, int IdPerson)
  54. {
  55. var t = ModelPublic.GetContext().Task.FirstOrDefault(w => w.Id == IdTask);
  56. t.StatusTaskId = Status;
  57. t.AcceptedTaskId = IdPerson;
  58. ModelPublic.GetContext().SaveChanges();
  59. }
  60. private RelayCommand _tbGo_Status;
  61. public RelayCommand TbGo_Status
  62. {
  63. get
  64. {
  65. return _tbGo_Status ?? new RelayCommand(obj =>
  66. {
  67. DataGrid dataGrid = (DataGrid)obj;
  68. if (dataGrid.SelectedItem is Model.Task t) //поиск выбранного элемента
  69. {
  70. if (t.StatusTaskId == 1)
  71. {
  72. Status(t.Id, 2, Users.Id);
  73. DataGoM(dataGrid);
  74. OnPropertyChanged();
  75. }
  76. else if (t.StatusTaskId == 2)
  77. {
  78. Status(t.Id, 3, Users.Id);
  79. DataGoM(dataGrid);
  80. OnPropertyChanged();
  81. }
  82. }
  83. });
  84. }
  85. }
  86. private RelayCommand _autho_ready;
  87. public RelayCommand Autho_ready
  88. {
  89. get
  90. {
  91. return _autho_ready ?? new RelayCommand(obj =>
  92. {
  93. Tasks task = new Tasks();
  94. task.Show();
  95. Window window = (Window)obj;
  96. window.Close();
  97. });
  98. }
  99. }
  100. }
  101. }