Модуль «kursach1.pro»

#-------------------------------------------------

#

# Project created by QtCreator 2017-10-31T22:47:55

#

#-------------------------------------------------

 

QT  += core gui

QT += xml

QT += axcontainer

 

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

 

TARGET = kursach1

TEMPLATE = app

 

SOURCES += main.cpp\

kurs1.cpp

HEADERS += kurs1.h

 

FORMS += kurs1.ui


 

Модуль «kurs1.h»

#ifndef KURS1_H#define KURS1_H #include <QMainWindow>#include <QDialog>#include <QString>#include <QDateTime>#include <QTime>#include <QDomDocument> namespaceUi {class kurs1;} class kurs1: public QMainWindow{ Q_OBJECT public:explicit kurs1(QWidget *parent = 0); ~ kurs1 ();QStringListElements(QDomElement root, QStringtagname, QString attribute); private slots:voidon_pushButton_clicked(); void on_pushButton_2_clicked(); void on_pushButton_9_clicked(); voidon_tabWidget_tabBarClicked(int index, intIndexPatient); void on_pushButton_10_clicked(); void on_pushButton_13_clicked(); void on_pushButton_3_clicked(); void on_pushButton_6_clicked(); void on_pushButton_12_clicked(); void on_pushButton_14_clicked(); void on_comboBox_4_activated(int index); void on_comboBox_5_activated(int index); void on_comboBox_7_activated(int index); void on_comboBox_9_activated(int index); void on_pushButton_11_clicked(); void on_pushButton_16_clicked(); voidon_checkBox_clicked(bool checked); void on_checkBox_4_clicked(bool checked); void on_checkBox_2_clicked(bool checked); void on_checkBox_3_clicked(bool checked); void on_pushButton_15_clicked(); void on_pushButton_4_clicked(); void on_pushButton_17_clicked(); void on_pushButton_7_clicked(); private:Ui::kurs1 *ui;QString Filename, filedoctors;voidWriteFile();voidAppFile();voidSearchValue();voidDeleteEnd();voidActived();void Print(); }; #endif // KURS1_H

 

Модуль «kurs1.cpp»

#include "kurs1.h"

#include "ui_kurs1.h"

#include <QMessageBox>

#include <QDebug>

#include <QFile>

#include <QTextStream>

#include <QtCore>

#include <QtXml>

#include <QString>

#include <QDate>

#include <QAxObject>

kurs1::kurs1(QWidget *parent):

QMainWindow(parent),

ui(new Ui::kurs1)

{

ui->setupUi(this);

Filename="C:\\Qt\\proekty\\7outt-work\\patients.xml";

filedoctors="C:\\Qt\\proekty\\7outt-work\\doctors.xml";

Actived();

on_tabWidget_tabBarClicked(1,0);

}

kurs1::~ kurs1 ()

{

deleteui;

}

// индекспациента

QVariantindexpat;

intnumberPatient=0,searchindex;

intnumm,chekchek=0, max;

QStringkabinet,Pname,Psurname,Dname,Ppolis,Dday,Dtime;//глобальныепеременныедляпечати

 

void kurs1::on_pushButton_clicked()

{

ui->tabWidget->setCurrentIndex(1);// переходнадругуювкладку

on_tabWidget_tabBarClicked(1,numberPatient);

}

void kurs1::on_pushButton_2_clicked()

{

ui->tabWidget->setCurrentIndex(3);

}

void kurs1::on_tabWidget_tabBarClicked(intindex,intindexPatient)

