SBO_SDK_DI添加物料主数据

 Public Function CreateItem(ByVal oItem As item) As ReturnStatus
        Dim vReturnStatus As New ReturnStatus
        Try
            Dim vItem As SAPbobsCOM.Items
            Dim Sql As String
            Dim oRs As SAPbobsCOM.Recordset
            oRs = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            'SBO物料编号DM没有---按SBO物料编号加1自动生成
            Sql = "select max(isnull(itemcode,''))+1 as 物料号 from oitm where itemcode<>'9999999999'"
            oRs.DoQuery(Sql)
            Dim Itemcode As String
            If oRs.RecordCount = 0 Then
                Itemcode = "100001"
            Else
                Itemcode = oRs.Fields.Item("物料号").Value
            End If
            Sql = "select top 1  isnull(itemcode,'') as itemcode from oitm where U_ProductID='" + oItem.productID + "'"
            oRs.DoQuery(Sql)
            '判断ERP系统中是否存在此物料
            If oRs.RecordCount = 0 Then
                'DM系统传入数据校验 If CheckItemDate(oItem) <> "" Then
                vReturnStatus.ErrMessage = CheckItemData(oItem)
                If vReturnStatus.ErrMessage <> "" Then
                    'DM系统传入数据校验失败
                    vReturnStatus.Succeed_ind = -1002
                    vReturnStatus.ErrMessage = CheckItemData(oItem)
                    vReturnStatus.ItemCode = ""
                    Return vReturnStatus
                Else
                    'DM系统传入数据校验成功
                    vItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
                    'vItemGroups = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItemGroups)
                    vItem.ItemCode = Itemcode          'SBO物料编号--DM没有自动产生---
                    vItem.UserFields.Fields.Item("U_ProductID").Value = oItem.productID 'SBO产品编码--DM产品编码
                    vItem.ItemName = oItem.itemName          'SBO物料名称--DM产品编码
                    vItem.User_Text = "由DM系统中导入"
                    If oItem.frgnName <> Nothing Then
                        vItem.ForeignName = oItem.frgnName       'SBO外文描述--DM产品型号
                    End If
                    vItem.UserFields.Fields.Item("U_Color").Value = oItem.color         'SBO颜色--DM颜色
                    If oItem.firmCode <> Nothing Then
                        vItem.Manufacturer = oItem.firmCode       'SBO制造商--DM产品经理------
                    End If
                    'vItem. = oItem.firmCode       'SBO制造商--DM产品经理------
                    'SBO管理物料--DM管理物料 N表示都不做,B表示批次管理,S表示序列号管理
                    If oItem.manBtchSerNum = "S" Then
                        'vItem.ManageSerialNumbers = "Y" '序列号管理
                        'vItem.ManageBatchNumbers = "N" '批号
                        vItem.ManageSerialNumbers = 1
                    Else
                        If oItem.manBtchSerNum = "B" Then
                            'vItem.ManageSerialNumbers = "N" '序列号
                            'vItem.ManageBatchNumbers = "Y" '批次管理
                            vItem.ManageBatchNumbers = 1 '批次管理"
                        Else
                            If oItem.manBtchSerNum = "N" Then
                                '管理物料无
                                vItem.ManageSerialNumbers = 0
                                vItem.ManageBatchNumbers = 0
                            End If
                        End If
                    End If
                    'SBO销项税码-- DM销项税码
                    If oItem.xvatGroup = "0" Then
                        vItem.SalesVATGroup = "X0"
                    Else
                        If oItem.xvatGroup = "17" Then
                            vItem.SalesVATGroup = "X1"
                        Else
                            If oItem.xvatGroup = "13" Then
                                vItem.SalesVATGroup = "X2"
                            End If
                            If oItem.xvatGroup = "6" Then
                                vItem.SalesVATGroup = "X3"
                            End If
                            If oItem.xvatGroup = "4" Then
                                vItem.SalesVATGroup = "X4"
                            End If
                        End If
                    End If
                    'SBO进项税码-- DM进项税码
                    If oItem.jvatGroup = "0" Then
                        vItem.PurchaseVATGroup = "J0"
                    Else
                        If oItem.jvatGroup = "17" Then
                            vItem.PurchaseVATGroup = "J1"
                        Else
                            If oItem.jvatGroup = "13" Then
                                vItem.PurchaseVATGroup = "J2"
                            End If
                            If oItem.jvatGroup = "3" Then
                                vItem.PurchaseVATGroup = "J3"
                            End If
                        End If
                    End If
                    vItem.UserFields.Fields.Item("U_OpeType").Value = oItem.opeType     'SBO派送方式--DM派送方式
                    vItem.UserFields.Fields.Item("U_CustomMade").Value = oItem.customMade '是否按单定制
                    If oItem.consumptionTax <> Nothing Then
                        vItem.UserFields.Fields.Item("U_ConsumptionTax").Value = oItem.consumptionTax  'SBO运营外包商--DM运营外包商
                    End If
                    vItem.ItemsGroupCode = oItem.itmsGrpCod   'SBO物料组  --DMERP产品线ID
                    vItem.UserFields.Fields.Item("U_Bandid").Value = oItem.bandid       'SBO品牌ID--ERP品牌ID
                    vItem.ItemType = SAPbobsCOM.ItemTypeEnum.itItems
                    vItem.SalesItem = SAPbobsCOM.BoYesNoEnum.tYES
                    vItem.PurchaseItem = SAPbobsCOM.BoYesNoEnum.tYES
                    ' 判断是否是虚拟物料, 是虚拟物料, 不是仓库物料
                    If oItem.phantom = "Y" Then
                        vItem.IsPhantom = 1          'SBO是否转单不开票--ERP是否转单不开票
                        vItem.InventoryItem = SAPbobsCOM.BoYesNoEnum.tNO
                        ''管理物料无
                        'vItem.ManageSerialNumbers = 0
                        'vItem.ManageBatchNumbers = 0
                    Else
                        vItem.IsPhantom = 0          'SBO是否转单不开票--ERP是否转单不开票
                        vItem.InventoryItem = SAPbobsCOM.BoYesNoEnum.tYES
                    End If
                    ' vItem.InventoryItem = SAPbobsCOM.BoYesNoEnum.tYES
                    'vItem.ManageSerialNumbersOnReleaseOnly =
                    If vItem.Add() = 0 Then
                        'SBO最高成本价--DM最高成本价;价格写入价格清单中。                 
                        Sql = "update itm1 set price=" + CStr(oItem.price) + " where  pricelist=1 and  itemcode='" + Itemcode + "'"
                        oRs.DoQuery(Sql)
                        vReturnStatus.Succeed_ind = 0 '(int类型)0:成功
                        vReturnStatus.ErrMessage = "物料添加成功!"
                        vReturnStatus.ItemCode = Itemcode
                        Return vReturnStatus
                    Else
                        vReturnStatus.Succeed_ind = oCompany.GetLastErrorCode
                        vReturnStatus.ErrMessage = oCompany.GetLastErrorDescription
                        vReturnStatus.ItemCode = ""
                        Return vReturnStatus
                    End If
                End If
            Else
                vReturnStatus.Succeed_ind = 0
                vReturnStatus.ErrMessage = "物料更新成功!DM产品编号和ERP系统中已存在!"
                vReturnStatus.ItemCode = oRs.Fields.Item("itemcode").Value
                Return vReturnStatus
            End If
        Catch ex As Exception
            vReturnStatus.Succeed_ind = -1001
            vReturnStatus.ErrMessage = ex.Message
            vReturnStatus.ItemCode = ""
            Return vReturnStatus
        End Try
    End Function
End Class
'ReturnStatus返回状态对象
'  result.getSucceed_ind(); //(int类型)0:成功
'  result.getItemCode();    //(字符串类型)返回的ERP物料号
'  result.getErrMessage();  //(字符串类型)错误信息
Public Class ReturnStatus
    Private iSucceed_ind As Integer
    Private sErrMessage As String
    Private sItemcode As String
    Property Succeed_ind() As Integer
        Get
            Return iSucceed_ind
        End Get
        Set(ByVal value As Integer)
            iSucceed_ind = value
        End Set
    End Property
    Property ErrMessage() As String
        Get
            Return sErrMessage
        End Get
        Set(ByVal value As String)
            sErrMessage = value
        End Set
    End Property
    Property ItemCode() As String
        Get
            Return sItemcode
        End Get
        Set(ByVal value As String)
            sItemcode = value
        End Set
    End Property
End Class

本文出自 “阚山” 博客,转载请与作者联系!

你可能感兴趣的:(职场,休闲,SBO_SDK_DI,SBO_SDK)