王 垚
2021-03-23 6cb6d56102ce66fc348655c112d9f178c08aaeb8
src/BLL/Demo.BillView/PRD/ProCompleteAnalysisDetails.cs
@@ -1,18 +1,15 @@
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using Kingdee.BOS.ServiceHelper;
using System.Threading.Tasks;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using ZD.Cloud.Logger;
namespace Demo.BillView
{
@@ -21,65 +18,81 @@
    public class ProCompleteAnalysisDetail : AbstractDynamicFormPlugIn
    {
        bool did = false;
        string FHMainICMOInterIDr = "";
        string FHMainICMOEntryID = "";
        string FHICMOInterID = "";
        public override void OnLoad(EventArgs e)
        {
            LogHelper.Info("[齐套分析明细加载列表]");
            base.OnLoad(e);
            if (this.View.OpenParameter.GetCustomParameter("FHMainICMOInterID") == null)
            {
                SearchList();
                ChangeColor();
            }
            else
            {
                if (did)
                    return;
                string FHMainICMOInterIDr = this.View.OpenParameter.GetCustomParameter("FHMainICMOInterID").ToString();//主生产订单主内码
                string FHMainICMOEntryID = this.View.OpenParameter.GetCustomParameter("FHMainICMOEntryID").ToString();// 主生产订单子内码
                string FHICMOInterID = this.View.OpenParameter.GetCustomParameter("FHICMOInterID").ToString();//日计划订单主内码
                //string FMatrailId_Id = this.View.OpenParameter.GetCustomParameter("FMatrailId_Id").ToString();
                //string FBillNo = this.View.OpenParameter.GetCustomParameter("FBillNo").ToString();
                string sql = string.Format(@"/*dialect*/select * from JIT_MOMaterReadysBill where FHMainICMOInterIDr ='{0}' and FHMainICMOEntryID ='{1}' and FHICMOInterID='{2}' and FIDENTIFICAT=1 ", FHMainICMOInterIDr, FHMainICMOEntryID, FHICMOInterID);
                  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++)
                    {
                        /*
                        计划发料数量 = 计划总数量 * 单位用料
                        齐套数量 = 齐套数 * 单位用料(考虑分层级* 父级)
                        缺料数量 = 1 - 2
                        是否齐套 = 缺料 < 0 ?
                        */
                        decimal FPlanIssueCount = Convert.ToDecimal(dt.Rows[i]["FSumPlanCount"]) * Convert.ToDecimal(dt.Rows[i]["FUNITDOSAGE"]);//计划发料数量
                        decimal FCompleteCount = Convert.ToDecimal(dt.Rows[i]["FCompleteCount"]) * Convert.ToDecimal(dt.Rows[i]["FUNITDOSAGE"]);//齐套数量
                        decimal FLackCount = FPlanIssueCount - FCompleteCount;//缺料数量
                        this.Model.CreateNewEntryRow("FEntity");
                        this.Model.SetValue("FSEQ", i + 1, i);//序号
                        this.Model.SetValue("FMateralDetailId", dt.Rows[i]["FHMATERID"], i);
                        this.Model.SetValue("FPlanIssueCount", FPlanIssueCount, i);//计划发料数量
                        this.Model.SetValue("FCompleteCount", FCompleteCount, i);//齐套数量
                        this.Model.SetValue("FLackCount", FLackCount, 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]["FHLeftQty"].ToString(), i);//物料数量
                        this.Model.SetValue("FCompleteDetailStatus", FLackCount > 0 ? "未齐套" : "齐套", 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.Model.SetValue("FErpClsID", dt.Rows[i]["FErpClsID"], i);//物料属性
                    }
                }
                did = true;
                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);
                    grid.SetRowBackcolor("#71FF98CB", _i);
                }
                _i++;
            }
        }
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.ToUpper() == "TBFILTER")
            {
                SearchList();
                ChangeColor();
            }
        }
        /// <summary>
@@ -93,35 +106,22 @@
            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 1=1";
            string sql = @"
/*dialect*/
select * from (
select FSumPlanCount*FUNITDOSAGE as FPlanIssueCountS,FCompleteCount*FUNITDOSAGE FCompleteCountS,(FSumPlanCount-FCompleteCount)*FUNITDOSAGE FLackCountS,case when FSumPlanCount>FCompleteCount then '未齐套' else '齐套' end CompleteStatus,
t2.FBillNo PRDBillNo,
t1.* from JIT_MOMaterReadysBill T1
JOIN T_PRD_MO t2 on t1.FHMainICMOInterIDr=t2.FID where FIDENTIFICAT=1
)AS T
";
            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)
            {
@@ -129,43 +129,64 @@
                if (!string.IsNullOrEmpty(FMateralId))
                    sqlwhere += $" and FHMATERID='{FMateralId}'";
            }
            //齐套
            string FCompleteStatus = Convert.ToString(this.Model.GetValue("FCompleteStatus"));
            if (!string.IsNullOrEmpty(FCompleteStatus))
                sqlwhere += $" and CompleteStatus='{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 PRDBillNo='{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");
            //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++)
                {
                    decimal FPlanIssueCount = Convert.ToDecimal(dt.Rows[i]["FSumPlanCount"]) * Convert.ToDecimal(dt.Rows[i]["FUNITDOSAGE"]);//计划发料数量
                    decimal FCompleteCount = Convert.ToDecimal(dt.Rows[i]["FCompleteCount"]) * Convert.ToDecimal(dt.Rows[i]["FUNITDOSAGE"]);//齐套数量
                    decimal FLackCount = FPlanIssueCount - FCompleteCount;//缺料数量
                    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]["FPlanIssueCountS"], i);//计划发料数量
                    this.Model.SetValue("FCompleteCount", dt.Rows[i]["FCompleteCountS"], i);//齐套数量
                    this.Model.SetValue("FLackCount", dt.Rows[i]["FLackCountS"], 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]["FHLeftQty"].ToString(), i);//物料数量
                    this.Model.SetValue("FCompleteDetailStatus", dt.Rows[i]["CompleteStatus"].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("FErpClsID", dt.Rows[i]["FErpClsID"], i);//物料属性
                    this.Model.SetValue("FOwnerId", dt.Rows[i]["FOwnerId"], i);//货主
                }
            }
            this.View.UpdateView();
            //this.View.UpdateView();
            did = true;
        }
    }
}