{

QStringfio, name, address,polis,bornStr;

QDateborn;

 

 

if(index==1) {// если открыта вторая вкладка

QDomDocument document;

QFilefile(Filename);

if(!file. open (QIODevice::ReadOnly|QIODevice::Text))

{

qDebug()<<"failed";

}

else

{

if(!document.setContent(&file))

  {

qDebug()<<"failed to load";

  }

file. close ();

}

QDomElement root=document.firstChildElement();

QDomNodeList books=root.elementsByTagName("Patient");

max=books.count();

//ищем по тегу и получаем его значение

QDomNodebooknode=books.at(numberPatient);// индекспацинта

if(booknode.isElement())

   {

QDomElement book=booknode.toElement();

fio=ListElements(book,"fio","name");// забираемфио

name=ListElements(book,"name","name");

address=ListElements(book,"address","value");

polis=ListElements(book,"polis","value");

bornStr=ListElements(book,"born","value");

   }

QDate born=QDate::fromString(bornStr,"yyyy.MM.dd");//переобразование

indexpat=numberPatient;//переобразуем индекс в вариант

ui->dateEdit->setDate(born);

ui->lineEdit_2->setText(indexpat.toString()); // index

ui->lineEdit_3->setText(fio); // выводфио

ui->lineEdit_4->setText(name); // выводимя

ui->lineEdit_5->setText(address); // выводадреса

ui->lineEdit_6->setText(polis); // вывод polis

}

ui->lineEdit->setText(indexpat.toString()); //выбранныйпациенткод

ui->lineEdit_7->setText(indexpat.toString());

Pname=ui->lineEdit_4->text();

Psurname=ui->lineEdit_3->text();

Ppolis=ui->lineEdit_6->text();

}

// находимзначениятега

QString kurs1::ListElements(QDomElement root, QStringtagname, QString attribute)

{

QDomNodeList items=root.elementsByTagName(tagname);

for (inti=0; i<items.count();i++)

{

QDomNodeitemnode= items.at(i);

if(itemnode.isElement())

     {

QDomElementitemele=itemnode.toElement();

return itemele.attribute(attribute); //возрващаетатрибуттега

     }

}

}

void kurs1::on_pushButton_10_clicked()//следующаязапись

{ if(indexpat<(max-1)){

numberPatient++;

on_tabWidget_tabBarClicked(1, numberPatient);

}

}

void kurs1::on_pushButton_9_clicked()//предудующаязапись

{  if(indexpat>0){

numberPatient--;

on_tabWidget_tabBarClicked(1, numberPatient);

}

}

//добавлеиеновойзаписи

void kurs1::WriteFile()

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

 

 

numm++;// следующий код пациента

QDomDocumentxml;

QDomElement root1=xml.createElement("Patient");

root1.setAttribute("id",QString::number(numm));

xml.appendChild(root1);

QDomElement node=xml.createElement("name");

node.setAttribute("name",ui->lineEdit_12->text());

root1.appendChild(node);

 

QDomElement node1=xml.createElement("fio");

node1.setAttribute("name",ui->lineEdit_13->text());

root1.appendChild(node1);

 

QDomElement node12=xml.createElement("address");

node12.setAttribute("value",ui->lineEdit_14->text());

root1.appendChild(node12);

 

QDomElement node13=xml.createElement("born");

node13.setAttribute("value",ui->dateEdit_2->date().toString("yyyy.MM.dd"));

root1.appendChild(node13);

 

QDomElement node14=xml.createElement("polis");

node14.setAttribute("value",ui->lineEdit_15->text());

root1.appendChild(node14);

 

QFilefile1(Filename);

if(!file1. open (QIODevice::Append|QIODevice::Text))

{

qDebug()<<"failed";

 

}

else

{

QTextStreamstream(&file1);

stream<<xml.toString();

stream<<"</Patients>";

file1. close ();

}

 

msgBox.setText("Пациентуспешнодобавлен!    ");

msgBox. exec ();

 

}

//поискпациента

void kurs1::SearchValue()

