附件明细保存附件时,校验当前附件是否与此单据已上传的附件有重名

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

附件明细保存附件时,校验当前附件是否与此单据已上传的附件有重名

【应用场景】

附件明细保存附件时,校验当前附件是否与此单据已上传的附件有重名。


【注意事项】

1、该二开方案只能干涉到附件明细保存附件。

2、快传和批量新增上传附件二开干预会对标准逻辑影响较大,会影响后续升级。

3、预计v9版本标准产品会有重名校验功能,该方案只针对v9以下版本。


【案例演示】

附件明细保存附件时,校验当前附件是否与此单据已上传的附件有重名。

如果有重名就给出提示,并取消保存。


【实现步骤】

<1>编写表单插件和服务插件,代码如下。 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Attachment;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Util;

namespace DemoPlugin
{
    [Description("附件明细插件扩展"), HotUpdate]
    public class AttachmentBillPlugInExt : AbstractBillPlugIn
    {
        public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
        {
            base.BeforeDoOperation(e);
            if (e.Operation.FormOperation.Operation.EqualsIgnoreCase("Save"))
            {
                var attachmentKey = GetAttachmentKey();
                object attachmentName;
                this.Model.DataObject.TryGetValue("AttachmentName", out attachmentName);
                if (!string.IsNullOrWhiteSpace(attachmentKey.BillType)
                    && !string.IsNullOrWhiteSpace(attachmentKey.BillInterID)
                    && !attachmentName.IsNullOrEmptyOrWhiteSpace())
                {
                    var sql = "SELECT 1 FROM T_BAS_ATTACHMENT WHERE FBILLTYPE = @FBILLTYPE AND FINTERID = @FINTERID AND FATTACHMENTNAME = @NAME";
                    var param = new SqlParam[]
                    {
                        new SqlParam(@"FBILLTYPE", KDDbType.String, attachmentKey.BillType),
                        new SqlParam(@"FINTERID", KDDbType.String, attachmentKey.BillInterID),
                        new SqlParam(@"NAME", KDDbType.String, attachmentName),
                    };
                    var data = DBUtils.ExecuteScalar<int?>(this.Context, sql, 0, param);
                    if (data == 1)
                    {
                        this.View.ShowWarnningMessage("当前附件与已上传附件有重名,请改名后再上传。");
                        e.Cancel = true;
                    }
                }
            }
        }

        /// <summary>
        /// 获取附件参数
        /// </summary>
        /// <returns></returns>
        private AttachmentKey GetAttachmentKey()
        {
            AttachmentKey attachmentKey = new AttachmentKey();
            //默认为编辑状态
            attachmentKey.OperationStatus = OperationStatus.EDIT;
            if (this.View.ParentFormView != null && this.View.ParentFormView.OpenParameter.GetCustomParameter(KeyConst.AttachmentKey) != null)
            {
                string json = this.View.ParentFormView.OpenParameter.GetCustomParameter(KeyConst.AttachmentKey).ToString();
                attachmentKey = AttachmentKey.ConvertFromString(json);

            }
            return attachmentKey;
        }
    }
}


<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。

<3>BOSIDE扩展附件明细(BOS_Attachment),注册表单插件,保存元数据,开发完毕。


【功能验证】

<1>登录业务站点,打开一个可在附件管理上传附件的单据,点击新增上传并保存附件


【金蝶云星空BOS二次开发案例演示】

https://vip.kingdee.com/article/94751030918525696



附件明细保存附件时,校验当前附件是否与此单据已上传的附件有重名

【应用场景】附件明细保存附件时,校验当前附件是否与此单据已上传的附件有重名。【注意事项】1、该二开方案只能干涉到附件明细保存附件。2...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息