16.3、 表单插件,读写数据库, DBUtils,IEnumerable,返回原创
金蝶云社区-林荫大道cc身份
林荫大道cc
17人赞赏了该文章 9891次浏览 未经作者许可,禁止转载编辑于2020年07月03日 18:41:19
封面

业务场景:销售出库单,点击按钮,执行sq后,返回值,再循环赋值,单据体获取全部物料




16.2




1、注释上一节代码




2、


                //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++;
                }



4、重新生成dll



5、最终效果,重新打开销售出库单,点测试按钮,带出全部的物料,跟上一节效果一样


image.png


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++;
                }
                
                //刷新
                this.View.UpdateView("FEntity");
            }
        }
    }
}


总目录链接

https://vip.kingdee.com/article/64993872014591232



赞 17