{

QString polis, fio,name;

intchek=0;

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

QDomDocument document;

QFilefile(Filename);

if(!file. open (QIODevice::ReadOnly|QIODevice::Text))

{

qDebug()<<"failed";

}

else

{

if(!document.setContent(&file))

  {

qDebug()<<"failed to load";

  }

file. close ();

}

QDomElement root=document.firstChildElement();

QDomNodeList patients=root.elementsByTagName("Patient");

if(ui->lineEdit_8->text().isEmpty()&&ui->lineEdit_9->text().isEmpty()&&ui->lineEdit_10->text().isEmpty())

{

msgBox.setText("Поляпусты!  ");

msgBox. exec ();

} else {

// Ищемпополису

if(!ui->lineEdit_10->text().isEmpty()){

 

for (inti=0; i<patients.count();i++){

QDomNodebooknode=patients.at(i);// индекспацинта

if(booknode.isElement())

  {

QDomElement book=booknode.toElement();

polis=ListElements(book,"polis","value");

if (polis==ui->lineEdit_10->text()){

chek=1;

searchindex=i;

break;}

  }

  } //ищемпоФИ

} if(!ui->lineEdit_8->text().isEmpty()&&!ui->lineEdit_9->text().isEmpty()){

for (inti=0; i<patients.count();i++){

QDomNodebooknode=patients.at(i);// индекспацинта

if(booknode.isElement())

   {

QDomElement book=booknode.toElement();

name=ListElements(book,"name","name");

fio=ListElements(book,"fio","name");

if (name==ui->lineEdit_8->text()&&fio==ui->lineEdit_9->text()){

chek=1;

searchindex=i;

break;}

   }

   }

}

if(chek==1){ // еслинайденпациент

numberPatient=searchindex;

msgBox.setWindowTitle("Картанайдена!");

msgBox.setInformativeText("Ок - Посмотретькарту\nCancel - остаться");

msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);

msgBox.setIcon(QMessageBox::Information);

msgBox.setDefaultButton(QMessageBox::Ok);

int res = msgBox. exec ();

if (res == QMessageBox::Ok) //нажатакнопка Ok

{

ui->tabWidget->setCurrentIndex(1);// переходнадругуювкладку

on_tabWidget_tabBarClicked(1,searchindex);

}

}

else{

msgBox.setText("Пациент не найден!  ");

msgBox. exec ();

}

}

}

//удаляем полседнюю строку

void kurs1::DeleteEnd()

{

intsizef;

QDomDocument document;

QFilefile(Filename);

QByteArraydata; // Создаем объект класса QByteArray, куда мы будем считывать данные

if (!file. open (QIODevice::ReadOnly)) // Проверяем, возможно ли открыть наш файл для чтения

qDebug()<<"ошибка чтения";

data = file.readAll(); //считываем все данные с файла в объект data

file. close ();

document.setContent(&file);

sizef=data.size();

data.replace(sizef-12,12,"");

   //получаюкол-вопациентов

QDomElement root=document.firstChildElement();

QDomNodeList patients=root.elementsByTagName("Patient");

numm= patients.count()-1;

file. close ();

if(!file. open (QIODevice::WriteOnly))

{

qDebug()<<"failed";

}

else

{

QTextStreamstream(&file);

stream<<QString(data);

file. close ();

}

}

void kurs1::Actived()

{

ui->comboBox_4->addItem("Понедельник");

ui->comboBox_4->addItem("Вторник");

ui->comboBox_4->addItem("Среда");

ui->comboBox_4->addItem("Четверг");

ui->comboBox_4->addItem("Пятница");

ui->comboBox_5->addItem("Понедельник");

ui->comboBox_5->addItem("Вторник");

ui->comboBox_5->addItem("Среда");

ui->comboBox_5->addItem("Четверг");

ui->comboBox_5->addItem("Пятница");

ui->comboBox_7->addItem("Понедельник");

ui->comboBox_7->addItem("Вторник");

ui->comboBox_7->addItem("Среда");

ui->comboBox_7->addItem("Четверг");

ui->comboBox_7->addItem("Пятница");

ui->comboBox_9->addItem("Понедельник");

ui->comboBox_9->addItem("Вторник");

ui->comboBox_9->addItem("Среда");

ui->comboBox_9->addItem("Четверг");

ui->comboBox_9->addItem("Пятница");

}

void kurs1::Print()

