
using System;
using System.Collections.Generic;
using System.Text;
using H3;

public class D000867Sscjmr10zg51xaa22ib6infyy2: H3.SmartForm.SmartFormController
{
    public D000867Sscjmr10zg51xaa22ib6infyy2(H3.SmartForm.SmartFormRequest request): base(request)
    {
    }

    protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response)
    {
        base.OnLoad(response);
    }

    protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response)
    {
        // 表单提交：由于附件控件新增的时候获取不了ID，因此通过前端传递传递。注意1：非Submit的情况下，不能通过 this.Request.BizObject["组件ID"] 取值。注意2：前端 AfterSubmit 提交后事件 调用服务不执行
        if(actionName == "sync")
        {
            // 附件控件 [注意：前端直接获取的附件ID，无文件相关信息。若需要如文件名称，需要单独再查询SQL]
            System.Data.DataTable attachments = this.Engine.Query.QueryTable(string.Format("select * from H_bizobjectfile where ObjectId in ({0})", this.Request["attachmentIds"]), null);
            // 请求处理 [项目名称，附件] - 异步
            string status = CP_Utils.syncDingDriveForProject(this.Engine, this.Request["projectName"] + string.Empty, this.Serialize(attachments));
        }
        // 审批节点：后端通过获取即可得到附件对象，返回值与H_bizobjectfile 结构一致
        if(actionName == "Submit" && this.Request.ActivityCode == "Activity3")  // 流程修改1：审批节点标识
        {
            string[] compIds = { "F0000001", "F0000003" }; // 流程修改2：附件组件id
            foreach(string compId in compIds)
            {
                H3.DataModel.BizObjectFileHeader[] files = (H3.DataModel.BizObjectFileHeader[]) this.Request.BizObject[compId];
                if(files != null) {
                    // 请求处理 [项目名称，附件] - 异步
                    CP_Utils.syncDingDriveForProject(this.Engine, this.Request.BizObject["F0000002"] + string.Empty, this.Serialize(files));  // 流程修改3：项目名称组件id
                }
            }
        }
        base.OnSubmit(actionName, postValue, response);
    }
}