Ejemplo n.º 1
0
        public virtual bool ReceiveBom(ProductBom bom, string itemCode, string batch_no)
        {
            count++;
            try
            {
                using (var trans = RF.TransactionScope(WMSEntityDataProvider.ConnectionStringName))
                {
                    //
                    var bomItem = DomainControllerFactory.Create <ItemController>().GetByCode(bom.Item.Code);
                    if (bomItem == null)
                    {
                        if (itemCode.IsNotEmpty())//单个下载就报错
                        {
                            throw new EntityNotFoundException(string.Format("不存在物料{0},请先下载最新物料".Translate(), bom.Item.Code));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    var existBom = DomainControllerFactory.Create <WorkOrderController>()
                                   .FindProductBom(bomItem) ?? bom;

                    existBom.Item    = bomItem;
                    existBom.ItemId  = bomItem.Id;
                    existBom.Code    = bom.Code;
                    existBom.Name    = bom.Name;
                    existBom.Version = bom.Version;

                    //EntityPhantomExtension.SetIsPhantom(bom, true);
                    //supplier.PersistenceStatus = existSupplier.PersistenceStatus;

                    foreach (var detail in bom.DetailList)
                    {
                        var existDtl = existBom.DetailList.Concrete().FirstOrDefault(p => p.Item.Code == detail.Item.Code) ?? detail;

                        //更新物料编码
                        var item = DomainControllerFactory.Create <ItemController>().GetByCode(detail.Item.Code);
                        if (item == null)
                        {
                            if (itemCode.IsNotEmpty())//单个下载就报错
                            {
                                throw new EntityNotFoundException(string.Format("不存在物料{0},请先下载最新物料".Translate(), detail.Item.Code));
                            }
                            else
                            {
                                return(false);
                            }
                        }

                        existDtl.Item         = item;
                        existDtl.ItemId       = item.Id;
                        existDtl.UnitQty      = detail.UnitQty;
                        existDtl.Warehouse    = detail.Warehouse;
                        existDtl.Rgekz        = detail.Rgekz;
                        existDtl.Unit         = detail.Unit;
                        existDtl.ProductBomId = existBom.Id;
                        existDtl.DownBatchNo  = batch_no;
                        RF.Save(existDtl);
                    }
                    var ls   = new List <ProductBomDetail>();
                    var list = existBom.DetailList.Concrete().Where(p => p.Id <= 0);
                    ls.AddRange(list);
                    foreach (var item in ls)
                    {
                        existBom.DetailList.Remove(item);
                    }
                    ;

                    RF.Save(existBom);
                    trans.Complete();
                }
                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("标准Bom数据下载异常:" + e.Message);
            }
        }
Ejemplo n.º 2
0
        private static List <ProductBom> ERP_MES_Bom(Hashtable import)
        {
            RFC rfc = new RFC(ConfigurationManager.AppSettings["sapServer"].ToString());
            //RFC rfc = new RFC("SAPTest");
            var lst = new List <ProductBom>();
            //RFC调用函数名
            string funcName = "ZWMS_BOM";
            //传输传给RFC函数的DataSet
            DataSet ids = new DataSet();
            //构建RFC传入表DataTable

            //返回数据的DataSet框架
            DataSet ods = new DataSet();
            //构建Export参数DataTable
            DataTable export = new DataTable();

            export.TableName = "Export";
            export.Columns.Add(new DataColumn("RTYPE", typeof(string))); //处理标识
            export.Columns.Add(new DataColumn("RTMSG", typeof(string))); //消息文本
            ods.Tables.Add(export);
            //构建RFC传出表DataTable
            DataTable odt1 = new DataTable();

            odt1.TableName = "T_HEADER";
            odt1.Columns.Add(new DataColumn("WERKS", typeof(string))); //工厂
            odt1.Columns.Add(new DataColumn("MATNR", typeof(string))); //物料代码
            odt1.Columns.Add(new DataColumn("VERID", typeof(string))); //生产版本
            //odt1.Columns.Add(new DataColumn("ZTEXT", typeof(string)));//BOM 文本
            //odt1.Columns.Add(new DataColumn("STKTX", typeof(string)));//可选文本
            odt1.Columns.Add(new DataColumn("LOEKZ", typeof(string)));//BOM 删除标志
            ods.Tables.Add(odt1);

            DataTable odt2 = new DataTable();

            odt2.TableName = "T_ITEM";
            odt2.Columns.Add(new DataColumn("MATNR", typeof(string))); //物料代码
            odt2.Columns.Add(new DataColumn("IDNRK", typeof(string))); //BOM 组件
            odt2.Columns.Add(new DataColumn("MAKTX", typeof(string))); //物料描述(短文本)
            odt2.Columns.Add(new DataColumn("MENGE", typeof(string))); //组件数量
            odt2.Columns.Add(new DataColumn("MEINS", typeof(string))); //组件计量单位
            odt2.Columns.Add(new DataColumn("LGORT", typeof(string))); //库存地点
            odt2.Columns.Add(new DataColumn("RGEKZ", typeof(string))); //是否反冲
            ods.Tables.Add(odt2);

            //执行RFC函数
            bool ret = rfc.DownloadByRFC(funcName, import, ids, ref ods);

            //根据RFC执行后返回的数据处理业务逻辑
            //DataTable dt = ods.Tables["T_ITEM"];
            foreach (DataRow h in ods.Tables["T_HEADER"].Rows)
            {
                var    bom  = new ProductBom();
                string code = h["MATNR"].ToString();
                string ver  = h["VERID"].ToString();
                string flag = h["LOEKZ"].ToString();
                bom.Item = new Item {
                    Code = code
                };
                bom.Name    = code;
                bom.Code    = code;
                bom.Version = ver;
                foreach (DataRow i in ods.Tables["T_ITEM"].AsEnumerable().Where(p => h["MATNR"].ToString() == p["MATNR"].ToString()))
                {
                    var resover   = i["RGEKZ"].ToString();
                    var bomDetail = new ProductBomDetail()
                    {
                        Item = new Item {
                            Code = i["IDNRK"].ToString()
                        },
                        UnitQty   = Convert.ToDouble(i["MENGE"] ?? 0),
                        Unit      = i["MEINS"].ToString(),
                        Rgekz     = resover.IsNullOrEmpty() || resover == "0" ? 0 : 1,
                        Warehouse = i["LGORT"].ToSafeString()
                    };
                    bom.DetailList.Add(bomDetail);
                }
                lst.Add(bom);
            }
            return(lst);
        }