-
Notifications
You must be signed in to change notification settings - Fork 0
/
medicine.py
51 lines (44 loc) · 1.41 KB
/
medicine.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
import pymysql
import datetime
now = datetime.datetime.now()
con = pymysql.connect("localhost","root","root","pharmacy" )
curs=con.cursor()
class Medicine:
def __init__(self,mid):
med_id=mid
stmt="""Select qty from medicine where mid=:1"""
curs.execute(stmt,(med_id))
result=curs.fetchall()
for i in result:
for j in i:
qty_avail=j
stmt="""Select exp_date from medicine where mid=:1"""
curs.execute(stmt,(med_id))
result=curs.fetchall()
for i in result:
for j in i:
med_expdate=datetime.datetime.strftime(j,"%Y-%M-%D")
stmt="""Select price from medicine where mid=:1"""
curs.execute(stmt,(med_id))
result=curs.fetchall()
for i in result:
for j in i:
price=j
def checkExpiry(self):
if(self.med_expdate>now.strftime("%Y-%M-%D")):
return True
else:
return False
def checkAvail(self):
if(self.qty_avail>0):
return True
else:
False
def updateQty(self,qty):
stmt="""Update medicine set qty=:1 where mid=:2"""
curs.execute(stmt,(self.qty_avail+qty,self.med_id))
con.commit()
def updateExp(self,dt):
stmt="""Update medicine set exp_date=:1 where mid=:2"""
curs.execute(stmt,(dt,self.med_id))
con.commit()