我正在使用QBFC将Items数据从快速书籍导入到我自己的项目中。
使用代码:1我可以找到totla在快速书籍中有多少项目。
我有一个要求,从快速书籍中找到并计数每种类型的物品。
但使用代码:我无法在特定项目(例如:Serive(中找到多少项目
代码:1
IORItemRet itemRet = default(IORItemRet);
IORItemRetList itemRetList = default(IORItemRetList);
IResponse response = responseSet.ResponseList.GetAt(0);
if ((response.Detail != null))
{
itemRetList = (IORItemRetList)response.Detail;
if ((itemRetList != null))
{
int i = 0;
for (int j = 0; j <= itemRetList.Count - 1; j++)
{
}
}
}
代码:2
IItemServiceRet itemSeriveRet = default(IItemServiceRet);
IItemServiceRetList itemServiceRetList = default(IItemServiceRetList);
IResponse response = responseSet.ResponseList.GetAt(0);
if ((response.Detail != null))
{
itemServiceRetList = (IItemServiceRetList)response.Detail; //Com object Error
if ((itemServiceRetList != null))
{
int i = 0;
for (int j = 0; j <= itemServiceRetList.Count - 1; j++)
{
}
}
}
//Com对象错误
无法强制转换类型为"System"的COM对象__ComObject"到接口类型"Interop.QBFC10.ItemServiceRetList"。此操作失败,因为对IID为"{C53D1081-9FE4-4569-9181-A9D7E0155907}"的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT中的异常:0x80004002(E_NOINTERFACE((。
现在让我看看如何从Quick books 中找到每个项目的计数
在您的代码中,您似乎正在检查该响应。详细信息不为null。但你是否也在检查回应的价值。状态代码和响应类型?如果您收到一个错误,那么您收到的响应可能没有实现IORItemRetList接口。请参阅屏幕参考中的以下代码。
IResponse response = responseList.GetAt(i);
//check the status code of the response, 0=ok, >0 is warning
if (response.StatusCode >= 0)
{
//the request-specific response is in the details, make sure we have some
if (response.Detail != null)
{
//make sure the response is the type we're expecting
ENResponseType responseType = (ENResponseType)response.Type.GetValue();
if (responseType == ENResponseType.rtItemQueryRs)
{
//upcast to more specific type here, this is safe because we checked with response.Type check above
IORItemRetList OR = (IORItemRetList)response.Detail;
WalkOR(OR);
}
}
}
上面代码注释中的注释:
这是安全的,因为我们检查了响应。上的类型检查
在SDK程序员指南(第107页(中指出:
作为查询响应的响应对象包含Ret列表对象其中可能包含多个Ret对象。响应对象不是仅包含一个Ret对象且没有Ret列表的查询响应。在处理响应时,这种差异至关重要数据
一旦接口检查到位,for循环应该可以正常工作。