// slot for choosing merchandize
void COperationWIndow::chooseMerchandize()
{
structOrder tmpOrder; // temp order
QList<QStandardItem*> OrderItemList; // order model item list
qDebug() << "m_iSelected: " << m_pMerchandizeBrowser->m_iSelected;
// FIXED: m_pMerchandizeBrowser->m_iSelected does not correctly show the index of selected image
/*
tmpOrder.iMerchandizeID=1;
tmpOrder.iMerchandizeQuantity=25;
tmpOrder.rMerchandizePrice=4.00;
tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice;
tmpOrder.strMerchandizeName=QString("Testni Artikel");
tmpOrder.strDisplayString=QString::number(tmpOrder.iMerchandizeID)+strMerchandizeSpaceDelimiter+\
QString(tmpOrder.strMerchandizeName)+strMerchandizeDelimiter+\
QString::number(tmpOrder.rMerchandizePrice, 'f', iMerchandizePricePrecision)+strMerchandizeSpaceDelimiter+\
QString::number(tmpOrder.iMerchandizeQuantity)+strMerchandizeSpaceDelimiter+\
QString::number(tmpOrder.rSubtotal, 'f', iMerchandizePricePrecision);
qDebug() << "tmpOrder.strDisplayString=" << tmpOrder.strDisplayString;
*/
// TODO: language id number must not be ignored in sql statement
QString queryString
("SELECT * from merchandize WHERE IdentificationNumber=%1 AND InUse=1;");
int iMerchandizeId=m_pMerchandizeBrowser->m_iSelected+1; // calcualtes id
queryString=queryString.arg(iMerchandizeId); // adds id to query string
qDebug() << "Query: " << queryString; // debug
QSqlQuery query
(queryString
);
// sets up query from query string qDebug() << query.lastError().text(); // debug
if (query.isActive())
{
while (query.next())
{
tmpOrder.iMerchandizeID=query.value(0).toInt();
tmpOrder.iMerchandizeQuantity=1;
tmpOrder.rMerchandizePrice=(qreal)query.value(3).toDouble();
tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice;
tmpOrder.
strMerchandizeName=QString(query.
value(2).
toString());
tmpOrder.
strDisplayString=QString::number(tmpOrder.
iMerchandizeID)+strMerchandizeSpaceDelimiter
+\
QString(tmpOrder.
strMerchandizeName)+strMerchandizeDelimiter
+\
QString::number(tmpOrder.
rMerchandizePrice,
'f', iMerchandizePricePrecision
)+strMerchandizeSpaceDelimiter
+\
QString::number(tmpOrder.
iMerchandizeQuantity)+strMerchandizeSpaceDelimiter
+\
QString::number(tmpOrder.
rSubtotal,
'f', iMerchandizePricePrecision
);
}
if(m_pShoppingCartView->order()->orders()->size()<=0)
{
// size of orders is zero, adds record to table
m_pShoppingCartView->order()->orders()->append(tmpOrder); // adds order to internal qlist
Q_CHECK_PTR(pItem); // checks creation
m_pShoppingCartView->shoppingCartModel()->appendRow(pItem);
}
else
{
for(qint16 iIndex=0; iIndex<(qint16)m_pShoppingCartView->order()->orders()->size(); iIndex++)
{
qDebug() << " m_pShoppingCartView->order()->orders()->at((int)iIndex).iMerchandizeID (" \
<< m_pShoppingCartView->order()->orders()->at((int)iIndex).iMerchandizeID << ")==" \
<< "tmpOrder.iMerchandizeID (" << tmpOrder.iMerchandizeID << ")?";
if(m_pShoppingCartView->order()->orders()->at((int)iIndex).iMerchandizeID==tmpOrder.iMerchandizeID)
/*
qDebug() << " iMerchandizeId (" << iMerchandizeId \
<< "tmpOrder.iMerchandizeID (" << tmpOrder.iMerchandizeID << ")?";
if(iMerchandizeId==tmpOrder.iMerchandizeID)
*/
{
// orderer merchandize found, so
tmpOrder.iMerchandizeQuantity++; // update quantity
tmpOrder.rSubtotal=tmpOrder.iMerchandizeQuantity*tmpOrder.rMerchandizePrice; // update total
tmpOrder.
strDisplayString=QString::number(tmpOrder.
iMerchandizeID)+strMerchandizeSpaceDelimiter
+\
QString(tmpOrder.
strMerchandizeName)+strMerchandizeDelimiter
+\
QString::number(tmpOrder.
rMerchandizePrice,
'f', iMerchandizePricePrecision
)+strMerchandizeSpaceDelimiter
+\
QString::number(tmpOrder.
iMerchandizeQuantity)+strMerchandizeSpaceDelimiter
+\
QString::number(tmpOrder.
rSubtotal,
'f', iMerchandizePricePrecision
);
m_pShoppingCartView->order()->orders()->replace((int)iIndex, tmpOrder); // saves changes
m_pShoppingCartView->shoppingCartModel()->clear(); // clears table view
for(qint16 iIndex=0; iIndex<(qint16)m_pShoppingCartView->order()->orders()->size(); iIndex++)
{
Q_CHECK_PTR(pItem); // checks creation
OrderItemList.append(pItem); // adds item to list
//m_pShoppingCartView->shoppingCartModel()->appendRow(pItem); // adds items
}
m_pShoppingCartView->shoppingCartModel()->appendRow(OrderItemList); // adds items
break;
}
else
{
// ordered merchandize not found, so adds it
m_pShoppingCartView->order()->orders()->append(tmpOrder); // adds order to internal qlist
Q_CHECK_PTR(pItem); // checks creation
m_pShoppingCartView->shoppingCartModel()->appendRow(pItem);
break;
} // for
} // for
} // if
/*
m_pShoppingCartView->resizeColumnsToContents();
m_pShoppingCartView->resizeRowsToContents();
*/
if(m_pOrderButton->isEnabled()==false)
m_pOrderButton->setEnabled(true); // enables order buttn
} // if
}
Bookmarks