二开案例.附件控件必录校验

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

二开案例.附件控件必录校验

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

image.webp

image.webp

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;
                }
            }
        }
    }
}


二开案例.附件控件必录校验

保存时,校验附件是否已上传。using Kingdee.BOS.Core.DynamicForm.PlugIn;using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;using Kingdee...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息