public virtual void SaveOrUpdateWxpo(WxWipIssueBill bill, string billNo)
        {
            try
            {
                if (bill.No.IsNullOrWhiteSpace())
                {
                    //    throw new ArgumentNullException("No");
                    return;
                }
                using (var trans = RF.TransactionScope(WMSEntityDataProvider.ConnectionStringName))
                {
                    var existBill = DomainControllerFactory.Create <WxWipIssueBillController>()
                                    .GetByNo(bill.No) ?? bill;
                    var supplier = DomainControllerFactory.Create <SupplierController>().GetSupplierByCode(bill.Supplier.Code);
                    if (supplier == null)
                    {
                        throw new EntityNotFoundException("不存在供应商[{0}],请先下载最新供应商".Translate().FormatArgs(bill.Supplier.Code));
                    }
                    existBill.Supplier         = supplier;
                    existBill.BillDate         = bill.BillDate;
                    existBill.WipIssueBillType = WipIssueBillType.ISSUEOEM;
                    //todo 移动类型

                    //InvOrgIdExtension.SetInvOrgId(bill, PlatformEnvironment.InvOrgId);

                    foreach (var detail in bill.WxWipIssueBillDetailList)
                    {
                        if (bill.WxWipIssueBillDetailList.Concrete().Any(p => p.WipIssueState != WipIssueState.New))
                        {
                            continue;
                        }
                        var existDtl = existBill.WxWipIssueBillDetailList.Concrete().FirstOrDefault(p => p.Item.Code == detail.Item.Code) ?? detail;

                        //更新物料编码
                        var item = DomainControllerFactory.Create <ItemController>().GetByCode(detail.Item.Code);
                        if (item == null)
                        {
                            if (billNo.IsNullOrEmpty())
                            {
                                throw new EntityNotFoundException("不存在物料[{0}],请先下载最新物料".Translate().FormatArgs(detail.Item.Code));
                            }
                            return;
                        }
                        var warehouse = DomainControllerFactory.Create <WarehouseController>().GetWarehouse(detail.IssueWarehouse.Code);
                        //if (warehouse == null)
                        //{
                        //    throw new EntityNotFoundException("不存在仓库[{0}],请先下载最新仓库".Translate().FormatArgs(detail.PickWarehouse.Code));
                        //}
                        existDtl.Item           = item;
                        existDtl.Factory        = detail.Factory;
                        existDtl.IssueWarehouse = warehouse;
                        //existDtl.PickWarehouse = warehouse;
                        existDtl.Qty         = detail.Qty;
                        existDtl.Unit        = detail.Unit;
                        existDtl.BillDtlDate = detail.BillDtlDate;
                        //existDtl.ActualQty = detail.ActualQty;
                        existDtl.WxWipIssueBillId = existBill.Id;
                        RF.Save(existDtl);
                    }
                    RF.Save(existBill);
                    // 排除已经下载 SAP更新后删除的明细 todo
                    trans.Complete();
                }
            }
            catch (Exception e)
            {
                throw new Exception("外协领料单下载异常:" + e.Message);
            }
        }
예제 #2
0
        private static List <WxWipIssueBill> ERP_MES_WX(Hashtable import)
        {
            RFC rfc = new RFC(ConfigurationManager.AppSettings["sapServer"].ToString());
            //RFC rfc = new RFC("SAPTest");
            var lst = new List <WxWipIssueBill>();
            //RFC调用函数名
            string funcName = "ZWMS_WXFLD";
            //传输传给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_TAB";
            odt1.Columns.Add(new DataColumn("ZBLNR", typeof(string))); //单号
            odt1.Columns.Add(new DataColumn("LIFNR", typeof(string))); //供应商
            odt1.Columns.Add(new DataColumn("LGORT", typeof(string))); //库存地点
            odt1.Columns.Add(new DataColumn("WERKS", typeof(string))); //工厂
            odt1.Columns.Add(new DataColumn("MATNR", typeof(string))); //物料号
            odt1.Columns.Add(new DataColumn("ZXLSL", typeof(string))); //数量
            odt1.Columns.Add(new DataColumn("CHARG", typeof(string))); //批号
            odt1.Columns.Add(new DataColumn("MEINS", typeof(string))); //基本计量单位
            ods.Tables.Add(odt1);

            //DataTable odt2 = new DataTable();
            //odt2.TableName = "T_TAB2";
            //odt2.Columns.Add(new DataColumn("ZBLNR", typeof(string)));//单号
            //odt2.Columns.Add(new DataColumn("LIFNR", typeof(string)));//供应商
            //ods.Tables.Add(odt2);


            //执行RFC函数
            bool ret = rfc.DownloadByRFC(funcName, import, ids, ref ods);
            //根据RFC执行后返回的数据处理业务逻辑

            var dtItem = ods.Tables["T_TAB"];
            var view   = dtItem.DefaultView;
            var dtHead = view.ToTable("T_HEAD", true, "ZBLNR", "LIFNR");

            foreach (DataRow h in dtHead.Rows)
            {
                var bill = new WxWipIssueBill();

                bill.No       = h["ZBLNR"].ToString().Trim();
                bill.Supplier = new BD.Suppliers.Supplier()
                {
                    Code = h["LIFNR"].ToString()
                };


                foreach (DataRow i in dtItem.AsEnumerable().Where(p => h["ZBLNR"].ToString() == p["ZBLNR"].ToString()))
                {
                    var billDtl = new WxWipIssueBillDetail()
                    {
                        Item = new Item {
                            Code = i["MATNR"].ToString()
                        },
                        //ProjectNo = i["EBELP"].ToString(),
                        Qty            = Convert.ToDouble(i["ZXLSL"] ?? 0),
                        Unit           = i["MEINS"].ToString(),
                        Factory        = i["WERKS"].ToString(),
                        BatchNo        = i["CHARG"].ToString(),
                        IssueWarehouse = new INV.Hisense.Warehouses.Warehouses.Warehouse {
                            Code = i["LGORT"].ToString()
                        },
                        //PickWarehouse = new INV.Hisense.Warehouses.Warehouses.Warehouse { Code = i["LGORT"].ToString() },
                    };
                    bill.WxWipIssueBillDetailList.Add(billDtl);
                }
                lst.Add(bill);
            }
            return(lst);
        }