预算数代码插件原创
金蝶云社区-挥着AK的悟空
挥着AK的悟空
3人赞赏了该文章 289次浏览 未经作者许可,禁止转载编辑于2020年08月03日 09:41:02
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GM_BudgetExpensePlugIn
{
    [System.ComponentModel.Description("预算数插件")]
    public class GM_YSPlugIn : AbstractDynamicFormPlugIn
    {
      
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            int m;
            int a;
            base.BarItemClick(e);
            if (e.BarItemKey == "预算数")
            {
                this.View.GetControl("FYSS").Text = null;
                this.View.GetControl("FZXS").Text = null;
                this.View.GetControl("FKYED").Text = null;
                //获取部门id、日期
                DynamicObject billObj = this.Model.DataObject;
                BaseDataField fldSupplier = this.View.BillBusinessInfo.GetField("FExpenseDeptID") as BaseDataField;
                DynamicObject fldSupplierValue = fldSupplier.DynamicProperty.GetValue(billObj) as DynamicObject;
                if (fldSupplierValue == null)
                {
                    this.View.ShowMessage("费用承担部门不能为空", MessageBoxType.Notice);
                    return;

                }
                string supplierId = Convert.ToInt64(fldSupplierValue[0]).ToString();

                object rq = Convert.ToDateTime(this.View.Model.GetValue("FDATE")).ToString("yyyy");
                if (rq == null)
                {
                    this.View.ShowMessage("日期不能为空", MessageBoxType.Notice);
                    return;
                }
                //获取单据体行数,并循环获取单据体的费用项目字段id
                m = this.View.Model.GetEntryRowCount("FEntity");
                for (a = 0; a < m; a++)
                {
                    double FVALUE = 0;
                    double FVALUE1 = 0;
                    object FExpID = this.View.Model.GetValue("FExpID", a) != null ? ((DynamicObject)this.View.Model.GetValue("FExpID", a))["id"] : "0";
                    object FYJE = this.Model.GetValue("FEXPSUBMITAMOUNT", a);
                    string FExpID1 = FExpID.ToString();
                    if (FExpID1 == null)
                    {
                        this.View.ShowMessage("费用项目不能为空", MessageBoxType.Notice);
                    }
                    //将获取的三个参数传递到数据库查询并返回预算数值
                    StringBuilder sb = new StringBuilder();
                    sb.Clear();
                    sb.AppendFormat("select  * from _V_GM_YSS where FDEPTID='" + supplierId + "'and FEXPID='" + FExpID + "'and FYEAR='" + rq + "'");
                    DynamicObjectCollection dyCols = DBServiceHelper.ExecuteDynamicObject(this.Context, sb.ToString(), null, null, CommandType.Text, null);
                    if (dyCols.Count != 0)
                    {
                        FVALUE = Convert.ToDouble(dyCols[0][1]);
                    }

                    //将获取的三个参数传递到数据库查询并返回执行数值
                    StringBuilder sb1 = new StringBuilder();
                    sb1.Clear();
                    sb1.AppendFormat("select * from _V_GMYS_ZXS where FDEPTID='" + supplierId + "'and FEXPID='" + FExpID + "'and FDATE='" + rq + "'");
                    DynamicObjectCollection dyCols1 = DBServiceHelper.ExecuteDynamicObject(this.Context, sb1.ToString(), null, null, CommandType.Text, null);
                    if (dyCols1.Count != 0)
                    {

                        FVALUE1 = Convert.ToDouble(dyCols1[0][0]);
                    }
                    //通过运算后,将预算数、执行数、可用额度分别赋值给FYSS、FZXS、FKYED 三个字段
                    double c = Convert.ToDouble(FVALUE1) + Convert.ToDouble(FYJE);
                    double b = Convert.ToDouble(FVALUE) - Convert.ToDouble(c);
                    this.Model.SetValue("FYSS", FVALUE, a);
                    this.Model.SetValue("FZXS", c, a);
                    this.Model.SetValue("FKYED", b, a);
                }

                this.View.UpdateView("FEntity");
            }


        }
    }
}




赞 3