将需要定时的任务发布的生成数据包装成一个类(Wrap the generated data published by the task that needs to be scheduled into a class)

//定时器代码可以写在另一个表单中调用这个类//只要写成了类就可以在本应用中调用//调用的方法是new这个类对象,然后用对象点出来public class FunctionSupClass
{//engine objectid 为参数传入 提交流程将true换成false
    public void FunctionSupTask(H3.IEngine Engine, string objectid)
    {
        //监督计划清单
        H3.DataModel.BizObject sourceBo = H3.DataModel.BizObject.Load(H3.Organization.User.SystemUserId, Engine, "D002033D002033FunctionSupervisionPlanList", objectid, false);
        //查询 监督检查部门 与 监督职责
        string sql = "SELECT" +
            "    b.objectid, b.joinSupervisionDepartment" +
            "    i_D002033HowToDoFunctionSupervision a" +
            "JOIN i_D002033FunctionSupervision b a.joinFunctionSupervision = b.objectid";
        System.Data.DataTable dt = Engine.Query.QueryTable(sql, null);
        if(dt != null && dt.Rows.Count > 0)
        {
            H3.DataModel.BizObject deptSetupBo = H3.DataModel.BizObject.Load(H3.Organization.User.SystemUserId, Engine, "D002033organiztionSetup", dt.Rows[0]["joinSupervisionDepartment"] + string.Empty, false);
            //监督检查对象
            H3.DataModel.BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema("D002033FunctionSupervisionTask");
            H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(Engine, schema, ((string[]) deptSetupBo["head"])[0]);
            targetBo["joinFunctionSupervisionPlanList"] = sourceBo.ObjectId; // 关联监督计划清单
            targetBo["FunctionSupervisionSub"] = sourceBo["FunctionSupervisionSub"]; //职能监督范围
            targetBo["HowToDoFunctionSupervisionSub"] = sourceBo["HowToDoFunctionSupervisionSub"]; //监督检查内容
            targetBo["isFocus"] = sourceBo["isFocus"]; //重点监督项
            targetBo["joinFunctionSupervision"] = dt.Rows[0]["objectid"];
            targetBo["joinSupervisionDepartment"] = deptSetupBo.ObjectId;
            targetBo["supervisionDepartment"] = deptSetupBo["department"];
            targetBo["supervisionDepartmentHead"] = deptSetupBo["head"];
            targetBo["supervisionDepartmentDirectLeadership"] = deptSetupBo["directLeadership"];

            string instanceId = System.Guid.NewGuid().ToString();
            if(string.IsNullOrEmpty(targetBo.WorkflowInstanceId))
                targetBo.WorkflowInstanceId = instanceId;

            targetBo.Create();

            H3.Workflow.Instance.WorkflowInstance wfInstance = Engine.WorkflowInstanceManager.GetWorkflowInstance(targetBo.WorkflowInstanceId);
            if(wfInstance == null)
            {
                //启动流程
                string workItemID = string.Empty;
                string errorMsg = string.Empty;
                H3.Workflow.Template.WorkflowTemplate wfTemp = Engine.WorkflowTemplateManager.GetDefaultWorkflow(targetBo.Schema.SchemaCode);
                Engine.Interactor.OriginateInstance(((string[]) targetBo["supervisionDepartmentHead"])[0], targetBo.Schema.SchemaCode,
                    wfTemp.WorkflowVersion, targetBo.ObjectId, targetBo.WorkflowInstanceId, H3.Workflow.WorkItem.AccessMethod.Web,
                    false, string.Empty, true, out workItemID, out errorMsg);
            }//第七个参数 false/true 为是否提交流程操作
        }
    }
————————
//定时器代码可以写在另一个表单中调用这个类//只要写成了类就可以在本应用中调用//调用的方法是new这个类对象,然后用对象点出来public class FunctionSupClass
{//engine objectid 为参数传入 提交流程将true换成false
    public void FunctionSupTask(H3.IEngine Engine, string objectid)
    {
        //监督计划清单
        H3.DataModel.BizObject sourceBo = H3.DataModel.BizObject.Load(H3.Organization.User.SystemUserId, Engine, "D002033D002033FunctionSupervisionPlanList", objectid, false);
        //查询 监督检查部门 与 监督职责
        string sql = "SELECT" +
            "    b.objectid, b.joinSupervisionDepartment" +
            "    i_D002033HowToDoFunctionSupervision a" +
            "JOIN i_D002033FunctionSupervision b a.joinFunctionSupervision = b.objectid";
        System.Data.DataTable dt = Engine.Query.QueryTable(sql, null);
        if(dt != null && dt.Rows.Count > 0)
        {
            H3.DataModel.BizObject deptSetupBo = H3.DataModel.BizObject.Load(H3.Organization.User.SystemUserId, Engine, "D002033organiztionSetup", dt.Rows[0]["joinSupervisionDepartment"] + string.Empty, false);
            //监督检查对象
            H3.DataModel.BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema("D002033FunctionSupervisionTask");
            H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(Engine, schema, ((string[]) deptSetupBo["head"])[0]);
            targetBo["joinFunctionSupervisionPlanList"] = sourceBo.ObjectId; // 关联监督计划清单
            targetBo["FunctionSupervisionSub"] = sourceBo["FunctionSupervisionSub"]; //职能监督范围
            targetBo["HowToDoFunctionSupervisionSub"] = sourceBo["HowToDoFunctionSupervisionSub"]; //监督检查内容
            targetBo["isFocus"] = sourceBo["isFocus"]; //重点监督项
            targetBo["joinFunctionSupervision"] = dt.Rows[0]["objectid"];
            targetBo["joinSupervisionDepartment"] = deptSetupBo.ObjectId;
            targetBo["supervisionDepartment"] = deptSetupBo["department"];
            targetBo["supervisionDepartmentHead"] = deptSetupBo["head"];
            targetBo["supervisionDepartmentDirectLeadership"] = deptSetupBo["directLeadership"];

            string instanceId = System.Guid.NewGuid().ToString();
            if(string.IsNullOrEmpty(targetBo.WorkflowInstanceId))
                targetBo.WorkflowInstanceId = instanceId;

            targetBo.Create();

            H3.Workflow.Instance.WorkflowInstance wfInstance = Engine.WorkflowInstanceManager.GetWorkflowInstance(targetBo.WorkflowInstanceId);
            if(wfInstance == null)
            {
                //启动流程
                string workItemID = string.Empty;
                string errorMsg = string.Empty;
                H3.Workflow.Template.WorkflowTemplate wfTemp = Engine.WorkflowTemplateManager.GetDefaultWorkflow(targetBo.Schema.SchemaCode);
                Engine.Interactor.OriginateInstance(((string[]) targetBo["supervisionDepartmentHead"])[0], targetBo.Schema.SchemaCode,
                    wfTemp.WorkflowVersion, targetBo.ObjectId, targetBo.WorkflowInstanceId, H3.Workflow.WorkItem.AccessMethod.Web,
                    false, string.Empty, true, out workItemID, out errorMsg);
            }//第七个参数 false/true 为是否提交流程操作
        }
    }