二开案例.附件控件必录校验原创
金蝶云社区-齐111
齐111
3人赞赏了该文章 265次浏览 未经作者许可,禁止转载编辑于2024年04月12日 09:22:34

保存时,校验附件是否已上传。

image.png

image.png

using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.JSON;
using System.Collections.Generic;

namespace Test24.PlugIns.BL
{
    [Kingdee.BOS.Util.HotUpdate]
    public class 文件上传控件必录 : AbstractDynamicFormPlugIn
    {
        bool fileUploaded = false;
        public override void CustomEvents(CustomEventsArgs e)
        {
            var attachmentFieldKey = "FAttachment"; //附件控件ID
            if (e.EventName == "FileChanged" && e.Key == attachmentFieldKey)
            {
                fileUploaded = false;
                var postData = KDObjectConverter.DeserializeObject<JSONObject>(e.EventArgs);
                if (postData != null)
                {
                    var uploadInfo = new JSONArray(postData["NewValue"].ToString());
                    if (uploadInfo.Count > 0)
                    {
                        var fileInfo = uploadInfo[0] as Dictionary<string, object>;
                        if (fileInfo != null)
                        {
                            var fileName = fileInfo["ServerFileName"].ToString();
                            fileUploaded = true;    //附件已上传
                        }
                    }
                }
            }
        }

        public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
        {
            if (e.Operation.FormOperation.Operation == "Save")
            {
                if (!fileUploaded)
                {
                    this.View.ShowErrMessage("请先上传附件");
                    e.Cancel = true;
                }
            }
        }
    }
}


图标赞 3
3人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!