/// <summary>
        /// 主单据体的字段携带完毕,与源单的关联关系创建好之后,触发此事件
        /// </summary>
        /// <param name="e"></param>
        public override void OnAfterCreateLink(CreateLinkEventArgs e)
        {
            // 预先获取一些必要的元数据,后续代码要用到:
            // 源单第二单据体
            Entity srcSecondEntity = e.SourceBusinessInfo.GetEntity("F_PAEZ_OtherEntity");

            // 目标单第一单据体
            Entity destMainEntity = e.TargetBusinessInfo.GetEntity("FEntity");

            // 目标单第二单据体
            Entity destSecondEntity = e.TargetBusinessInfo.GetEntity("F_PAEZ_OtherEntity");

            // 目标单关联子单据体
            Entity linkEntity = null;
            Form   form       = e.TargetBusinessInfo.GetForm();

            if (form.LinkSet != null &&
                form.LinkSet.LinkEntitys != null &&
                form.LinkSet.LinkEntitys.Count != 0)
            {
                linkEntity = e.TargetBusinessInfo.GetEntity(
                    form.LinkSet.LinkEntitys[0].Key);
            }

            if (linkEntity == null)
            {
                return;
            }

            // 获取生成的全部下游单据
            ExtendedDataEntity[] billDataEntitys = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead");

            // 对下游单据,逐张单据进行处理
            foreach (var item in billDataEntitys)
            {
                DynamicObject destBillObject = item.DataEntity;

                // 定义一个集合,用于收集本单对应的源单内码
                HashSet <long> srcBillIds = new HashSet <long>();

                // 开始到主单据体中,读取关联的源单内码
                DynamicObjectCollection destMainEntryRows =
                    destMainEntity.DynamicProperty.GetValue(destBillObject) as DynamicObjectCollection;
                foreach (var mainEntityRow in destMainEntryRows)
                {
                    DynamicObjectCollection linkRows =
                        linkEntity.DynamicProperty.GetValue(mainEntityRow) as DynamicObjectCollection;
                    foreach (var linkRow in linkRows)
                    {
                        long srcBillId = Convert.ToInt64(linkRow["SBillId"]);
                        if (srcBillId != 0 && srcBillIds.Contains(srcBillId) == false)
                        {
                            srcBillIds.Add(srcBillId);
                        }
                    }
                }
                if (srcBillIds.Count == 0)
                {
                    continue;
                }
                // 开始加载源单第二单据体上的字段

                // 确定需要加载的源单字段(仅加载需要携带的字段)
                List <SelectorItemInfo> selector = new List <SelectorItemInfo>();
                selector.Add(new SelectorItemInfo("F_PAEZ_Desc"));
                // TODO: 继续添加其他需要携带的字段,示例代码略
                // 设置过滤条件
                string filter = string.Format(" {0} IN ({1}) ",
                                              e.SourceBusinessInfo.GetForm().PkFieldName,
                                              string.Join(",", srcBillIds));

                OQLFilter filterObj = OQLFilter.CreateHeadEntityFilter(filter);

                // 读取源单
                IViewService viewService = ServiceHelper.GetService <IViewService>();
                var          srcBillObjs = viewService.Load(this.Context,
                                                            e.SourceBusinessInfo.GetForm().Id,
                                                            selector,
                                                            filterObj);

                // 开始把源单单据体数据,填写到目标单上
                DynamicObjectCollection destSecondEntryRows =
                    destSecondEntity.DynamicProperty.GetValue(destBillObject) as DynamicObjectCollection;
                destSecondEntryRows.Clear();    // 删除空行

                foreach (var srcBillObj in srcBillObjs)
                {
                    DynamicObjectCollection srcEntryRows =
                        srcSecondEntity.DynamicProperty.GetValue(srcBillObj) as DynamicObjectCollection;

                    foreach (var srcEntryRow in srcEntryRows)
                    {
                        // 目标单添加新行,并接受源单字段值
                        DynamicObject newRow = new DynamicObject(destSecondEntity.DynamicObjectType);
                        destSecondEntryRows.Add(newRow);
                        // 填写字段值
                        newRow["F_PAEZ_Desc"] = srcEntryRow["F_PAEZ_Desc"];
                        // TODO: 逐个填写其他字段值,示例代码略
                    }
                }
            }
        }
        public override void EndOperationTransaction(BOS.Core.DynamicForm.PlugIn.Args.EndOperationTransactionArgs e)
        {
            lotIds.Clear();
            List <SqlObject> sqlList = new List <SqlObject>();

            foreach (var item in e.DataEntitys)
            {
                string formId = "";
                if (item.DynamicObjectType.Name.Equals("InvInit"))
                {
                    formId = "STK_InvInit";
                }
                else
                {
                    formId = item["FFormId"].ToString();
                }

                DynamicObjectCollection details = null;
                switch (formId)
                {
                case "STK_MISCELLANEOUS":
                    details = item["STK_MISCELLANEOUSENTRY"] as DynamicObjectCollection;
                    break;

                case "STK_InStock":
                    details = item["InStockEntry"] as DynamicObjectCollection;
                    break;

                case "SP_InStock":
                    details = item["Entity"] as DynamicObjectCollection;
                    break;

                case "STK_OEMInStock":
                    details = item["OEMInStockEntry"] as DynamicObjectCollection;
                    break;

                case "STK_InitInStock":
                    details = item["InitInStockEntry"] as DynamicObjectCollection;
                    break;

                case "STK_InvInit":
                    details = item["InvInitDetail"] as DynamicObjectCollection;
                    break;

                default: break;
                }
                if (details == null)
                {
                    return;
                }
                foreach (var entryItem in details)
                {
                    Object lotObj = entryItem["LOT"];
                    if (null != lotObj && Convert.ToInt16((lotObj as DynamicObject)["BizType"]) == 1)
                    {
                        sqlList.Add(this.getSqlParams(formId, entryItem, item));
                    }
                }
            }
            if (sqlList.Count > 0 && lotIds.Count > 0)
            {
                DBUtils.ExecuteBatch(this.Context, sqlList);
                string          filter     = string.Format("FLOTID IN ({0})", string.Join(",", lotIds));
                OQLFilter       of         = OQLFilter.CreateHeadEntityFilter(filter);
                DynamicObject[] lotMasters = BusinessDataServiceHelper.Load(this.Context, "BD_BatchMainFile", null, of);
                ISaveService    service    = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>();
                service.Save(this.Context, lotMasters);
            }
        }
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        DynamicObject GetUser(string userID)
        {
            OQLFilter filter = OQLFilter.CreateHeadEntityFilter(string.Format("FUSERID={0}", userID));

            return(BusinessDataServiceHelper.Load(this.View.Context, FormIdConst.SEC_User, null, filter).FirstOrDefault());
        }
        /// <summary>
        /// 主单据体的字段携带完毕,与源单的关联关系创建好之后,触发此事件
        /// </summary>
        /// <param name="e"></param>
        public override void OnAfterCreateLink(CreateLinkEventArgs e)
        {
            base.OnAfterCreateLink(e);
            //预先获取一些必要的元数据,后续代码要用到
            //源单第一单据体
            Entity srcFirstEntity = e.SourceBusinessInfo.GetEntity("FEntity");

            //目标单第一单据体
            Entity mainEntity = e.TargetBusinessInfo.GetEntity("FEntityDetail");


            // 目标单关联子单据体
            Entity linkEntity = null;
            Form   form       = e.TargetBusinessInfo.GetForm();

            if (form.LinkSet != null &&
                form.LinkSet.LinkEntitys != null &&
                form.LinkSet.LinkEntitys.Count != 0)
            {
                linkEntity = e.TargetBusinessInfo.GetEntity(
                    form.LinkSet.LinkEntitys[0].Key);
            }

            if (linkEntity == null)
            {
                return;
            }

            // 获取生成的全部下游单据
            ExtendedDataEntity[] billDataEntitys = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead");

            // 对下游单据,逐张单据进行处理
            foreach (var item in billDataEntitys)
            {
                DynamicObject dataObject = item.DataEntity;

                // 定义一个集合,用于收集本单对应的源单内码
                HashSet <long> srcBillIds = new HashSet <long>();

                // 开始到主单据体中,读取关联的源单内码
                DynamicObjectCollection mainEntryRows =
                    mainEntity.DynamicProperty.GetValue(dataObject) as DynamicObjectCollection;
                DynamicObject           mainEntityRow = mainEntryRows[0];
                DynamicObjectCollection linkRows      =
                    linkEntity.DynamicProperty.GetValue(mainEntityRow) as DynamicObjectCollection;
                long srcBillId = Convert.ToInt64(linkRows[0]["SBillId"]);
                if (srcBillId != 0 &&
                    srcBillIds.Contains(srcBillId) == false)
                {
                    srcBillIds.Add(srcBillId);
                }
                if (srcBillIds.Count == 0)
                {
                    continue;
                }
                #region 隐藏
                //foreach (var mainEntityRow in mainEntryRows)
                //{
                //    DynamicObjectCollection linkRows =
                //        linkEntity.DynamicProperty.GetValue(mainEntityRow) as DynamicObjectCollection;
                //    foreach (var linkRow in linkRows)
                //    {
                //        long srcBillId = Convert.ToInt64(linkRow["SBillId"]);
                //        if (srcBillId != 0
                //            && srcBillIds.Contains(srcBillId) == false)
                //        {
                //            srcBillIds.Add(srcBillId);
                //        }
                //    }
                //}
                //if (srcBillIds.Count == 0)
                //{
                //    continue;
                //}
                #endregion

                // 开始加载源单第二单据体上的字段

                // 确定需要加载的源单字段(仅加载需要携带的字段)
                List <SelectorItemInfo> selector = new List <SelectorItemInfo>();
                selector.Add(new SelectorItemInfo("FDate"));       //日期
                selector.Add(new SelectorItemInfo("FCustomerID")); //客户
                selector.Add(new SelectorItemInfo("FSaleDeptID")); //销售部门
                selector.Add(new SelectorItemInfo("FMaterialID")); //物料
                selector.Add(new SelectorItemInfo("FTaxPrice"));   //含税单价
                // TODO: 继续添加其他需要携带的字段,示例代码略
                // 设置过滤条件
                string filter = string.Format(" {0} IN ({1}) ",
                                              e.SourceBusinessInfo.GetForm().PkFieldName,
                                              string.Join(",", srcBillIds));
                OQLFilter filterObj = OQLFilter.CreateHeadEntityFilter(filter);

                // 读取源单
                Kingdee.BOS.Contracts.IViewService viewService = Kingdee.BOS.App.ServiceHelper.GetService <Kingdee.BOS.Contracts.IViewService>();
                var srcBillObjs = viewService.Load(this.Context,
                                                   e.SourceBusinessInfo.GetForm().Id,
                                                   selector,
                                                   filterObj);
                #region 隐藏
                // 开始把源单单据体数据,填写到目标单上
                //DynamicObjectCollection secondEntryRows =
                //    secondEntity.DynamicProperty.GetValue(dataObject) as DynamicObjectCollection;
                //secondEntryRows.Clear();    // 删除空行
                #endregion

                foreach (DynamicObject srcBillObj in srcBillObjs)
                {
                    DynamicObject dept = srcBillObj["SaleDeptID"] as DynamicObject; //销售部门
                    DynamicObject Cust = srcBillObj["CustomerID"] as DynamicObject; //客户
                    //bool isRight = !Cust["FKHBD"].Equals("1") && !Cust["FKHBD"].Equals("2") ? Convert.ToInt32(Cust["FSAP"]) == 2 : Convert.ToInt32(Cust["FKHBD"]) == 1 ? true: Convert.ToInt32(Cust["FKHBD"]) == 2 ? true:false;
                    //补差、丢货或者客户结算方式是现金
                    bool isRight = (Cust["FKHBD"].Equals("1") || Cust["FKHBD"].Equals("2")) ? true : Convert.ToInt32(Cust["FSAP"]) == 2 ? true : false;
                    //if ((Convert.ToInt32(Cust["FSAP"]) == 2 || Convert.ToInt32(Cust["FKHBD"]) == 1 || Convert.ToInt32(Cust["FKHBD"]) == 2) && Convert.ToInt32(dept["FDEPTTYPE"]) == 4)

                    if (isRight && Convert.ToInt32(dept["FDEPTTYPE"]) == 4)//部门类别外埠
                    {
                        //外埠现金客户执行销售政策折扣
                        Dictionary <string, double> disCounts = TLMBServiceHelper.GetDiscounts(base.Context, Convert.ToInt64(dept["id"]), Convert.ToDateTime(srcBillObj["Date"]));
                        //遍历应收单,通过销售折扣计算折后的含税单价赋值。
                        foreach (DynamicObject mainEntryRow in mainEntryRows)
                        {
                            double discount = 0.0;
                            if (disCounts.TryGetValue(Convert.ToString(((DynamicObject)mainEntryRow["MATERIALID"])["FWLFL"]), out discount))
                            {
                                double ZK = Convert.ToDouble(disCounts["" + Convert.ToString(((DynamicObject)mainEntryRow["MATERIALID"])["FWLFL"]) + ""]);
                                mainEntryRow["TaxPrice"]        = Convert.ToDouble(mainEntryRow["TaxPrice"]) * ZK;
                                mainEntryRow["F_PAEZ_DisCount"] = ZK;
                            }
                        }
                    }

                    //DynamicObjectCollection srcEntryRows =
                    //    srcSecondEntity.DynamicProperty.GetValue(srcBillObj) as DynamicObjectCollection;

                    //foreach (var srcEntryRow in srcEntryRows)
                    //{
                    //    // 目标单添加新行,并接受源单字段值
                    //    DynamicObject newRow = new DynamicObject(secondEntity.DynamicObjectType);
                    //    secondEntryRows.Add(newRow);
                    //    // 填写字段值
                    //    newRow["F_JD_Text"] = srcEntryRow["F_JD_Text"];
                    //    // TODO: 逐个填写其他字段值,示例代码略
                    //}
                }
            }
        }
