DialogBox.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Caliburn.Micro;
  2. using System;
  3. using System.Linq;
  4. using System.Windows;
  5. namespace OpenSEMI.ClientBase
  6. {
  7. public class DialogBox
  8. {
  9. public static DialogButton ShowError(MESSAGE msgEnum, params object[] param)
  10. {
  11. string msg = GetMsg(msgEnum);
  12. return ShowError(msg, param);
  13. }
  14. public static DialogButton ShowError(string msg, params object[] param)
  15. {
  16. return ShowDialog(DialogButton.OK, DialogType.ERROR, msg, param);
  17. }
  18. public static DialogButton ShowWarning(MESSAGE msgEnum, params object[] param)
  19. {
  20. string msg = GetMsg(msgEnum);
  21. return ShowWarning(msg, param);
  22. }
  23. public static DialogButton ShowWarning(string msg, params object[] param)
  24. {
  25. return ShowDialog(DialogButton.OK, DialogType.WARNING, msg, param);
  26. }
  27. public static DialogButton ShowInfo(MESSAGE msgEnum, params object[] param)
  28. {
  29. string msg = GetMsg(msgEnum);
  30. return ShowInfo(msg, param);
  31. }
  32. public static DialogButton ShowInfo(string msg, params object[] param)
  33. {
  34. return ShowDialog(DialogButton.OK, DialogType.INFO, msg, param);
  35. }
  36. public static bool Confirm(MESSAGE msgEnum, params object[] param)
  37. {
  38. string msg = GetMsg(msgEnum);
  39. return Confirm(msg, param);
  40. }
  41. public static bool Confirm(string msg, params object[] param)
  42. {
  43. DialogButton dialogButton = ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, msg, param);
  44. if (dialogButton == DialogButton.Yes)
  45. {
  46. return true;
  47. }
  48. return false;
  49. }
  50. public static string GetMsg(MESSAGE msgEnum)
  51. {
  52. string text = Application.Current.Resources[msgEnum.ToString()] as string;
  53. string[] array = text.Split(new string[1]
  54. {
  55. "\\n"
  56. }, StringSplitOptions.RemoveEmptyEntries);
  57. string text2 = string.Empty;
  58. int num = 0;
  59. string[] array2 = array;
  60. foreach (string str in array2)
  61. {
  62. text2 = ((num != array.Count() - 1) ? (text2 + str + Environment.NewLine) : (text2 + str));
  63. num++;
  64. }
  65. return text2;
  66. }
  67. public static DialogButton ShowDialog(DialogButton buttons, DialogType type, MESSAGE msgEnum, params object[] param)
  68. {
  69. string msg = GetMsg(msgEnum);
  70. return ShowDialog(buttons, type, msg, param);
  71. }
  72. public static DialogButton ShowDialog(DialogButton buttons, DialogType type, string msg, params object[] Params)
  73. {
  74. WindowManager windowManager = new WindowManager();
  75. MessageDialogViewModel messageDialogViewModel = new MessageDialogViewModel();
  76. messageDialogViewModel.DialogButton = buttons;
  77. if (Params != null && Params.Length != 0)
  78. {
  79. msg = string.Format(msg, Params);
  80. }
  81. messageDialogViewModel.Text = msg;
  82. messageDialogViewModel.DialogType = type;
  83. windowManager.ShowDialogWithNoStyle(messageDialogViewModel, null);
  84. return messageDialogViewModel.DialogResult;
  85. }
  86. }
  87. }