列表调用动态表单处理数据原创
金蝶云社区-田野迷鸟
田野迷鸟
7人赞赏了该文章 1,665次浏览 未经作者许可,禁止转载编辑于2021年08月24日 17:05:38

场景:单据中添加字段,在列表里,选中单据记录,调用动态表单进行数据填充,确定后保存数据,并刷新列表显示数据。



1、新增动态表单

唯一标识:PSEA_LatestDeliveryDateEdit

新增菜单:确定:tbReturnData    退出:tbCancel


2、列表新增菜单

    在列表插件中调用下面的代码


3、列表插件调用动态表单、处理返回数据

        private void SetLatestDeliveryDate()
        {
            IListView listView = (IListView)this.View;
            ListSelectedRowCollection listRows = listView.SelectedRowsInfo;
            if (listRows.Count <= 0)
            {
                return;
            }

            //汇总单据EntryID
            List<string> entryIDList = new List<string>();
            foreach (ListSelectedRow listRow in listRows)
            {
                entryIDList.Add(listRow.EntryPrimaryKeyValue);
            }

            //如果存在单据FID
            if (entryIDList.Count > 0)
            {

                DynamicFormShowParameter param;
                //选择窗体的参数
                param = new DynamicFormShowParameter
                {
                    FormId = "PSEA_LatestDeliveryDateEdit",
                    ParentPageId = base.View.PageId,
                    CustomComplexParams = {
                                        {
                                            "entryIDList", entryIDList
                                        }
                                    }
                };

                //打开选择窗体(动态表单)
                this.View.ShowForm(param,
                    new Action<FormResult>((formResult) =>
                    {
                        //如果存在返回结果,则赋值
                        if (formResult != null && formResult.ReturnData != null)
                        {

                            //获取返回结果
                            DynamicObject returnRowData = formResult.ReturnData as DynamicObject;

                            DynamicObjectCollection dycLatestDeliveryDateList = returnRowData["FEntity"] as DynamicObjectCollection;

                            //更新sql模板
                            string updateSql = @"/*dialect*/
                                    UPDATE T_PUR_POORDERENTRY SET F_PWOR_YTL_ZXJQ = {1} WHERE FEntryId = {0}

                                    UPDATE ReqE 
                                    SET ReqE.F_PWOR_YTL_ZXJQ = poE.F_PWOR_YTL_ZXJQ
                                    FROM T_PUR_ReqEntry ReqE
                                        INNER JOIN t_PUR_POOrderEntry_LK poE_LK ON poE_LK.FStableName = 'T_PUR_ReqEntry' AND poE_LK.FSID = ReqE.FEntryId
                                        INNER JOIN T_PUR_PoOrderEntry poE ON poE.FEntryId = poE_LK.FEntryId 
                                    WHERE poE_LK.FEntryId = {0}
                                ";

                            //拼接sql
                            List<string> updateSqlList = new List<string>();

                            foreach (DynamicObject dycLatestDeliveryDate in dycLatestDeliveryDateList)
                            {

                                long FPurOrderEntryId = Convert.ToInt64(dycLatestDeliveryDate["FPurOrderEntryId"]);

                                if (dycLatestDeliveryDate["FPurOrderEntryId"] != null)
                                {

                                    decimal FRemainReceiveQty = Convert.ToDecimal(dycLatestDeliveryDate["FRemainReceiveQty"]);
                                    string FMRPCloseStatus = Convert.ToString(dycLatestDeliveryDate["FMRPCloseStatus"]);
                                    string FMRPFreezeStatus = Convert.ToString(dycLatestDeliveryDate["FMRPFreezeStatus"]);
                                    string FMRPTerminateStatus = Convert.ToString(dycLatestDeliveryDate["FMRPTerminateStatus"]);

                                    //剩余收料数量>0 且行状态是正常的才允许更新
                                    if (FRemainReceiveQty > 0 && FMRPCloseStatus == "正常" && FMRPFreezeStatus == "正常" && FMRPTerminateStatus == "正常")
                                    {
                                        string FLatestDeliveryDate = string.Empty;
                                        DateTime dtFLatestDeliveryDate = Convert.ToDateTime(dycLatestDeliveryDate["FLatestDeliveryDate"]);
                                        if (dtFLatestDeliveryDate == DateTime.MinValue)
                                        {
                                            FLatestDeliveryDate = "null";
                                        }
                                        else
                                        {
                                            FLatestDeliveryDate = "'" + Convert.ToString(dtFLatestDeliveryDate) + "'";
                                        }
                                        updateSqlList.Add(string.Format(updateSql, FPurOrderEntryId, FLatestDeliveryDate));
                                    }

                                }
                            }
                            //批量执行
                            Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteBatch(this.Context, updateSqlList);

                            //刷新
                            listView.Refresh();

                        }
                    }
                    
                    )
                );

            }
        }


