2026-03-30 17:09:29 +09:00

188 lines
7.5 KiB
C#

using Aurora.Api;
using System.Collections.Generic;
using System.Windows;
using VisionCommon;
using VisionCommonUI.Resources;
namespace VisionCommonUI {
public class MessageBoxUtil : Application {
private static Logger _Logger = new Logger(typeof(MessageBoxUtil).Name);
public static void ShowMessageBoxOk(string msgOk) {
Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var messageBoxOk = new MessageBoxOk();
messageBoxOk.Owner = Application.Current.MainWindow;
messageBoxOk.Show(msgOk);
})
);
}
public static void ShowMessageBoxInfo(string msgInfo) {
Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var messageBoxInfo = new MessageBoxInfo();
messageBoxInfo.Owner = Application.Current.MainWindow;
messageBoxInfo.Show(msgInfo);
})
);
}
public static void ShowMessageBoxWarning(string msgWarning) {
Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
_Logger.FuncW(msgWarning);
var messageBoxWarning = new MessageBoxWarning();
messageBoxWarning.Owner = Application.Current.MainWindow;
messageBoxWarning.Show(msgWarning);
})
);
}
public static void ShowDialogMessageBoxWarning(string msgWarning) {
_Logger.FuncW(msgWarning);
var messageBoxWarning = new MessageBoxWarning();
messageBoxWarning.Owner = Application.Current.MainWindow;
messageBoxWarning.ShowDialog(msgWarning);
}
public static void ShowMessageBoxError(string msgError) {
Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
_Logger.FuncE(msgError);
var messageBoxError = new MessageBoxError();
messageBoxError.Owner = Application.Current.MainWindow;
messageBoxError.Show(msgError);
})
);
}
public static void ShowDialogMessageBoxError(string msgError) {
_Logger.FuncE(msgError);
var messageBoxError = new MessageBoxError();
messageBoxError.Owner = Application.Current.MainWindow;
messageBoxError.ShowDialog(msgError);
}
public static MessageBoxResult ShowMessageBoxQuestion(string msgQuestion) {
var result = MessageBoxResult.None;
Application.Current.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var messageBoxQuestion = new MessageBoxQuestion();
messageBoxQuestion.Owner = Application.Current.MainWindow;
result = messageBoxQuestion.ShowDialog(msgQuestion);
})
);
return result;
}
public static MessageBoxOptionResult ShowMessageBoxQuestionOption(string msgQuestion, string optTitle, params string[] optList) {
var result = MessageBoxResult.None;
var idx = -1;
Application.Current.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var messageBoxQuestion = new MessageBoxQuestionOption(optTitle, optList);
messageBoxQuestion.Owner = Application.Current.MainWindow;
result = messageBoxQuestion.ShowDialog(msgQuestion);
idx = messageBoxQuestion.SelIndex;
})
);
return new MessageBoxOptionResult() { Result = result, SelIndex = idx };
}
public static MessageBoxResult ShowMessageBoxSaveData(
Dictionary<string, object> oldValues, Dictionary<string, object> newValues, string msgQuestion = "Do you want to save data?") {
var result = MessageBoxResult.None;
Application.Current.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var messageBoxQuestion = new MessageBoxSaveData(oldValues, newValues);
messageBoxQuestion.Owner = Application.Current.MainWindow;
result = messageBoxQuestion.ShowDialog(msgQuestion);
})
);
return result;
}
public static string ShowMessageBoxPassword() {
var result = "";
Application.Current.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var messageBoxPassword = new MessageBoxPassword();
messageBoxPassword.Owner = Application.Current.MainWindow;
result = messageBoxPassword.ShowPasswordWindow();
})
);
return result;
}
public static void ShowMessageBoxDataSaved(int result) {
if (result == VisionKeys.SUCCESS) {
Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var msgInfo = "Data has been saved successfully.";
var messageBoxInfo = new MessageBoxInfo();
messageBoxInfo.Owner = Application.Current.MainWindow;
messageBoxInfo.Show(msgInfo);
})
);
}
else {
Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new System.Action(() => {
var msgWarning = "Failed to save data.";
var messageBoxWarning = new MessageBoxWarning();
messageBoxWarning.Owner = Application.Current.MainWindow;
messageBoxWarning.Show(msgWarning);
})
);
}
}
public static bool ShowMessageBoxConfirmSave() {
if (ShowMessageBoxQuestion(
string.Format(StrTokens.MSG_Q_ConfirmSave)) == MessageBoxResult.Yes)
return true;
return false;
}
public static bool ShowMessageBoxConfirmSaveOnAutoOperation() {
if (ShowMessageBoxQuestion(
string.Format(StrTokens.MSG_Q_ConfirmSaveOnAutoOperation)) == MessageBoxResult.Yes)
return true;
return false;
}
public static bool ShowMessageBoxConfirmSaveOnMotionCalComplete() {
if (ShowMessageBoxQuestion(
string.Format(StrTokens.MSG_Q_ConfirmSaveOnMotionCalComplete)) == MessageBoxResult.Yes)
return true;
return false;
}
}
public class MessageBoxOptionResult
{
public MessageBoxResult Result { get; set; }
public int SelIndex { get; set; }
}
}