王 垚
2021-02-04 3bdc41a3c5a0857b04c1ee4d6f7cc515d1983820
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Data;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
 
namespace Demo.BillView
{
    [Description("齐套分析列表功能")]
    [HotUpdate]
    public class ProCompleteAnalysisDetail : AbstractDynamicFormPlugIn
    {
        bool did = false;
        string FHMainICMOInterIDr = "";
        string FHMainICMOEntryID = "";
        string FHICMOInterID = "";
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.View.OpenParameter.GetCustomParameter("FHMainICMOInterID") == null)
            {
                SearchList();
                ChangeColor();
            }
            else
            {
                if (did)
                    return;
                  FHMainICMOInterIDr = this.View.OpenParameter.GetCustomParameter("FHMainICMOInterID").ToString();//主生产订单主内码
                  FHMainICMOEntryID = this.View.OpenParameter.GetCustomParameter("FHMainICMOEntryID").ToString();// 主生产订单子内码
                  FHICMOInterID = this.View.OpenParameter.GetCustomParameter("FHICMOInterID").ToString();//日计划订单主内码
                string sql = string.Format(@"/*dialect*/select * from view_JIT_MOMaterReadysBill where FHMainICMOInterIDr ='{0}' and FHMainICMOEntryID ='{1}' and FHICMOInterID='{2}' order by FPlanDate, FHStockQty desc ,FHMaterID ", FHMainICMOInterIDr, FHMainICMOEntryID, FHICMOInterID);
                DataTable dt = DBServiceHelper.ExecuteDataSet(this.Context, sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        this.Model.CreateNewEntryRow("FEntity");
                        this.Model.SetValue("FSEQ", i + 1, i);//序号
                        this.Model.SetValue("FMateralDetailId", dt.Rows[i]["FHMATERID"], i);
                        this.Model.SetValue("FPlanIssueCount", dt.Rows[i]["FSumPlanCount"], i);//计划发料数量
                        this.Model.SetValue("FCompleteCount", dt.Rows[i]["FCompleteCount1"], i);//齐套数量  
                        this.Model.SetValue("FLackCount", dt.Rows[i]["FLackCount"], i);//缺料数量  
                        this.Model.SetValue("FPassableCount", dt.Rows[i]["FHLeftQty"].ToString(), i);//可用数量   
                        this.Model.SetValue("FMateralCount", dt.Rows[i]["FHStockQty"].ToString(), i);//物料数量   
                        this.Model.SetValue("FOccupyCount", dt.Rows[i]["FOccupyCount"].ToString(), i);//占用数量   
                        this.Model.SetValue("FCompleteDetailStatus", dt.Rows[i]["FComPlete"].ToString(), i);//是否齐套   
                        this.Model.SetValue("FIsHavePur", dt.Rows[i]["FIsHavePur"].ToString(), i);//是否有采购订单   
                        this.Model.SetValue("FHMainICMOInterIDr", dt.Rows[i]["FHMainICMOInterIDr"].ToString(), i);//生产订单内码   
                        this.Model.SetValue("FPRDBillNo", dt.Rows[i]["FPRDBillNo"].ToString(), i);//生产订单内码   
                        this.Model.SetValue("FPlanDate", dt.Rows[i]["FPlanDate"].ToString(), i);//日计划日期   
                        this.Model.SetValue("FOrgId", dt.Rows[i]["FHStockOrgID"], i);//库存组织  
                        this.Model.SetValue("FOwnerTypeId", dt.Rows[i]["FOwnerTypeId"], i);//货主类型  
                        this.Model.SetValue("FOwnerId", dt.Rows[i]["FOwnerId"], i);//货主 
                    }
                }
 
