RecipePermissionSelectViewModel.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using OpenSEMI.ClientBase;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. namespace FurnaceUI.Views.Recipes
  10. {
  11. public class RecipePermissionSelectViewModel: DialogViewModel<string>
  12. {
  13. public RecipePermissionSelectViewModel(string DialogName="",string permission="", string comment = "")
  14. {
  15. this.DisplayName = DialogName;
  16. this.Comment = comment;
  17. switch(permission)
  18. {
  19. case "Read":
  20. CurrentPermission = 0;
  21. break;
  22. case "Read&Write":
  23. CurrentPermission = 1;
  24. break;
  25. case "Free":
  26. CurrentPermission = 2;
  27. break;
  28. default:
  29. CurrentPermission = 2;
  30. break;
  31. }
  32. }
  33. public ObservableCollection<string> permissionselections { get; set; }
  34. private int CurrentPermission;
  35. private string _comment;
  36. public string Comment
  37. {
  38. get
  39. {
  40. return _comment;
  41. }
  42. set
  43. {
  44. _comment = value;
  45. NotifyOfPropertyChange(nameof(Comment));
  46. }
  47. }
  48. private int _selectedPermission;
  49. public int SelectedPermission
  50. {
  51. get
  52. {
  53. return _selectedPermission;
  54. }
  55. set
  56. {
  57. _selectedPermission = value;
  58. NotifyOfPropertyChange(nameof(SelectedPermission));
  59. }
  60. }
  61. public string RecipePermission { get; set; }
  62. public string RecipeComment { get; set; }
  63. public string Dialogname { get; set; }
  64. protected override void OnInitialize()
  65. {
  66. base.OnInitialize();
  67. permissionselections = new ObservableCollection<string>() { "Read", "Read&Write","Free" };
  68. if (string.IsNullOrEmpty(CurrentPermission.ToString()))
  69. SelectedPermission = 2;
  70. else
  71. SelectedPermission = CurrentPermission;
  72. }
  73. protected override void OnActivate()
  74. {
  75. base.OnActivate();
  76. }
  77. public void OK()
  78. {
  79. RecipePermissionSelectView recipePermissionSelectView = ((Window)GetView()).Content as RecipePermissionSelectView;
  80. //RecipePermission = recipePermissionSelectView.cbPermission.Text;
  81. RecipePermission = "";
  82. RecipeComment = recipePermissionSelectView.tbComment.Text;
  83. IsCancel = false;
  84. TryClose(true);
  85. }
  86. public void Cancel()
  87. {
  88. IsCancel = true;
  89. TryClose(false);
  90. }
  91. }
  92. }