Dialogbox.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. //using form = System.Windows.Forms;
  8. using Caliburn.Micro;
  9. using MECF.Framework.UI.Client.ClientBase;
  10. namespace OpenSEMI.ClientBase
  11. {
  12. public class DialogBox
  13. {
  14. #region Folder Browser Dialog
  15. /// <summary>
  16. /// Folder Browser Dialog
  17. /// </summary>
  18. /// <returns>User Seleted Path</returns>
  19. //public static String ShowFolderBrowserDialog()
  20. //{
  21. // form.FolderBrowserDialog dialog = new form.FolderBrowserDialog();
  22. // dialog.ShowNewFolderButton = false;
  23. // dialog.RootFolder = Environment.SpecialFolder.MyComputer;
  24. // form.DialogResult result = dialog.ShowDialog();
  25. // return result == form.DialogResult.OK ? dialog.SelectedPath : String.Empty;
  26. //}
  27. ///// <summary>
  28. ///// Folder Browser Dialog
  29. ///// </summary>
  30. ///// <param name="oldPath">old path</param>
  31. ///// <param name="rootDialog">default path</param>
  32. ///// <param name="isShowNewFolderButton">show new folder button</param>
  33. ///// <returns>User Seleted Path</returns>
  34. //public static String ShowFolderBrowserDialog(String oldPath, Environment.SpecialFolder rootDialog = Environment.SpecialFolder.MyComputer, Boolean isShowNewFolderButton = false)
  35. //{
  36. // form.FolderBrowserDialog dialog = new form.FolderBrowserDialog();
  37. // dialog.ShowNewFolderButton = isShowNewFolderButton;
  38. // if (String.IsNullOrWhiteSpace(oldPath))
  39. // {
  40. // dialog.RootFolder = rootDialog;
  41. // }
  42. // else
  43. // {
  44. // dialog.SelectedPath = oldPath;
  45. // }
  46. // form.DialogResult result = dialog.ShowDialog();
  47. // return result == form.DialogResult.OK ? dialog.SelectedPath : String.Empty;
  48. //}
  49. #endregion
  50. #region Simple dialog
  51. public static DialogButton ShowError(MESSAGE msgEnum, params object[] param)
  52. {
  53. string msg = GetMsg(msgEnum);
  54. return ShowError(msg, param);
  55. }
  56. public static DialogButton ShowError(string msg, params object[] param)
  57. {
  58. return ShowDialog(DialogButton.OK, DialogType.ERROR, msg, param);
  59. }
  60. public static DialogButton ShowWarning(MESSAGE msgEnum, params object[] param)
  61. {
  62. string msg = GetMsg(msgEnum);
  63. return ShowWarning(msg, param);
  64. }
  65. public static DialogButton ShowWarning(string msg, params object[] param)
  66. {
  67. return ShowDialog(DialogButton.OK, DialogType.WARNING, msg, param);
  68. }
  69. public static DialogButton ShowInfo(MESSAGE msgEnum, params object[] param)
  70. {
  71. string msg = GetMsg(msgEnum);
  72. return ShowInfo(msg, param);
  73. }
  74. public static DialogButton ShowInfo(string msg, params object[] param)
  75. {
  76. return ShowDialog(DialogButton.OK, DialogType.INFO, msg, param);
  77. }
  78. public static bool Confirm(MESSAGE msgEnum, params object[] param)
  79. {
  80. string msg = GetMsg(msgEnum);
  81. return Confirm(msg, param);
  82. }
  83. public static bool Confirm(string msg, params object[] param)
  84. {
  85. DialogButton btn = ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, msg, param);
  86. if (btn == DialogButton.Yes)
  87. return true;
  88. else
  89. return false;
  90. }
  91. #endregion
  92. /// <summary>
  93. /// get message by enmu from resource
  94. /// </summary>
  95. /// <param name="msgEnum"></param>
  96. /// <returns></returns>
  97. public static string GetMsg(MESSAGE msgEnum)
  98. {
  99. //check contain key
  100. var msg = Application.Current.Resources[msgEnum.ToString()] as string;
  101. var msgs = msg.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries);
  102. string msgStr = string.Empty;
  103. int i = 0;
  104. foreach (var str in msgs)
  105. {
  106. if (i == msgs.Count() - 1)
  107. msgStr += str;
  108. else
  109. msgStr += str + Environment.NewLine;
  110. i++;
  111. }
  112. return msgStr;
  113. }
  114. public static DialogButton ShowDialog(DialogButton buttons, DialogType type, MESSAGE msgEnum, params object[] param)
  115. {
  116. string msg = GetMsg(msgEnum);
  117. return ShowDialog(buttons, type, msg, param);
  118. }
  119. public static DialogButton ShowDialog(DialogButton buttons, DialogType type, string msg, params object[] Params)
  120. {
  121. WindowManager wm = new WindowManager();
  122. MessageDialogViewModel dlg = new MessageDialogViewModel();
  123. dlg.DialogButton = buttons;
  124. if (Params != null && Params.Length > 0)
  125. msg = string.Format(msg, Params);
  126. dlg.Text = msg;
  127. dlg.DialogType = type;
  128. wm.ShowDialogWithNoStyle(dlg);
  129. return dlg.DialogResult;
  130. }
  131. }
  132. }