{

QAxObject* WordApplication=new QAxObject("Word.Application"); // Создаюинтерфейск MSWord

QAxObject* WordDocuments = WordApplication->querySubObject("Documents()");

WordDocuments = WordDocuments->querySubObject("Add()"); // Создаюновыйдокумент

 

QAxObject* Range = WordDocuments->querySubObject("Range()");

Range->dynamicCall("SetRange(int, int)",0,100);

Range->querySubObject("Text","Врач: "+Dname+" "+kabinet);

 

Range->dynamicCall("insertParagraphAfter()");// новыйабзац

 

QAxObject* Range1 = WordDocuments->querySubObject("Range()");

Range1->dynamicCall("SetRange(int, int)",101,200);

Range1->querySubObject("Text","ФИпациента: "+Pname+" "+Psurname+". Полиспациента:"+Ppolis);

 

Range->dynamicCall("insertParagraphAfter()");

QAxObject* Range2 = WordDocuments->querySubObject("Range()");

Range2->dynamicCall("SetRange(int, int)",201,300);

Range2->querySubObject("Text","Датаприема: "+Dday+" "+Dtime+":00");

 

WordApplication->setProperty("Visible", true); // Делаем Word видимым

}

int time[5];

voidpartime(QString times){ //раскладываемвремя

 

intbuf;

buf=times.toInt();

time[0]=buf/100000000;

time[1]=(buf%100000000)/1000000;

time[2]=(buf%1000000)/10000;

time[3]=(buf%10000)/100;

time[4]=(buf%100);

}

void kurs1::on_pushButton_13_clicked() //поиск

{

SearchValue();

}

//переход к вкладке создания карты

void kurs1::on_pushButton_3_clicked()

{

ui->tabWidget->setCurrentIndex(4);

}

void kurs1::on_pushButton_6_clicked()

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание!");

if(ui->lineEdit_12->text().isEmpty()||ui->lineEdit_13->text().isEmpty()||ui->lineEdit_14->text().isEmpty()||ui->lineEdit_15->text().isEmpty())

{

msgBox.setText("Заполните все поля!  ");

msgBox. exec ();

} else {

 

msgBox.setInformativeText("Ок - Добавнить новую карту\nCancel - отмена");

msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);

msgBox.setIcon(QMessageBox::Information);

msgBox.setDefaultButton(QMessageBox::Ok);

intres = msgBox. exec ();

if (res == QMessageBox::Ok) //нажатакнопкаOk

{

DeleteEnd();

WriteFile();

}

}

 

}

 

void kurs1::on_pushButton_12_clicked()

{

ui->lineEdit_12->setText("");

ui->lineEdit_13->setText("");

ui->lineEdit_14->setText("");

ui->lineEdit_15->setText("");

}

 

void kurs1::on_pushButton_14_clicked()

{

ui->lineEdit_8->setText("");

ui->lineEdit_9->setText("");

ui->lineEdit_10->setText("");

}

void kurs1::on_comboBox_4_activated(int index)// первыйдоктор

{

chekchek=0;

QDomDocument document;

QFilefile(filedoctors);

if(!file. open (QIODevice::ReadOnly|QIODevice::Text))

{

qDebug()<<"failed";

}

else

{

if(!document.setContent(&file))

  {

qDebug()<<"failed to load";

  }

file. close ();

}

QString day, name,surname;

QDomElement root=document.firstChildElement();

 

QDomNodeList books=root.elementsByTagName("Doctor");

QDomNodebooknode=books.at(0);// индексдоктора

if(booknode.isElement())

   {

QDomElement book=booknode.toElement();

day=ListElements(book,"week","day"+QString::number(index+1));

name=ListElements(book,"name","value");// забираемфио

surname=ListElements(book,"surname","value");// забираемфио

   }

 

ui->label_15->setText(name+" "+surname);

partime(day);

ui->comboBox_3->clear();

for(inti=0;i<5;i++)

{

if(time[i]!=0)

ui->comboBox_3->addItem(QString::number(time[i]));

time[i]=0;

}

 

}

 

