供应商对账单二开添加字段!原创
金蝶云社区-GZ何伟
GZ何伟
7人赞赏了该文章 123次浏览 未经作者许可,禁止转载编辑于2024年07月15日 16:36:49

一、供应商对账单二开添加字段,继承原来供应商对账单表单插件Statement基类


using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.FIN.AP.Business.PlugIn;
using Kingdee.K3.FIN.AP.ServiceHelper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Dynamic;
using System.Linq;
namespace Demo.BusinessPlugIn
{
    /// <summary>
    /// khdzdBillPlugin 的摘要说明
    /// </summary>
    [Kingdee.BOS.Util.HotUpdate]
    [Description("供应商对账单二开添加字段")]
    public class GysdzdBillPlugin : Statement
    {
        string customerName = ""; //过滤条件往来单位
        string newtempTable = ""; //新的临时表
        bool NewSearch = false; //是否是新查询的数据
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            if (e.BarItemKey == "tbFilter")
            {
                this.customerName = "";
                NewSearch = true;
            }
            if (e.BarItemKey == "tbRefresh")
            {
                NewSearch = true;
            }
            base.BarItemClick(e);
        }
        public override void DataChanged(DataChangedEventArgs e)
        {
            if (e.Field.Key == "FCombo")
            {
                NewSearch = false;
            }
            base.DataChanged(e);
        }
        protected override void Refresh()
        {
            
            if (this.filterPara == null)
            {
                return;
            }
            string oldSelectedValue = Convert.ToString(this.View.Model.GetValue("FCombo"));
            if (Convert.ToBoolean(this.filterPara.CustomFilter["FByContact"]))
            {
                customerName = this.GetSupplierData(oldSelectedValue);
            }
            dropTempTable();
            base.Refresh();
        }
        public override void BeforeClosed(BeforeClosedEventArgs e)
        {
            dropTempTable();
            base.BeforeClosed(e);
        }
        /// 将标准的对账单生成的临时表数据复制到带有扩展字段的临时表里面去
        public void CopyDataToNewTempTable()
        {
            var custmoFilter = this.filterPara.CustomFilter;
            
            this.newtempTable = GetTempTable();
            string sql = string.Format(@"/*dialect*/ 
            select * into {1} from (
            select  
t1.*,'CCCCCCCC' 'F_TAIC_Text'
                       from {0} t1
                ) tab  ",
                   this.tempTable, this.newtempTable);
            DBUtils.Execute(this.Context, sql);
        }
        /// 获取新的带有扩展字段的数据
        public DynamicObjectCollection GetNewData()
        {
            CopyDataToNewTempTable();
            DynamicObjectCollection dataByContactUnit = StatementServiceHelper.GetDataByContactUnit(base.Context, this.newtempTable, customerName);
            return dataByContactUnit;
        }
        /// 获取新的带扩展字段的汇总数据
        public DynamicObjectCollection GetNewSumDate()
        {
            DynamicObjectCollection sumDataByContactUnit = StatementServiceHelper.GetSumDataByContactUnit(base.Context, this.newtempTable, this.agingKeys.Keys.ToList(), customerName);
            return sumDataByContactUnit;
        }
      
        public override void SetListData(DynamicObjectCollection data)
        {
            if (NewSearch)
            {
                DynamicObjectCollection dt = GetNewData();
                string oldTempTable = this.tempTable;
                this.tempTable = this.newtempTable;
                this.newtempTable = oldTempTable;
                base.SetListData(dt);
            }
            else
            {
                base.SetListData(data);
            }
        }
        public override void SetListSumData(DynamicObjectCollection data)
        {
            if (NewSearch)
            {
                DynamicObjectCollection dt = GetNewSumDate();
                base.SetListSumData(dt);
            }
            else
            {
                base.SetListSumData(data);
            }
        }
        /// 删除临时表
        private void dropTempTable()
        {
            if (!string.IsNullOrWhiteSpace(this.newtempTable))
            {
                IDBService dbservice = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();
                dbservice.DeleteTemporaryTableName(this.Context, new string[] { this.newtempTable });
                this.newtempTable = "";
            }
        }
        /// 获取临时表名称
        private string GetTempTable()
        {
            IDBService dbservice = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();
            string[] temptables = dbservice.CreateTemporaryTableName(this.Context, 1);
            return temptables[0];
        }
    }
}


二,供应商对账单注册插件,停用继承的插件

image.png

图标赞 7
7人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!

您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!

请选择打赏金币数 *

10金币20金币30金币40金币50金币60金币
可用金币: 0