-
Notifications
You must be signed in to change notification settings - Fork 0
/
brmtrans.py
executable file
·161 lines (136 loc) · 3.89 KB
/
brmtrans.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
161
#!/usr/bin/python
import sys
import sqlite3
from fce import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
DEBUG=0
scb="Scan barcode now"
app=QApplication(sys.argv)
mainWidget=QWidget()
mainWidget.resize(1280,1024)
mainWidget.setWindowTitle("BrmbarSAP - Transfer credit")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmTransfer(mw=None):
if DEBUG: print("brmTransfer")
lbls=mw.findChildren(QLabel)
fr=lbls[-5]
to=lbls[-2]
le=mw.findChildren(QLineEdit)
pswd=hashlib.sha512(brmSatanize(le[0].text())).hexdigest()
amount=str(le[1].text())
if amount=="0":
le[1].setStyleSheet(le[1].styleSheet()+STYLE_BADLE)
return
else:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_OKLE)
# users set?
if fr.text()==to.text() or fr.text()[0]=="<" or to.text()[0]=="<":
return
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT id,cash,pass FROM users WHERE"
" name='"+brmSatanize(fr.text())+"' LIMIT 1;")
frdb=dbc.fetchone()
if DEBUG: print(" "+str(frdb))
if frdb[1]<=BUY_LIMIT:
db.close()
sys.exit(EXIT_NOCREDIT)
if frdb[2]!=pswd:
db.close()
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
le[0].setText("")
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
dbc.execute("UPDATE users SET cash=cash-("+amount+") WHERE"
" name='"+brmSatanize(fr.text())+"' LIMIT 1;")
dbc.execute("UPDATE users SET cash=cash+("+amount+") WHERE"
" name='"+brmSatanize(to.text())+"' LIMIT 1;")
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"(SELECT id FROM users WHERE name='"+str(fr.text())+"' LIMIT 1),0,1,"
"-("+amount+"),0);")
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"(SELECT id FROM users WHERE name='"+str(to.text())+"' LIMIT 1),0,1,"
"+("+amount+"),0);")
db.commit()
db.close()
sys.exit(EXIT_TRANSFERRED)
def brmSetWho(val=""):
if DEBUG: print("brmSetWho: code='"+val+"'")
#le=mainWidget.findChildren(QLineEdit)[-1]
if val=="":
return
lbls=mainWidget.findChildren(QLabel)
fr=lbls[-5]
to=lbls[-2]
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
dbc.execute("SELECT name FROM users WHERE code='"+brmSatanize(val)+""
"' LIMIT 1;")
rec=dbc.fetchone()
if DEBUG: print(" "+str(rec))
if rec==None:
return
print(" "+fr.text())
if fr.text()==scb:
fr.setText(brmSatanize(rec[0]))
to.setText(scb)
else:
to.setText(brmSatanize(rec[0]))
db.close()
fbox=QHBoxLayout()
cf=QLabel("Credit from:")
cf.setStyleSheet(STYLE_TEXT)
fbox.addWidget(cf)
fbox.addStretch(1)
cf2=QLabel(scb)
cf2.setStyleSheet(STYLE_MSG+"margin-right:100px;")
fbox.addWidget(cf2)
pbox=QHBoxLayout()
pl=QLabel("Password (if set)")
pl.setStyleSheet(STYLE_TEXT)
pbox.addWidget(pl)
pbox.addStretch(1)
brmAddLine(pbox,"",'T',STYLE_LE,
lambda:QTimer.singleShot(0,mainWidget.findChildren(QLineEdit)[-1],
SLOT('setFocus()')),c=0)
tbox=QHBoxLayout()
ct=QLabel("Credit to:")
ct.setStyleSheet(STYLE_TEXT)
tbox.addWidget(ct)
tbox.addStretch(1)
ct2=QLabel("")
ct2.setStyleSheet(STYLE_MSG+"margin-right:100px;")
tbox.addWidget(ct2)
cbox=QHBoxLayout()
al=QLabel("Amount:")
al.setStyleSheet(STYLE_TEXT)
cbox.addWidget(al)
cbox.addStretch(1)
brmAddLine(cbox,"0","N1",STYLE_LE,
lambda:QTimer.singleShot(0,mainWidget.findChildren(QLineEdit)[-1],
SLOT('setFocus()')),c=0)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Transfer",lambda:brmTransfer(mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Transfer credit")
screenbox.addStretch(1)
screenbox.addLayout(fbox)
screenbox.addLayout(pbox)
screenbox.addStretch(1)
screenbox.addLayout(tbox)
screenbox.addStretch(1)
screenbox.addLayout(cbox)
screenbox.addStretch(5)
screenbox.addLayout(bbox)
brmAddLine(screenbox,"",'T',STYLE_HIDDEN,brmSetWho)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
mainWidget.findChildren(QLineEdit)[0].setEchoMode(2) # Password masking
app.exec_()
sys.exit(EXIT_CANCEL)