RecipeMonitorPosViewModel.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using FurnaceUI.Models;
  9. using FurnaceUI.Views.Recipes;
  10. namespace FurnaceUI.Views.Editors
  11. {
  12. public class RecipeMonitorPosViewModel : FurnaceUIViewModelBase
  13. {
  14. public RecipeLayoutEntityNormal NormalEntity { get; set; }
  15. private bool _isBetweenChecked;
  16. public bool IsBetweenChecked
  17. {
  18. get => _isBetweenChecked;
  19. set
  20. {
  21. _isBetweenChecked = value;
  22. NotifyOfPropertyChange(nameof(IsBetweenChecked));
  23. }
  24. }
  25. private bool _isSlotChecked;
  26. public bool IsSlotChecked
  27. {
  28. get => _isSlotChecked;
  29. set
  30. {
  31. _isSlotChecked = value;
  32. NotifyOfPropertyChange(nameof(IsSlotChecked));
  33. }
  34. }
  35. public void Close()
  36. {
  37. NormalEntity.MonitorPosition = IsBetweenChecked ? "BetweenCassette" : "Slot";
  38. ((Window)GetView())?.Close();
  39. }
  40. private ObservableCollection<string> items = new ObservableCollection<string>();
  41. public ObservableCollection<string> Items
  42. {
  43. get
  44. {
  45. return items;
  46. }
  47. set
  48. {
  49. items = value;
  50. NotifyOfPropertyChange(nameof(Items));
  51. }
  52. }
  53. protected override void OnViewLoaded(object view)
  54. {
  55. base.OnViewLoaded(view);
  56. //if (string.IsNullOrEmpty(NormalEntity.MonitorBetweenCassetteNo))
  57. //{
  58. // for (int i = 1; i <= 7; i++)
  59. // {
  60. // Items.Add("None");
  61. // }
  62. // return;
  63. //}
  64. //foreach (var item in NormalEntity.MonitorBetweenCassetteNo.Split(','))
  65. //{
  66. // Items.Add(item);
  67. //}
  68. IsSlotChecked = NormalEntity.MonitorPosition == "Slot";
  69. IsBetweenChecked = !IsSlotChecked;
  70. }
  71. public void BtnClick(int iIndex, object strContent)
  72. {
  73. if (iIndex <= 0) return;
  74. string strValue = string.Empty;
  75. if (strContent.Equals("OFF"))
  76. strValue = "ON";
  77. else
  78. strValue = "OFF";
  79. Items[iIndex - 1] = strValue;
  80. }
  81. protected override void OnDeactivate(bool close)
  82. {
  83. base.OnDeactivate(close);
  84. //NormalEntity.MonitorBetweenCassetteNo = string.Empty;
  85. //foreach (var item in Items)
  86. //{
  87. // NormalEntity.MonitorBetweenCassetteNo += "," + item;
  88. //}
  89. //NormalEntity.MonitorBetweenCassetteNo = NormalEntity.MonitorBetweenCassetteNo.Substring(1);
  90. }
  91. }
  92. }