|
@@ -0,0 +1,376 @@
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Documents;
|
|
|
+using System.Windows.Input;
|
|
|
+using System.Windows.Media;
|
|
|
+
|
|
|
+namespace UniformMaterialManagementSystem.Custom
|
|
|
+{
|
|
|
+ public static class MessageEx
|
|
|
+ {
|
|
|
+ #region Information Dialog
|
|
|
+ public static MessageBoxResult ShowInformationDialog(string message)
|
|
|
+ {
|
|
|
+ return ShowInformationDialog(message, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowInformationDialog(string message, string appendedMessage)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ cls.ShowDialog();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowInformationDialog(string message, Window owner)
|
|
|
+ {
|
|
|
+ return ShowInformationDialog(message, "", owner);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowInformationDialog(string message, string appendedMessage, Window owner)
|
|
|
+ {
|
|
|
+ owner.Opacity = 0.7;
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Information, owner);
|
|
|
+ cls.ShowDialog();
|
|
|
+ owner.Opacity = 1;
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowInformation(string message)
|
|
|
+ {
|
|
|
+ return ShowInformation(message, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowInformation(string message, string appendedMessage)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ cls.Show();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Question Dialog
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowQuestionDialog(string message)
|
|
|
+ {
|
|
|
+ return ShowQuestionDialog(message, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowQuestionDialog(string message, string appendedMessage)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ cls.ShowDialog();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowQuestionDialog(string message, Window owner)
|
|
|
+ {
|
|
|
+ return ShowQuestionDialog(message, "", owner);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowQuestionDialog(string message, string appendedMessage, Window owner)
|
|
|
+ {
|
|
|
+ owner.Opacity = 0.7;
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.YesNo, MessageBoxImage.Question, owner);
|
|
|
+ cls.ShowDialog();
|
|
|
+ owner.Opacity = 1;
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Warning Dialog
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowWarningDialog(string message)
|
|
|
+ {
|
|
|
+ return ShowWarningDialog(message, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowWarningDialog(string message, string appendedMessage)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ cls.ShowDialog();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowWarningDialog(string message, Window owner)
|
|
|
+ {
|
|
|
+ return ShowWarningDialog(message, "", owner);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowWarningDialog(string message, string appendedMessage, Window owner)
|
|
|
+ {
|
|
|
+ owner.Opacity = 0.7;
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Warning, owner);
|
|
|
+ cls.ShowDialog();
|
|
|
+ owner.Opacity = 1;
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Error Dialog
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowErrorDialog(string message)
|
|
|
+ {
|
|
|
+ return ShowErrorDialog(message, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowErrorDialog(string message, string appendedMessage)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ cls.ShowDialog();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+ public static MessageBoxResult ShowErrorDialog(string message, Window owner)
|
|
|
+ {
|
|
|
+ return ShowErrorDialog(message, "", owner);
|
|
|
+ }
|
|
|
+ public static MessageBoxResult ShowErrorDialog(string message, string appendedMessage, Window owner)
|
|
|
+ {
|
|
|
+ owner.Opacity = 0.7;
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, MessageBoxButton.OK, MessageBoxImage.Error, owner);
|
|
|
+ cls.ShowDialog();
|
|
|
+ owner.Opacity = 1;
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region General Dialog
|
|
|
+
|
|
|
+ public static MessageBoxResult Show(string message, string appendedMessage, MessageBoxButton messageBoxButton, MessageBoxImage messageBoxImage, Brush color)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, messageBoxButton, messageBoxImage, color);
|
|
|
+ cls.Show();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowDialog(string message, string appendedMessage, MessageBoxButton messageBoxButton, MessageBoxImage messageBoxImage, Brush color)
|
|
|
+ {
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, messageBoxButton, messageBoxImage, color);
|
|
|
+ cls.ShowDialog();
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageBoxResult ShowDialog(string message, string appendedMessage, MessageBoxButton messageBoxButton, MessageBoxImage messageBoxImage, Brush color, Window owner)
|
|
|
+ {
|
|
|
+ owner.Opacity = 0.7;
|
|
|
+ var cls = new MessageBoxEx(message, appendedMessage, messageBoxButton, messageBoxImage, color, owner);
|
|
|
+ cls.ShowDialog();
|
|
|
+ owner.Opacity = 1;
|
|
|
+ return cls.Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+
|
|
|
+ public partial class MessageBoxEx : Window
|
|
|
+ {
|
|
|
+ #region Variables
|
|
|
+
|
|
|
+ public string Message { get; set; } = "";
|
|
|
+
|
|
|
+ public string AppendedMessage { get; set; } = "";
|
|
|
+
|
|
|
+ public bool HasAppendedMessage { get; private set; }
|
|
|
+
|
|
|
+ public MessageBoxImage Image { get; set; } = MessageBoxImage.Information;
|
|
|
+
|
|
|
+ public MessageBoxButton Button { get; set; } = MessageBoxButton.OK;
|
|
|
+
|
|
|
+ public MessageBoxResult Result { get; private set; } = MessageBoxResult.None;
|
|
|
+
|
|
|
+ public MessageBoxResult DefaultResult { get; set; } = MessageBoxResult.None;
|
|
|
+
|
|
|
+ public bool IsEnabledEffect { get; set; } = false;
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Caption Variables
|
|
|
+
|
|
|
+ public string OkCaption { get; set; } = "OK";
|
|
|
+
|
|
|
+ public string YesCaption { get; set; } = "Yes";
|
|
|
+
|
|
|
+ public string NoCaption { get; set; } = "No";
|
|
|
+
|
|
|
+ public string CancelCaption { get; set; } = "Cancel";
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Color Variables
|
|
|
+
|
|
|
+ public Brush Color { get; set; } = Brushes.Black;
|
|
|
+
|
|
|
+ public Brush BackgroundColor { get; set; } = Brushes.White;
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Initializer
|
|
|
+
|
|
|
+ public MessageBoxEx()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ }
|
|
|
+
|
|
|
+ public MessageBoxEx(string message, Window? owner = null)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Message = message;
|
|
|
+ if (owner is not null && PresentationSource.FromVisual(owner) is not null) this.Owner = owner;
|
|
|
+ }
|
|
|
+ public MessageBoxEx(string message, string appendedMessage, Window? owner = null)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Message = message;
|
|
|
+ AppendedMessage = appendedMessage;
|
|
|
+ if (owner is not null && PresentationSource.FromVisual(owner) is not null) this.Owner = owner;
|
|
|
+ }
|
|
|
+ public MessageBoxEx(string message, MessageBoxButton button, MessageBoxImage image, Window? owner = null)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Message = message;
|
|
|
+ Button = button;
|
|
|
+ Image = image;
|
|
|
+ if (owner is not null && PresentationSource.FromVisual(owner) is not null) this.Owner = owner;
|
|
|
+ }
|
|
|
+
|
|
|
+ public MessageBoxEx(string message, string appendedMessage, MessageBoxButton button, MessageBoxImage image, Window? owner = null)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Message = message;
|
|
|
+ AppendedMessage = appendedMessage;
|
|
|
+ Button = button;
|
|
|
+ Image = image;
|
|
|
+ if (owner is not null && PresentationSource.FromVisual(owner) is not null) this.Owner = owner;
|
|
|
+ }
|
|
|
+
|
|
|
+ public MessageBoxEx(string message, MessageBoxButton button, MessageBoxImage image, Brush color, Window? owner = null)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Message = message;
|
|
|
+ Button = button;
|
|
|
+ Image = image;
|
|
|
+ Color = color;
|
|
|
+ if (owner is not null && PresentationSource.FromVisual(owner) is not null) this.Owner = owner;
|
|
|
+ }
|
|
|
+
|
|
|
+ public MessageBoxEx(string message, string appendedMessage, MessageBoxButton button, MessageBoxImage image, Brush color, Window? owner = null)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Message = message;
|
|
|
+ AppendedMessage = appendedMessage;
|
|
|
+ Button = button;
|
|
|
+ Image = image;
|
|
|
+ Color = color;
|
|
|
+ if (owner is not null && PresentationSource.FromVisual(owner) is not null) this.Owner = owner;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ DataContext = this;
|
|
|
+ HasAppendedMessage = !string.IsNullOrEmpty(AppendedMessage);
|
|
|
+
|
|
|
+ var document = MessageRichTextBox.Document;
|
|
|
+ document.PagePadding = new Thickness(0);
|
|
|
+ var range = new TextRange(document.ContentStart, document.ContentEnd);
|
|
|
+ range.Text = Message;
|
|
|
+
|
|
|
+ SetupIconVisibility();
|
|
|
+ SetupButton();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CopyMenuItem_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not MenuItem) return;
|
|
|
+
|
|
|
+ var s = Message + (string.IsNullOrEmpty(AppendedMessage) ? "" : "\r\n" + AppendedMessage);
|
|
|
+ Clipboard.SetText(s);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ base.OnMouseLeftButtonDown(e);
|
|
|
+ this.DragMove();
|
|
|
+ }
|
|
|
+ private void SetupIconVisibility()
|
|
|
+ {
|
|
|
+ switch (Image)
|
|
|
+ {
|
|
|
+ case MessageBoxImage.None:
|
|
|
+ break;
|
|
|
+ case MessageBoxImage.Error: //Same : MessageBoxImage.Stop, Hand
|
|
|
+ ErrorIcon.Visibility = Visibility.Visible;
|
|
|
+ break;
|
|
|
+ case MessageBoxImage.Question:
|
|
|
+ QuestionIcon.Visibility = Visibility.Visible;
|
|
|
+ break;
|
|
|
+ case MessageBoxImage.Warning: //Same : Exclamation
|
|
|
+ WarningIcon.Visibility = Visibility.Visible;
|
|
|
+ break;
|
|
|
+ case MessageBoxImage.Information: //Same : Asterisk
|
|
|
+ InfomationIcon.Visibility = Visibility.Visible;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void SetupButton()
|
|
|
+ {
|
|
|
+ switch (Button)
|
|
|
+ {
|
|
|
+ case MessageBoxButton.OK:
|
|
|
+ LeftButton.Visibility = Visibility.Collapsed;
|
|
|
+ MiddleButton.Visibility = Visibility.Collapsed;
|
|
|
+ RightButton.Content = OkCaption;
|
|
|
+ RightButton.Tag = MessageBoxResult.OK; //Set MessageBoxResult to Tag
|
|
|
+ Keyboard.Focus(RightButton);
|
|
|
+ break;
|
|
|
+ case MessageBoxButton.OKCancel:
|
|
|
+ LeftButton.Visibility = Visibility.Collapsed;
|
|
|
+ MiddleButton.Content = OkCaption;
|
|
|
+ RightButton.Content = CancelCaption;
|
|
|
+ MiddleButton.Tag = MessageBoxResult.OK;
|
|
|
+ RightButton.Tag = MessageBoxResult.Cancel;
|
|
|
+ Keyboard.Focus(DefaultResult == MessageBoxResult.OK ? MiddleButton : RightButton);
|
|
|
+ break;
|
|
|
+ case MessageBoxButton.YesNoCancel:
|
|
|
+ LeftButton.Content = YesCaption;
|
|
|
+ MiddleButton.Content = NoCaption;
|
|
|
+ RightButton.Content = CancelCaption;
|
|
|
+ LeftButton.Tag = MessageBoxResult.Yes;
|
|
|
+ MiddleButton.Tag = MessageBoxResult.No;
|
|
|
+ RightButton.Tag = MessageBoxResult.Cancel;
|
|
|
+ switch (DefaultResult)
|
|
|
+ {
|
|
|
+ case MessageBoxResult.Yes:
|
|
|
+ Keyboard.Focus(LeftButton);
|
|
|
+ break;
|
|
|
+ case MessageBoxResult.No:
|
|
|
+ Keyboard.Focus(MiddleButton);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ Keyboard.Focus(RightButton);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case MessageBoxButton.YesNo:
|
|
|
+ LeftButton.Visibility = Visibility.Collapsed;
|
|
|
+ MiddleButton.Content = YesCaption;
|
|
|
+ RightButton.Content = NoCaption;
|
|
|
+ MiddleButton.Tag = MessageBoxResult.Yes;
|
|
|
+ RightButton.Tag = MessageBoxResult.No;
|
|
|
+ Keyboard.Focus(DefaultResult == MessageBoxResult.Yes ? MiddleButton : RightButton);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ var button = (Button)sender;
|
|
|
+ Result = (MessageBoxResult)button.Tag; //Get MessageBoxResult from Tag
|
|
|
+ this.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|