-
Notifications
You must be signed in to change notification settings - Fork 11
/
confirm.cpp
156 lines (135 loc) · 3.77 KB
/
confirm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "confirm.h"
#include "ui_confirm.h"
#include<iostream>
#include<cstdio>
#include<cstring>
#include<fstream>
#include<QFile>
#include<QTextStream>
#include<QDebug>
#include<QDate>
#include<QDateTimeEdit>
#include<QMessageBox>
#include<QIODevice>
confirm::confirm(QWidget *parent) :
QDialog(parent),
ui(new Ui::confirm)
{
ui->setupUi(this);
this->setWindowTitle("CONFIRMATION");
//get the details of choosen src , dst, and date from file temp.txt
QString src,dst,date,arr_time,fare,avail,train_no,train_name,day;
QString filename1="D:\\qt\\irctc3\\temp.txt";
QFile file1(filename1);
if(!file1.exists()){
qDebug() << "NO exist "<<filename1;
}else{
qDebug() << filename1<<" exits...";
}
QString line1;
if (file1.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream stream1(&file1);
while (!stream1.atEnd()){
line1 = stream1.readLine();
day= line1.split(" ").at(0);
date= line1.split(" ").at(1);
src= line1.split(" ").at(2);
dst= line1.split(" ").at(3);
}
}
file1.close();
//get the details of selected train from file select.txt
QString filename="D:\\qt\\irctc3\\select.txt";
QFile file(filename);
if(!file.exists()){
qDebug() << "NO exist "<<filename;
}else{
qDebug() << filename<<" exits...";
}
QString line;
if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream stream(&file);
while (!stream.atEnd()){
line = stream.readLine();
train_no= line.split(" ").at(0);
train_name= line.split(" ").at(1);
arr_time= line.split(" ").at(2);
avail= line.split(" ").at(3);
fare= line.split(" ").at(4);
}
}
file.close();
//print the details on upper part of window
ui->label->setText("Day of Travelling:"+day+", "+date+"\nsource: "+src+"\ndestination:"+dst+"\nTrain no. and name :"+train_no+", "+train_name+"\nArrival time: "+arr_time);
}
confirm::~confirm()
{
delete ui;
}
void confirm :: payment_debit()
{
deb=new debit(this);
deb->show();
}
void confirm::on_pushButton_clicked()
{
exit(0);
}
void confirm::on_pushButton_2_clicked()
{
//write details from table to file
//ask user to enter details of passenger
QString name,age,adhar,gender;
int i=0;
QString filename="D:\\qt\\irctc3\\p-detail.txt";
QFile file(filename);
if(!file.exists()){
qDebug() << "NO exist "<<filename;
}else{
qDebug() << filename<<" exits...";
}
QTextStream out(&file);
file.open((QIODevice::WriteOnly | QIODevice::Text));
QTableWidgetItem* itm,*itm3,*itm4,*itm5;
itm = ui->tableWidget->item( 0, 0 );
itm3 = ui->tableWidget->item( 0, 1 );
itm4 = ui->tableWidget->item( 0, 2 );
qDebug()<<"items:: "<<itm->text()<<" "<<itm3->text()<<" "<<itm4->text();
while (itm && itm3 && itm4)
{
name=itm->text();
out<<name<<" ";
age=itm3->text();
out<<age<<" ";
gender=itm4->text();
out<<gender<<" ";
qDebug()<<"items:: "<<name<<" "<<age<<" "<<gender;
itm5 = ui->tableWidget->item( i, 3 );
if(itm5){
adhar=itm5->text();
out<<adhar<<"\n";
}
//hello
itm = ui->tableWidget->item( i+1, 0 );
itm3 = ui->tableWidget->item( i+1, 1 );
itm4 = ui->tableWidget->item( i+1, 2 );
i++;
}
file.close();
itm = ui->tableWidget->item( i-1, 0 );
itm3 = ui->tableWidget->item( i-1, 1 );
itm4 = ui->tableWidget->item( i-1, 2 );
/*
if(!itm || !itm3 || !itm4)
{
QMessageBox::critical(this,tr("error"),tr("fields are empty"));
}
else
{
this->hide();
payment_debit();
}
*/
this->hide();
payment_debit();
}