예제 #5
0
        public override void ButtonClick(BOS.Core.DynamicForm.PlugIn.Args.ButtonClickEventArgs e)
        {
            base.ButtonClick(e);
            string PformId = this.View.BillBusinessInfo.GetForm().Id;

            switch (PformId)
            {
            case "STK_InStock":      //采购入库
                tableName = "T_STK_INSTOCKENTRY";
                break;

            case "STK_MISCELLANEOUS":    //其他入库
                tableName = "T_STK_MISCELLANEOUSENTRY";
                break;

            case "SP_InStock":    //简单生产入库
                tableName = "T_SP_INSTOCKENTRY";
                break;

            case "STK_InitInStock":    //期初采购入库
                tableName = "T_STK_INITINSTOCKENTRY";
                break;

            case "STK_OEMInStock":    //受托加工材料入库
                tableName = "T_STK_OEMINSTOCKENTRY";
                break;

            case "STK_InvInit":
                tableName = "T_STK_INVINITDETAIL";
                break;

            default: break;
            }

            //string a;
            //if ((a = e.Key.ToUpper()) != null)
            //{
            //    if (!(a == "FBTNCONFIRM"))
            //    {
            //        if (a == "FBTNCANCEL")
            //        {
            //            this.View.Close();
            //        }
            //    }
            //    else
            //    {
            //value = this.View.Model.GetValue("F_BEM_QANO");
            //if (value == null)
            //{
            //    this.View.ShowMessage("请输入质保书号");
            //    return;
            //}
            if (!lotIds.IsEmpty() && !lotIds.Equals("0"))
            {
                string    filter     = string.Format("FLOTID IN ('{0}')", lotIds);
                OQLFilter of         = OQLFilter.CreateHeadEntityFilter(filter);
                var       lotMasters = BusinessDataServiceHelper.Load(this.Context, "BD_BatchMainFile", null, of);
                foreach (var lot in lotMasters)
                {
                    lot["F_QANo"] = value;
                }
                ISaveService service = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>();
                service.Save(this.Context, lotMasters);
                updateSqls.Add(string.Format(@"UPDATE  {0}  set F_QANo ='{1}'  WHERE flot  in ('{2}')  ", tableName, value, lotIds));
            }


            if (!ids.IsEmpty())
            {
                updateSqls.Add(string.Format(@"UPDATE  {0}  set F_QANo ='{1}'  WHERE fid  in ('{2}')  ", tableName, value, ids));
            }
            else if (!entryIds.IsEmpty())
            {
                updateSqls.Add(string.Format(@"UPDATE  {0}  set F_QANo ='{1}'  WHERE fentryid  in ('{2}')  ", tableName, value, entryIds));
            }

            DBUtils.ExecuteBatch(this.Context, updateSqls, updateSqls.Count);

            //}
            //返回值到父窗口
            //  this.View.ReturnToParentWindow("true");
            this.View.Close();
        }