mojianhong 发表于 2011-2-13 16:15:58

U8库存API应用-‘弃审采购到货单’完整VB代码

Option Explicit
Public Sub CallU8Api()
On Error GoTo ErrHandler
      Dim sysID As String
      Dim m_NetLogin As Object
      sysID = "AS"
      Set m_NetLogin = CreateObject("UFSoft.U8.Framework.Login.UI.clsLogin")
      If m_NetLogin.login_2(sysID) = False Then
            MsgBox m_NetLogin.ErrDescript
            Exit Sub
      End If
   
    '第一步:构造u8login对象并登陆
    '如果当前环境中有login对象则可以省去第一步
    Dim ologin As Object
    Set ologin = CreateObject("U8Login.clsLogin")
    Call ologin.ConstructLogin(m_NetLogin.userToken)
    If Not ologin.Login("AS", ologin.cAcc_Id, ologin.cIYear, ologin.cUserId, ologin.SysPassword, ologin.CurDate, ologin.cServer, ologin.cSerial) Then   '不能登陆到应用服务器,请检查服务器配置或查看服务器日志
      MsgBox ologin.ShareString
    Else
      '第二步:构造环境上下文对象,传入login,并按需设置其它上下文参数
      Dim u8EnvCtx As New U8EnvContext
      Set u8EnvCtx.U8Login = ologin
      '采购所有接口均支持内部独立事务和外部事务,默认内部事务
      '如果是外部事务,则需要传递ADO.Connection对象,并将IsIndependenceTransaction设置为false
      'Dim bizDbConn As New ADO.Connection
      'Set u8EnvCtx.BizDbConnection = bizDbConn
      'u8EnvCtx.IsIndependenceTransaction = false
      '设置上下文参数
      u8EnvCtx.SetApiContext "VoucherType", "2"             '上下文数据类型:int,含义:单据类型, 采购到货单 2
      u8EnvCtx.SetApiContext "bPositive", "True"               '上下文数据类型:bool,含义:红蓝标识:True,蓝字;False,红字
      u8EnvCtx.SetApiContext "sBillType", "0"               '上下文数据类型:string,含义:到货单类型, 到货单 0 退货单 1
      u8EnvCtx.SetApiContext "sBusType", "普通采购"                '上下文数据类型:string,含义:业务类型:普通采购,直运采购,受托代销
      '第三步:构造ApiBroker对象,调用Connect,传入Api的地址标识(Url),传入上下文
      Dim u8apiBroker As New U8ApiComBroker
      u8apiBroker.Connect "U8API/ArrivedGoods/CancelconfirmArr", u8EnvCtx
      '第四步:API参数赋值
      '给BO表头参数DomHead赋值,此BO参数的业务类型为到货单,属表头参数。BO参数均按引用传递
      '提示:给BO表头参数DomHead赋值有两种方法
      '方法一是直接传入MSXML2.DOMDocument对象
      'Dim DomHead As New MSXML2.DOMDocument
      'u8apiBroker.AssignNormalValue "DomHead", DomHead
      '方法二是构造BusinessObject对象,具体方法如下:
      Dim DomHead As BusinessObject
      Set DomHead = u8apiBroker.GetBoParam("DomHead")
      DomHead.RowCount = 1 '设置BO对象(表头)行数,只能为一行
      '给BO对象(表头)的字段赋值,值可以是真实类型,也可以是无类型字符串
      '****************************** 以下是必输字段 *****************************
      DomHead(0).setValue "id", ""               '主关键字段,Integer类型
      DomHead(0).setValue "cbustype", ""         '业务类型,Integer类型
      DomHead(0).setValue "ccode", ""            '单据号,String类型
      DomHead(0).setValue "ddate", ""            '日期,Date类型
      DomHead(0).setValue "cvenabbname", ""      '供应商,String类型
      DomHead(0).setValue "cdepname", ""         '部门,String类型
      DomHead(0).setValue "cexch_name", ""         '币种,String类型
      DomHead(0).setValue "iexchrate", ""          '汇率,Double类型
      '***************************** 以下是非必输字段 ****************************
      DomHead(0).setValue "ipresent", ""         '现存量,String类型
      DomHead(0).setValue "cmaketime", ""          '制单时间,Date类型
      DomHead(0).setValue "cmodifytime", ""      '修改时间,Date类型
      DomHead(0).setValue "cmodifydate", ""      '修改日期,Date类型
      DomHead(0).setValue "creviser", ""         '修改人,String类型
      DomHead(0).setValue "caudittime", ""         '审核时间,Date类型
      DomHead(0).setValue "cauditdate", ""         '审核日期,Date类型
      DomHead(0).setValue "cptname", ""            '采购类型,String类型
      DomHead(0).setValue "ccloser", ""            '关闭人,String类型
      DomHead(0).setValue "iverifystateex", ""   '审核状态,String类型
      DomHead(0).setValue "ireturncount", ""       '打回次数,String类型
      DomHead(0).setValue "iswfcontrolled", ""   '是否启用工作流,String类型
      DomHead(0).setValue "cpersonname", ""      '业 务 员,String类型
      DomHead(0).setValue "cscname", ""            '运输方式,String类型
      DomHead(0).setValue "itaxrate", ""         '税率,Double类型
      DomHead(0).setValue "cmemo", ""            '备注,String类型
      DomHead(0).setValue "cmaker", ""             '制单人,String类型
      DomHead(0).setValue "ivtid", ""            '单据模版号,Integer类型
      DomHead(0).setValue "cverifier", ""          '审核人,String类型
      DomHead(0).setValue "bnegative", ""          '负发票标志,String类型
      DomHead(0).setValue "cvencode", ""         '供货单位编号,String类型
      DomHead(0).setValue "cdepcode", ""         '部门编号,String类型
      DomHead(0).setValue "cptcode", ""            '采购类型编码,String类型
      DomHead(0).setValue "cpaycode", ""         '付款条件编码,String类型
      DomHead(0).setValue "cpersoncode", ""      '职员编号,String类型
      DomHead(0).setValue "ufts", ""               '时间戳,String类型
      DomHead(0).setValue "cpayname", ""         '付款条件,String类型
      DomHead(0).setValue "csccode", ""            '运输方式编码,String类型
      DomHead(0).setValue "cdefine1", ""         '表头自定义项1,String类型
      DomHead(0).setValue "cdefine2", ""         '表头自定义项2,String类型
      DomHead(0).setValue "cdefine3", ""         '表头自定义项3,String类型
      DomHead(0).setValue "cdefine4", ""         '表头自定义项4,Date类型
      DomHead(0).setValue "cdefine5", ""         '表头自定义项5,Integer类型
      DomHead(0).setValue "cdefine6", ""         '表头自定义项6,Date类型
      DomHead(0).setValue "cdefine7", ""         '表头自定义项7,Double类型
      DomHead(0).setValue "cdefine8", ""         '表头自定义项8,String类型
      DomHead(0).setValue "cdefine9", ""         '表头自定义项9,String类型
      DomHead(0).setValue "cdefine10", ""          '表头自定义项10,String类型
      DomHead(0).setValue "cdefine11", ""          '表头自定义项11,String类型
      DomHead(0).setValue "cdefine12", ""          '表头自定义项12,String类型
      DomHead(0).setValue "cdefine13", ""          '表头自定义项13,String类型
      DomHead(0).setValue "cdefine14", ""          '表头自定义项14,String类型
      DomHead(0).setValue "cdefine15", ""          '表头自定义项15,Integer类型
      DomHead(0).setValue "cdefine16", ""          '表头自定义项16,Double类型
      DomHead(0).setValue "cvendefine1", ""      '供应商自定义项1,String类型
      DomHead(0).setValue "cvendefine2", ""      '供应商自定义项2,String类型
      DomHead(0).setValue "cvendefine3", ""      '供应商自定义项3,String类型
      DomHead(0).setValue "cvendefine4", ""      '供应商自定义项4,String类型
      DomHead(0).setValue "cvendefine5", ""      '供应商自定义项5,String类型
      DomHead(0).setValue "cvendefine6", ""      '供应商自定义项6,String类型
      DomHead(0).setValue "cvendefine7", ""      '供应商自定义项7,String类型
      DomHead(0).setValue "cvendefine8", ""      '供应商自定义项8,String类型
      DomHead(0).setValue "cvendefine9", ""      '供应商自定义项9,String类型
      DomHead(0).setValue "cvendefine10", ""       '供应商自定义项10,String类型
      DomHead(0).setValue "cvendefine11", ""       '供应商自定义项11,String类型
      DomHead(0).setValue "cvendefine12", ""       '供应商自定义项12,String类型
      DomHead(0).setValue "cvendefine13", ""       '供应商自定义项13,String类型
      DomHead(0).setValue "cvendefine14", ""       '供应商自定义项14,String类型
      DomHead(0).setValue "cvendefine15", ""       '供应商自定义项15,String类型
      DomHead(0).setValue "cvendefine16", ""       '供应商自定义项16,String类型
      DomHead(0).setValue "idiscounttaxtype", ""   '扣税类别,Integer类型
      DomHead(0).setValue "ibilltype", ""          '单据类型,Integer类型
      DomHead(0).setValue "cvenpuomprotocol", ""   '收付款协议编码,String类型
      DomHead(0).setValue "cvenpuomprotocolname", ""'收付款协议名称,String类型

      '第五步:调用API
      If u8apiBroker.InvokeApi() = False Then
            '第六步:错误处理
            MsgBox u8apiBroker.GetLastError()
            If u8apiBroker.ErrorType = ExceptionType_Business Then
                '处理API业务错误
            ElseIf u8apiBroker.ErrorType = ExceptionType_System Then
                '处理系统错误
            End If
      Else
            '第七步:获取返回结果
            '获取返回值
            '获取普通返回值。此返回值数据类型为String,此参数按值传递,表示错误描述:空,正确;非空,错误
            Dim result As String
            result = CStr(u8apiBroker.GetReturnValue())
      End If
      '结束本次调用,释放API资源
      u8apiBroker.Disconnect
      Set u8apiBroker = Nothing
    End If
    Exit Sub
