Files
TimetableDesigner/TimetableDesigner/Services/MessageBox/MessageBoxService.cs
2023-05-07 17:39:24 +02:00

46 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using TimetableDesigner.Properties;
namespace TimetableDesigner.Services.MessageBox
{
public class MessageBoxService : IMessageBoxService
{
#region PUBLIC METHODS
public void ShowError(string message) => ShowError(message, Resources.MessageBox_Error);
public void ShowError(string message, string title) => System.Windows.Forms.MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
public MessageBoxQuestionResult ShowQuestion(string message, bool hideCancelButton = false) => ShowQuestion(message, Resources.MessageBox_Question, hideCancelButton);
public MessageBoxQuestionResult ShowQuestion(string message, string title, bool hideCancelButton = false)
{
MessageBoxButton buttons = MessageBoxButton.YesNoCancel;
if (hideCancelButton)
{
buttons = MessageBoxButton.YesNo;
}
MessageBoxResult result = System.Windows.MessageBox.Show(message, title, buttons, MessageBoxImage.Question);
switch (result)
{
case MessageBoxResult.Yes: return MessageBoxQuestionResult.Yes;
case MessageBoxResult.No: return MessageBoxQuestionResult.No;
default: return MessageBoxQuestionResult.Cancel;
}
}
public void ShowWarning(string message) => ShowWarning(message, Resources.MessageBox_Warning);
public void ShowWarning(string message, string title) => System.Windows.Forms.MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
public void ShowInformation(string message) => ShowInformation(message, Resources.MessageBox_Information);
public void ShowInformation(string message, string title) => System.Windows.Forms.MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
#endregion
}
}