void kurs1::on_comboBox_5_activated(int index) //второйдоктор

{

chekchek=0;

QDomDocument document;

QFilefile(filedoctors);

if(!file. open (QIODevice::ReadOnly|QIODevice::Text))

{

qDebug()<<"failed";

}

else

{

if(!document.setContent(&file))

  {

qDebug()<<"failed to load";

  }

file. close ();

}

QString day, name,surname;

QDomElement root=document.firstChildElement();

 

QDomNodeList books=root.elementsByTagName("Doctor");

QDomNodebooknode=books.at(1);// индексдоктора

if(booknode.isElement())

   {

QDomElement book=booknode.toElement();

day=ListElements(book,"week","day"+QString::number(index+1));

name=ListElements(book,"name","value");// забираемфио

surname=ListElements(book,"surname","value");// забираемфио

   }

 

ui->label_23->setText(name+" "+surname);

partime(day);

ui->comboBox_6->clear();

for(inti=0;i<5;i++)

{

if(time[i]!=0)

ui->comboBox_6->addItem(QString::number(time[i]));

time[i]=0;

}

 

}

 

void kurs1::on_comboBox_7_activated(int index)

{

chekchek=0;

QDomDocument document;

QFilefile(filedoctors);

if(!file. open (QIODevice::ReadOnly|QIODevice::Text))

{

qDebug()<<"failed";

  }

else

{

if(!document.setContent(&file))

  {

qDebug()<<"failed to load";

  }

file. close ();

}

QString day, name,surname;

QDomElement root=document.firstChildElement();

 

QDomNodeList books=root.elementsByTagName("Doctor");

QDomNodebooknode=books.at(2);// индексдоктора

if(booknode.isElement())

   {

QDomElement book=booknode.toElement();

day=ListElements(book,"week","day"+QString::number(index+1));

name=ListElements(book,"name","value");// забираемфио

surname=ListElements(book,"surname","value");// забираемфио

   }

 

ui->label_25->setText(name+" "+surname);

partime(day);

ui->comboBox_8->clear();

for(inti=0;i<5;i++)

{

if(time[i]!=0)

ui->comboBox_8->addItem(QString::number(time[i]));

time[i]=0;

}

 

}

 

void kurs1::on_comboBox_9_activated(int index)//4 ыйдоктор

{ chekchek=0;

QDomDocument document;

QFilefile(filedoctors);

if(!file. open (QIODevice::ReadOnly|QIODevice::Text))

{

qDebug()<<"failed";

}

else

{

if(!document.setContent(&file))

  {

qDebug()<<"failed to load";

  }

file. close ();

}

QString day, name,surname;

QDomElement root=document.firstChildElement();

QDomNodeList books=root.elementsByTagName("Doctor");

QDomNodebooknode=books.at(3);// индексдоктора

if(booknode.isElement())

   {

QDomElement book=booknode.toElement();

day=ListElements(book,"week","day"+QString::number(index+1));

name=ListElements(book,"name","value");// забираемфио

surname=ListElements(book,"surname","value");// забираемфио

   }

ui->label_27->setText(name+" "+surname);

partime(day);

ui->comboBox_10->clear();

for(inti=0;i<5;i++)

{

if(time[i]!=0)

ui->comboBox_10->addItem(QString::number(time[i]));

time[i]=0;

}

}

void kurs1::on_pushButton_11_clicked()// кнопказаписькврачу 1

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

if(chekchek==0){

msgBox.setText("Времяневыбрано!       ");

msgBox. exec ();

}

else{

msgBox.setText("Пациентуспешнозаписан. Держиталон!");

msgBox. exec ();

Print();

}

}

void kurs1::on_pushButton_16_clicked()

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

 

if(chekchek==0){

msgBox.setText("Времяневыбрано!       ");

msgBox. exec ();

}

else{

msgBox.setText("Пациентуспешнозаписан. Держиталон!");

msgBox. exec ();

Print();

}

}

