BaseViewModel.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using ivf_tl_Entity.Enums;
  3. using ivf_tl_Manage.Win;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace ivf_tl_Manage.ViewModels
  10. {
  11. public class BaseViewModel: ObservableObject
  12. {
  13. protected string ViewModelName { get; set; } = "BaseViewModel";
  14. public string NavName { get; set; }
  15. public List<BaseViewModel> NavList { get; set; } = new List<BaseViewModel>();
  16. protected void ToastShow(bool b)
  17. {
  18. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, b).Show();
  19. }
  20. protected void ToastMessageShow(string mess)
  21. {
  22. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, mess).Show();
  23. }
  24. protected bool? MessageBoxShow(string title, string mess)
  25. {
  26. try
  27. {
  28. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  29. var a = new MessageBoxWindow(title, mess, AppData.Instance.MainWindow).ShowDialog();
  30. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  31. return a;
  32. }
  33. catch (Exception ex)
  34. {
  35. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  36. ExLog(ex, "MessageBoxShow");
  37. return false;
  38. }
  39. }
  40. protected void ExLog(Exception ex, string name)
  41. {
  42. AppData.Instance.LogService.ExceptionLog(ex, $"{ViewModelName}.{name}", LogEnum.RunException);
  43. }
  44. protected void ErrorLog(string message, LogEnum logType)
  45. {
  46. AppData.Instance.LogService.TLLog($"{ViewModelName}.{message}", logType);
  47. }
  48. protected void DebugLog(string message, LogEnum logType)
  49. {
  50. AppData.Instance.LogService.TLLog($"{ViewModelName}.{message}", logType);
  51. }
  52. protected void TimeLog(string message, LogEnum logType)
  53. {
  54. AppData.Instance.LogService.TLLog($"{ViewModelName}.{message}", logType);
  55. }
  56. }
  57. }