f6192b8086
SVN-Revision: r1211
268 lines
11 KiB
C#
268 lines
11 KiB
C#
/******************************
|
|
* 说明:弹出框
|
|
* 创建人:龚宇超
|
|
* 创建日期:2017-08-09
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using DevExpress.XtraEditors;
|
|
using Lskj.Data;
|
|
using System.Windows.Forms;
|
|
using System.Diagnostics;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Business;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
/// <summary>
|
|
/// 系统消息框
|
|
/// </summary>
|
|
public sealed class MessageUtil
|
|
{
|
|
/// <summary>
|
|
/// <para>说明:弹出Ok对话框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
public static DialogResult Show(string msg)
|
|
{
|
|
if (msg.Contains("未将对象引用设置到对象的实例"))
|
|
{
|
|
try
|
|
{
|
|
string callStackInfo = GetBusinessCallStack();
|
|
msg = "未将对象引用设置到对象的实例\r\n" + callStackInfo;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(msg) && msg.Contains("与另一个进程被死锁在")&& !SystemInfo.Instance.PromptDeadlock)
|
|
msg = "网络连接超时,请稍候再试!";
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
msg = Business.Impl.LanguageTranslation.GetTranslatedText(msg);
|
|
}
|
|
|
|
return XtraMessageBox.Show(msg, ResourceKeys.SystemTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:弹出报错信息提示框</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2021-09-10 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
public static DialogResult Show(string msg, string errorMessage)
|
|
{
|
|
if (errorMessage.Contains("未将对象引用设置到对象的实例"))
|
|
{
|
|
try
|
|
{
|
|
string callStackInfo = GetBusinessCallStack();
|
|
errorMessage = "未将对象引用设置到对象的实例\r\n" + callStackInfo;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(errorMessage) && errorMessage.Contains("与另一个进程被死锁在") && !SystemInfo.Instance.PromptDeadlock)
|
|
{
|
|
errorMessage = "网络连接超时,请稍候再试!";
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
errorMessage = Business.Impl.LanguageTranslation.GetTranslatedText(errorMessage);
|
|
}
|
|
return XtraMessageBox.Show(errorMessage, ResourceKeys.SystemTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(errorMessage) && errorMessage.Contains("事务在触发器中结束。批处理已中止"))
|
|
{
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
errorMessage = Business.Impl.LanguageTranslation.GetTranslatedText(errorMessage);
|
|
}
|
|
return XtraMessageBox.Show(errorMessage, ResourceKeys.SystemTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
DevExpress.XtraEditors.Controls.Localizer.Active = new MessboxClass();
|
|
MessageBoxButtons msgButton = MessageBoxButtons.YesNo;
|
|
DialogResult dr = new DialogResult();
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
msg = Business.Impl.LanguageTranslation.GetTranslatedText(msg);
|
|
}
|
|
dr = XtraMessageBox.Show(msg, ResourceKeys.SystemTip, msgButton, MessageBoxIcon.Information);
|
|
if (dr != DialogResult.Yes && !string.IsNullOrWhiteSpace(errorMessage))
|
|
{
|
|
errorMessage = ErrorMessage.StackTrace;
|
|
if (SystemInfo.Instance.HideErrorSQL)
|
|
{
|
|
errorMessage = errorMessage.Split(new string[] { "SQL=[" }, StringSplitOptions.None)[0];
|
|
}
|
|
XtraMessageBox.Show(errorMessage, ResourceKeys.SystemTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
DevExpress.XtraEditors.Controls.Localizer.Active = null;
|
|
return DialogResult.OK;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:弹出Ok对话框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-07 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="ex">The ex.</param>
|
|
/// <returns>DialogResult.</returns>
|
|
public static DialogResult Show(Exception ex)
|
|
{
|
|
if (ex.Message.Contains("未将对象引用设置到对象的实例"))
|
|
{
|
|
try
|
|
{
|
|
//string callStackInfo = GetBusinessCallStack();
|
|
//string msgnew = "未将对象引用设置到对象的实例\r\n" + callStackInfo;
|
|
|
|
string errorInfo = $"【报错时间】:{DateTime.Now}\n" +
|
|
$"【异常类型】:{ex.GetType().Name}\n" +
|
|
$"【错误消息】:{ex.Message}\n" +
|
|
$"【报错方法】:{ex.TargetSite?.DeclaringType?.FullName}.{ex.TargetSite?.Name}\n" +
|
|
$"【完整调用栈】:\n{ex.StackTrace}\n" +
|
|
$"【内部异常】:{ex.InnerException?.Message}";
|
|
|
|
|
|
return XtraMessageBox.Show(errorInfo, ResourceKeys.SystemTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception )
|
|
{
|
|
}
|
|
}
|
|
|
|
if (Debugger.IsAttached)
|
|
{
|
|
string msg = ex == null ? ResourceKeys.UnKownErrorTip : ex.StackTrace;
|
|
if (!string.IsNullOrEmpty(msg) && msg.Contains("与另一个进程被死锁在") && !SystemInfo.Instance.PromptDeadlock)
|
|
msg = "网络连接超时,请稍候再试!";
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
msg = Business.Impl.LanguageTranslation.GetTranslatedText(msg);
|
|
}
|
|
return XtraMessageBox.Show(ex.Message, ResourceKeys.SystemTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
string msg = ex == null ? ResourceKeys.UnKownErrorTip : ex.Message; //ResourceKeys.SystemErrorTip + "\r\n" + ex.Message + "\r\n" + ex.StackTrace;
|
|
if (!string.IsNullOrEmpty(msg) && msg.Contains("与另一个进程被死锁在") && !SystemInfo.Instance.PromptDeadlock)
|
|
msg = "网络连接超时,请稍候再试!";
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
msg = Business.Impl.LanguageTranslation.GetTranslatedText(msg);
|
|
}
|
|
//DialogResult result = Show(ex.Message, MessageBoxButtons.OKCancel);
|
|
//if (result == DialogResult.OK)
|
|
//{
|
|
// // 写入数据到lscrm
|
|
// bool isSuccess = BaseImpl.AddExceptionToLsCrm(msg);
|
|
|
|
// Show(isSuccess ? ResourceKeys.ExceptionSaveSuccess : ResourceKeys.ExceptionSaveFault);
|
|
//}
|
|
return Show(msg);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:弹出是否对话框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="msg">The MSG.</param>
|
|
/// <param name="buttons">The buttons.</param>
|
|
public static DialogResult Show(string msg, MessageBoxButtons buttons)
|
|
{
|
|
|
|
if (msg.Contains("未将对象引用设置到对象的实例"))
|
|
{
|
|
try
|
|
{
|
|
string callStackInfo = GetBusinessCallStack();
|
|
msg = "未将对象引用设置到对象的实例\r\n" + callStackInfo;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
msg = Business.Impl.LanguageTranslation.GetTranslatedText(msg);
|
|
}
|
|
return XtraMessageBox.Show(msg, ResourceKeys.SystemTip, buttons, MessageBoxIcon.Information);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:弹出是否对话框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-07 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="ex">The ex.</param>
|
|
/// <param name="buttons">The buttons.</param>
|
|
/// <returns>DialogResult.</returns>
|
|
public static DialogResult Show(Exception ex, MessageBoxButtons buttons)
|
|
{
|
|
string msg = ex == null ? "未知提示." : ex.StackTrace;
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
msg = Business.Impl.LanguageTranslation.GetTranslatedText(msg);
|
|
}
|
|
return XtraMessageBox.Show(msg, ResourceKeys.SystemTip, buttons, MessageBoxIcon.Information);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取业务代码的调用栈(过滤框架/自身方法,只保留业务层调用)
|
|
/// </summary>
|
|
private static string GetBusinessCallStack()
|
|
{
|
|
try
|
|
{
|
|
// 创建堆栈跟踪,true 表示包含文件路径和行号(需生成pdb文件)
|
|
StackTrace stackTrace = new StackTrace(true);
|
|
StackFrame[] frames = stackTrace.GetFrames();
|
|
|
|
if (frames == null) return "无法获取调用栈";
|
|
|
|
// 过滤堆栈帧:跳过当前方法(GetBusinessCallStack)和 Show 方法,只保留业务调用层
|
|
var businessFrames = frames
|
|
.SkipWhile(frame =>
|
|
frame.GetMethod()?.DeclaringType == typeof(MessageUtil) // 跳过当前类的方法
|
|
|| frame.GetMethod()?.Module.ScopeName.StartsWith("System.") == true // 跳过系统框架方法
|
|
|| fr |