SettingForm.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Linq;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Collections.Generic;
  5. using SHJX.Service.Common.ReadXML;
  6. using SHJX.Service.Librarys.setting;
  7. using SHJX.Service.Model.Global;
  8. using SHJX.Service.ModelView;
  9. using SHJX.Service.Model.Dao;
  10. using System.Collections.ObjectModel;
  11. using SHJX.Service.Dao;
  12. namespace SHJX.Service.View.View
  13. {
  14. /// <summary>
  15. /// SettingForm.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class SettingForm : Window
  18. {
  19. private Dictionary<string, UserControl> _userControl;
  20. public readonly MainViewModel Maincontroller;
  21. /// <summary>
  22. /// 配置文件读取
  23. /// </summary>
  24. private readonly ReadConfigUtil _config;
  25. private SettingViewModel _settingView;
  26. List<Wavekey> waves;
  27. public SettingForm()
  28. {
  29. InitForm();
  30. }
  31. public SettingForm(MainViewModel controllor,ReadConfigUtil config)
  32. {
  33. Maincontroller = controllor;
  34. _config = config;
  35. InitForm();
  36. }
  37. private void InitForm()
  38. {
  39. Owner = Application.Current.MainWindow;
  40. _settingView = new SettingViewModel(_config);
  41. DataContext = _settingView;
  42. //waves = Maincontroller.Maincontroller.DataManager.GetWavekeys();
  43. //if (waves.Any())
  44. //{
  45. // Wavekeys = new ObservableCollection<string>((from wave in waves select wave.WaveKey).ToList());
  46. //}
  47. InitializeComponent();
  48. _userControl = new Dictionary<string, UserControl>()
  49. {
  50. {"加热相关", new HeatControl(_settingView)},
  51. {"设备相关", new LiquidControl(_settingView)},
  52. {"手动校准", new ManualControl(_settingView,_config)},
  53. {"其他设置", new OtherControl(_settingView)}
  54. };
  55. if (CurrentUser.UserName.ToUpper().Equals("ADMIN"))
  56. {
  57. _userControl.Add("滴定相关", new TitrationControl(_settingView));
  58. }
  59. foreach (var item in _userControl.Keys)
  60. {
  61. TabItem tab = new TabItem
  62. {
  63. Header = item
  64. };
  65. Menu.Items.Add(tab);
  66. }
  67. Menu.SelectedItem = Menu.Items[0];
  68. }
  69. private void Menu_SelectionChanged(object sender, SelectionChangedEventArgs e)
  70. {
  71. var ibs = (sender as TabControl)?.SelectedItem as TabItem;
  72. StackPanelMain.Children.Clear();
  73. StackPanelMain.Children.Add(_userControl.FirstOrDefault(item => item.Key.Equals(ibs?.Header)).Value);
  74. }
  75. private void Cancel_Click(object sender, RoutedEventArgs e)
  76. {
  77. Close();
  78. }
  79. private void btn_setting_close_Click(object sender, RoutedEventArgs e)
  80. {
  81. Close();
  82. }
  83. private void SettingTag_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  84. {
  85. DragMove();
  86. }
  87. }
  88. }