金蝶k3cloud高效分录赋值方法

来源:互联网 发布:办公表格软件excel 编辑:程序博客网 时间:2024/05/24 07:15

k3cloud两种分录赋值方法对比,后者比前者快10倍左右。代码如下:

如有问题加qq群:金蝶k3cloud二次开发群 188617330  有大量的学习文档。

using Kingdee.BOS.App.Data;

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using System.ComponentModel;
using System.Diagnostics;


namespace TestCore
{
    [Description("批量设置分录")]
    public class CreateEntryNewDataPlus : AbstractBillPlugIn
    {
        public override void BarItemClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.Equals("tbButton") == true)
            {
                Stopwatch watch = new Stopwatch();//实例化一个计时器 
                watch.Start();//开始计时/*此处为要计算的运行代码例如
                this.Model.BeginIniti();
                this.Model.DeleteEntryData("FEntity");
                for (int i = 0; i < 100000; i++)
                {
                    int newEntry = this.Model.GetEntryRowCount("FEntity");
                    this.Model.CreateNewEntryRow("FEntity");
                    this.Model.SetValue("FName", 2344, i);
                }
                this.Model.EndIniti();
                this.View.UpdateView("FEntity");
                watch.Stop();//结束计时 //获取当前实例测量得出的总运行时间(以毫秒为单位) 
                string time = watch.ElapsedMilliseconds.ToString();
                this.View.ShowMessage(time);
            }
            if (e.BarItemKey.Equals("tbButton1") == true)
            {
                Stopwatch watch = new Stopwatch();//实例化一个计时器 
                watch.Start();//开始计时/*此处为要计算的运行代码例如:int sum=0; for(int i=0; i<100;i++){ for(int j=0;j<100;j++){sum+=j;}}*/ 


                this.Model.BeginIniti();
                this.Model.DeleteEntryData("FEntity");
                Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
                DynamicObjectCollection rows = this.Model.GetEntityDataObject(entity);
              //  rows.RemoveAt(0);
                // 把加载的数据包,加入到单据体行集合中
                // 示例代码,创建一个空的数据包,仅用来演示如何向单据体集合添加新行
                for (int i = 0; i < 100000; i++)
                {
                    DynamicObject row = new DynamicObject(entity.DynamicObjectType);
                    row["FName"] = "122";
                    row["Seq"] = i+1;
                    rows.Add(row);
                }
                this.Model.EndIniti();
                this.View.UpdateView("FEntity");
                watch.Stop();//结束计时 //获取当前实例测量得出的总运行时间(以毫秒为单位) 
                string time = watch.ElapsedMilliseconds.ToString();
                this.View.ShowMessage(time);
            }
        }
    }
}
1 0
原创粉丝点击