void kurs1::on_checkBox_clicked(bool checked) // еслинажата. надособратьинфудляпечати

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

if(ui->comboBox_3->itemText(0)!="" && checked==true){

Dday=ui->comboBox_4->itemText(ui->comboBox_4->currentIndex());

Dtime=ui->comboBox_3->itemText(ui->comboBox_3->currentIndex());

kabinet=ui->toolBox_3->itemText(0);

Dname=ui->label_15->text();

chekchek=1;

} else if(checked==true) {

msgBox.setText("Выберите доступное время!  ");

msgBox. exec ();

}

}

void kurs1::on_checkBox_4_clicked(bool checked)

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

if(ui->comboBox_5->itemText(0)!="" && checked==true){

Dday=ui->comboBox_6->itemText(ui->comboBox_6->currentIndex());

Dtime=ui->comboBox_5->itemText(ui->comboBox_5->currentIndex());

kabinet=ui->toolBox_3->itemText(1);

Dname=ui->label_23->text();

chekchek=1;

} else if(checked==true) {

msgBox.setText("Выберите доступное время!  ");

msgBox. exec ();

}

}

void kurs1::on_checkBox_2_clicked(bool checked)

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

if(ui->comboBox_8->itemText(0)!="" && checked==true){

Dday=ui->comboBox_7->itemText(ui->comboBox_7->currentIndex());

Dtime=ui->comboBox_8->itemText(ui->comboBox_8->currentIndex());

kabinet=ui->toolBox_4->itemText(0);

Dname=ui->label_25->text();

chekchek=1;

} else if(checked==true) {

msgBox.setText("Выберите доступное время!  ");

msgBox. exec ();

}

}

void kurs1::on_checkBox_3_clicked(bool checked)

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

if(ui->comboBox_10->itemText(0)!="" && checked==true){

Dday=ui->comboBox_9->itemText(ui->comboBox_9->currentIndex());

   Dtime=ui->comboBox_10->itemText(ui->comboBox_10->currentIndex());

kabinet=ui->toolBox_5->itemText(0);

Dname=ui->label_27->text();

chekchek=1;

} else if(checked==true) {

msgBox.setText("Выберите доступное время!  ");

msgBox. exec ();

}

}

 

void kurs1::on_pushButton_15_clicked()

{

}

void kurs1::on_pushButton_4_clicked()

{

ui->tabWidget->setCurrentIndex(2);

}

void kurs1::on_pushButton_17_clicked()

{

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание");

 

if(chekchek==0){

msgBox.setText("Времяневыбрано!       ");

msgBox. exec ();

}

else{

msgBox.setText("Пациентуспешнозаписан. Держиталон!");

msgBox. exec ();

Print();

}

}

 

void kurs1::on_pushButton_7_clicked()

{

 

QMessageBoxmsgBox;

msgBox.setWindowTitle("Внимание!");

 

msgBox.setInformativeText("Ок - Выйтиизпрограммы\nCancel - отмена");

msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);

msgBox.setIcon(QMessageBox::Information);

msgBox.setDefaultButton(QMessageBox::Ok);

int res = msgBox. exec ();

if (res == QMessageBox::Ok) //нажатакнопка Ok

{

qApp->exit();

}

 

 

}

 


Модуль «main.cpp»

#include "kurs1.h"#include <QApplication> #include <QTextCodec> int main(intargc, char *argv[]){   QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); //руссикйязыкQApplicationa(argc, argv); kurs1 w;w.show(); returna.exec();}

 





ПРИЛОЖЕНИЕ Б

 

На рисунках Б.1-Б.9 показаны содержимое слайдов презентации к защите курсового проекта.

 

Рисунок Б.1

 

Рисунок Б.2

 

Рисунок Б.3

 

Рисунок Б.4

 

 

Рисунок Б.5

Рисунок Б.6

Рисунок Б.7

Рисунок Б.8

 

Рисунок Б.9

 


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: