bool TradeDb::GetOrderDataFromId(qint64 orderId, OrderDataEntity* entity)
{
if(!entity)
return false;
bool isok = false;
QSqlQuery query(m_TradeDb);
QString strSql(SELECT_PRINT_DATA.arg(QString("=%1").arg(orderId)));
isok = query.exec(strSql);
if(!isok)
return isok;
int index = 0;
while(query.next())
{
QSqlRecord record = query.record();//返回本次查询所有的记录
if(index == 0)
{
QSqlField field;
QString fieldName;
QVariant fieldValue;
const QMetaObject* metaobj = entity->metaObject();
for ( int i = 0; i < record.count(); ++i)//每条记录中的列数
{
field = record.field(i);//每条记录里的第i列
fieldName = field.name();
fieldValue = field.value();
//隐含要求,field名称与property的名称一致
int propindex = metaobj->indexOfProperty(
fieldName.toAscii().constData());
if ( propindex == -1)
{
continue;
}
else
{
entity->setProperty(fieldName.toLatin1().data(), fieldValue);
}
}
++index;
}
OrderItemEntityPtr spItem = QSharedPointer<OrderItemEntity>(new OrderItemEntity());
spItem->SetOrder_id( record.value(0).toLongLong());
spItem->SetSku_id(record.value(21).toLongLong()); //sku_id
spItem->SetSku_name(record.value(22).toString()); //"sku_name"
spItem->SetJd_price(record.value(23).toLongLong()); //jd_price
spItem->SetItem_total(record.value(24).toInt()); //item_total
spItem->SetProduct_no(record.value(25).toString());
spItem->SetOuter_sku_id(record.value(26).toString());//outer_sku_id 2013/7/12 add by YJ 商家SKUID
spItem->SetSkuAttributes(record.value(27).toString()); //
entity->SetItemsList(spItem);
}
return isok;
}
{
if(!entity)
return false;
bool isok = false;
QSqlQuery query(m_TradeDb);
QString strSql(SELECT_PRINT_DATA.arg(QString("=%1").arg(orderId)));
isok = query.exec(strSql);
if(!isok)
return isok;
int index = 0;
while(query.next())
{
QSqlRecord record = query.record();//返回本次查询所有的记录
if(index == 0)
{
QSqlField field;
QString fieldName;
QVariant fieldValue;
const QMetaObject* metaobj = entity->metaObject();
for ( int i = 0; i < record.count(); ++i)//每条记录中的列数
{
field = record.field(i);//每条记录里的第i列
fieldName = field.name();
fieldValue = field.value();
//隐含要求,field名称与property的名称一致
int propindex = metaobj->indexOfProperty(
fieldName.toAscii().constData());
if ( propindex == -1)
{
continue;
}
else
{
entity->setProperty(fieldName.toLatin1().data(), fieldValue);
}
}
++index;
}
OrderItemEntityPtr spItem = QSharedPointer<OrderItemEntity>(new OrderItemEntity());
spItem->SetOrder_id( record.value(0).toLongLong());
spItem->SetSku_id(record.value(21).toLongLong()); //sku_id
spItem->SetSku_name(record.value(22).toString()); //"sku_name"
spItem->SetJd_price(record.value(23).toLongLong()); //jd_price
spItem->SetItem_total(record.value(24).toInt()); //item_total
spItem->SetProduct_no(record.value(25).toString());
spItem->SetOuter_sku_id(record.value(26).toString());//outer_sku_id 2013/7/12 add by YJ 商家SKUID
spItem->SetSkuAttributes(record.value(27).toString()); //
entity->SetItemsList(spItem);
}
return isok;
}