ErrHandler:
    MsgBox Err.Description
End Sub

请问: If Not ologin.Login("AS", ologin.cAcc_Id, ologin.cIYear, ologin.cUserId, ologin.SysPassword, ologin.CurDate, ologin.cServer, ologin.cSerial) Then 不能成功执行,返回True,这是为什么呢?

lth009 发表于 2015-1-12 11:22:00

新手开发U8,真的很难,有没有好人,给份资料吧。。。

dachu888 发表于 2015-12-14 20:18:31

粘贴的API浏览器中的参照代码,没意思.

emerson01 发表于 2014-3-13 13:39:21

学习了 感谢分享   

expoqd 发表于 2015-2-11 11:48:40

学习了,谢谢楼主分享

szsos 发表于 2014-5-5 16:01:47

好好学习,天天向上

decembersh 发表于 2011-2-14 08:56:31

学习

Matgek 发表于 2011-3-22 15:26:32

我用c#,也是这个问题,不知道为什么

修志 发表于 2011-3-26 08:52:44

不错,谢谢

修志 发表于 2011-3-26 09:19:46

不错,谢谢

昕寒 发表于 2011-3-26 10:36:22

好贴,顶一下

pro0001 发表于 2011-8-19 11:35:26

这个问题解决了吗?现在也遇到这个问题,无法进行了:'(

隋飞 发表于 2011-8-25 22:07:22

是不是开发版本的问题

op336 发表于 2011-9-6 16:21:36

学习uap。谢谢提供。

topunion009 发表于 2011-9-6 21:05:39

这个问题现在有答案了吗?

shouzhuabing 发表于 2012-8-1 08:45:45

学习一下。。。

shouzhuabing 发表于 2012-8-3 08:45:48

需要Debug版的Login文件,跟用友要就可以了。

dhawk 发表于 2013-2-23 21:35:22

我也说不好怎么回事,好像U8Login.clsLogin不能直接登录,后来一般都用。NET版本的LOGIN登录,成功以后用U8LOGIN。CLSLOGIN的CONTRACTTOKEN来完成登录。

zhaosanxing 发表于 2013-4-28 16:10:45

碰到楼上的问题,各位怎么解决的啊?

harwinxia 发表于 2013-12-16 20:45:35

学习了,感谢楼主
页: [1] 2
查看完整版本: U8库存API应用-‘弃审采购到货单’完整VB代码