这篇将继续围绕上篇所说的第二种方法,记录说明一下自己遇到的问题以及解决方法。
一、创建或更新包含子表的表单
二、流程事件变化后执行某些逻辑
一、创建或更新包含子表的表单
1、首先介绍关于在后端创建包含子表的表单:
1 //根据ID查询当前表单数据 2 string sql1 = "select Warehouse1 as Warehouse1,MyProject as MyProject,Class1 as Class1,People as People,Dept as Dept," + 3 "Principal as Principal from I_D000399SgProductionAcquisition where Objectid = ‘" + ObjectId + "‘"; 4 System.Data.DataTable table1 = this.Engine.Query.QueryTable(sql1, null); 5 int rowCount1 = table1.Rows.Count; 6 7 //根据ID查询当前表单子表数据 8 string sql2 = "select ControlCatalogue as ControlCatalogue,No as No,MaterialName as MaterialName,Type as Type,Unit1 as Unit1 " + 9 "from I_D000399SgBugApplyDetails where parentobjectid = ‘" + ObjectId + "‘"; 10 System.Data.DataTable table2 = this.Engine.Query.QueryTable(sql2, null); 11 int rowCount2 = table2.Rows.Count; 12 13 List < H3.DataModel.BizObject > _list = new List<H3.DataModel.BizObject>(); 14 for(int i = 0;i < rowCount2; i++) { 15 //创建子表对象 16 H3.DataModel.BizObject childBo = new H3.DataModel.BizObject(this.Request.Engine, this.Request.Engine.BizObjectManager.GetPublishedSchema("D000399SqOutbound01"), this.Request.UserContext.UserId); 17 childBo["ControlCatalogue"] = table2.Rows[i]["ControlCatalogue"].ToString(); 18 childBo["No"] = table2.Rows[i]["No"].ToString(); 19 childBo["MaterialName"] = table2.Rows[i]["MaterialName"].ToString(); 20 childBo["Type"] = table2.Rows[i]["Type"].ToString(); 21 childBo["Unit1"] = table2.Rows[i]["Unit1"].ToString(); 22 childBo.Create(); 23 _list.Add(childBo); 24 } 25 26 //创建主表对象 27 H3.DataModel.BizObject bo = new H3.DataModel.BizObject(this.Engine, this.Engine.BizObjectManager.GetPublishedSchema("D000399SqOutbound"), this.Request.UserContext.UserId); 28 bo["WDate"] = DateTime.Today.ToString("yyyy-MM-dd"); 29 bo["YearMonth"] = DateTime.Today.ToString("yyyyMM"); 30 bo["Title"] = "审核批量,生产领用出库"; 31 bo["Acquisition"] = ObjectId; 32 bo["No"] = No; 33 bo["Money"] = AllMoney; 34 for(int i = 0;i < rowCount1; i++) { 35 bo["Warehouse1"] = table1.Rows[i]["Warehouse1"].ToString(); 36 bo["MyProject"] = table1.Rows[i]["MyProject"].ToString(); 37 bo["Class"] = table1.Rows[i]["Class1"].ToString(); 38 bo["People"] = table1.Rows[i]["People"].ToString(); 39 bo["Dept"] = table1.Rows[i]["Dept"].ToString(); 40 bo["Principal"] = table1.Rows[i]["Principal"].ToString(); 41 } 42 bo["D000399SqOutbound01"] = _list.ToArray(); 43 bo.Status = H3.DataModel.BizObjectStatus.Effective; 44 bo.Create();
上述代码是根据ID,查询某表单以及其子表数据,再将数据对应赋值给创建的表单以及创建表单的子表,这里表单或者其子表的ID都是系统自己随机生成,同时可以设置创建表单的状态,需要注意的是这里创建后的表单继续会触发它对应的业务规则。
2、再介绍关于在后端更新包含子表的表单:
1 //查询当前表单子表中需要冲减的数量 2 string sql1 = "select ControlCatalogue as ControlCatalogue,Num3 as Num3 from I_D000399SgBuyDetails" + 3 " where parentobjectId = ‘" + BuyApply + "‘ and Num3 != 0"; 4 System.Data.DataTable table1 = this.Engine.Query.QueryTable(sql2, null); 5 int rowCount1 = table1.Rows.Count; 6 7 H3.Data.Filter.Filter filter = new H3.Data.Filter.Filter(); 8 H3.Data.Filter.And andMatcher = new H3.Data.Filter.And(); 9 10 andMatcher.Add(new H3.Data.Filter.ItemMatcher("ObjectId", H3.Data.ComparisonOperatorType.Equal, UseAllPlan)); 11 filter.Matcher = andMatcher; 12 H3.DataModel.BizObjectSchema accountSchema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D000399SgUseAllPlan"); 13 H3.DataModel.BizObject[] customers = H3.DataModel.BizObject.GetList(this.Request.Engine, this.Request.UserContext.UserId, 14 accountSchema, H3.DataModel.GetListScopeType.GlobalAll, filter); 15 if(customers != null && customers.Length > 0) 16 { 17 H3.DataModel.BizObject[] details = (H3.DataModel.BizObject[]) customers[0]["D000399SgUseAllDetails"]; 18 List < H3.DataModel.BizObject > boList = new List<H3.DataModel.BizObject>(); 19 //保存原子表记录,先获取子表内容,循环将其原有数据添加到boList 20 if(details != null) 21 { 22 foreach(H3.DataModel.BizObject dt in details) 23 { 24 for(int i = 0;i < rowCount1; i++) { 25 string ControlCatalogue = table1.Rows[i]["ControlCatalogue"].ToString(); 26 string Num3 = table1.Rows[i]["Num3"].ToString(); 27 28 if(string.Equals(dt["ControlCatalogue"], ControlCatalogue)) 29 { 30 int temp1 = Convert.ToInt32(dt["Num4"]) - Convert.ToInt32(Num3); 31 dt["Num4"] = Convert.ToString(temp1); 32 int temp2 = Convert.ToInt32(dt["Num5"]) + Convert.ToInt32(Num3); 33 dt["Num5"] = Convert.ToString(temp2); 34 } 35 } 36 boList.Add(dt); 37 } 38 } 39 H3.DataModel.BizObjectSchema schema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D000399SgUseAllPlan"); 40 H3.DataModel.BizObject schemaObject = new H3.DataModel.BizObject(this.Request.Engine, schema, this.Request.UserContext.UserId); 41 schemaObject.ObjectId = UseAllPlan; //更新的表单ID为UseAllPlan 42 schemaObject.Load(); 43 schemaObject["D000399SgUseAllDetails"] = boList.ToArray(); 44 schemaObject.Update(); 45 }
上述代码是根据ID,更新目标表单的子表数据,需要注意的是这里更新后的表单同样会触发它对应的业务规则,如果不想触发业务规则,也可采用sql语句更新的方式,如下所示。
1 //将‘项目信息‘中项目成员赋值给‘我的项目’的项目成员 2 string sql1 = "update I_D000399SgProjectMy set I_D000399SgProjectMy.Members = (select Members from I_D000399SgProject "+ 3 "where I_D000399SgProjectMy.Project = I_D000399SgProject.Objectid)"; 4 this.Engine.Query.QueryTable(sql1, null);
二、流程事件变化后执行某些逻辑
当一个表单生效或作废后,若有业务规则首先会执行业务规则,通常有更新或新增等操作。然后再执行流程变化后事件。前提是当前表单已经开启了表单流程。代码如下:
1 protected override void OnWorkflowInstanceStateChanged(H3.Workflow.Instance.WorkflowInstanceState oldState, H3.Workflow.Instance.WorkflowInstanceState newState) 2 { 3 //流程审批结束,业务规则执行。还有个审批流程结束(finished状态下直接删除),就直接删除也会触发业务规则执行。在submit里面处理 4 if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Running && newState == H3.Workflow.Instance.WorkflowInstanceState.Finished) 5 { 6 DoAfterPass1(this.Request.BizObject.ObjectId); 7 } 8 //流程审批结束后,重新激活,业务规则会执行。还有个审批流程结束(finished状态下直接删除),就直接删除也会触发业务规则执行。在submit里面处理 9 if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Finished && newState == H3.Workflow.Instance.WorkflowInstanceState.Running) 10 { 11 DoAfterPass2(this.Request.BizObject.ObjectId); 12 } 13 base.OnWorkflowInstanceStateChanged(oldState, newState); 14 }
this.Request.BizObject.ObjectId; //当前表单的ID
至此是对氚云部分功能的一个简单介绍,后续会继续说明其它部分功能所遇到的问题以及解决方法。
如有疏漏错误之处,还请不吝赐教!
原文地址:https://www.cnblogs.com/yijialong/p/9579331.html
时间: 2024-10-24 10:14:20