-
Notifications
You must be signed in to change notification settings - Fork 1
/
vettap.py
160 lines (125 loc) · 5.41 KB
/
vettap.py
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
157
158
159
160
#!/usr/bin/env python3
'''
This file is part of VetApp.
VetApp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VetApp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VetApp. If not, see <http://www.gnu.org/licenses/>.
'''
import sys
from PyQt4 import QtGui
import datetime
from models import SqlHandler
#from models.animal import Animal, Sex, Race, Color
#from models.specie import Specie
#from models.postoffice import PostOffice, PostNumber
#from models.owner import Owner
from mainwindowtabs import Tabmanager
from mainwindowtabs.mainmenutab import MainMenuTab
from mainwindowtabs.searchtab import SearchTab
from mainwindowtabs.visittab import VisitTab
from mainwindowtabs.animaltab import AnimalTab
from mainwindowtabs.ownertab import OwnerTab
from mainwindowtabs.vettab import VetTab
from mainwindowtabs.generictreewidget import GenericTreeWidget, ButtonType
from mainwindowtabs.addNewDialog import AddNewDialog, AddNewWeight
from mainwindowtabs.searchlineedit import SearchLineEdit
from mainwindowtabs.operationbasecreator import OperationBaseCreator
from mainwindowtabs.itemcreatordialog import ItemCreatorDialog
from mainWindow import MainWindow
from login_dialog import LoginDialog
from mainwindowtabs.printFileCreator import PrintFileCreator
from mainwindowtabs.operationSelectorDialog import OperationSelectorDialog
from PyQt4.QtGui import QProgressDialog, QMessageBox
from configfile import genDBString, getDBName
import os.path
def init(status):
if not status:
session = SqlHandler.newSession()
SqlHandler.addItems(session,[SqlHandler.ALV(alv=24,alv_class=1), #Normal items
SqlHandler.ALV(alv=10,alv_class=2), #Medicines
SqlHandler.ALV(alv=14,alv_class=3)]) #Feed
SqlHandler.addItems(session, [SqlHandler.GlobalVar(key="clinicpayment", value="20.00"),
SqlHandler.GlobalVar(key="km_price", value="0.48")])
#create species
koira = SqlHandler.Specie('Koira')
kissa = SqlHandler.Specie('Kissa')
hevonen = SqlHandler.Specie('Hevonen')
#add species
SqlHandler.addItems(session, [koira, kissa, hevonen])
item_list = []
dogs_file_name = "koirarodut.txt"
cats_file_name = "kissarodut.txt"
horse_file_name = "hevosrodut.txt"
try:
f = open(dogs_file_name, "r", encoding="utf-8")
for race_name in f.readlines():
item_list.append(SqlHandler.Race(race_name.strip(),koira.id))
f.close()
except IOError:
print("Can not find file named: " + dogs_file_name)
pass
try:
f = open(cats_file_name, "r", encoding="utf-8")
for race_name in f.readlines():
item_list.append(SqlHandler.Race(race_name.strip(),kissa.id))
f.close()
except IOError:
print("Can not find file named: "+ cats_file_name)
pass
try:
f = open(horse_file_name, "r", encoding="utf-8")
for race_name in f.readlines():
item_list.append(SqlHandler.Race(race_name.strip(),hevonen.id))
f.close()
except IOError:
print("Can not find file named: "+ cats_file_name)
pass
SqlHandler.addItems(session,item_list)
try:
f = open('postinumerot.txt', "r", encoding="utf-8")
raw_p_data = f.readlines()
offices = []
offices_dict = {}
for line in raw_p_data:
if len(line) > 1:
office = SqlHandler.PostOffice(line.split(' ')[0])
offices.append(office)
offices_dict[line.split(' ')[0]] = office;
SqlHandler.addItems(session,offices)
numbers = []
for line in raw_p_data:
if len(line) > 1:
for item in line.split(' ')[1].strip().split(','):
numbers.append(SqlHandler.PostNumber(offices_dict[line.split(' ')[0]].id, int(item)))
SqlHandler.addItems(session,numbers)
f.close()
except IOError:
print("Can not find file named: "+ cats_file_name)
pass
def main():
#you can change databasename at models.__init__
#status = False
#if SqlHandler.usesLite():
status = True #os.path.exists(getDBName())
app = QtGui.QApplication(sys.argv)
#try:
if not SqlHandler.initialize():
print(g_error_msg_dict['database_init'])
return
if LoginDialog().exec_() == QtGui.QDialog.Accepted:
vet_app = MainWindow()
Tabmanager.openTab(tabCreator=MainMenuTab)
vet_app.showMaximized()
sys.exit(app.exec_())
#except:
#box = QMessageBox()
#box.setText('Error: can not connect to server! ')
#box.exec_()
main()