                ChangeColor();
                 did = true;
            }
        }
 
        private void ChangeColor() {
            Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
            //单据体信息转换为列表集合
            DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity);
            EntryGrid grid = this.View.GetControl<EntryGrid>("FEntity");
            int _i = 0;
            foreach (DynamicObject current in entityDataObjoct)
            {
                if (Convert.ToString(current["FCompleteDetailStatus"]) == "未齐套")
                {
                    grid.SetRowBackcolor("#FF0000", _i);
                }
                _i++;
            }
        }
       
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.ToUpper() == "TBFILTER")
            {
                SearchList();
                ChangeColor();
            }
        }
        /// <summary>
        /// 行双击 跳出齐套分析明细列表
        /// </summary>
        /// <param name="e"></param>
        public override void EntityRowDoubleClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.EntityRowClickEventArgs e)
        {
            var m = e.Row;
            var n = e.Key;
            base.EntityRowClick(e);
            DynamicFormShowParameter formPa = new DynamicFormShowParameter();
            formPa.FormId = "paez_CompleteAnalysisMateriel";
            /* jsonModel.Add("FHMainICMOInterID", FMainInterID);//主生产订单主内码
             jsonModel.Add("FHMainICMOEntryID", FMainEntryID);//主生产订单子内码
             jsonModel.Add("FHICMOInterID", FDayPlanWorkID);//日计划订单主内码
            current["FMatrailId_Id"].ToString(), current["FHMainSourceInterID"].ToString(), current["FHMainSourceEntryID"].ToString(), current["FDayPlanWorkID"].ToString())
            */
            formPa.CustomParams.Add("FHMainICMOInterIDr", Convert.ToString(this.View.Model.GetValue("FHMainICMOInterIDr", e.Row).ToString()));
            formPa.CustomParams.Add("FMatrailId", Convert.ToString((this.View.Model.GetValue("FMateralDetailId", e.Row) as DynamicObject)["Id"].ToString()));
            this.View.ShowForm(formPa);
        }
        /// <summary>
        /// 查询事件
        /// </summary>
        public void SearchList()
        {
            string sqlwhere = $" where FHMainICMOInterIDr ='{FHMainICMOInterIDr}' and FHMainICMOEntryID ='{FHMainICMOEntryID}' and FHICMOInterID='{FHICMOInterID}'";
            string sql = string.Format(@"/*dialect*/select * from view_JIT_MOMaterReadysBill  ");
            //物料
            if ((this.Model.GetValue("FMateralId") as DynamicObject) != null)
            {
                string FMateralId = (this.Model.GetValue("FMateralId") as DynamicObject)["Id"].ToString();
                if (!string.IsNullOrEmpty(FMateralId))
                    sqlwhere += $" and FHMATERID='{FMateralId}'";
            }
            //齐套
            string FCompleteStatus = Convert.ToString(this.Model.GetValue("FCompleteStatus"));
            if (!string.IsNullOrEmpty(FCompleteStatus))
                sqlwhere += $" and FComPlete='{FCompleteStatus}'";
            //有无采购订单
            string FIsHavePurs = Convert.ToString(this.Model.GetValue("FIsHavePurs"));
            if (!string.IsNullOrEmpty(FIsHavePurs))
                sqlwhere += $" and FIsHavePur='{FIsHavePurs}'";
 
            //日计划日期
            string FPlanDate = Convert.ToString(this.Model.GetValue("FPlanDate2"));
            if (!string.IsNullOrEmpty(FPlanDate))
                sqlwhere += $" and FPlanDate='{FPlanDate}'";
 
            //生产订单号
            string PRDBillNo = Convert.ToString(this.Model.GetValue("FScOrderNo"));
            if (!string.IsNullOrEmpty(PRDBillNo))
                sqlwhere += $" and FPRDBillNo='{PRDBillNo}'";
 
            sql += sqlwhere;
            sql += "order by FPlanDate, FHStockQty desc ,FHMaterID";
            DataTable dt = DBServiceHelper.ExecuteDataSet(this.Context, sql).Tables[0];
            //this.Model.DeleteEntryData("FEntity");
            while (this.Model.GetEntryRowCount("FEntity") > 0)
            {
                this.Model.DeleteEntryRow("FEntity", 0);
            }
            //this.View.Refresh();
 
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.Model.CreateNewEntryRow("FEntity");
                    this.Model.SetValue("FSEQ", i + 1, i);//序号
                    this.Model.SetValue("FMateralDetailId", dt.Rows[i]["FHMATERID"], i);
                    this.Model.SetValue("FPlanIssueCount", dt.Rows[i]["FSumPlanCount"], i);//计划发料数量
                    this.Model.SetValue("FCompleteCount", dt.Rows[i]["FCompleteCount1"], i);//齐套数量  
                    this.Model.SetValue("FLackCount", dt.Rows[i]["FLackCount"], i);//缺料数量  
                    this.Model.SetValue("FPassableCount", dt.Rows[i]["FHLeftQty"].ToString(), i);//可用数量   
                    this.Model.SetValue("FMateralCount", dt.Rows[i]["FHStockQty"].ToString(), i);//物料数量   
                    this.Model.SetValue("FOccupyCount", dt.Rows[i]["FOccupyCount"].ToString(), i);//占用数量   
                    this.Model.SetValue("FCompleteDetailStatus", dt.Rows[i]["FComPlete"].ToString(), i);//是否齐套   
                    this.Model.SetValue("FIsHavePur", dt.Rows[i]["FIsHavePur"].ToString(), i);//是否有采购订单   
                    this.Model.SetValue("FHMainICMOInterIDr", dt.Rows[i]["FHMainICMOInterIDr"].ToString(), i);//生产订单内码   
                    this.Model.SetValue("FPRDBillNo", dt.Rows[i]["FPRDBillNo"].ToString(), i);//生产订单内码   
                    this.Model.SetValue("FPlanDate", dt.Rows[i]["FPlanDate"].ToString(), i);//日计划日期   
                    this.Model.SetValue("FOrgId", dt.Rows[i]["FHStockOrgID"], i);//库存组织  
                    this.Model.SetValue("FOwnerTypeId", dt.Rows[i]["FOwnerTypeId"], i);//货主类型  
                    this.Model.SetValue("FOwnerId", dt.Rows[i]["FOwnerId"], i);//货主 
                }
            }
 
            //this.View.UpdateView();
            did = true;
        }
    }
}