金蝶K310.3接口开发问题

想飞的狼 2014-02-19 09:06:08
本次主要目的是想将物流系统中的进销记录可以利用K3提供的接口直接在K3中自动生成凭证,在网上找的K3凭证接口实例及用法,可放在我的软件中时总是报错,请高手帮忙指点。
K3实例

Private Function MakeVouchPack(PropString As String, DataString As Variant) As Object
'入口参数
'1.PropString 为账套连接字符串
'2.DataString 为传入的凭证所需要保存的信息与数据
Dim i As Long, j As Long, k As Long
Dim Vdict As KFO.Dictionary, EVect As KFO.Vector, ent As KFO.Dictionary
Dim Dt As KFO.Dictionary, dtVect As KFO.Vector
Dim itemID, ItemClassID
Dim ItemNumber As Integer '核算项目数
Dim VchEntryNumber As Integer '凭证分录数
'此处检查相关的凭证信息是否有效(省略)
Set Vdict = New KFO.Dictionary '一张凭证,包含的凭证头的信息
'凭证日期
Vdict ("FDate")
'业务日期
Vdict ("FTransDate")
'凭证字ID
Vdict ("FGroupID")
'参考信息
Vdict ("FReference")
'附件张数
Vdict ("FAttachments")
'会计主管
Vdict ("FHandler")
'凭证序号
Vdict ("FSerialNum")
'不为空是 机制凭证(不能修改删除)
Vdict ("FInternalInd")
'其他系统传入凭证对象接口描述
Vdict ("FObjectName")
'接口参数
Vdict ("FParameter")
5
Set EVect = New KFO.Vector '一张凭证,所包含的业务信息的数据包
For i = 0 To VchEntryNumber - 1
Set ent = New KFO.Dictionary ''此处表示的是存储一条凭证分录所需要的信息
'摘要
ent ("FExplanation")
'科目
ent ("FAccountID")
FAccountNumber
'币别
ent ("FCurrencyID")
'计量单位
ent ("FMeasureUnitID")
'汇率
ent ("FExchangeRate")
'借方
ent ("FDebit")
'贷方
ent ("FCredit")
'总计
ent ("FAmountFor")
'核算项目
'此处表示存储一条核算项目的方法
Set dtVect = New KFO.Vector
For k = 0 To ItemNumber - 1
Set Dt = New KFO.Dictionary
Dt ("FItemID")
Dt ("FItemClassID")
dtVect.Add Dt
Next k
'===========================
Set ent("_Details") = dtVect
'===========================
'现金流转
ent ("CashFlowDetail")
Set dtVect = New KFO.Vector
For k = 0 To ItemNumber - 1
Set Dt = New KFO.Dictionary
Dt ("FItemID")
Dt ("FAmountFor")
Dt ("FAmount")
dtVect.Add Dt
Next k
'===========================
6
Set ent("CashFlow") = dtVect
'===========================
EVect.Add ent
Next i '下一条分录
If EVect.Size < 2 Then Exit Function '分录小于2 条
'分账制检查原币平衡
'检查借贷平衡
Set Vdict("_Entries") = EVect
Set MakeVouchPack = Vdict
End Function



我利用接口实例做了一个小实验,代码如下:


Private Function MakeVouchPack() As Object
'入口参数

Dim i As Long, k As Long
Dim Vdict As KFO.Dictionary, EVect As KFO.Vector, ent As KFO.Dictionary
Dim Dt As KFO.Dictionary, dtVect As KFO.Vector
'Dim itemID, ItemClassID
Dim ItemNumber As Integer = 1 '核算项目数
Dim VchEntryNumber As Integer = 1 '凭证分录数
'此处检查相关的凭证信息是否有效(省略)
Vdict = New KFO.Dictionary '一张凭证,包含的凭证头的信息
'凭证日期
Vdict("FDate") = CDate("2013-12-01")

'业务日期
Vdict("FTransDate") = CDate("2013-12-01")
'凭证字ID
Vdict("FGroupID") = CLng("121")
'参考信息
Vdict("FReference") = "xx"
'附件张数
Vdict("FAttachments") = CLng("1")
'会计主管
' Vdict("FHandler") = "kevin"
'凭证序号
Vdict("FSerialNum") = CLng("1")
'不为空是 机制凭证(不能修改删除)
'Vdict("FInternalInd") = ""
''其他系统传入凭证对象接口描述
'Vdict("FObjectName") = ""
''接口参数
'Vdict("FParameter") = ""

EVect = New KFO.Vector '一张凭证,所包含的业务信息的数据包
' For i = 0 To VchEntryNumber - 1
ent = New KFO.Dictionary ''此处表示的是存储一条凭证分录所需要的信息
'摘要
ent("FExplanation") = "xxxccxcxcxc"
'科目
ent("FAccountID") = CLng("1000")
' FAccountNumber()
'币别
ent("FCurrencyID") = CInt("1")
'计量单位
ent("FMeasureUnitID") = CLng("0")
'汇率
ent("FExchangeRate") = CDec("1")
'借方
ent("FDebit") = CDec("100")
'贷方
ent("FCredit") = CDec("100")
'总计
ent("FAmountFor") = CDec("100")
'核算项目
'此处表示存储一条核算项目的方法
dtVect = New KFO.Vector
' For k = 0 To ItemNumber - 1
Dt = New KFO.Dictionary
Dt("FItemID") = CLng("236")

Dt("FItemClassID") = CLng("8")
dtVect.Add(Dt)
'Next k
'===========================
ent("_Details") = dtVect
'===========================
'现金流转
' ent("CashFlowDetail") = ""
dtVect = New KFO.Vector
' For k = 0 To ItemNumber - 1
Dt = New KFO.Dictionary
Dt("FItemID") = CLng("236")
Dt("FAmountFor") = CDec("100")
Dt("FAmount") = CDec("100")
dtVect.Add(Dt)
'Next k
'===========================

ent("CashFlow") = dtVect
'===========================
EVect.Add(ent)
' Next i '下一条分录
'If EVect.Size < 2 Then
' Exit Function
'End If
'分录小于2 条
'分账制检查原币平衡
'检查借贷平衡
Vdict("_Entries") = EVect
MakeVouchPack = Vdict
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hasconn As Boolean

objK3Login = CreateObject("K3Login.ClsLogin")
If Not objK3Login.CheckLogin Then
hasconn = False '设置为未连接状态s
objK3Login = Nothing

MsgBox("未登录账套")
End
Else
My.Settings.erpserver = Trim(TextBox1.Text)
My.Settings.erpuser = Trim(TextBox2.Text)
My.Settings.erppw = Trim(TextBox3.Text)
My.Settings.erpdb = Trim(TextBox4.Text)
My.Settings.jdserver = Trim(TextBox5.Text)
My.Settings.jduser = Trim(TextBox6.Text)
My.Settings.jdpw = Trim(TextBox7.Text)
My.Settings.jddb = Trim(TextBox8.Text)
MsgBox("登录账套成功")
MakeVouchPack()
end if



就是想把一个规定好的内容以凭证的形式生成,登录K3都是正常的,一执行的时候会出
system.runtime.interopservices.comexception(0x8002005):类型不匹配
在kfo.dictionaryclass.set_value(string name,object&pvar)
在k3.form1.makevouchpack()位置 *** 行号556
行号556就是Vdict("FDate") = CDate("2013-12-01")
...全文
155 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
稻庄 2014-02-19
  • 打赏
  • 举报
回复
纯属帮顶

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