private bool ValidateNullValue(BOMMaster _bom, Organization _beOrgContext)
        {
            bool   bRlt         = false;
            string strErrorItem = "<errorItem bomMasterCode=\"{0}\" bomCompCode=\"{1}\" errorDescription=\"{2}\" />";

            string strError = "<Error Description=\"{0}\" />";

            if (string.IsNullOrEmpty(_bom.ItemMasterCode))
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, "", "母件物料编码ItemMasterCode为空"));
                bRlt = true;
            }
            if (_bom.BOMType != 0 && _bom.BOMType != 1)
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, "", "BOM类型BOMType指定错误"));
                bRlt = true;
            }
            ItemMaster beItemMaster = ItemMaster.Finder.Find("Code=@code and Org=@org",
                                                             new OqlParam[] { new OqlParam(_bom.ItemMasterCode), new OqlParam(_beOrgContext.ID) });

            if (beItemMaster == null)
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, "", string.Format("母件料号{0}不存在。", _bom.ItemMasterCode)));
                bRlt = true;
            }

            int i = 1;

            foreach (var bomComp in _bom.Components)
            {
                if (string.IsNullOrEmpty(bomComp.ItemCode))
                {
                    strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, "", string.Format("明细子项第{0}项中ItemCode为空。", i.ToString())));
                    bRlt = true;
                }

                ItemMaster beItemComponent = ItemMaster.Finder.Find("Code=@code and Org=@org",
                                                                    new OqlParam[] { new OqlParam(bomComp.ItemCode), new OqlParam(_beOrgContext.ID) });
                if (beItemComponent == null)
                {
                    strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, bomComp.ItemCode, string.Format("子件料号{0}不存在。", bomComp.ItemCode)));
                    bRlt = true;
                }

                if (beItemComponent != null)
                {
                    if (beItemComponent.Effective.EffectiveDate.CompareTo(DateTime.Now.Date) > 0)
                    {
                        strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, bomComp.ItemCode,
                                                           string.Format("子件料号{0}生效日期{1}晚于当前日期。", bomComp.ItemCode, beItemComponent.Effective.EffectiveDate.ToShortDateString())));
                        bRlt = true;
                    }
                }
                i++;
            }
            return(bRlt);
        }
        /// <summary>
        /// 创建删除子件BOM服务的DTO
        /// </summary>
        /// <param name="_bom"></param>
        /// <param name="_beBOM"></param>
        /// <returns></returns>
        private BOMMasterDTO4CreateSv DelBOMPartDTO(BOMMaster _bom, UFIDA.U9.CBO.MFG.BOM.BOMMaster _beBOM)
        {
            BOMMasterDTO4CreateSv dtoMasterDelPart = null;

            foreach (var beBOMPart in _beBOM.BOMComponents)
            {
                bool bCompIsExists = false;
                foreach (var bompart in _bom.Components)
                {
                    //当传入的BOM子件中没有该物料编码,则从BOM中删除此子件
                    if (bompart.ItemCode == beBOMPart.ItemMaster.Code)
                    {
                        bCompIsExists = true;
                        continue;
                    }
                }

                if (!bCompIsExists)
                {
                    if (dtoMasterDelPart == null)
                    {
                        dtoMasterDelPart = PubMethod.GetDataOfBOMMaster(_beBOM);
                        dtoMasterDelPart.BOMComponents.Clear();
                    }

                    //检索出原始BOM中存在的子件加入到需删除子件服务的dtoMasterDelPart中
                    UFIDA.U9.CBO.MFG.BOM.BOMComponent.EntityList elstBOMComponent = UFIDA.U9.CBO.MFG.BOM.BOMComponent.Finder.FindAll("BOMMaster=@BOMID and ItemMaster.Code=@ItemCode ",
                                                                                                                                     new OqlParam[] { new OqlParam(_beBOM.ID), new OqlParam(beBOMPart.ItemMaster.Code) });
                    if (elstBOMComponent != null && elstBOMComponent.Count > 0)
                    {
                        for (int i = 0; i < elstBOMComponent.Count; i++)
                        {
                            UFIDA.U9.CBO.MFG.BOM.BOMComponent beBOMComponent = elstBOMComponent[i];
                            BOMComponentDTO4CreateSv          dtoComponent   = PubMethod.GetDataOfBOMComponent(beBOMComponent);
                            if (dtoMasterDelPart.BOMComponents.Contains(dtoComponent))
                            {
                                continue;
                            }
                            else
                            {
                                dtoMasterDelPart.BOMComponents.Add(dtoComponent);
                            }
                        }
                    }
                }
            }

            return(dtoMasterDelPart);
        }
        private UFIDA.U9.ISV.MFG.BOM.BOMComponentDTO4CreateSv CreateBOMComponentDTO(BOMComponent _bomComponent, int _iSeq, BOMMaster _bom, Organization _beOrg)
        {
            try
            {
                UFIDA.U9.ISV.MFG.BOM.BOMComponentDTO4CreateSv dtoComponent = new UFIDA.U9.ISV.MFG.BOM.BOMComponentDTO4CreateSv();

                dtoComponent.Sequence     = _iSeq;
                dtoComponent.OperationNum = "10";//默认工序号:空
                ItemMaster beItemComponent = ItemMaster.Finder.Find("Code=@code and Org=@org",
                                                                    new OqlParam[] { new OqlParam(_bomComponent.ItemCode), new OqlParam(_beOrg.ID) });
                if (beItemComponent == null)
                {
                    throw new Exception(string.Format("子件料号{0}在组织{1}下不存在!", _bomComponent.ItemCode, _beOrg.Code));
                }

                dtoComponent.ItemMaster      = new CommonArchiveDataDTO();
                dtoComponent.ItemMaster.ID   = beItemComponent.ID;
                dtoComponent.ItemMaster.Code = beItemComponent.Code;
                dtoComponent.ItemMaster.Name = beItemComponent.Name;
                //子项物料启用了版本管理
                if (beItemComponent.ItemMasterVersions != null && beItemComponent.ItemMasterVersions.Count > 0)
                {
                    dtoComponent.ItemVersionCode = _bomComponent.ItemVersionCode;
                }

                dtoComponent.ComponentType = ComponentTypeEnum.StandardComp;//标准

                dtoComponent.BOMCompSubstituteDTO4CreateSv = new List <BOMComponentDTO4CreateSv>();
                dtoComponent.UsageQtyType    = UsageQuantityTypeEnum.Variable;
                dtoComponent.UsageQty        = _bomComponent.UsageQty;
                dtoComponent.IssueUOM        = new CommonArchiveDataDTO();
                dtoComponent.IssueUOM.ID     = beItemComponent.MaterialOutUOM.ID;
                dtoComponent.IssueUOM.Code   = beItemComponent.MaterialOutUOM.Code;
                dtoComponent.IssueUOM.Name   = beItemComponent.MaterialOutUOM.Name;
                dtoComponent.PlanPercent     = 0;
                dtoComponent.IsCharge        = true;
                dtoComponent.FromQty         = 0;
                dtoComponent.ToQty           = 0;
                dtoComponent.IsEffective     = true;
                dtoComponent.SubstituteStyle = SubstituteStyleEnum.None;
                dtoComponent.ScrapType       = ScrapTypeEnum.SingleScrap;
                dtoComponent.FixedScrap      = beItemComponent.MfgInfo.ImmovableWaste; //固定损耗率
                dtoComponent.Scrap           = _bomComponent.Scrap;                    //损耗率
                dtoComponent.ParentQty       = _bomComponent.ParentQty;


                dtoComponent.SupplyStyle   = SupplyStyleEnum.Org;
                dtoComponent.IssueOrg      = new CommonArchiveDataDTO();
                dtoComponent.IssueOrg.ID   = _beOrg.ID;
                dtoComponent.IssueOrg.Code = _beOrg.Code;
                dtoComponent.IssueOrg.Name = _beOrg.Name;

                if (beItemComponent.InventoryInfo.Warehouse != null)
                {
                    dtoComponent.SupplyWareHouse      = new CommonArchiveDataDTO();//供应地点
                    dtoComponent.SupplyWareHouse.ID   = beItemComponent.InventoryInfo.Warehouse.ID;
                    dtoComponent.SupplyWareHouse.Code = beItemComponent.InventoryInfo.Warehouse.Code;
                    dtoComponent.SupplyWareHouse.Name = beItemComponent.InventoryInfo.Warehouse.Name;
                }
                dtoComponent.SetChkAtComplete    = false;
                dtoComponent.SetChkAtOptComplete = false;
                dtoComponent.SetChkAtOptStart    = false;
                if (_bom.BOMType == 1)
                {
                    dtoComponent.IsWholeSetIssue = true;
                }
                else
                {
                    dtoComponent.IsWholeSetIssue = false;
                }
                dtoComponent.StandardMaterialScale = 0;
                dtoComponent.IsOverIssue           = false;
                dtoComponent.IsATP             = false;
                dtoComponent.IsCTP             = false;
                dtoComponent.LeadTimeOffSet    = 0;
                dtoComponent.IsMandatory       = false;
                dtoComponent.IsExclude         = false;
                dtoComponent.IsDefault         = false;
                dtoComponent.IsOptionDependent = false;
                dtoComponent.IsCalcPrice       = false;
                dtoComponent.MinSelectedQty    = 1;
                dtoComponent.MaxSelectedQty    = 1;
                dtoComponent.CostElement       = new CommonArchiveDataDTO();
                CostElement beCost = CostElement.Finder.Find("Name='材料费'", new OqlParam[] { });
                if (beCost != null)
                {
                    dtoComponent.CostElement.ID   = beCost.ID;
                    dtoComponent.CostElement.Code = beCost.Code;
                    dtoComponent.CostElement.Name = beCost.Name;
                }
                dtoComponent.CostPercent = 0;//成本百分比
                dtoComponent.Remark      = _bomComponent.Remark;
                //直接读取料品属性,属于虚拟
                if (beItemComponent.ItemFormAttribute == ItemTypeAttributeEnum.Phantom)
                {
                    //如果子项勾选‘虚拟’,此处选择‘不发料
                    dtoComponent.IsPhantomPart = true;
                    dtoComponent.IssueStyle    = IssueStyleEnum.Phantom;
                }
                else
                {
                    dtoComponent.IsPhantomPart = false;
                    dtoComponent.IssueStyle    = IssueStyleEnum.Push;
                }
                //收货审核属性RCVApproved,标准接口未提供。

                dtoComponent.IsCeiling        = false; //是否取整
                dtoComponent.IsSpecialUseItem = false; //是否专项控制:默认不启用
                if (!String.IsNullOrEmpty(_bomComponent.CompProject))
                {
                    Project itemProject = Project.Finder.Find("Name=@name and Org=@org",
                                                              new OqlParam[] { new OqlParam(_bomComponent.CompProject), new OqlParam(_beOrg.ID) });

                    if (itemProject != null)
                    {
                        dtoComponent.CompProject      = new CommonArchiveDataDTO();
                        dtoComponent.CompProject.ID   = itemProject.ID;
                        dtoComponent.CompProject.Code = itemProject.Code;
                        dtoComponent.CompProject.Name = itemProject.Name;

                        dtoComponent.IsSpecialUseItem = true;//是否专项控制:指定项目后则设定为启用。
                    }
                    else
                    {
                        throw new Exception(string.Format("在{0}组织下没有找到{1}的项目号.", _beOrg.Name, _bomComponent.CompProject));
                    }
                }

                return(dtoComponent);
            }
            catch (Exception ex)
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, _bomComponent.ItemCode, ex.Message));
                return(null);
            }
        }
        /// <summary>
        /// 创建修改BOM服务的DTO
        /// </summary>
        /// <param name="_bom"></param>
        /// <param name="_beBOM"></param>
        /// <returns></returns>
        private BOMMasterDTO4CreateSv ModifyBOMMasterDTO(BOMMaster _bom, UFIDA.U9.CBO.MFG.BOM.BOMMaster _beBOM, Organization _beOrgContext)
        {
            BOMMasterDTO4CreateSv dtoMasterModify = PubMethod.GetDataOfBOMMaster(_beBOM);

            try
            {
                //清除系统原有子件清单
                dtoMasterModify.BOMComponents.Clear();
                int iSeq = PubMethod.GetNextMaxSequence(_beBOM);
                //加入待修改的子件清单
                bool isAllBomCompOK = true;
                foreach (var bomComp in _bom.Components)
                {
                    UFIDA.U9.CBO.MFG.BOM.BOMComponent.EntityList elstBOMComponent = UFIDA.U9.CBO.MFG.BOM.BOMComponent.Finder.FindAll("BOMMaster=@BOMID and ItemMaster.Code=@ItemCode ",
                                                                                                                                     new OqlParam[] { new OqlParam(_beBOM.ID), new OqlParam(bomComp.ItemCode) });
                    //在系统后台根据BOM主ID和子件的物料编码检索,如果有此子件则由GetDataOfBOMComponent直接创建子件DTO添加dtoMasterModify。
                    if (elstBOMComponent != null && elstBOMComponent.Count > 0)
                    {
                        //处理母件下有相同的子件物料的明细行
                        for (int i = 0; i < elstBOMComponent.Count; i++)
                        {
                            UFIDA.U9.CBO.MFG.BOM.BOMComponent beBOMComponent = elstBOMComponent[i];
                            BOMComponentDTO4CreateSv          dtoComponent   = PubMethod.GetDataOfBOMComponent(beBOMComponent);

                            if (dtoMasterModify.BOMComponents.Contains(dtoComponent))
                            {
                                continue;
                            }
                            else
                            {
                                //修改内容
                                dtoComponent.UsageQty  = bomComp.UsageQty;  //用量
                                dtoComponent.Scrap     = bomComp.Scrap;     //损耗率
                                dtoComponent.ParentQty = bomComp.ParentQty; //母件底数
                                dtoComponent.Remark    = bomComp.Remark;    //备注

                                if (!String.IsNullOrEmpty(bomComp.CompProject))
                                {
                                    Project itemProject = Project.FindByCode(bomComp.CompProject);
                                    if (itemProject != null)
                                    {
                                        dtoComponent.CompProject      = new CommonArchiveDataDTO();
                                        dtoComponent.CompProject.ID   = itemProject.ID;
                                        dtoComponent.CompProject.Code = itemProject.Code;
                                        dtoComponent.CompProject.Name = itemProject.Name;
                                    }
                                }
                                else
                                {
                                    //原接口未对项目置空的处理(UFIDA.U9.ISV.MFG.BOM.PubMethod.UpdateBOMComponent)
                                    string strUpdateVersion = string.Format("update uu set uu.CompProject = null from CBO_BOMComponent uu "
                                                                            + "where uu.ID = {0}", beBOMComponent.ID.ToString());
                                    DataAccessor.RunSQL(DatabaseManager.GetCurrentConnection(), strUpdateVersion, null);

                                    //dtoComponent.CompProject.ID = 1L;//
                                    //dtoComponent.CompProject.Code = string.Empty;
                                    //dtoComponent.CompProject.Name = string.Empty;
                                    //dtoComponent.CompProject = new CommonArchiveDataDTO();
                                }

                                dtoMasterModify.BOMComponents.Add(dtoComponent);
                                break;
                            }
                        }
                    }
                    else
                    {
                        #region 新增子件
                        BOMComponentDTO4CreateSv dtoComponent = CreateBOMComponentDTO(bomComp, iSeq, _bom, _beBOM.Org);
                        if (dtoComponent == null)
                        {
                            isAllBomCompOK = false;
                        }
                        dtoMasterModify.BOMComponents.Add(dtoComponent);
                        iSeq += 10;
                        #endregion
                    }
                }
                if (!isAllBomCompOK)
                {
                    dtoMasterModify = null;
                }
            }
            catch (Exception ex)
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, "", ex.Message));
                dtoMasterModify = null;
            }
            return(dtoMasterModify);
        }
        /// <summary>
        /// 创建新增BOM服务的DTO
        /// </summary>
        /// <param name="_bom"></param>
        /// <returns></returns>
        private BOMMasterDTO4CreateSv CreateBOMMasterDTO(BOMMaster _bom, Organization _beOrgContext)
        {
            BOMMasterDTO4CreateSv dtoMaster = new BOMMasterDTO4CreateSv();

            try
            {
                if (string.IsNullOrEmpty(_bom.ItemMasterCode))
                {
                    throw new Exception("母件料号编码传入为空字符串。");
                }
                ItemMaster beItemMaster = ItemMaster.Finder.Find("Code=@code and Org=@org",
                                                                 new OqlParam[] { new OqlParam(_bom.ItemMasterCode), new OqlParam(_beOrgContext.ID) });
                if (beItemMaster == null)
                {
                    throw new Exception(string.Format("母件料号{0}在组织{1}下不存在!", _bom.ItemMasterCode, _beOrgContext.Code));
                }
                #region 检查历史BOM上版本的生效、失效日期。不允许同一天内两次版本升级。
                OqlParamList lstParam = new OqlParamList();
                string       opath    = " Org=@org and ItemMaster=@item and BOMType=@bomType ";
                lstParam.Add(new OqlParam(_beOrgContext.ID));
                lstParam.Add(new OqlParam(beItemMaster.ID));
                lstParam.Add(new OqlParam(_bom.BOMType));

                UFIDA.U9.CBO.MFG.BOM.BOMMaster.EntityList lstBomOld = new UFIDA.U9.CBO.MFG.BOM.BOMMaster.EntityList();

                lstBomOld = UFIDA.U9.CBO.MFG.BOM.BOMMaster.Finder.FindAll(opath, lstParam.ToArray());
                foreach (var itemOldBom in lstBomOld)
                {
                    if (itemOldBom.EffectiveDate.Date == DateTime.Now.Date)
                    {
                        throw new Exception(string.Format("BOM母件{0}在{1}有版本{2}不允许同一天叠加版本升级。",
                                                          _bom.ItemMasterCode, DateTime.Today.ToShortDateString(), itemOldBom.BOMVersionCode));
                    }
                }
                #endregion


                #region BOM表头
                dtoMaster.Org      = new CommonArchiveDataDTO();
                dtoMaster.Org.ID   = _beOrgContext.ID;
                dtoMaster.Org.Code = _beOrgContext.Code;
                dtoMaster.Org.Name = _beOrgContext.Name;

                //不启用货主组织
                //dtoMaster.OwnerOrg = new CommonArchiveDataDTO();
                //dtoMaster.OwnerOrg.ID = beOrg.ID;
                //dtoMaster.OwnerOrg.Code = beOrg.Code;
                //dtoMaster.OwnerOrg.Name = beOrg.Name;

                dtoMaster.ItemMaster      = new CommonArchiveDataDTO();
                dtoMaster.ItemMaster.ID   = beItemMaster.ID;
                dtoMaster.ItemMaster.Code = beItemMaster.Code;
                dtoMaster.ItemMaster.Name = beItemMaster.Name;
                AlternateTypesEnum enumAlter = AlternateTypesEnum.GetFromValue(_bom.BOMType);//BOM类型
                if (enumAlter == null)
                {
                    throw new Exception(string.Format("传入的BOM类型值{0}在U9中无法找到对应值。", _bom.BOMType.ToString()));
                }

                //CBOBOM.BOMVersion beMasterBOMVersion = CBOBOM.BOMVersion.CreateBOMVersion(beItemMaster.Key, enumAlter, _bom.BOMVersionCode, _beOrgContext.Key);

                dtoMaster.BOMVersionCode  = _bom.BOMVersionCode;//默认
                dtoMaster.AlternateType   = enumAlter;
                dtoMaster.Lot             = 1;
                dtoMaster.ProductUOM      = new CommonArchiveDataDTO();
                dtoMaster.ProductUOM.ID   = beItemMaster.ManufactureUOM.ID;
                dtoMaster.ProductUOM.Code = beItemMaster.ManufactureUOM.Code;
                dtoMaster.ProductUOM.Name = beItemMaster.ManufactureUOM.Name;
                dtoMaster.EffectiveDate   = DateTime.Now.Date;
                dtoMaster.DisableDate     = DateTime.MaxValue;
                dtoMaster.FromQty         = 0;
                dtoMaster.ToQty           = 0;
                dtoMaster.IsPrimaryLot    = true;
                dtoMaster.Explain         = _bom.Explain;
                dtoMaster.BOMType         = BOMTypeEnum.GetFromValue(_bom.BOMType);
                //成本卷积IsCostRoll 在接口DTO中未提供
                dtoMaster.Status = MFGDocStatusEnum.Approved;//已核准

                dtoMaster.BOMComponents = new List <BOMComponentDTO4CreateSv>();
                #endregion

                #region BOM表体
                int  iSeq           = 10;
                bool isAllBomCompOK = true;
                foreach (var bomComponent in _bom.Components)
                {
                    BOMComponentDTO4CreateSv dtoComponent = CreateBOMComponentDTO(bomComponent, iSeq, _bom, _beOrgContext);
                    if (dtoComponent == null)
                    {
                        isAllBomCompOK = false;
                        continue;
                    }
                    dtoMaster.BOMComponents.Add(dtoComponent);
                    iSeq += 10;
                }
                #endregion

                if (!isAllBomCompOK)
                {
                    dtoMaster = null;
                }
            }
            catch (Exception ex)
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, "", ex.Message));
                dtoMaster = null;
            }
            return(dtoMaster);
        }