16.4、 表单插件,读写数据库, DBUtils,DynamicObjectCollection原创
12人赞赏了该文章
1.7万次浏览
编辑于2020年07月03日 20:41:12
业务场景:销售出库单,点击按钮,执行sq后,返回值,再循环赋值,单据体获取全部物料
续
1、注释上一节代码
2、
//执行sql语句,返回DynamicObjectCollection DynamicObjectCollection Dyobj = DBUtils.ExecuteDynamicObject(this.Context, "/*dialect*/select FMATERIALID,FNumber from T_BD_MATERIAL"); //循环 int j = 0; foreach(DynamicObject obj in Dyobj) { //新增行 this.View.Model.CreateNewEntryRow("FEntity"); //给基础资料物料,赋值 this.View.Model.SetValue("FMaterialID", obj["FMATERIALID"].ToString(), j); //调用物料,值更新 this.View.InvokeFieldUpdateService("FMaterialID", j); //给备注,赋值 this.View.Model.SetValue("FEntrynote", obj["FNumber"].ToString(), j); j++; } //刷新 this.View.UpdateView("FEntity");
3、重新生成dll
4、最终效果,重新打开销售出库单,点测试按钮,带出全部的物料,跟上一节效果一样
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Kingdee.BOS; using Kingdee.BOS.Core.Bill.PlugIn; using System.ComponentModel; //数据库 using Kingdee.BOS.App.Data; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Core.DynamicForm; using System.Data; namespace Kingdee.Bos.ProjectName.BillExecuteSql { [Description("执行数据库")] [Kingdee.BOS.Util.HotUpdate] public class ClassName:AbstractBillPlugIn { //点击按钮事件 public override void BarItemClick(BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e) { base.BarItemClick(e); //当点击YDIE_tbTest按钮,触发 if (e.BarItemKey == "YDIE_tbTest") { // //执行sql语句返回Int,表示影响了多少行 //int x = DBUtils.Execute(this.Context, "/*dialect*/update T_SAL_OUTSTOCKENTRY set FNOTE ='测试'"); // //弹窗显示 //this.View.ShowMessage(x.ToString()); //执行sql语句返回DataSet //ExecuteDataSet执行 //this.Context 上下文关联 //抓取 物料表T_BD_MATERIAL的 ID和代码 //DataTable,Tables[0] 操作数据库,读取第一张表,赋值给dt //DataTable dt = DBUtils.ExecuteDataSet(this.Context, "/*dialect*/select FMATERIALID,FNumber from T_BD_MATERIAL").Tables[0]; ////循环,读取dt表有多少行 //for(int i =0; i<dt.Rows.Count;i++) //{ // //新增行 // this.View.Model.CreateNewEntryRow("FEntity"); // //给基础资料物料,赋值 // this.View.Model.SetValue("FMaterialId", dt.Rows[i]["FMATERIALID"].ToString(), i); // //调用物料,值更新 // this.View.InvokeFieldUpdateService("FMaterialID", i); // //给备注,赋值 // this.View.Model.SetValue("FEntrynote", dt.Rows[i]["FNumber"].ToString(), i); //} ////DBUtils.ExecuteEnumerable 执行sql //IEnumerable<IDataRecord> itemDataTable = DBUtils.ExecuteEnumerable(this.Context, "/*dialect*/select FMATERIALID,FNumber from T_BD_MATERIAL"); ////循环 //int i = 0; //foreach(IDataRecord drItem in itemDataTable) //{ // //新增行 // this.View.Model.CreateNewEntryRow("FEntity"); // //给基础资料物料,赋值 // this.View.Model.SetValue("FMaterialID", drItem["FMATERIALID"].ToString(), i); // //调用物料,值更新 // this.View.InvokeFieldUpdateService("FMaterialID", i); // //给备注,赋值 // this.View.Model.SetValue("FEntrynote", drItem["FNumber"].ToString(), i); // i++; //} //执行sql语句,返回DynamicObjectCollection DynamicObjectCollection Dyobj = DBUtils.ExecuteDynamicObject(this.Context, "/*dialect*/select FMATERIALID,FNumber from T_BD_MATERIAL"); //循环 int j = 0; foreach(DynamicObject obj in Dyobj) { //新增行 this.View.Model.CreateNewEntryRow("FEntity"); //给基础资料物料,赋值 this.View.Model.SetValue("FMaterialID", obj["FMATERIALID"].ToString(), j); //调用物料,值更新 this.View.InvokeFieldUpdateService("FMaterialID", j); //给备注,赋值 this.View.Model.SetValue("FEntrynote", obj["FNumber"].ToString(), j); j++; } //刷新 this.View.UpdateView("FEntity"); } } } }
总目录链接
https://vip.kingdee.com/article/64993872014591232
Kingdee.Bos.Test16.zip(57.85KB)
赞 12
12人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读