2020年8月18日更新:
如果想问下代码问题的,建议先咨询官方提供的代码客服。另外可以直接私聊我,平时不看帖子。
——————————————————————————————————
以下分享的都是常用到的一些功能
标红色的是氚云原有的代码框架。
标蓝色的是一些关键参数,请留意参数的意义。
标绿色的是注释,描述一些重要提醒。
模板1:根据角色权限,控制按钮的显示。官方示例:http://help.h3yun.com/channels/3.html#表单
protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response) { base.OnLoad(response);
H3.Organization.OrgRole[] orgs = this.Request.Engine.Organization.GetUserRoles(this.Request.UserContext.UserId, true);//获取用户的角色 bool isNQ = false; foreach(H3.Organization.OrgRole org in orgs) { if(org.Name == "财务部")//判断用户的角色 { isNQ = true; break; } } if(this.Request.BizObject.Status == H3.DataModel.BizObjectStatus.Effective) {response.Actions.Remove("Remove"); //去除一部分按钮response.Actions.Remove("Edit"); //去除一部分按钮 Dictionary < string, H3.SmartForm.ViewAction > dicActions = new Dictionary<string, H3.SmartForm.ViewAction>(); if(this.Request.BizObject.Status == H3.DataModel.BizObjectStatus.Effective && isNQ == true) { dicActions.Add("Edit", new H3.SmartForm.ViewAction("Edit", "编辑", "")); }//根据角色条件新增一部分按钮 if(this.Request.IsCreateMode == false && this.Request.UserContext.UserId == this.Request.BizObject["CreatedBy"]+string.Empty) {dicActions.Add("BtnZCTJ", new H3.SmartForm.ViewAction("BtnZCTJ", "再次提交", "1")); }//根据角色条件新增一部分按钮 foreach(KeyValuePair < string, H3.SmartForm.ViewAction > action in response.Actions) dicActions.Add(action.Key, action.Value); response.Actions = new Dictionary<string, H3.SmartForm.ViewAction>(); response.Actions = dicActions; }
}
模板2:关于子表(数组格式)的一些代码(读取、写入)。
官方示例:http://help.h3yun.com/channels/3.html#后台代码
"如何获取/修改子表数据"
H3.DataModel.BizObject[] details = (H3.DataModel.BizObject[]) this.Request.BizObject["D001700Fd87ff61f9c764eeaa13fe8fef7136adf"];//获取当前子表对象,是一个数组格式 List < H3.DataModel.BizObject > lstObject = new List<H3.DataModel.BizObject>();//创建新数组,类似于string创建新的变量 foreach(H3.DataModel.BizObject detail in details)//数组格式,用遍历的方式读取里面一条条的内容,这个跟传统直线思维有所区别,details是整个数组,detail是单条数据。 { detail["F0000039"] = this.Request.BizObject["SeqNo"] + string.Empty; lstObject.Add(detail);//将重新编辑的数组一条一条地添加到新数组 } this.Request.FormData["D001700Fd87ff61f9c764eeaa13fe8fef7136adf"].Value = lstObject.ToArray();//将新数组赋值到当前子表
模板3:读取当前时间(可以结合节点读取审批时间)。
this.Request.BizObject["F0000020"] = this.Request.BizObject["F0000020"] != null ? this.Request.BizObject["F0000020"] : System.DateTime.Now;
模板4:创建业务对象(复制订单、生成流水记录等)。
官方示例:http://help.h3yun.com/channels/3.html#业务对象
模板5:查询业务对象(读取其他表,更新其他表)。
官方示例:http://help.h3yun.com/channels/3.html#业务对象
模板6:主表控件前端请求后端(表单输入内容的时候执行特定指令)。
官方示例:http://help.h3yun.com/channels/3.html#后台代码
“如何构建虚业务对象返回前端”
模板7:子表控件前端请求后端(表单输入内容的时候执行特定指令)。
var that=this;this.D001700Fahbra3qlyox7m5lb87xlo2vy4.BindChange("Set", //子表变化事件 function(data) { var responseData = data[0]; if (responseData != null && responseData.DataField == "D001700Fahbra3qlyox7m5lb87xlo2vy4.F0000003")//子表里面的控件的变化事件 { var currentRowId = responseData.ObjectId; var course = this.GetCellManager(currentRowId, "D001700Fahbra3qlyox7m5lb87xlo2vy4.F0000003").GetValue(); { $.SmartForm.PostForm("Getcourse",{currentRowIdback:currentRowId},function(data)//提交后端的动作指令和提交后端的数据 { //该括号内是你想系统为你做的事情 var result=data.ReturnData; var Id=result["Id"]; that.D001700Fahbra3qlyox7m5lb87xlo2vy4.UpdateRow(currentRowId, { "D001700Fahbra3qlyox7m5lb87xlo2vy4.F0000016": Id }); var a=that.D001700Fahbra3qlyox7m5lb87xlo2vy4.GetCellManager( currentRowId, "D001700Fahbra3qlyox7m5lb87xlo2vy4.F0000016" ); var b=that.D001700Fahbra3qlyox7m5lb87xlo2vy4.GetCellManager( currentRowId, "D001700Fahbra3qlyox7m5lb87xlo2vy4.F0000002" ); a.SetReadonly(true); b.SetVisible(false); } ,function(error){$.IShowError("错误",JSON.stringify(error));},false); } })
模板8:从另一表获取数据,并加载默认项。
protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response) { H3.Data.Filter.Filter filter = new H3.Data.Filter.Filter(); H3.Data.Filter.And andMatcher = new H3.Data.Filter.And(); andMatcher.Add(new H3.Data.Filter.ItemMatcher("F0000002", H3.Data.ComparisonOperatorType.Equal, true)); filter.Matcher = andMatcher; filter.AddSortBy(new H3.Data.Filter.SortBy("F0000003", H3.Data.Filter.SortDirection.Ascending)); H3.DataModel.BizObjectSchema accountSchema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D001700428bfc13942c4f09aad0c286144ade90"); H3.DataModel.BizObject[] customers = H3.DataModel.BizObject.GetList(this.Request.Engine, this.Request.UserContext.UserId, accountSchema, H3.DataModel.GetListScopeType.GlobalAll, filter); if(customers != null) { List < H3.DataModel.BizObject > lstObject = new List<H3.DataModel.BizObject>(); foreach(H3.DataModel.BizObject customer in customers) { H3.DataModel.BizObject newChild = new H3.DataModel.BizObject(this.Engine, this.Engine.BizObjectManager.GetPublishedSchema("D001700Fcb370695565640bd89ad5fac1c93f43e"), this.Request.UserContext.UserId); newChild["F0000020"] = customer["F0000001"]; newChild["F0000022"] = customer["F0000004"]; lstObject.Add(newChild); } this.Request.BizObject["D001700Fcb370695565640bd89ad5fac1c93f43e"] = lstObject.ToArray(); } base.OnLoad(response); }
模板9:后端自定义SQL查询系统表。
string insuretype = this.Request.BizObject["F0000001"] + string.Empty; string organization = this.Request.BizObject["OwnerDeptId"] + string.Empty; string manager = null; string mysql1 = "SELECT ObjectId,ManagerId FROM H_Company where ObjectId='" + organization + "'";//构造mysql文本语言 string mysql2 = "SELECT ObjectId,ManagerId,ParentId FROM H_Organizationunit where ObjectId='" + organization + "'"; string mysql = null; if(organization == "18f923a7-5a5e-426d-94ae-a55ad1a4b240") { mysql = mysql1; } else { { mysql = mysql2; } } System.Data.DataTable dtAccount = this.Request.Engine.Query.QueryTable(mysql, null);//获取mysql读取到的数据 manager = dtAccount.Rows[0]["ManagerId"].ToString();