U9 使能控件使用范例说明 版 本 号 :V1.0 作者:胡朋威 版本记录 【此部分要记录该文档形成过程中的历次版本变更过程及变更的内容】 版本 修改与参与人 修改时间 修改原因 修改概述 审批人1.0 胡朋威 2008/06/30 原始文档建立 一.问题域说明 UI 上的控件可能存在互相制约的关系,当某个控件满足一定的条件的时候,需要控制与这个控件相关的一些控件是否可用或者只读属性等,这个时候就要使用使能控件。 二.基本原理 可以直接在 UBF 设计器上直接添加使能控件,也可以用 CodeBlock 代码控制。 在 UBF 设计器上直接添加使能控件,设置触发控件的触发事件,触发表达式和响应控制的响应属性。 三.关键代码及说明 1. 在 UBF 设计器上添加使能控件示例 注:根据需要在 UBF 设计器里把“在服务器端运行”打上钩。 2. 使用代码控制示例 ///
/// 控制卡片上控件使能 /// ///
触发控件 ///
目标控件 ///
禁用时的条件 public static void SetCardEnableAssociation(IUFControl sourceControl, IUFControl[] targetControls, string expression) { AssociationControl assControl; CodeBlock codeBlock; assControl = new AssociationControl(); ; codeBlock = new CodeBlock(); assControl.SourceServerControl = sourceControl; assControl.SourceControl.EventName = "onchange"; codeBlock.Condition = expression; assControl.addBlock(codeBlock); foreach (IUFControl ctr in targetControls) { if (ctr is IUFLabel) // Label控件设置enable { codeBlock.TargetControls.addControl(ctr, "Enabled", "false"); } else// 其它控制设置只读 { codeBlock.TargetControls.addControl(ctr, "ReadOnly", "true"); } } codeBlock = new CodeBlock(); expression = " else "; codeBlock.Condition = expression; assControl.addBlock(codeBlock); foreach (IUFControl ctr in targetControls) { if (ctr is IUFLabel) { codeBlock.TargetControls.addControl(ctr, "Enabled", "true"); } else { codeBlock.TargetControls.addControl(ctr, "ReadOnly", "false"); } } } 本示例代码参见: E:\View\U9UICode\U9.VOB.PD.FI\CFP\Code\CFPCommonUI\UITools.cs 46-88 行 ///
/// Grid上的某列的使能关联 /// ///
禁用时的条件 ///
列对应的属性名 ///
DataGrid public static void SetGridEnableColumnAssociation(string expression, string colName, IUFDataGrid DataGrid1) { AssociationControl assControl = new AssociationControl(); CodeBlock codeBlock = new CodeBlock(); assControl.SourceServerControl = DataGrid1; assControl.SourceControl.EventName = "OnBeforeCellFocusEnter"; UFWebClientGridAdapter grid = new UFWebClientGridAdapter(DataGrid1); codeBlock.Condition = expression; assControl.addBlock(codeBlock); ((IUFClientAssoGrid)assControl.SourceControl).FireEventCols.Add(colName); //设置enable grid.EnabledCols.Add(new string[] { colName, "false", "" }); codeBlock.TargetControls.addControl(grid); } 本示例代码参见: E:\View\U9UICode\U9.VOB.PD.FI\CFP\Code\CFPCommonUI\UITools.cs 109-136 行 四.源代码使用说明 卡片上的控制 UFWebClientDropDownListAdapter ddlContent = new UFWebClientDropDownListAdapter(this.Content); //当预测内容为银行时银行账号可用,其它情况不可用 expression = "if (" + ddlContent.Value + " != " + (int)ContentEnumData.Bank + ")"; UITools.SetCardClearValueAssociation(this.Content, "", targetControls); SetEnableAssociation(this.Content, getContentRelateControls(), “”); private IUFControl[] getContentRelateControls() { return new IUFControl[] { this.lblBankAccount, this.BankAccount, this.lblBankAccCombin, this.BankAccCombin }; } 列表上的控制 string expression = string.Format("if ({0} != '{1}')", grid.getSelectedValuePK("Content"), (int)ContentEnumData.Bank); UITools.SetGridEnableColumnAssociation(expression, “BankAccount”,DataGrid1); 五.组装发布说明(可选)