#include "browser.h"
#include "login.h"
#include "addcreature.h"
#include <QtWidgets>
#include <QtSql>
#include <QDebug>
#include "adddistr.h"
#include "basicquery.h"
#include "basicchange.h"
#include <QSqlQuery>
#include "showbarchart.h"
#include "registerdialog.h"
Browser::Browser(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
table->addAction(insertRowAction);
table->addAction(deleteRowAction);
table->addAction(submitAction);
table->addAction(revertAction);
while(!openConnectWidget());
connectionWidget->refresh();
if(mydb.userName()!="biodbAdmin"&&mydb.userName()!="root"){
groupBox->setVisible(false);
connectionWidget->setVisible(false);
}else{
}
QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
if (tm)
tm->setEditStrategy(QSqlTableModel::OnManualSubmit);
emit statusMessage(tr("就绪"));
}
Browser::~Browser()
{
}
void Browser::exec()
{
QSqlQueryModel *model = new QSqlQueryModel(table);
model->setQuery(QSqlQuery(sqlEdit->toPlainText(), mydb));
table->setModel(model);
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
else if (model->query().isSelect())
emit statusMessage(tr("执行成功"));
else
emit statusMessage(tr("执行成功,受影响的行数: %1").arg(
model->query().numRowsAffected()));
updateActions();
}
void Browser::exec(QString sqlstr)
{
QSqlQueryModel *model = new QSqlQueryModel(table);
model->setQuery(QSqlQuery(sqlstr, mydb));
table->setModel(model);
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
else if (model->query().isSelect())
emit statusMessage(tr("执行成功"));
else
emit statusMessage(tr("执行成功,受影响的行数: %1").arg(
model->query().numRowsAffected()));
updateActions();
}
QSqlError Browser::addConnection(const QString &driver, const QString &dbName, const QString &host,
const QString &user, const QString &passwd, int port)
{
QSqlError err;
QSqlDatabase db = QSqlDatabase::addDatabase(driver, QString("db"));
db.setDatabaseName(dbName);
db.setHostName(host);
db.setPort(port);
if (!db.open(user, passwd)) {
err = db.lastError();
db = QSqlDatabase();
QSqlDatabase::removeDatabase(QString("db"));
}
return err;
}
bool Browser::openConnectWidget()
{
Login dialog(this);
if (dialog.exec() != QDialog::Accepted)
return 0;
if(dialog.userName()==""){
QMessageBox::warning(this, tr("错误"), tr("用户名不能为空"));
return 0;
}
if(dialog.password()==""){
QMessageBox::warning(this, tr("错误"), tr("密码不能为空"));
return 0;
}
QSqlError err = addConnection("QMYSQL", dialog.databaseName(), "localhost",
dialog.userName(), dialog.password());
if (err.type() != QSqlError::NoError){
QMessageBox::warning(this, tr("不能打开数据库"), tr("建立连接时发生错误") + err.text());
return 0;
}
QStringList connectionNames = QSqlDatabase::connectionNames();
mydb=QSqlDatabase::database(connectionNames.at(0));
return 1;
}
void Browser::showTable(const QString &t)
{
QSqlTableModel *model = new CustomModel(table, mydb);
model->setEditStrategy(QSqlTableModel::OnRowChange);
model->setTable(mydb.driver()->escapeIdentifier(t, QSqlDriver::TableName));
model->select();
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
table->setModel(model);
table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
connect(table->selectionModel(), &QItemSelectionModel::currentRowChanged,
this, &Browser::currentChanged);
updateActions();
}
void Browser::showMetaData(const QString &t)
{
QSqlRecord rec = mydb.record(t);
QStandardItemModel *model = new QStandardItemModel(table);
model->insertRows(0, rec.count());
model->insertColumns(0, 7);
model->setHeaderData(0, Qt::Horizontal, "属性名");
model->setHeaderData(1, Qt::Horizontal, "类型");
model->setHeaderData(2, Qt::Horizontal, "长度");
model->setHeaderData(3, Qt::Horizontal, "精度");
model->setHeaderData(4, Qt::Horizontal, "能否为空");
model->setHeaderData(5, Qt::Horizontal, "自动值");
model->setHeaderData(6, Qt::Horizontal, "默认值");
for (int i = 0; i < rec.count(); ++i) {
QSqlField fld = rec.field(i);
model->setData(model->index(i, 0), fld.name());
model->setData(model->index(i, 1), fld.typeID() == -1
? QString(QMetaType::typeName(fld.type()))
: QString("%1 (%2)").arg(QMetaType::typeName(fld.type())).arg(fld.typeID()));
model->setData(model->index(i, 2), fld.length());
model->setData(model->index(i, 3), fld.precision());
model->setData(model->index(i, 4), fld.requiredStatus() == -1 ? QVariant("?")
: QVariant(bool(fld.requiredStatus())));
model->setData(model->index(i, 5), fld.isAutoValue());
model->setData(model->index(i, 6), fld.defaultValue());
}
table->setModel(model);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
updateActions();
}
void Browser::insertRow()
{
QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
if (!model)
return;
QModelIndex insertIndex = table->currentIndex();
int row = insertIndex.row() == -1 ? 0 : insertIndex.row();
model->insertRow(row);
insertIndex = model->index(row, 0);
table->setCurrentIndex(insertIndex);
table->edit(insertIndex);
}
void Browser::deleteRow()
{
QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
if (!model)
return;
QModelIndexList currentSelection = table->selectionModel()->selectedIndexes();
for (int i = 0; i < currentSelection.count(); ++i) {
if (currentSelection.at(i).column() != 0)
continue;
model->removeRow(currentSelection.at(i).row());
}
updateActions();
}
void Browser::updateActions()
{
QSqlTableModel * tm = qobject_cast<QSqlTableModel *>(table->model());
bool enableIns = tm;
bool enableDel = enableIns && table->currentIndex().isValid();
insertRowAction->setEnabled(enableIns);
deleteRowAction->setEnabled(enableDel);
submitAction->setEnabled(tm);
revertAction->setEnabled(tm);
}
void Browser::about()
{
QMessageBox::about(this, tr("开源代码许可"), tr("demonstration applications of the Qt Toolkit "
"Copyright (C) 2016 The Qt Company Ltd.\n"
"Licensed under BSD\n"
"Redistribution and use in source and binary forms, with or without\n"
" modification, are permitted provided that the following conditions are\n"
" met:\n"
" * Redistributions of source code must retain the above copyright\n"
" notice, this list of conditions and the following disclaimer.\n"
" * Redistributions in binary form must reproduce the above copyright\n"
" notice, this list of conditions and the following disclaimer in\n"
"
没有合适的资源?快使用搜索试试~ 我知道了~
人工智能-项目实践-信息管理系统-基于林奈生物分类法的生物信息管理系统(数据库课程设计作业)
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共33个文件
cpp:10个
h:9个
ui:8个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 91 浏览量
2024-03-10
22:15:48
上传
评论
收藏 557KB ZIP 举报
温馨提示
基于林奈生物分类法的生物信息管理系统(数据库课程设计作业) 管理员登录时,提供了SQL的接口和基本表的展示,对于单表支持在图形化界面上删改。另外还分为研究者和管理者两个角色作为系统的使用者,此时隐藏管理员后台的内容,前者能进行查询插入删除和修改,而后者只支持查询。同时支持统计功能,对部分数据进行可视化展示。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 33 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d5b8e16cddf148da83293d5bb68d9224_admin_maxin.jpg!1)
博士僧小星
- 粉丝: 1947
- 资源: 5905
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)