【056】使用警告弹窗提示用户信息
侧边栏壁纸
  • 累计撰写 60 篇文章
  • 累计收到 2 条评论

【056】使用警告弹窗提示用户信息

秋驰雪隙
2025-06-06 / 1 评论 / 22 阅读 / 正在检测是否收录...
某些操作,如果有小部分信息缺失不影响逻辑,但是有些场景又必须要填写
遇到过很多次客户想能不能弹出警告提示一下,再进行一次确认动作
刚好在库存->转总账模块看到生成凭证有弹窗,特此记录如何使用U9系统的

ShowMsg函数

curPart是UI插件的IPart及其实现类
如果不是UI插件,是webPart页面,直接用this即可

/// <summary>
/// 弹出提示信息
/// </summary>
/// <param name="targetType">触发类型,用于单个页面有多个弹窗的时候判断</param>
/// <param name="errorList">提示信息,最好不超过4行</param>
private void ShowMsg(string targetType, params string[] errorList)
{
    if (errorList == null || errorList.Length == 0) return;
    string TaskID = curPart.TaskId.ToString();
    if (curPart.CurrentState["ReMakePland"] != null)
    {
        curPart.CurrentState["ReMakePland"] = false;
    }
    NameValueCollection nameValues = new NameValueCollection();
    curPart.CurrentState["ErrorString"] = errorList.ToList();
    curPart.CurrentState["TargetType"] = targetType;
    curPart.ShowModalDialog("4034d041-4190-4eb8-9e0a-16a214370108", "", "600", "152", TaskID, nameValues, true, true);
}

BeforeRender处理点击确认的信息

如果不是UI插件,是webPart页面,那在AfterUIModelBinding中处理

public override void BeforeRender(IPart Part, EventArgs args)
{
    base.BeforeRender(Part, args);

    // ReMakePland=true就表示用户点击了确认
    if (bool.TryParse(Part.CurrentState["ReMakePland"]?.ToString(), out bool reMakePland) && reMakePland)
    {
        // 如果插件只有一个弹窗可以不判断TargetType,但是TargetType最后也要=null
        string targetType = Part.CurrentState["TargetType"]?.ToString();
        switch (targetType)
        {
            case "操作1": // do操作1的方法
                break;
            case "操作2": // do操作2的方法
                break;
            default: break;
        }
        
        Part.CurrentState["ReMakePland"] = null;
        Part.CurrentState["TargetType"] = null;
    }
}

弹窗效果图示

提示信息最好不超过4行

image.png

0

评论 (1)

取消
  1. 头像
    秋驰雪隙 作者
    Windows 10 · Google Chrome

    画图

    回复