groupmanager import 구현
git-svn-id: svn://192.168.0.12/source@75 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <QSqlRecord>
|
||||
#include <QFile>
|
||||
#include <QStack>
|
||||
#include <QFileDialog>
|
||||
Widget::Widget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
@@ -165,19 +166,22 @@ QGroupBox *Widget::setGroupWidgets()
|
||||
QPushButton *pInsert = new QPushButton("Insert");
|
||||
QPushButton *pDelete = new QPushButton("Delete");
|
||||
QPushButton *pClear = new QPushButton("Clear");
|
||||
QPushButton *pModify = new QPushButton("Modify");
|
||||
QPushButton *pModify = new QPushButton("Modify");
|
||||
QPushButton *pImport = new QPushButton("Import");
|
||||
QPushButton *pExport = new QPushButton("Export");
|
||||
QPushButton *pRefresh = new QPushButton("Refresh");
|
||||
hlayout->addWidget(pInsert);
|
||||
hlayout->addWidget(pDelete);
|
||||
hlayout->addWidget(pClear);
|
||||
hlayout->addWidget(pModify);
|
||||
hlayout->addWidget(pImport);
|
||||
hlayout->addWidget(pExport);
|
||||
hlayout->addWidget(pRefresh);
|
||||
connect(pInsert, SIGNAL(released()),this, SLOT(on_group_button_insert()));
|
||||
connect(pDelete, SIGNAL(released()),this, SLOT(on_group_button_delete()));
|
||||
connect(pClear, SIGNAL(released()),this, SLOT(on_group_button_clear()));
|
||||
connect(pModify, SIGNAL(released()),this, SLOT(on_group_button_modify()));
|
||||
connect(pImport, SIGNAL(released()),this, SLOT(on_group_button_import()));
|
||||
connect(pExport, SIGNAL(released()),this, SLOT(on_group_button_export()));
|
||||
connect(pRefresh, SIGNAL(released()),this, SLOT(on_group_button_refresh()));
|
||||
vlayout->addLayout(hlayout);
|
||||
@@ -491,6 +495,126 @@ void Widget::on_group_button_export()
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::on_group_button_import()
|
||||
{
|
||||
|
||||
QStringList strgroup;
|
||||
foreach (QModelIndex index,m_ptableGroup->selectionModel()->selectedRows(0))
|
||||
{
|
||||
QSqlRecord rec = m_pmodelGroup->record(index.row());
|
||||
strgroup.push_back(rec.value("id").toString());
|
||||
}
|
||||
|
||||
|
||||
QString strFilename = QFileDialog::getOpenFileName(0,"Import file",QDir::currentPath(),
|
||||
"csv files (*.csv);;All files (*.*)",new QString("Text files (*.csv)"));
|
||||
|
||||
QFile file(strFilename);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
|
||||
|
||||
|
||||
|
||||
//STable *pNew = new STable;
|
||||
QTextStream in(&file);
|
||||
int ncRow=0;
|
||||
int nCount=0;
|
||||
bool bQuit = true;
|
||||
int nRead = 0;
|
||||
QStringList attributes;
|
||||
QString strquery;
|
||||
while(!in.atEnd())
|
||||
{
|
||||
QString strLine;
|
||||
/*
|
||||
{
|
||||
QByteArray byte = file.readLine();
|
||||
if (byte.isEmpty()) { bQuit = false; continue; }
|
||||
strLine = codec->toUnicode(byte);
|
||||
nRead += byte.size();
|
||||
}*/
|
||||
|
||||
strLine = in.readLine();
|
||||
if (nCount == 0)
|
||||
{
|
||||
QStringList strings = strLine.split(",", QString::SkipEmptyParts);
|
||||
if (strings.at(0).trimmed() == QString("#Head#"))
|
||||
{
|
||||
for (int i = 1; i < strings.size();i++)
|
||||
attributes << strings.at(i);
|
||||
nCount++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < strings.size();i++)
|
||||
attributes << strings.at(i);
|
||||
nCount++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
strquery = "insert into data_" + strgroup.at(0) + " (";
|
||||
|
||||
foreach(QString str, attributes)
|
||||
{
|
||||
strquery += (str.trimmed() + ",");
|
||||
}
|
||||
|
||||
strquery = strquery.left(strquery.length() - 1);
|
||||
strquery += ") VALUES (";
|
||||
|
||||
foreach(QString str,attributes)
|
||||
{
|
||||
strquery += ":" + str.trimmed().toUpper() + ",";
|
||||
}
|
||||
strquery = strquery.left(strquery.length() - 1);
|
||||
strquery += ")";
|
||||
|
||||
|
||||
strLine = strLine.replace("\"","");
|
||||
QStringList strings = strLine.split(",");
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare(strquery.toUtf8());
|
||||
// qDebug() << strquery;
|
||||
for(int i=0; i<attributes.size();i++)
|
||||
{
|
||||
if(attributes.at(i).trimmed() == "article_order")
|
||||
{
|
||||
if(strings.at(i).trimmed().length() == 0)
|
||||
{
|
||||
QString strEmpty;
|
||||
query.bindValue(":"+attributes.at(i).toUpper(), strEmpty.toInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
query.bindValue(":"+attributes.at(i).toUpper(), strings.at(i).trimmed().toInt());
|
||||
}
|
||||
// qDebug() << " articleorder is executed";
|
||||
}
|
||||
|
||||
if(strings.at(i).trimmed().length() == 0)
|
||||
{
|
||||
QString strEmpty;
|
||||
query.bindValue(":"+attributes.at(i).trimmed().toUpper(), strEmpty.toUtf8());
|
||||
}
|
||||
else
|
||||
{
|
||||
query.bindValue(":"+attributes.at(i).trimmed().toUpper(), strings.at(i).trimmed().toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
if(query.exec() == false)
|
||||
{
|
||||
qDebug() << "error : " << query.lastError().text();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_group_button_refresh()
|
||||
{
|
||||
QString strQuery;
|
||||
|
||||
@@ -41,13 +41,13 @@ private slots:
|
||||
void on_group_button_delete();
|
||||
void on_group_button_clear();
|
||||
void on_group_button_modify();
|
||||
void on_group_button_import();
|
||||
void on_group_button_export();
|
||||
void on_group_button_copy_start();
|
||||
void on_group_button_copy_clear();
|
||||
void on_group_button_copy_from();
|
||||
void on_group_button_copy_to();
|
||||
void on_group_button_refresh();
|
||||
|
||||
void on_crawling_button_insert();
|
||||
void on_crawling_button_delete();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user