1.下面代码实现了VB6.0中调用U8EAI-BOM构成服务,以下代码均为项目实际代码,可直接复制应用。
2.在u811.1版本中委外BOM构成与正常的BOM构成是同系列表,不单独存储。
3.是以存货档案中有 委外标识标为是委外件。
4.下面调用的通用方法在: http://www.cnblogs.com/spring_wang/p/3393147.html
作者:王春天 2013-10-28
地址:http://www.cnblogs.com/spring_wang/p/3393359.html
具体代码如下:
一、下面是实际调用的方法,其中一个参数是"Add"与"Edit"是新增构成还是修改构成。那条SQL查询是判断是否有在u8存在构成。
'2.上传u8,如果上传成功再进行更新U8数据表 Dim flag '上传u8 3.先保存u8数据表 Set mrcu8 = U8Query("select * from v_BOM_BomParent where InvCode = '" & U(bpbh) & "'", msgtext) If mrcu8.EOF Then If Outsourcing_bom(U(bpbh), labBpmc.Caption, FGridArg, "Add") = False Then MsgBox ("委外构成上传U8出错!") Exit Sub End If Else If Outsourcing_bom(U(bpbh), labBpmc.Caption, FGridArg, "Edit") = False Then MsgBox ("委外构成上传U8出错!") Exit Sub End If End If
二、下面是公用调用EAI的BOM构成的方法。
其中更新Inventory存货档案表,是更新委外标识。
'ds_data 数据列 InvCode 子件编码,desl 定额数量 Public Function Outsourcing_bom(as_fjCode As String, as_fjName As String, ds_data As MSHFlexGrid, as_proc As String) As Boolean 'as_proc = "Edit" Outsourcing_bom = False Dim ls_xml As String Dim ls_sender As String Dim ls_data As String Dim ls_BomId As String Dim ls_BomType As String Dim ls_Version As String Dim ls_VersionDesc As String Dim ls_VersionEffDate As String Dim ls_Status As String Dim ls_VenCode As String Dim ls_VenDesc As String Dim ls_InvCode As String Dim ls_InvName As String Dim ls_ParentScrap As String ls_sender = U8_XTM '"001" ls_InvCode = as_fjCode '"WW" '父件编码 ls_InvName = as_fjName '"委外测试" '父件名称 ls_BomType = "1" 'BOM类型 不可为空 ls_Version = "10" '版本号 ls_VersionDesc = "01" '版本描述 ls_Status = "3" 'BOM状态 ls_ParentScrap = "0" '父件损耗率 ls_BomId = "1000000000" 'BOMID 不可为空 ls_VersionEffDate = "2000-01-01T00:00:00+00:00" '版本生效日 '增加文件头相关信息 ls_xml = "<?xml version=""1.0"" encoding=""UTF-8""?>" + vbCrLf ls_xml = ls_xml & "<ufinterface sender=""" & ls_sender & """ receiver=""u8"" roottag=""bom"" docid="""" proc=""" & as_proc & """ renewproofno = ""Y"" codeexchanged=""N"" exportneedexch=""N"" display="""" family="""" timestamp="""">" + vbCrLf ls_xml = ls_xml & "<Bom>" + vbCrLf '一、增加文件中版本信息 version ls_xml = ls_xml & "<Version>" + vbCrLf ls_xml = ls_xml & "<BomId>" & ls_BomId & "</BomId>" + vbCrLf 'BOMID 不可为空 ls_xml = ls_xml & "<BomType>" & ls_BomType & "</BomType>" + vbCrLf 'BOM类型 不可为空 ls_xml = ls_xml & "<Version>" & ls_Version & "</Version>" + vbCrLf '版本号 ls_xml = ls_xml & "<VersionDesc>" & ls_VersionDesc & "</VersionDesc>" + vbCrLf '版本说明 ls_xml = ls_xml & "<VersionEffDate>" & ls_VersionEffDate & "</VersionEffDate>" + vbCrLf '版本生效日 ls_xml = ls_xml & "<IdentCode/>" + vbCrLf ls_xml = ls_xml & "<IdentDesc/>" + vbCrLf ls_xml = ls_xml & "<Define1/>" + vbCrLf ls_xml = ls_xml & "<Define2/>" + vbCrLf ls_xml = ls_xml & "<Define3/>" + vbCrLf ls_xml = ls_xml & "<Define4/>" + vbCrLf ls_xml = ls_xml & "<Define5/>" + vbCrLf ls_xml = ls_xml & "<Define6/>" + vbCrLf ls_xml = ls_xml & "<Define7/>" + vbCrLf ls_xml = ls_xml & "<Define8/>" + vbCrLf ls_xml = ls_xml & "<Define9/>" + vbCrLf ls_xml = ls_xml & "<Define10/>" + vbCrLf ls_xml = ls_xml & "<Define11/>" + vbCrLf ls_xml = ls_xml & "<Define12/>" + vbCrLf ls_xml = ls_xml & "<Define13/>" + vbCrLf ls_xml = ls_xml & "<Define14/>" + vbCrLf ls_xml = ls_xml & "<Define15/>" + vbCrLf ls_xml = ls_xml & "<Define16/>" + vbCrLf ls_xml = ls_xml & "<ApplyCode/>" + vbCrLf ls_xml = ls_xml & "<ApplySeq/>" + vbCrLf ls_xml = ls_xml & "<Status>" & ls_Status & "</Status>" + vbCrLf 'BOM状态 ls_xml = ls_xml & "<ModifyTime/>" + vbCrLf ls_xml = ls_xml & "<CustCode/>" + vbCrLf ls_xml = ls_xml & "<CustDesc/>" + vbCrLf ls_xml = ls_xml & "<OrderType/>" + vbCrLf ls_xml = ls_xml & "<OrderCode/>" + vbCrLf ls_xml = ls_xml & "<OrderSeq/>" + vbCrLf ls_xml = ls_xml & "<OrderDId/>" + vbCrLf ls_xml = ls_xml & "<VenCode>" & ls_VenCode & "</VenCode>" + vbCrLf '供应商编码 ls_xml = ls_xml & "<VenDesc>" & ls_VenDesc & "</VenDesc>" + vbCrLf '供应商名称 Dim ls_ufts As String ls_ufts = "AAAAAAA6aEU" ls_xml = ls_xml & "<Ufts>" & ls_ufts & "</Ufts>" + vbCrLf ' '<Ufts>AAAAAAA6aEU=</Ufts> ls_xml = ls_xml & "</Version>" + vbCrLf '增加文件中父件信息 Parent ls_xml = ls_xml & "<Parent>" + vbCrLf ls_xml = ls_xml & "<BomId>" & ls_BomId & "</BomId>" + vbCrLf 'BOMID 不可为空 ls_xml = ls_xml & "<InvCode>" & ls_InvCode & "</InvCode>" + vbCrLf '父件编码 ls_xml = ls_xml & "<InvName>" & ls_InvName & "</InvName>" + vbCrLf '父件名称 ls_xml = ls_xml & "<InvAddCode/>" + vbCrLf ls_xml = ls_xml & "<Free1/>" + vbCrLf ls_xml = ls_xml & "<Free2/>" + vbCrLf ls_xml = ls_xml & "<Free3/>" + vbCrLf ls_xml = ls_xml & "<Free4/>" + vbCrLf ls_xml = ls_xml & "<Free5/>" + vbCrLf ls_xml = ls_xml & "<Free6/>" + vbCrLf ls_xml = ls_xml & "<Free7/>" + vbCrLf ls_xml = ls_xml & "<Free8/>" + vbCrLf ls_xml = ls_xml & "<Free9/>" + vbCrLf ls_xml = ls_xml & "<Free10/>" + vbCrLf ls_xml = ls_xml & "<EngineerFigNo/>" + vbCrLf ls_xml = ls_xml & "<ParentScrap>" & ls_ParentScrap & "</ParentScrap>" + vbCrLf '父件损耗率 ls_xml = ls_xml & "</Parent>" + vbCrLf '二、Component 子件信息 For i = 1 To ds_data.rows - 1 'ds_data.RecordCount ls_xml = ls_xml & "<Component>" + vbCrLf ' ls_data = "100000000" & Trim(str(i)) ls_data = "1" For j = 1 To 9 - Len(Trim(str(i))) ls_data = ls_data & "0" Next j ls_data = ls_data & Trim(str(i)) ls_xml = ls_xml & "<OpComponentId>" & ls_data & "</OpComponentId>" + vbCrLf '子件资料Id ls_data = "0" ls_xml = ls_xml & "<BomId>" & ls_BomId & "</BomId>" + vbCrLf 'BomId ls_data = Trim(str(i * 10)) ls_xml = ls_xml & "<SortSeq>" & ls_data & "</SortSeq>" + vbCrLf '序号 ls_xml = ls_xml & "<OpSeq>0000</OpSeq>" + vbCrLf '子件编码 ' If i = 1 Then ' ls_data = "3910510723" ' Else ' ls_data = "3910510523" ' End If ls_data = Trim(ds_data.TextMatrix(i, 1)) ls_xml = ls_xml & "<InvCode>" & ls_data & "</InvCode>" + vbCrLf '子件编码 ls_xml = ls_xml & "<Free1/>" + vbCrLf ls_xml = ls_xml & "<Free2/>" + vbCrLf ls_xml = ls_xml & "<Free3/>" + vbCrLf ls_xml = ls_xml & "<Free4/>" + vbCrLf ls_xml = ls_xml & "<Free5/>" + vbCrLf ls_xml = ls_xml & "<Free6/>" + vbCrLf ls_xml = ls_xml & "<Free7/>" + vbCrLf ls_xml = ls_xml & "<Free8/>" + vbCrLf ls_xml = ls_xml & "<Free9/>" + vbCrLf ls_xml = ls_xml & "<Free10/>" + vbCrLf ls_xml = ls_xml & "<EngineerFigNo/>" + vbCrLf ls_data = "2000-01-01T00:00:00+00:00" ls_xml = ls_xml & "<EffBegDate>" & ls_data & "</EffBegDate>" + vbCrLf '子件生效日期 ls_data = "2099-12-31T00:00:00+00:00" ls_xml = ls_xml & "<EffEndDate>" & ls_data & "</EffEndDate>" + vbCrLf '子件失效日期 ls_data = "1" ls_xml = ls_xml & "<FVFlag>" & ls_data & "</FVFlag>" + vbCrLf '固定/变动批量(0/1) '子件定额数量 ls_data = Trim(ds_data.TextMatrix(i, 2)) ls_xml = ls_xml & "<BaseQtyN>" & ls_data & "</BaseQtyN>" + vbCrLf '基本用量-分子 ls_data = "1" ls_xml = ls_xml & "<BaseQtyD>" & ls_data & "</BaseQtyD>" + vbCrLf '基本用量-分母 ls_data = "0" ls_xml = ls_xml & "<CompScrap>" & ls_data & "</CompScrap>" + vbCrLf '子件损耗率 ls_data = "false" ls_xml = ls_xml & "<ByproductFlag>" & ls_data & "</ByproductFlag>" + vbCrLf '是否联副产品 ls_data = "100000000" & Trim(str(i)) ls_data = "1" For j = 1 To 9 - Len(Trim(str(i))) ls_data = ls_data & "0" Next j ls_data = ls_data & Trim(str(i)) ls_xml = ls_xml & "<OptionsId>" & ls_data & "</OptionsId>" + vbCrLf '选项资料Id ls_xml = ls_xml & "<AuxUnitCode/>" + vbCrLf ls_xml = ls_xml & "<ChangeRate/>" + vbCrLf ls_xml = ls_xml & "<AuxBaseQtyN/>" + vbCrLf ls_data = "1" ls_xml = ls_xml & "<ProductType>" & ls_data & "</ProductType>" + vbCrLf ' ls_xml = ls_xml & "<Define22/>" + vbCrLf ls_xml = ls_xml & "<Define23/>" + vbCrLf ls_xml = ls_xml & "<Define24/>" + vbCrLf ls_xml = ls_xml & "<Define25/>" + vbCrLf ls_xml = ls_xml & "<Define26/>" + vbCrLf ls_xml = ls_xml & "<Define27/>" + vbCrLf ls_xml = ls_xml & "<Define28/>" + vbCrLf ls_xml = ls_xml & "<Define29/>" + vbCrLf ls_xml = ls_xml & "<Define30/>" + vbCrLf ls_xml = ls_xml & "<Define31/>" + vbCrLf ls_xml = ls_xml & "<Define32/>" + vbCrLf ls_xml = ls_xml & "<Define33/>" + vbCrLf ls_xml = ls_xml & "<Define34/>" + vbCrLf ls_xml = ls_xml & "<Define35/>" + vbCrLf ls_xml = ls_xml & "<Define36/>" + vbCrLf ls_xml = ls_xml & "<Define37/>" + vbCrLf ls_xml = ls_xml & "<Remark/>" + vbCrLf ls_xml = ls_xml & "</Component>" + vbCrLf Next i '三、ComponentOpt 子件其它信息 For i = 1 To ds_data.rows - 1 'ds_data.RecordCount ls_xml = ls_xml & "<ComponentOpt>" + vbCrLf ' ls_data = "100000000" & Trim(str(i)) ls_data = "1" For j = 1 To 9 - Len(Trim(str(i))) ls_data = ls_data & "0" Next j ls_data = ls_data & Trim(str(i)) ls_xml = ls_xml & "<OptionsId>" & ls_data & "</OptionsId>" + vbCrLf '选项资料Id ls_xml = ls_xml & "<Offset>0</Offset>" + vbCrLf ls_data = "3" ls_xml = ls_xml & "<WIPType>" & ls_data & "</WIPType>" + vbCrLf 'WIP属性(1入库/2工序/3领料/4虚拟) ls_data = "true" ls_xml = ls_xml & "<AccuCostFlag>" & ls_data & "</AccuCostFlag>" + vbCrLf '是/否累计成本 ls_xml = ls_xml & "<DrawDeptCode/>" + vbCrLf ls_xml = ls_xml & "<Whcode/>" + vbCrLf ls_data = "false" ls_xml = ls_xml & "<OptionalFlag>" & ls_data & "</OptionalFlag>" + vbCrLf '是否可选 ls_data = "2" ls_xml = ls_xml & "<MutexRule>" & ls_data & "</MutexRule>" + vbCrLf '互斥原则(1-ONE/2-ALL/3-ANY/4-AL0) ls_data = "100" ls_xml = ls_xml & "<PlanFactor>" & ls_data & "</PlanFactor>" + vbCrLf '计划比例 ls_data = "false" ls_xml = ls_xml & "<CostWIPRel>" & ls_data & "</CostWIPRel>" + vbCrLf '固定/变动批量(0/1) ls_data = "0" ls_xml = ls_xml & "<Offset>" & ls_data & "</Offset>" + vbCrLf '偏置期 ls_xml = ls_xml & "</ComponentOpt>" + vbCrLf Next i '增加文件尾相关信息 ls_xml = ls_xml & "</Bom>" + vbCrLf ls_xml = ls_xml & "</ufinterface>" + vbCrLf Dim xml_document As New DOMDocument xml_document.loadXML (ls_xml) fn2 = App.Path & "u8_code2.xml" xml_document.save (fn2) Dim ls_temp As String '接收返回消息,如果成功,返回U8中物料代码,如果失败,返回错误信息 If SendToEAI(ls_xml, ls_temp) Then '成功 ' MsgBox "上传成功" & ls_temp Dim sqls() As String Dim sqls_range Dim msgtext As String sqls_range = 0 ReDim Preserve sqls(sqls_range) sqls(sqls_range) = "update Inventory set bProxyForeign = 1 where cInvCode = '" & as_fjCode & "' " If U8Update(sqls, msgtext) = False Then '数据库更新失败退出 MsgBox msgtext Outsourcing_bom = False Else Outsourcing_bom = True End If Else '失败 MsgBox ls_temp Outsourcing_bom = False End If End Function