王 垚
2021-11-12 0ce538e3c3dc01153ce1bfc2d75276881206c222
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.Core.MFG.EntityHelper;
using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.BD.ServiceArgs;
using Kingdee.K3.MFG.Common.BusinessEntity.PRD;
using Kingdee.K3.BD.ServiceHelper;
using Kingdee.K3.Core.BD;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Log;
using Kingdee.K3.Core.MFG;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Core.Metadata;
using Kingdee.K3.MFG.ServiceHelper;
using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List;
 
namespace Demo.BillView.PRD
{
    [Description("提料计划列表 列表插件")]
    [HotUpdate]
 
    public class PODemandPlanListFilter : AbstractListPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            //关闭
            if (e.BarItemKey.ToUpper().Equals("BTNCLOSE"))
            {
                //获取选择记录
                ListSelectedRowCollection selectRows = this.ListView.SelectedRowsInfo;
                //读取ID,放到数组
                string[] ID = selectRows.GetPrimaryKeyValues();
                string FID = "";
 
                //没有选择行提示
                if (ID.Length == 0)
                {
                    //如果选择的是0,即没有选择行记录,弹窗报错,返回
                    this.View.ShowMessage("请选择单据!", MessageBoxType.Notice);
                    return;
                }
                else
                {
                    //如果点击成功,循环ID
                    for (int i = 0; i < ID.Length; i++)
                    {
                        FID = FID + ID[i].ToString() + ",";
                    }
                    FID = FID.Substring(0, FID.Length - 1);
                    string sql = string.Format(@"/*dialect*/
update Cg_PODemandPlanBillMain set
FHCloseMan = {0},
FHCloseDate = GETDATE(),
FHCloseType = 1
where fid IN ({1})", Context.UserId, FID);
                    DBServiceHelper.Execute(Context, sql);
                    sql = string.Format(@"/*dialect*/
UPDATE A SET
A.FPODemandPlanCount -= B.FHQTY
FROM t_PUR_POOrderEntry A
JOIN Cg_PODemandPlanBillSub B ON A.FENTRYID = B.FHPOOrderEntryID
where B.FID IN (select FID FROM Cg_PODemandPlanBillMain WHERE FHCloseType = 0 AND FID IN ({0}))  AND B.FCLOSESTATUS = 0 
", FID);
                    this.View.Refresh();
                    this.View.ShowMessage("操作成功");
                }
            }
        }
 
        public override void PrepareFilterParameter(global::Kingdee.BOS.Core.List.PlugIn.Args.FilterArgs e)
        {
            base.PrepareFilterParameter(e);
            //如果过滤条件含有最新结果关键字,则在此基础上处理,以支持最新结果内置方案另存增加条件(关键字是根据生产订单状态过滤)
            if (e.FilterString.IsNullOrEmptyOrWhiteSpace())
            {
                int FSupplierId = GetSupplierId();
                if (FSupplierId > 0)
                    e.FilterString = $" FSUPPLIERID IN ({FSupplierId})";
            }
            else
            {
                int FSupplierId = GetSupplierId();
                if (FSupplierId > 0)
                    e.FilterString += $" AND FSUPPLIERID IN (FSupplierId)";
            }
        }
        public int GetSupplierId()
        {
            long userId = this.Context.UserId;
            string sql = $"/*dialect*/ select FSupplierId from T_SEC_user a join T_SCP_USERDATA b on a.FUSERID = b.FUSERID where FUSERTYPE = 2 and a.FUSERID ={userId}";
            ////LogHelper.Info(sql);
            int FSupplierId = DBServiceHelper.ExecuteScalar<int>(Context, sql, 0);
            return FSupplierId;
        }
    }
}