4、动态表单数据处理---显示数据

        /// <summary>
        /// 动态表单加载数据完成之后,需要处理的功能
        /// </summary>
        /// <param name="e"></param>
        public override void AfterCreateNewData(EventArgs e)
        {
            if (this.View.OpenParameter.GetCustomParameter("entryIDList") != null)
            {
                List<string> poEntryIdList = this.View.OpenParameter.GetCustomParameter("entryIDList") as List<string>;

                if (poEntryIdList != null &&  poEntryIdList.Count > 0)
                {
                    string selectSql = @"
                    SELECT poE.FEntryId as FPurOrderEntryId, poH.FBillNo, sup_L.FName AS FSupplierName, mH.FNumber AS FMaterialNumber, mH_L.FName AS FMaterialName, 
					    poE_D.FDeliveryDate as FExpectedArrivalDate, poE.F_PWOR_YTL_ZXJQ as FLatestDeliveryDate, 
                        poE.F_PWOR_CGDDZZS as FManufacturer, poE.F_PWOR_CGDDZZSXH as FManufacturerModel, poE.FQty as FPurQty, poE_R.FRemainReceiveQty, 
						CASE poE.FMRPCloseStatus WHEN 'A' THEN '正常' ELSE '业务关闭' END AS FMRPCloseStatus, 
						CASE poE.FMRPFreezeStatus WHEN 'A' THEN '正常' ELSE '业务冻结' END AS FMRPFreezeStatus, 
						CASE poE.FMRPTerminateStatus WHEN 'A' THEN '正常' ELSE '业务终止' END AS FMRPTerminateStatus
				    FROM t_PUR_POOrder poH
					    LEFT JOIN T_BD_Supplier_L sup_L ON sup_L.FSupplierId = poH.FSupplierId AND sup_L.FLOCALEID = {1}
					    LEFT JOIN t_PUR_POOrderEntry poE ON poE.FID = poH.FID
					    LEFT JOIN t_PUR_POOrderEntry_D poE_D ON poE_D.FEntryId = poE.FEntryId
					    LEFT JOIN t_PUR_POOrderEntry_R poE_R ON poE_R.FEntryId = poE.FEntryId
					    LEFT JOIN T_BD_Material mH ON mH.FMaterialId = poE.FMaterialId
					    LEFT JOIN T_BD_Material_L mH_L ON mH_L.FMaterialId = poE.FMaterialId AND mH_L.FLOCALEID = {1}
				    WHERE poE.FEntryId IN({0}) 
                    ";
                    selectSql = string.Format(selectSql, string.Join(",", poEntryIdList), this.Context.UserLocale.LCID);
                    DynamicObjectCollection dycPoEntryInfoList = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDynamicObject(this.Context, selectSql);

                    if (dycPoEntryInfoList != null && dycPoEntryInfoList.Count > 0)
                    {

                        int rowCount = dycPoEntryInfoList.Count;
                        this.View.Model.BatchCreateNewEntryRow("FEntity", rowCount);

                        int rowIndex = 0;
                        foreach (DynamicObject dycPoEntryInfo in dycPoEntryInfoList)
                        {
                            this.View.Model.SetValue("FPurOrderEntryId", Convert.ToString(dycPoEntryInfo["FPurOrderEntryId"]), rowIndex);
                            this.View.Model.SetValue("FBillNo", Convert.ToString(dycPoEntryInfo["FBillNo"]), rowIndex);
                            this.View.Model.SetValue("FSupplierName", Convert.ToString(dycPoEntryInfo["FSupplierName"]), rowIndex);
                            this.View.Model.SetValue("FMaterialNumber", Convert.ToString(dycPoEntryInfo["FMaterialNumber"]), rowIndex);
                            this.View.Model.SetValue("FMaterialName", Convert.ToString(dycPoEntryInfo["FMaterialName"]), rowIndex);
                            this.View.Model.SetValue("FExpectedArrivalDate", Convert.ToString(dycPoEntryInfo["FExpectedArrivalDate"]), rowIndex);
                            this.View.Model.SetValue("FLatestDeliveryDate", Convert.ToString(dycPoEntryInfo["FLatestDeliveryDate"]), rowIndex);
                            this.View.Model.SetValue("FManufacturer", Convert.ToString(dycPoEntryInfo["FManufacturer"]), rowIndex);
                            this.View.Model.SetValue("FManufacturerModel", Convert.ToString(dycPoEntryInfo["FManufacturerModel"]), rowIndex);
                            this.View.Model.SetValue("FRemainReceiveQty", Convert.ToDecimal(dycPoEntryInfo["FRemainReceiveQty"]), rowIndex);
                            this.View.Model.SetValue("FMRPCloseStatus", Convert.ToString(dycPoEntryInfo["FMRPCloseStatus"]), rowIndex);
                            this.View.Model.SetValue("FMRPFreezeStatus", Convert.ToString(dycPoEntryInfo["FMRPFreezeStatus"]), rowIndex);
                            this.View.Model.SetValue("FMRPTerminateStatus", Convert.ToString(dycPoEntryInfo["FMRPTerminateStatus"]), rowIndex);

                            rowIndex = rowIndex + 1;
                        }
                    }
                }
            }
        }


5、动态表单数据处理---返回数据

        public override void BarItemClick(BarItemClickEventArgs e)
        {
            switch (e.BarItemKey.ToUpper())
            {
                case "TBCANCEL":
                    this.View.Close();

                    break;

                case "TBRETURNDATA":
                    ReturnCurDataAndClose();

                    break;
                default:
                    break;
            }
        }
        

        /// <summary>
        /// 返回数据以及关闭当前窗体
        /// </summary>
        private void ReturnCurDataAndClose()
        {
            DynamicObject date = this.View.Model.DataObject;
            this.View.ReturnToParentWindow(date);
            this.View.Close();
        }




返回目录

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