氚云平台更新表单子表数据方法


1、更新子表数据
    /**
     * 此方法更新子表数据:注意:必须放在提交后面,否则不会生效
     * schemaCode 控件编码,objectid 数据ID,schemaCodeList 需要更新的子表数据ID,ControlCode 需要更新的子表控制编码,controlValue 需要更新的子表控件值
     */
    protected void UpdateSchemaList(string schemaCode, string objectid, string schemaCodeList, string ControlCode, string controlValue)
    {
        H3.DataModel.BizObject masterBo = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Request.Engine, schemaCode, objectid, false);                                             //Load出要修改数据的主表业务对象
        H3.DataModel.BizObjectSchema childSchema = masterBo.Schema.GetChildSchema(schemaCodeList);	//获取子表结构体对象
        List < H3.DataModel.BizObject > newChildBoList = new List();	    //定义新的子表数据集合

        H3.DataModel.BizObject[] childBoArray = (H3.DataModel.BizObject[]) masterBo[schemaCodeList];//获取子表内已有数据
        if(childBoArray != null && childBoArray.Length > 0)
        {
            foreach(H3.DataModel.BizObject itemBo in childBoArray)
            {
                itemBo[ControlCode] = controlValue;
                newChildBoList.Add(itemBo); //将子表内已有数据循环添加到新的子表数据集合里
            }
        }
        masterBo[schemaCodeList] = newChildBoList.ToArray();	//将新的子表数据集合赋值到子表控
        masterBo.Update();  //修改主表业务对象,系统会自动识别出上面子表数据被修改了,执行完Update方法,新的子表数据就会被保存到数据库
    }
2、创建数据并发起流程
    /**
     * 此方法用于子表数据发起子流程
     * schemaCode 需要创建数据的表单编码,子表数据
     */
    protected void test(string schemaCode, H3.DataModel.BizObject itemBo)
    {
        H3.DataModel.BizObjectSchema  schema = this.Engine.BizObjectManager.GetPublishedSchema(schemaCode);
        H3.DataModel.BizObject  bo = new H3.DataModel.BizObject(this.Request.Engine, schema, this.Request.UserContext.UserId);
        bo["Department"] = this.Request["Department"];              //所属部门
        //bo.Status = H3.DataModel.BizObjectStatus.Effective; //设置状态为有效

        string instanceId = System.Guid.NewGuid().ToString();
        if(string.IsNullOrEmpty(bo.WorkflowInstanceId))
            bo.WorkflowInstanceId = instanceId;
        bo.Create();    //创建

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