Subversion Repositories public

Rev

Rev 50 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
43 root 1
/***************************************************************************
52 andreas 2
 *   Copyright (C) 2007 by Andreas Theofilu                                *
3
 *   andreas@TheoSys.at                                                    *
43 root 4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
52 andreas 7
 *   the Free Software Foundation version 3 of the License.                *
43 root 8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
44 andreas 20
#include <kmessagebox.h>
21
#include <klocale.h>
50 andreas 22
#include <klistview.h>
23
#include <kdatewidget.h>
24
#include <knuminput.h>
25
#include <qcheckbox.h>
26
#include <qstring.h>
27
#include <qfile.h>
28
#include <qdir.h>
29
#include <qlistview.h>
30
 
52 andreas 31
//#include <iostream.h>
50 andreas 32
 
43 root 33
#include "ziaendwidget.h"
50 andreas 34
#include "tilgplan.h"
35
#include "helper.h"
43 root 36
 
37
ziaendWidget::ziaendWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
38
		: ziaendWidgetBase ( parent,name, modal,fl )
50 andreas 39
{
40
QString hdir = QDir::homeDirPath ();
41
QFile zaf;
42
ZIAEND Zi;
43
char datum[16], prz[24], rate[24], rv[2], ber[2];
44
int day, mon, year, fd;
43 root 45
 
50 andreas 46
	kDateWidget_Datum->setDate(QDate::currentDate());
47
	kListView_Table->setColumnWidth(0, 80);
48
	kListView_Table->setColumnWidth(1, 90);
49
	kListView_Table->setColumnAlignment(1, Qt::AlignRight);
50
	kListView_Table->setColumnWidth(2, 100);
51
	kListView_Table->setColumnAlignment(2, Qt::AlignRight);
52
	kListView_Table->setColumnWidth(3, 60);
53
	kListView_Table->setColumnAlignment(3, Qt::AlignCenter);
54
	kListView_Table->setColumnWidth(4, 60);
55
	kListView_Table->setColumnAlignment(4, Qt::AlignCenter);
52 andreas 56
	kListView_Table->setSortColumn(0);
50 andreas 57
 
58
	hdir.append("/.zinsaend.dat");
59
	zaf.setName(hdir);
60
 
61
	if (zaf.open(IO_ReadOnly) != FALSE)
62
	{
63
	   fd = zaf.handle();
64
 
65
	   while (read(fd, &Zi, sizeof(ZIAEND)) >= sizeof(ZIAEND))
66
	   {
67
	      date_int(&day, &mon, &year, Zi.Datum);
68
	      sprintf (datum, "%02d.%02d.%d", day, mon, year);
69
	      sprintf (prz, "%.3f", Zi.Zins);
70
	      sprintf (rate, "%.2f", Zi.NewRate);
71
	      rv[0] = (Zi.FixRate) ? 'F' : 'N';
72
	      ber[0] = (Zi.Rate) ? 'B' : 'N';
73
	      rv[1] = ber[1] = 0;
52 andreas 74
 
75
	      QListViewItem *element = new QListViewItem(kListView_Table, QString(datum), QString(prz), QString(rate), QString(rv), QString(ber));
50 andreas 76
	      kListView_Table->insertItem(element);
77
 	   }
78
 
79
	   zaf.close();
80
	}
81
}
82
 
43 root 83
ziaendWidget::~ziaendWidget()
84
{}
85
 
86
/*$SPECIALIZATION$*/
50 andreas 87
void ziaendWidget::tbSelectSlot(QListViewItem *item)
88
{
89
//QListViewItem *item = kListView_Table->selectedItem();
90
long datum;
91
int day, mon, year;
92
QString str;
93
QDate dt;
43 root 94
 
50 andreas 95
	datum = get_date((char *)item->text(0).ascii());
96
	date_int (&day, &mon, &year, datum);
97
	dt.setYMD(year, mon, day);
98
	kDateWidget_Datum->setDate(dt);
99
	kDoubleNumInput_Zinssatz->setValue(item->text(1).toDouble());
100
	kDoubleNumInput_Rate->setValue(item->text(2).toDouble());
101
	str = item->text(3);
102
 
103
	if (!str.compare(i18n("N")))
104
	   checkBox_Rate->setChecked(FALSE);
105
	else
106
	   checkBox_Rate->setChecked(TRUE);
107
 
108
	str = item->text(4);
109
 
110
	if (!str.compare(i18n("N")))
111
	   checkBox_KalkRate->setChecked(FALSE);
112
	else
113
	   checkBox_KalkRate->setChecked(TRUE);
114
}
115
 
