UserWindow.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using NEIntelligentControl2.Models.Pages;
  2. using NEIntelligentControl2.Models.User;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace NEIntelligentControl2.Windows
  17. {
  18. /// <summary>
  19. /// 用户登录窗口
  20. /// </summary>
  21. public partial class UserWindow : Window
  22. {
  23. private IPageAction _IPageAction;
  24. public UserWindow(IPageAction ipa)
  25. {
  26. InitializeComponent();
  27. _IPageAction = ipa;
  28. }
  29. internal bool Show(string tag)
  30. {
  31. SwitchPage(tag);
  32. this.Owner = Application.Current.MainWindow;
  33. var v = this.ShowDialog();
  34. return v != null && v == true;
  35. }
  36. internal bool Show(string tag, UserInfo user)
  37. {
  38. var page = _IPageAction[tag] as Pages.User.PageUserEdit;
  39. page.EditUser(user);
  40. SwitchPage(page);
  41. this.Owner = Application.Current.MainWindow;
  42. var v = this.ShowDialog();
  43. return v != null && v == true;
  44. }
  45. private void SwitchPage(string tag)
  46. {
  47. Page page = _IPageAction[tag];
  48. SwitchPage(page);
  49. }
  50. private void SwitchPage(Page page)
  51. {
  52. if (page is IPageMessage pg)
  53. {
  54. pg.OnMessage = OnPageMessage;
  55. }
  56. _Frame.Navigate(page);
  57. if (!_Frame.NavigationService.CanGoBack) return;
  58. var en = _Frame.NavigationService.RemoveBackEntry();
  59. while (en != null)
  60. {
  61. en = _Frame.NavigationService.RemoveBackEntry();
  62. }
  63. }
  64. private void OnPageMessage(object obj)
  65. {
  66. if(obj.ToString() == "success")
  67. {
  68. this.DialogResult = true;
  69. return;
  70. }
  71. SwitchPage(obj as string);
  72. }
  73. private void ContentControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  74. {
  75. this.DialogResult = false;
  76. }
  77. }
  78. }