123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #include "%1.h"
- #include "MessageException.h"
- #include "%2.h"
- #include "Application.h"
- #include <QMessageBox>
- #if _MSC_VER >= 1600
- #pragma execution_character_set("utf-8")
- #endif
- %1::%1(QWidget *parent)
- : QWidget(parent)
- , m_PageIndex(0)
- {
- ui = new Ui::%1();
- ui->setupUi(this);
- init();
- doQuery();
- }
- %1::~%1()
- {
- delete ui;
- }
- void %1::init()
- {
- initTableView();
- initModel();
- initService();
- initPagination();
- initFormBuilder();
- }
- void %1::initTableView()
- {
- ui->tvData->setMultipleSelect(true);
- }
- void %1::initModel()
- {
- m_Model = new %3(this);
- m_Model->setMultiSelect(true);
- ui->tvData->setModel(m_Model);
- }
- void %1::initService()
- {
- m_Service = new %4(this);
- }
- void %1::initFormBuilder()
- {
- m_FormBuilder = new FormBuilder(this);
- }
- void %1::initPagination()
- {
- ui->pagination->setPageCount(0);
- ui->pagination->setRecordCount(0);
- connect(ui->pagination, &Pagination::selectPage, [=](int value) {
- doQuery(value);
- });
- }
- QList<%2_ptr> %1::convertToList(qx::IxCollection *collection)
- {
- QList<%2_ptr> objs;
- for (size_t i = 0; i < collection->_count(); i++)
- {
- objs << collection->_get<%2_ptr>(i);
- }
- return objs;
- }
- void %1::doQuery(int pageIndex /*= 0*/)
- {
- QString name = ui->leQName->text();
- try
- {
- m_Model->fetchByName(name, pageIndex);
- ui->pagination->setRecordCount(m_Model->getTotalCount());
- ui->pagination->setPageCount(m_Model->getPageCount());
- }
- catch (MessageException &e)
- {
- QMessageBox::critical(this, "错误", e.getMessage());
- }
- }
- void %1::onQuery()
- {
- doQuery();
- }
- void %1::onReset()
- {
- ui->leQName->clear();
- doQuery();
- }
- void %1::onAdd()
- {
- QWidget *widget = m_FormBuilder->build<%2>("添加%5");
- m_FormBuilder->clear();
- int result = Application::instance()->showModalDialog(widget, this);
- if (result == QDialog::Accepted)
- {
- %2_ptr obj = m_FormBuilder->getValue<%2>();
- try
- {
- m_Service->add(obj);
- }
- catch (MessageException &e)
- {
- QMessageBox::critical(this, "错误", e.getMessage());
- return;
- }
- doQuery();
- }
- }
- void %1::onEdit()
- {
- QModelIndex index = ui->tvData->currentIndex();
- if (!index.isValid())
- {
- QMessageBox::information(this, "提示", "请选中要修改的数据!");
- return;
- }
- %2_ptr oldObj = m_Model->getByRow(index.row());
-
- QWidget *widget = m_FormBuilder->build<%2>("修改%5");
- m_FormBuilder->clear();
- m_FormBuilder->fill(oldObj);
- int result = Application::instance()->showModalDialog(widget, this);
- if (result == QDialog::Accepted)
- {
- try{
- %2_ptr newObj = m_FormBuilder->getValue<%2>();
- newObj->setID(oldObj->getID());
- m_Service->updateById(newObj);
- }
- catch (MessageException &e){
- QMessageBox::critical(this, "错误", e.getMessage());
- return;
- }
- doQuery();
- }
- }
- void %1::onRemove()
- {
- qx::IxCollection * collection = ui->tvData->getSelectedRecord();
- if (collection->_count() <= 0)
- {
- QMessageBox::information(this, "提示", "请选中要删除的数据!");
- return;
- }
- QMessageBox::StandardButton msgBox;
- msgBox = QMessageBox::question(this, "提示", "确定删除选中的数据吗?", QMessageBox::Yes | QMessageBox::No);
- if (msgBox == QMessageBox::No)
- return;
- try
- {
- m_Service->deleteById(convertToList(collection));
- m_Model->clear();
- doQuery();
- }
- catch (MessageException &e)
- {
- QMessageBox::critical(this, "错误", e.getMessage());
- }
- }
|