43 root 116
void ziaendWidget::pbSaveSlot()
44 andreas 117
{
50 andreas 118
QString hdir = QDir::homeDirPath ();
119
QString str;
120
QFile zaf;
121
QListViewItem *item;
122
int fd, men, i;
123
ZIAEND Zi;
124
 
125
	hdir.append("/.zinsaend.dat");
126
	zaf.setName(hdir);
127
 
128
	if (zaf.open(IO_ReadWrite | IO_Truncate) == FALSE)
129
	{
130
	   KMessageBox::error(0, QString("Could not open file for reading: %1").arg(zaf.errorString()));
131
	   done(QDialog::Rejected);
132
	}
133
 
134
	fd = zaf.handle();
135
	// wegschreiben der Daten in der ListBox
136
	men = kListView_Table->childCount();
137
	item->firstChild();
138
 
139
	for (i = 0; i < men; i++)
140
	{
141
	   item = kListView_Table->itemAtIndex(i);
142
	   Zi.Datum = get_date ((char *)item->text(0).ascii());
143
	   Zi.Zins = item->text(1).toDouble();
144
	   Zi.NewRate = item->text(2).toDouble();
52 andreas 145
	   Zi.FixRate = (!strcmp(item->text(3).ascii(), "N")) ? 0 : 1;
146
	   Zi.Rate = (!strcmp(item->text(4).ascii(), "N")) ? 0 : 1;
50 andreas 147
 
148
	   write (fd, &Zi, sizeof(ZIAEND));
149
	}
150
 
151
	zaf.close ();
44 andreas 152
	done(QDialog::Accepted);
153
}
43 root 154
 
155
void ziaendWidget::pbRemoveSlot()
50 andreas 156
{
157
QListViewItem *item = kListView_Table->selectedItem();
158
long datum;
159
int day, mon, year;
160
QString str;
161
QDate dt;
43 root 162
 
50 andreas 163
	datum = get_date((char *)item->text(0).ascii());
164
	date_int (&day, &mon, &year, datum);
165
	dt.setYMD(year, mon, day);
166
	kDateWidget_Datum->setDate(dt);
167
	kDoubleNumInput_Zinssatz->setValue(item->text(1).toDouble());
168
	kDoubleNumInput_Rate->setValue(item->text(2).toDouble());
169
	str = item->text(3);
170
 
171
	if (!str.compare(i18n("N")))
172
	   checkBox_Rate->setChecked(FALSE);
173
	else
174
	   checkBox_Rate->setChecked(TRUE);
175
 
176
	str = item->text(4);
177
 
178
	if (!str.compare(i18n("N")))
179
	   checkBox_KalkRate->setChecked(FALSE);
180
	else
181
	   checkBox_KalkRate->setChecked(TRUE);
182
 
183
	kListView_Table->takeItem(kListView_Table->currentItem());
184
}
185
 
43 root 186
void ziaendWidget::pbInsertSlot()
50 andreas 187
{
188
QString datum, prz, rate, rv, ber;
189
QDate dt;
190
double dr, dp;
191
char hv0[128];
43 root 192
 
50 andreas 193
	dt = kDateWidget_Datum->date();
194
 
195
	if (dt <= QDate::currentDate())
196
	{
197
	   KMessageBox::error(0, i18n("Das Datum muss größer als das aktuelle Datum sein!"));
198
	   return;
199
	}
200
 
201
	dp = kDoubleNumInput_Zinssatz->value();
202
	dr = kDoubleNumInput_Rate->value();
203
 
204
	if (dp <= 0.0 && !checkBox_Rate->isChecked())
205
	{
206
	   KMessageBox::error(0, i18n("Der Zinssatz darf nicht Null sein!"));
207
	   return;
208
	}
209
 
210
	if (dp < 0.0 || dp > 100.0)
211
	{
212
	   KMessageBox::error(0, i18n("Der Zinnsatz darf nicht kleiner als Null oder größer als 100 sein!"));
213
	   return;
214
	}
215
 
216
	if (checkBox_Rate->isChecked() && dr <= 0.0)
217
	{
218
	   KMessageBox::error(0, i18n("Die Rate muss größer als Null sein!"));
219
	   return;
220
	}
221
 
222
	sprintf (hv0, "%02d.%02d.%d", dt.day(), dt.month(), dt.year());
223
	datum = QString::fromUtf8(hv0);
224
	prz = prz.setNum (dp, 'f', 3);
225
	rate = rate.setNum (dr, 'f', 2);
226
	rv = QString::fromUtf8(checkBox_Rate->isChecked() ? "F" : "N");
227
	ber = QString::fromUtf8(checkBox_KalkRate->isChecked() ? "B" : "N");
228
	QListViewItem *element = new QListViewItem(kListView_Table, datum, prz, rate, rv, ber);
229
	kListView_Table->clearSelection();
230
	kListView_Table->insertItem(element);
231
}
232
 
44 andreas 233
void ziaendWidget::pbCancelSlot()
234
{
235
	done(QDialog::Rejected);
236
}
43 root 237
 
238
void ziaendWidget::cbRateSlot()
239
{}
240
 
44 andreas 241
void ziaendWidget::cbKalkRateSlot()
242
{}
243
 
43 root 244
void ziaendWidget::numRateSlot()
245
{}
246
 
247
void ziaendWidget::numZinssatzSlot()
248
{}
249
 
250
void ziaendWidget::dtDatumSlot()
251
{}
252
 
253
 
254
 
255
#include "ziaendwidget.moc"
256