Subversion Repositories public

Rev

Rev 52 | 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
long datum;
90
int day, mon, year;
91
QString str;
92
QDate dt;
43 root 93
 
64 andreas 94
	if (!item)
95
	   return;
96
 
50 andreas 97
	datum = get_date((char *)item->text(0).ascii());
98
	date_int (&day, &mon, &year, datum);
99
	dt.setYMD(year, mon, day);
100
	kDateWidget_Datum->setDate(dt);
101
	kDoubleNumInput_Zinssatz->setValue(item->text(1).toDouble());
102
	kDoubleNumInput_Rate->setValue(item->text(2).toDouble());
103
	str = item->text(3);
104
 
105
	if (!str.compare(i18n("N")))
106
	   checkBox_Rate->setChecked(FALSE);
107
	else
108
	   checkBox_Rate->setChecked(TRUE);
109
 
110
	str = item->text(4);
111
 
112
	if (!str.compare(i18n("N")))
113
	   checkBox_KalkRate->setChecked(FALSE);
114
	else
115
	   checkBox_KalkRate->setChecked(TRUE);
116
}
117
 
43 root 118
void ziaendWidget::pbSaveSlot()
44 andreas 119
{
50 andreas 120
QString hdir = QDir::homeDirPath ();
121
QString str;
122
QFile zaf;
123
QListViewItem *item;
124
int fd, men, i;
125
ZIAEND Zi;
126
 
127
	hdir.append("/.zinsaend.dat");
128
	zaf.setName(hdir);
129
 
130
	if (zaf.open(IO_ReadWrite | IO_Truncate) == FALSE)
131
	{
132
	   KMessageBox::error(0, QString("Could not open file for reading: %1").arg(zaf.errorString()));
133
	   done(QDialog::Rejected);
134
	}
135
 
136
	fd = zaf.handle();
137
	// wegschreiben der Daten in der ListBox
138
	men = kListView_Table->childCount();
139
	item->firstChild();
140
 
141
	for (i = 0; i < men; i++)
142
	{
143
	   item = kListView_Table->itemAtIndex(i);
144
	   Zi.Datum = get_date ((char *)item->text(0).ascii());
145
	   Zi.Zins = item->text(1).toDouble();
146
	   Zi.NewRate = item->text(2).toDouble();
52 andreas 147
	   Zi.FixRate = (!strcmp(item->text(3).ascii(), "N")) ? 0 : 1;
148
	   Zi.Rate = (!strcmp(item->text(4).ascii(), "N")) ? 0 : 1;
50 andreas 149
 
150
	   write (fd, &Zi, sizeof(ZIAEND));
151
	}
152
 
153
	zaf.close ();
44 andreas 154
	done(QDialog::Accepted);
155
}
43 root 156
 
157
void ziaendWidget::pbRemoveSlot()
50 andreas 158
{
159
QListViewItem *item = kListView_Table->selectedItem();
160
long datum;
161
int day, mon, year;
162
QString str;
163
QDate dt;
43 root 164
 
50 andreas 165
	datum = get_date((char *)item->text(0).ascii());
166
	date_int (&day, &mon, &year, datum);
167
	dt.setYMD(year, mon, day);
168
	kDateWidget_Datum->setDate(dt);
169
	kDoubleNumInput_Zinssatz->setValue(item->text(1).toDouble());
170
	kDoubleNumInput_Rate->setValue(item->text(2).toDouble());
171
	str = item->text(3);
172
 
173
	if (!str.compare(i18n("N")))
174
	   checkBox_Rate->setChecked(FALSE);
175
	else
176
	   checkBox_Rate->setChecked(TRUE);
177
 
178
	str = item->text(4);
179
 
180
	if (!str.compare(i18n("N")))
181
	   checkBox_KalkRate->setChecked(FALSE);
182
	else
183
	   checkBox_KalkRate->setChecked(TRUE);
184
 
185
	kListView_Table->takeItem(kListView_Table->currentItem());
186
}
187
 
43 root 188
void ziaendWidget::pbInsertSlot()
50 andreas 189
{
190
QString datum, prz, rate, rv, ber;
191
QDate dt;
192
double dr, dp;
193
char hv0[128];
43 root 194
 
50 andreas 195
	dt = kDateWidget_Datum->date();
196
 
197
	if (dt <= QDate::currentDate())
198
	{
199
	   KMessageBox::error(0, i18n("Das Datum muss größer als das aktuelle Datum sein!"));
200
	   return;
201
	}
202
 
203
	dp = kDoubleNumInput_Zinssatz->value();
204
	dr = kDoubleNumInput_Rate->value();
205
 
206
	if (dp <= 0.0 && !checkBox_Rate->isChecked())
207
	{
208
	   KMessageBox::error(0, i18n("Der Zinssatz darf nicht Null sein!"));
209
	   return;
210
	}
211
 
212
	if (dp < 0.0 || dp > 100.0)
213
	{
214
	   KMessageBox::error(0, i18n("Der Zinnsatz darf nicht kleiner als Null oder größer als 100 sein!"));
215
	   return;
216
	}
217
 
218
	if (checkBox_Rate->isChecked() && dr <= 0.0)
219
	{
220
	   KMessageBox::error(0, i18n("Die Rate muss größer als Null sein!"));
221
	   return;
222
	}
223
 
64 andreas 224
	datum.sprintf ("%02d.%02d.%d", dt.day(), dt.month(), dt.year());
225
//	datum = QString::fromUtf8(hv0);
50 andreas 226
	prz = prz.setNum (dp, 'f', 3);
227
	rate = rate.setNum (dr, 'f', 2);
228
	rv = QString::fromUtf8(checkBox_Rate->isChecked() ? "F" : "N");
229
	ber = QString::fromUtf8(checkBox_KalkRate->isChecked() ? "B" : "N");
230
	QListViewItem *element = new QListViewItem(kListView_Table, datum, prz, rate, rv, ber);
231
	kListView_Table->clearSelection();
64 andreas 232
	kListView_Table->setCurrentItem(kListView_Table->lastItem());
50 andreas 233
	kListView_Table->insertItem(element);
234
}
235
 
44 andreas 236
void ziaendWidget::pbCancelSlot()
237
{
238
	done(QDialog::Rejected);
239
}
43 root 240
 
241
void ziaendWidget::cbRateSlot()
242
{}
243
 
44 andreas 244
void ziaendWidget::cbKalkRateSlot()
245
{}
246
 
43 root 247
void ziaendWidget::numRateSlot()
248
{}
249
 
250
void ziaendWidget::numZinssatzSlot()
251
{}
252
 
253
void ziaendWidget::dtDatumSlot()
254
{}
255
 
256
 
257
 
258
#include "ziaendwidget.moc"
259