コード例 #1
0
        //[OperationBehavior]
        public System.String DoEx(ICommonDataContract commonData, System.String contextInfo, System.String bOMInfo)
        {
            this.CommonData = commonData;
            try
            {
                BeforeInvoke("UFIDA.U9.Cust.ZX.BaiLiSV.CreateBOMSV");
                CreateBOMSV objectRef = new CreateBOMSV();

                objectRef.ContextInfo = contextInfo;
                objectRef.BOMInfo     = bOMInfo;

                //处理返回类型.
                System.String result = objectRef.Do();
                return(result);

                return(result);
            }
            catch (System.Exception e)
            {
                DealException(e);
                throw;
            }
            finally
            {
                FinallyInvoke("UFIDA.U9.Cust.ZX.BaiLiSV.CreateBOMSV");
            }
        }
コード例 #2
0
        public override object Do(object obj)
        {
            CreateBOMSV bpObj = (CreateBOMSV)obj;

            //get business operation context is as follows
            //IContext context = ContextManager.Context

            //auto generating code end,underside is user custom code
            //and if you Implement replace this Exception Code...
            throw new NotImplementedException();
        }
コード例 #3
0
        public override object Do(object obj)
        {
            CreateBOMSV bpObj = (CreateBOMSV)obj;


            StringBuilder strbResult = new StringBuilder();

            #region 基础校验&提前检查
            if (string.IsNullOrEmpty(bpObj.BOMInfo))
            {
                logger.Error(string.Format("创建BOM失败:传入参数BOMInfo为空。"));
                strbResult.AppendFormat(string.Format("<ResultInfo error={0} />", "创建BOM失败:传入参数BOMInfo为空。"));
                return(strbResult.ToString());
            }
            BOMInfo     bominfoAll = new BOMInfo();
            ContextInfo cxtInfo    = new ContextInfo();
            try
            {
                bominfoAll = XmlSerializerHelper.XmlDeserialize <BOMInfo>(bpObj.BOMInfo, Encoding.Unicode);
                cxtInfo    = XmlSerializerHelper.XmlDeserialize <ContextInfo>(bpObj.ContextInfo, Encoding.Unicode);
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("反序列化BOMInfo失败:{0}", bpObj.BOMInfo));
                strbResult.AppendFormat(string.Format("<ResultInfo error={0} />", string.Format("反序列化BOMInfo失败:{0}", bpObj.BOMInfo)));
                return(strbResult.ToString());
            }


            if (bominfoAll.Masters.Count <= 0)
            {
                logger.Error(string.Format("传入的BOMInfo中没有BOM母件信息"));
                strbResult.AppendFormat(string.Format("<ResultInfo error={0} />", "传入的BOMInfo中没有BOM母件信息"));
                return(strbResult.ToString());
            }

            Organization beOrgContext = Organization.FindByCode(cxtInfo.OrgCode);//原历史版本
            #endregion

            ImportBOMSv svModify = new ImportBOMSv();
            List <BOMMasterDTO4CreateSv> lstBOMMasterModifyDTO = new List <BOMMasterDTO4CreateSv>();
            svModify.IsThrowEx = true;
            CreateBOMSv svCreate = new CreateBOMSv();
            List <BOMMasterDTO4CreateSv> lstBOMMasterCreateDTO = new List <BOMMasterDTO4CreateSv>();
            svCreate.IsThrowEx = true;
            DeletePartBOMSv svDelPart = new DeletePartBOMSv();
            List <BOMMasterDTO4CreateSv> lstBOMMasterDelPartDTO = new List <BOMMasterDTO4CreateSv>();
            svDelPart.IsThrowEx = true;

            User       beUser     = User.Finder.FindByID(cxtInfo.UserID);
            ContextDTO dtoContext = new ContextDTO();
            dtoContext.CultureName = cxtInfo.CultureName;    // "zh-CN";
            dtoContext.UserCode    = beUser.Code;            //默认:系统管理员admin
            dtoContext.EntCode     = cxtInfo.EnterpriseCode; // "van0323";//测试默认公司:van0323.正式使用请根据需要指定。
            dtoContext.OrgCode     = cxtInfo.OrgCode;        //

            svCreate.ContextDTO  = dtoContext;
            svModify.ContextDTO  = dtoContext;
            svDelPart.ContextDTO = dtoContext;

            Int64 l = 1;
            try
            {
                foreach (var bomMaster in bominfoAll.Masters)
                {
                    #region 校验从PLM传过来的组织、物料是否有效
                    if (ValidateNullValue(bomMaster, beOrgContext))
                    {
                        continue;
                    }
                    ItemMaster beItemMaster = ItemMaster.Finder.Find("Code=@code and Org=@org  and Effective.IsEffective=1 and Effective.DisableDate >= @nowdate1 and Effective.EffectiveDate <= @nowdate2",
                                                                     new OqlParam[] { new OqlParam(bomMaster.ItemMasterCode), new OqlParam(beOrgContext.ID), new OqlParam(DateTime.Now.Date.ToShortDateString()),
                                                                                      new OqlParam(DateTime.Now.Date.ToShortDateString()), new OqlParam(DateTime.Now.Date.ToShortDateString()) });

                    if (beItemMaster == null)
                    {
                        strbError.AppendLine(string.Format(strErrorItem, bomMaster.ItemMasterCode, "", string.Format("BOMInfo中第{0}项物料编码{1}在组织{2}无法找到!",
                                                                                                                     l.ToString(), bomMaster.ItemMasterCode, beOrgContext.Code)));
                        continue;
                    }
                    if (!beItemMaster.IsBOMEnable)
                    {
                        strbError.AppendLine(string.Format(strErrorItem, bomMaster.ItemMasterCode, "", "母件不允许建BOM。"));
                        continue;
                    }
                    //加入料品状态必须为“已核准”的条件:State=2
                    if (beItemMaster.State != ItemStateEnum.Verified)
                    {
                        strbError.AppendLine(string.Format(strErrorItem, bomMaster.ItemMasterCode, "", string.Format("BOMInfo中第{0}项物料编码{1}料品状态不是“已核准状态”!",
                                                                                                                     l.ToString(), bomMaster.ItemMasterCode)));
                        continue;
                    }
                    bool bFor = false;
                    foreach (var bomComp in bomMaster.Components)
                    {
                        ItemMaster beItemComponent = ItemMaster.Finder.Find("Code=@code and Org=@org and Effective.IsEffective=1 and Effective.DisableDate >= @nowdate1 and Effective.EffectiveDate <= @nowdate2",
                                                                            new OqlParam[] { new OqlParam(bomComp.ItemCode), new OqlParam(beOrgContext.ID),
                                                                                             new OqlParam(DateTime.Now.Date.ToShortDateString()), new OqlParam(DateTime.Now.Date.ToShortDateString()) });
                        if (beItemComponent == null)
                        {
                            strbError.AppendLine(string.Format(strErrorItem, bomMaster.ItemMasterCode, bomComp.ItemCode, string.Format("第{0}项子件物料编码ItemCode{1}在组织{2}无法找到!",
                                                                                                                                       l.ToString(), bomComp.ItemCode, beOrgContext.Code)));
                            bFor = true;//当子项物料无法找到异常时,上级的for循环跳转到下一条记录。
                        }
                        if (beItemComponent.State != ItemStateEnum.Verified)
                        {
                            strbError.AppendLine(string.Format(strErrorItem, bomMaster.ItemMasterCode, "", string.Format("第{0}项子件物料编码{1}料品状态不是“已核准状态”!",
                                                                                                                         l.ToString(), bomComp.ItemCode)));
                            bFor = true;
                        }
                    }
                    //当子项物料无法找到异常时,上级的for循环跳转到下一条记录。
                    if (bFor)
                    {
                        continue;
                    }
                    #endregion

                    #region 校验传入的BOM是否存在.如果不存在,则转入到BOM创建服务CreateBOMSv中。
                    //检查上下文组织下料号、BOM种类(自制/委外)、版本号是否存在。一旦存在,则使用修改BOM服务。
                    UFIDA.U9.CBO.MFG.BOM.BOMMaster beBOMMaster = UFIDA.U9.CBO.MFG.BOM.BOMMaster.Finder.Find("Org=@org and ItemMaster=@item and BomType = @bomtype and BOMVersionCode = @bomVersion ",
                                                                                                            new OqlParam[] { new OqlParam(beOrgContext.ID), new OqlParam(beItemMaster.ID), new OqlParam(bomMaster.BOMType), new OqlParam(bomMaster.BOMVersionCode) });
                    if (beBOMMaster == null)
                    {
                        BOMMasterDTO4CreateSv dtoMasterCreate = CreateBOMMasterDTO(bomMaster, beOrgContext);
                        if (dtoMasterCreate != null)
                        {
                            lstBOMMasterCreateDTO.Add(dtoMasterCreate);
                        }
                        continue;
                    }
                    else
                    {
                        #region 若存在,则转入到BOM修改服务ImportBOMSv中。
                        BOMMasterDTO4CreateSv dtoMasterModify = ModifyBOMMasterDTO(bomMaster, beBOMMaster, beOrgContext);
                        if (dtoMasterModify != null)
                        {
                            lstBOMMasterModifyDTO.Add(dtoMasterModify);
                        }
                        #endregion
                    }
                    #endregion
                    #region 若存在,检查是否存在需要删除的子件加入到DeleteBOMPartSv中。
                    BOMMasterDTO4CreateSv dtoMasterDelPart = DelBOMPartDTO(bomMaster, beBOMMaster);
                    if (dtoMasterDelPart != null)
                    {
                        lstBOMMasterDelPartDTO.Add(dtoMasterDelPart);
                    }
                    #endregion

                    l++;
                }
                //}

                if (lstBOMMasterCreateDTO.Count > 0)
                {
                    svCreate.BOMMasterDTOList = lstBOMMasterCreateDTO;
                    svCreate.ContextDTO       = dtoContext;
                    List <LogDTO4CreateSv> lstBOMLog = new List <LogDTO4CreateSv>();
                    lstBOMLog = svCreate.Do();

                    foreach (var itemLog in lstBOMLog)
                    {
                        if (itemLog.IsOperationSuccess)
                        {
                            #region 标准BOMAPI目前不提供成本卷积和子件收货审核属性赋值.这里补充处理
                            string strUpdateIsCostRoll = string.Format("update vv set vv.IsCostRoll = 1 from CBO_BOMMaster vv where vv.ID = {0} and vv.BOMType = 0",
                                                                       itemLog.BOMMasterDTO.BOMMasterID.ToString());
                            string strUpdateRCVApproved = string.Format("update uu set uu.RCVApproved = 1 from CBO_BOMComponent uu "
                                                                        + "join CBO_BOMMaster vv on vv.ID = uu.BOMMaster where vv.ID = {0} and vv.BOMType = 1",
                                                                        itemLog.BOMMasterDTO.BOMMasterID.ToString());
                            //DataAccessor.RunSQL(DatabaseManager.GetCurrentConnection(), strUpdateIsCostRoll, null);
                            DataAccessor.RunSQL(DatabaseManager.GetCurrentConnection(), strUpdateRCVApproved, null);
                            #endregion
                            strbSuccess.AppendLine(string.Format(strInfoItem, itemLog.BOMMasterDTO.ItemMaster.Code));
                        }
                        else
                        {
                            strbError.AppendLine(string.Format(strErrorItem, itemLog.BOMMasterDTO.ItemMaster.Code, "",
                                                               string.Format("U9系统创建BOM母件{0}失败:{1}.", itemLog.BOMMasterDTO.ItemMaster.Code, itemLog.ErrorMsg)));
                        }
                    }
                }
                if (lstBOMMasterModifyDTO.Count > 0)
                {
                    svModify.BOMMasterDTOList = lstBOMMasterModifyDTO;
                    svModify.ContextDTO       = dtoContext;
                    List <LogDTO4CreateSv> lstBOMLog = new List <LogDTO4CreateSv>();
                    lstBOMLog = svModify.Do();

                    foreach (var itemLog in lstBOMLog)
                    {
                        if (itemLog.IsOperationSuccess)
                        {
                            strbSuccess.AppendLine(string.Format(strInfoItem, itemLog.BOMMasterDTO.ItemMaster.Code));
                        }
                        else
                        {
                            strbError.AppendLine(string.Format(strErrorItem, itemLog.BOMMasterDTO.ItemMaster.Code, "",
                                                               string.Format("U9系统修改BOM母件{0}失败:{1}.", itemLog.BOMMasterDTO.ItemMaster.Code, itemLog.ErrorMsg)));
                        }
                    }
                }
                if (lstBOMMasterDelPartDTO.Count > 0)
                {
                    svDelPart.BOMMasterDTOList = lstBOMMasterDelPartDTO;
                    svDelPart.ContextDTO       = dtoContext;
                    List <LogDTO4CreateSv> lstBOMLog = new List <LogDTO4CreateSv>();
                    svDelPart.Do();

                    //string strBOM = "<BOM ItemMasterCode=\"{0}\" Description=\"删除子件导入成功!\"/>";
                    //foreach (var item in lstBOMMasterDelPartDTO)
                    //{
                    //    strbSuccess.AppendLine(string.Format(strBOM, item.ItemMaster.Code));
                    //}
                }
                strbResult.AppendLine("<ResultInfo>");
                strbResult.AppendLine(strbError.ToString());
                strbResult.AppendLine(strbSuccess.ToString());
                strbResult.AppendLine("</ResultInfo>");
            }
            catch (Exception ex)
            {
                strbResult.AppendLine(string.Format("<ResultInfo error=\"{0}\">", ex.Message));
                strbResult.AppendLine(strbError.ToString());
                strbResult.AppendLine("</ResultInfo>");
            }
            return(strbResult.ToString());
        }