You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
6.7 KiB
149 lines
6.7 KiB
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using DevExpress.Utils;
|
|
using DevExpress.XtraEditors;
|
|
|
|
namespace Eas.Client
|
|
{
|
|
public class MessageBoxHelper
|
|
{
|
|
/// <summary>
|
|
/// 显示一般的提示信息
|
|
/// </summary>
|
|
/// <param name="message">提示信息</param>
|
|
public static DialogResult Show(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return ShowEx(message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示警告信息
|
|
/// </summary>
|
|
/// <param name="message">警告信息</param>
|
|
public static DialogResult ShowWarning(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return ShowEx(message, "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示错误信息
|
|
/// </summary>
|
|
/// <param name="message">错误信息</param>
|
|
public static DialogResult ShowError(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return ShowEx(message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示询问用户信息,并显示错误标志
|
|
/// </summary>
|
|
/// <param name="message">错误信息</param>
|
|
public static DialogResult ShowYesNoAndError(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "错误信息", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
|
return ShowEx(message, "错误信息", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示询问用户信息,并显示提示标志
|
|
/// </summary>
|
|
/// <param name="message">错误信息</param>
|
|
public static DialogResult ShowYesNoAndTips(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
|
return ShowEx(message, "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示询问用户信息,并显示警告标志
|
|
/// </summary>
|
|
/// <param name="message">警告信息</param>
|
|
public static DialogResult ShowYesNoAndWarning(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "警告信息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
|
return ShowEx(message, "警告信息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示询问用户信息,并显示提示标志
|
|
/// </summary>
|
|
/// <param name="message">错误信息</param>
|
|
public static DialogResult ShowYesNoCancelAndTips(string message)
|
|
{
|
|
//return DevExpress.XtraEditors.XtraMessageBox.Show(message, "提示信息", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
|
|
return ShowEx(message, "提示信息", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
|
|
}
|
|
/// <summary>
|
|
/// 显示数字输入文本框,并显示提示标志
|
|
/// </summary>
|
|
/// <param name="caption">标题</param>
|
|
/// /// <param name="tip">提示信息</param>
|
|
public static int ShowInputNumber(string caption, string tip)
|
|
{
|
|
string tips = "请在此输入" + caption + ":";
|
|
if (tip != "") tips += "\n" + tip;
|
|
DevExpress.XtraEditors.XtraInputBoxArgs xtraInputBoxArgs = new DevExpress.XtraEditors.XtraInputBoxArgs();
|
|
xtraInputBoxArgs.DefaultResponse = "0";
|
|
xtraInputBoxArgs.Caption = caption;
|
|
xtraInputBoxArgs.Prompt =tips ;
|
|
var results = DevExpress.XtraEditors.XtraInputBox.Show(xtraInputBoxArgs);
|
|
int num = -3;
|
|
if (results == null) num= -1;
|
|
else if (results.ToString() == "") num= -2;
|
|
else
|
|
{
|
|
try
|
|
{
|
|
num=Convert.ToInt32(results.ToString());
|
|
if (num <= 0)
|
|
{
|
|
ShowInputNumber(caption, "打印数量只能大于0,请重新输入!");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
ShowInputNumber(caption,"您输入了非数字的字符,请重新输入!");
|
|
}
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public static DialogResult ShowEx(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, int fsize = 48, int width = 900, int height = 1200)
|
|
{
|
|
XtraMessageBoxForm form = new XtraMessageBoxForm();
|
|
Font defaultFont = AppearanceObject.DefaultFont;
|
|
FontFamily defaultFontFamily = defaultFont.FontFamily;
|
|
Font _MessageFont = new Font(defaultFontFamily, fsize);
|
|
form.Appearance.Font = _MessageFont;
|
|
form.MaximumSize = new Size(width, height);
|
|
DialogResult dr = form.ShowMessageBoxDialog(new XtraMessageBoxArgs(null, null, text, caption, MessageBoxButtonsToDialogResults(buttons), MessageBoxIconToIcon(icon), 0));
|
|
form.Dispose();
|
|
return dr;
|
|
}
|
|
|
|
private static Icon MessageBoxIconToIcon(MessageBoxIcon mbIcon)
|
|
{
|
|
Assembly asm = Assembly.LoadFile(Application.StartupPath + "\\DevExpress.XtraEditors.v17.1.dll");
|
|
Type t1 = asm.GetType("DevExpress.XtraEditors.XtraMessageHelper");
|
|
MethodInfo mi = t1.GetMethod("MessageBoxIconToIcon", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
|
|
return (Icon)mi.Invoke(null, new Object[] { mbIcon });
|
|
}
|
|
|
|
private static DialogResult[] MessageBoxButtonsToDialogResults(MessageBoxButtons buttons)
|
|
{
|
|
Assembly asm = Assembly.LoadFile(Application.StartupPath + "\\DevExpress.XtraEditors.v17.1.dll");
|
|
Type t1 = asm.GetType("DevExpress.XtraEditors.XtraMessageHelper");
|
|
MethodInfo mi = t1.GetMethod("MessageBoxButtonsToDialogResults", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
|
|
return (DialogResult[])mi.Invoke(null, new Object[] { buttons });
|
|
}
|
|
}
|
|
}
|
|
|
|
|