ItemsSelectDialogViewModel.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  2. using MECF.Framework.UI.Client.ClientBase;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. namespace MECF.Framework.UI.Client.CenterViews.Dialogs
  8. {
  9. public class ItemsSelectDialogViewModel : ModuleUiViewModelBase
  10. {
  11. #region properties
  12. public bool IsRadio { get; set; } = false;//默认支持多选
  13. public bool IsSpin { get; set; } = false;//Spin module 选择时需要特殊处理
  14. public int ColumnsCount { get; set; } = 1;
  15. public ObservableCollection<Option> Items { get; set; } = new ObservableCollection<Option>();
  16. public int ButtonHeight { get; set; } = 50;
  17. public int ButtonWidth { get; set; } = 200;
  18. public int ButtonMargin { get; set; } = 5;
  19. public bool IsSingleModule { get; set; } = false;
  20. public string Result
  21. {
  22. get
  23. {
  24. string strRet = string.Empty;
  25. foreach (var item in Items.Where(x => x.IsChecked))
  26. {
  27. strRet += $",{item.Name}";
  28. }
  29. return strRet.Trim(',');
  30. }
  31. }
  32. #endregion
  33. #region Function
  34. public void SelectItem(Option option)
  35. {
  36. if (IsSpin)
  37. {
  38. var obj = Items.FirstOrDefault(x => x.IsChecked);
  39. if (obj != null)
  40. {
  41. string[] firstElement = obj.Name.Split(' ');
  42. if (option.Name.Split(' ')[0] != firstElement[0])
  43. return;
  44. //resist和rrc 同时只能选择一个
  45. if(firstElement.Length>1 && obj!=option)
  46. {
  47. string[] conflictModuleName = { "resist","rrc" };
  48. if(firstElement[1].ToLower().Contains("resist")||firstElement[1].ToLower().Contains("rrc"))
  49. {
  50. if (option.Name.ToLower().Contains("resist") || option.Name.ToLower().Contains("rrc"))
  51. return;
  52. }
  53. }
  54. }
  55. }
  56. option.IsChecked = !option.IsChecked;
  57. if (IsRadio)
  58. {
  59. foreach (var item in Items.Where(x => x != option))
  60. {
  61. item.IsChecked = false;
  62. }
  63. }
  64. try
  65. {
  66. if (IsSingleModule)
  67. {
  68. foreach (var item in Items.Where(x => x.Name.Split(' ')[0] != option.Name.Split(' ')[0]))
  69. {
  70. item.IsChecked = false;
  71. }
  72. }
  73. }
  74. catch (System.Exception)
  75. {
  76. }
  77. }
  78. public void OK()
  79. {
  80. (this.GetView() as Window).DialogResult = true;
  81. }
  82. public void Cancel()
  83. {
  84. (this.GetView() as Window).DialogResult = false;
  85. }
  86. #endregion
  87. }
  88. }