Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 111 → Rev 112

/trunk/DBViewer/database.cpp
19,6 → 19,10
}
 
void MainWindow::buildTree(QTreeWidgetItem * model_item){
 
 
 
 
QString model_name;
QString rootClassID;
QString rootClassInctance;
36,8 → 40,15
item_tmp = new QTreeWidgetItem(item); // â äåðåâå, îòîáðàæàþùåì îáúåêòû êëàññîâ, ñîçäàåì íîâûé óçåë
item_tmp->setText(0, model_item->child(0)->text(0)); // ñ íàçâàíèåì êëàññà
 
showClassObjects(item_tmp, model_item->child(0)); // è âûâîäèì âñå îáúåêòû äàííîãî êëàññà
//showClassObjects(item_tmp, model_item->child(0)); // è âûâîäèì âñå îáúåêòû äàííîãî êëàññà
 
showObjects(item_tmp, model_item->child(0), tr(""));
}
 
 
/*****************************************************/
 
 
}
 
 
164,7 → 175,123
}
 
 
void MainWindow::showObjects(QTreeWidgetItem * parent_object_item, QTreeWidgetItem * model_item){
void MainWindow::showObjects(QTreeWidgetItem * parent_object_item, QTreeWidgetItem * model_item, QString filtr){
QString classID; // èäåíòèôèêàòîð êëàññà
QString inctance; // èìÿ òàáëèöû, õðàíèëèùà
QString className; // èìÿ êëàññà
int field_ID;
bool filtr_empty;
bool ok;
QSqlQuery q;
QString sql_str;
QString str_tmp;
filtr_empty = filtr.isEmpty();
classID = model_item->text(1);
className = model_item->text(0);
inctance = getClassInctance(classID);
 
sql_str = tr("select * "
" from " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà
);
sql_str.append(inctance);
if (!filtr.isEmpty()) { // åñëè ôèëüòð íå ïóñòîé
sql_str.append(tr(" "));
sql_str.append(filtr); // äîáàâëÿåì â çàïðîñ ôèëüòð
}
 
q.prepare(sql_str);
 
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
return;
}
 
field_ID = q.record().indexOf(tr("ID"));
 
while(q.next()){
if (q.record().count() > 1)
{
QString value_tmp;
QString ID_tmp;
QTreeWidgetItem * itm;
ID_tmp = q.value(field_ID).toString(); // îïðåäåëÿåì èäåíòèôèêàòîð îáúåêòà
value_tmp = q.value(1).toString(); // îïðåäåëÿåì èìÿ îáúåêòà (äîëæíî õðàíèòüñÿ â ïåðâîì ïîëå)
itm = new QTreeWidgetItem(parent_object_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
itm->setText(0, value_tmp);
 
for (int i=0; i < model_item->childCount(); i++) // ïðîâåðÿåì, åñòü ëè ó êëàññà äî÷åðíèå êëàññû
{
QTreeWidgetItem * model_item_tmp; // åñëè åñòü
QString pointer_name;
QString filtr_tmp;
bool pointer_isEmpty;
model_item_tmp = model_item->child(i); // îòîáðàæàåì îáúåêòû äî÷åðíèõ êëàññîâ
pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1));
pointer_isEmpty = pointer_name.isEmpty();
filtr_tmp = tr("where ");
filtr_tmp.append(tr("`"));
filtr_tmp.append(pointer_name);
filtr_tmp.append(tr("` = '"));
filtr_tmp.append(ID_tmp);
filtr_tmp.append(tr("'"));
showObjects(itm, model_item_tmp, filtr_tmp);
//MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp);
 
}
 
 
}
 
}
 
 
 
 
for (int i; i < model_item->childCount(); i++) // ïðîâåðÿåì, åñòü ëè ó êëàññà äî÷åðíèå êëàññû
{
 
 
}
 
}
 
QString MainWindow::getPointerFieldName(QString parent_class_id, QString chield_class_id){
 
QSqlQuery q;
QString sql_str;
QString str_tmp;
QString field;
QString result;
int field_name;
bool ok;
sql_str = tr("select * "
" from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`DefaultValue` = " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà
);
 
sql_str.append(tr("'"));
sql_str.append(parent_class_id);
sql_str.append(tr("' "));
sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '"));
sql_str.append(chield_class_id);
sql_str.append(tr("'"));
q.prepare(sql_str);
 
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
return result;
}
field_name = q.record().indexOf(tr("FieldName"));
while(q.next()){
result = q.value(field_name).toString();
}
return result;
}