#include "addprescription.h"
#include "ui_addprescription.h"
extern QString gd_pnum;
extern QString gs_dnum;
QString prnum;
QString AddPrescription::get_time(){
QString curTime=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
return curTime;
}
QString AddPrescription::getPrNum(){
int temp=1;
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1 ="select PRNUM from prescri order by cast(PRNUM as decimal )";
query.exec(str1);
if(query.numRowsAffected()){
query.last();
temp=query.value(0).toInt();
qDebug()<<temp;
temp++;
}
qDebug()<<temp;
return QString::number(temp);
}
QString AddPrescription::getPreNum(){
int temp=1;
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1 ="select * from presctiption";
query.exec(str1);
if(query.numRowsAffected()){
query.last();
temp=query.value(0).toInt();
qDebug()<<temp;
temp++;
}
qDebug()<<temp;
return QString::number(temp);
}
QString AddPrescription::getConNum(){
int temp=1;
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1 ="select * from consrecord";
query.exec(str1);
if(query.numRowsAffected()){
query.last();
temp=query.value(0).toInt();
qDebug()<<temp;
temp++;
}
qDebug()<<temp;
return QString::number(temp);
}
QString AddPrescription::getDrNum(QString str){
QString res;
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1 ="select DRNUM from DRUG where DENAME='"+str+"'";
qDebug()<<str1;
if(query.exec(str1)){
query.first();
res=query.value(0).toString();
}else{
QMessageBox::information(this,"提示","药品编号查找失败!");
}
return res;
}
void AddPrescription::ChangeStatus(QString str){
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1="update res_p_d set STAUS = '已开处方' where PNUM = '"+str+"'";
qDebug()<<str1;
if(!query.exec(str1)){
QMessageBox::information(this,"提示","状态更新失败!");
}
}
void AddPrescription::init_AddPR(){
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
prnum = getPrNum();
QString curtime=get_time();
QString str1="insert into prescri value ('"+prnum+"','"+gs_dnum+"','"+gd_pnum+"','"+curtime+"')";
qDebug()<<str1;
if(!query.exec(str1)){
QMessageBox::information(this,"提示","添加失败!");
}
}
void AddPrescription::init_APT(){
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1="select PRENUM,DENAME,WAY,COUNT,DEFEES from pres_drug where PNUM='"+gd_pnum+"' and PRNUM='"+prnum+"'";
if(query.exec(str1)){
int rows=query.numRowsAffected();
qDebug()<<rows;
QSqlRecord res = query.record();
int cols=res.count();
qDebug()<<cols;
QStandardItemModel *model=new QStandardItemModel();
model->setColumnCount(cols);
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->setRowCount(rows);
int i=0;
while (query.seek(i)) {
model->setItem(i,0,new QStandardItem(query.value(0).toString()));
model->setItem(i,1,new QStandardItem(query.value(1).toString()));
model->setItem(i,2,new QStandardItem(query.value(2).toString()));
model->setItem(i,3,new QStandardItem(query.value(3).toString()));
model->setItem(i,4,new QStandardItem(query.value(4).toString()));
i++;
}
ui->tableView->setModel(model);
}
}
void AddPrescription::init_APW(){
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1="select DENAME from DRUG";
if(query.exec(str1)){
while (query.next()) {
ui->comboBox->addItem(query.value(0).toString());
}
}else{
QMessageBox::information(this,"提示","初始化失败!");
}
QString str2="select PNAME,EMED from rec_m_r where PNUM ='"+gd_pnum+"'";
qDebug()<<str2;
if(query.exec(str2)){
query.first();
ui->label_3->setText(query.value(0).toString());
ui->textBrowser->setText(query.value(1).toString());
}
else{
QMessageBox::information(this,"提示","初始化失败!");
}
}
AddPrescription::AddPrescription(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::AddPrescription)
{
ui->setupUi(this);
init_APW();
init_AddPR();
}
AddPrescription::~AddPrescription()
{
delete ui;
}
void AddPrescription::on_pushButton_clicked()
{
bool flag1=false;
if(ui->lineEdit_2->text()=="") flag1=true;
if(ui->textEdit->toPlainText()=="") flag1=true;
if(flag1){
QMessageBox::information(this,"提示","请输入完整的信息!");
}else{
QString prenum=getPreNum();
QString drnum=getDrNum(ui->comboBox->currentText());
QString way=ui->textEdit->toPlainText();
QString count=ui->lineEdit_2->text();
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1="insert into presctiption value ('"+prenum+"','"+prnum+"','"+drnum+"','"+way+"',"+count+")";
qDebug()<<str1;
if(!query.exec(str1)){
QMessageBox::information(this,"提示","添加失败!");
}
}
init_APT();
}
void AddPrescription::on_pushButton_3_clicked()
{
init_APT();
}
void AddPrescription::on_pushButton_2_clicked()
{
bool flag1=false;
if(ui->lineEdit->text()=="") flag1=true;
if(flag1){
QMessageBox::information(this,"提示","请输入要删除的药品编号!");
}else{
QString del_num=ui->lineEdit->text();
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1="delete from presctiption where PRENUM='"+del_num+"'";
qDebug()<<str1;
if(!query.exec(str1)){
QMessageBox::information(this,"提示","删除失败!");
}
init_APT();
}
}
void AddPrescription::on_pushButton_4_clicked()
{
QSqlDatabase db=QSqlDatabase::database();
if(!db.open()){
QMessageBox::information(this,"错误","数据库连接失败!");
}
QSqlQuery query(db);
QString str1 ="select * from presctiption";
query.exec(str1
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
QT源码.zip (75个子文件)
doctorwindow.h 1KB
startwindow.ui 4KB
doctorwindow.cpp 8KB
showcasehistory.h 669B
patientmanager.ui 3KB
adddrugsum.ui 4KB
image.qrc 132B
startwindow.cpp 5KB
doctormanager.ui 4KB
bill.h 778B
image
pay.qrc 98B
pay.png 388KB
updatedrug.h 594B
adddrug.h 555B
demo01.pro.user 40KB
showdrug.h 637B
showcasehistory.ui 2KB
diagnose.ui 6KB
drugmanager.cpp 7KB
paywin.cpp 2KB
updatedoctor.cpp 9KB
diagnose.h 726B
updatedrug.ui 3KB
updatepatient.cpp 7KB
patientwindow.ui 5KB
paywin.ui 5KB
adddoctor.cpp 7KB
adddoctor.h 861B
doctorwindow.ui 3KB
roommanager.ui 3KB
adddrugsum.h 687B
addroom.ui 3KB
updatedrug.cpp 3KB
doctormanager.cpp 9KB
addroom.h 575B
updatedoctor.h 896B
adaminwindow.cpp 1KB
adddoctor.ui 9KB
addprescription.h 1KB
doctormanager.h 1KB
addpatient.h 703B
showcasehistory.cpp 2KB
updatepatient.ui 9KB
adddrugsum.cpp 1KB
addprescription.cpp 9KB
showdrug.cpp 2KB
showdrug.ui 2KB
patientwindow.cpp 8KB
adaminwindow.h 754B
patientmanager.cpp 4KB
diagnose.cpp 3KB
bill.cpp 8KB
main.cpp 331B
startwindow.h 1015B
reservation.h 800B
paywin.h 635B
reservation.ui 6KB
addpatient.ui 9KB
drugmanager.ui 5KB
bill.ui 5KB
adddrug.cpp 2KB
updatepatient.h 715B
addroom.cpp 2KB
updatedoctor.ui 8KB
patientmanager.h 918B
adaminwindow.ui 3KB
adddrug.ui 4KB
patientwindow.h 1KB
drugmanager.h 1010B
addpatient.cpp 5KB
roommanager.cpp 2KB
roommanager.h 812B
demo01.pro 2KB
reservation.cpp 3KB
addprescription.ui 6KB
共 75 条
- 1
Epsilon0
- 粉丝: 47
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5