准备工作
创建TEST04文件夹,在其中创建视图模型Test04,添加一个dataset1(AutoSqlDataset)数据来自EMPLOYEE表,再添加一个table1(DataTable),一个form1(Autoform),一个datapilot1(DataPilot),全部与dataset1绑定。
设置匹配条件
第一步使用向导(Wizard)增加dataset1的匹配条件。点击左侧的向导(Wizard) 图标,或者在dataset1的右键菜单中选择"Wizard"菜单项。
AutoSqlDataset的设置查询条件过程实际上是一个拼SQL语句的过程。如果不设置任何查询条件,所生成的SQL语句相当于"SELECT * "。 |
在AutoSqlDataset Wizard中,切换到Where标签页,选中EMPLOYEE_ID再点击 右键头。
在下拉框Op.中选择"like",在Value中输入":Employee_ID"。
以此类推,再添加两个条件字段选择SALARY,Op.与Value分别是>= :SalaryMin和<=:SalaryMax。点击按钮OK保存设置。
这时,再点击dataset1子节点MatchRules时,会看到多了3个匹配条件MatchRule ,仔细观察其属性datatype、operator、originField、table、value等就是在向导中设置的。
使用向导与使用MatchRules的右键菜单(Insert->BaseMatchRule)是相效的。
这时生成JSP进行浏览,会看到没有数据输出。
在MatchRules中将ecacpaeEnabled属性设为true。
这时再浏览页面,就会看到数据呈现了。
添加条件数据集
第二步添加一个FormDatset , 重命名为datasetConditions。
在datasetConditions子节点Fields添加3个Field,重命名为Employee_ID, SalaryMin, SalaryMax。
添加用于条件输入的表单
在Controls中添加一个AutoForm,重命名为formConditions,设置其dataset属性为datasetConditions。
添加查询命令
添加一个QueryCommand,重命名为commandQuery。
设置commandQuery的queryDataset为dataset1,conditionDataset为datasetConditions。
添加查询按钮
添加一个按钮,设置button1的command属性为commandQuery。
改进
将button1输出到JSP,浏览页面,在Employ_ID文本框中输入"%AN%",在SalaryMin与SalaryMax中分别输入1000与5000,点击button1,就得到工号中包含"AN",并且Salary大于等于1000,并且Salary小于等于5000的记录。
做一处改进,一个是在commandQuery的beforeExecute方法中添加代码。
var Employee_ID = datasetConditions.getValue("Employee_ID"); if (Employee_ID) { command.parameters().setValue("Employee_ID", "%" + Employee_ID + "%"); } else { command.parameters().setValue("Employee_ID", ""); }
这样在Employee_ID中输入"AN"即可,不用在前后特别加上2个通配符"%"了。
再做一处改进,在datasetConditions的Fields中的SalaryMin与SalaryMax的dataType属性设为double。这样在页面上SalaryMin与SalaryMax就只接入数字型的输入了。
dorado原理:dorado中的查询
|
dorado中的查询通常需要两个dataset, 一个用于承载查询结果,一个用于承载查询条件。用于承载查询条件的dataset通常使用FormDataset,即其数据是来自于前台页面的,而不是如AutoSqlDataset等是来自于后台业务逻辑的。相对于FormDataset的Controls通常是AutoForm。查询是与后台发生数据交互的,因此是button+QueryCommand的操作方式。 |
dorado原理:dorado查询的运行时态
|
|
Attachments:

























