-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.py
262 lines (235 loc) · 8.8 KB
/
queries.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.26
# in conjunction with Tcl version 8.6
# Oct 28, 2019 02:21:42 PM IST platform: Linux
import os
import sys
from subprocess import call
import MySQLdb
from fpdf import FPDF
string = ""
m = []
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
from tkinter import messagebox
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import queries_support
def click_home():
global root
root.destroy()
root = None
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
root.option_add('*Dialog.msg.font', 'Arial 12 bold')
queries_support.set_Tk_var()
top = query (root)
queries_support.init(root, top)
root.mainloop()
w = None
def create_query(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
queries_support.set_Tk_var()
top = query (w)
queries_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_query():
global w
w.destroy()
w = None
class query:
def click_search(self):
global string, m
aadhar = self.Entry1.get()
count = 0
if not len(aadhar) == 12:
messagebox.showerror("Search Error", "12 Digit Aadhaar Number is required")
return
self.cursor_que.execute("SELECT aid FROM farmer WHERE aid = {}".format(aadhar))
result = self.cursor_que.fetchone()
try:
if result is None:
messagebox.showerror("Search Error", "Farmer not registered")
return
except:
messagebox.showerror("Search Error", "Incorrect Aadhaar Number")
return
l = []
#self.cursor
try:
self.cursor_que.execute("SELECT * FROM scheme WHERE sid = ( SELECT sid FROM takes WHERE aid = {})".format(aadhar))
result = self.cursor_que.fetchone()
l.append(" ")
l.append("Loan Information of Farmer:-")
l.append(result[1] + " " +result[2])
l.append(" ")
except:
count += 1
try:
self.cursor_que.execute("SELECT * FROM service WHERE (service_mode, pincode) = any (SELECT service_mode, pincode FROM business WHERE aid = {})".format(aadhar))
result = self.cursor_que.fetchall()
length = len(result)
k = 0
l.append("Service information of Farmer:-")
l.append(" ")
while k < length:
l.append(result[k][0] + " " + result[k][1] + " " +result[k][2])
k += 1
l.append(" ")
except:
count += 1
try:
self.cursor_que.execute("SELECT SUM(income) FROM business GROUP BY (aid) having aid = {}".format(aadhar))
result = self.cursor_que.fetchone()
l.append("Income Information of Farmer:-")
l.append(" ")
l.append(result[0])
l.append(" ")
except:
count += 1
try:
self.cursor_que.execute("SELECT * FROM field WHERE fid = any(SELECT fid FROM sector WHERE aid = {})".format(aadhar))
result = self.cursor_que.fetchall()
length = len(result)
k = 0
l.append("Crops taken from farmer are :-")
l.append(" ")
while k < length:
l.append(result[k][1] + " " + result[k][2] + " " +result[k][3])
k += 1
l.append(" ")
except:
count += 1
try:
self.cursor_que.execute("SELECT sector_no FROM sector WHERE aid = {}".format(aadhar))
result = self.cursor_que.fetchall()
length = len(result)
k = 0
l.append("Farmer has farm at sectors:-")
l.append("")
s = ""
while k < length:
s += result[k][0] + ","
k += 1
s = s.rstrip(',')
l.append(s)
l.append("")
except:
count += 1
if count == 5:
messagebox.showwarning("Search Error", "Farmer has not registered for facilities")
length = len(l)
m = []
for i in l:
m.append(str(i))
string = '\n'.join(m)
k = 0
while k < length:
self.Listbox1.insert(k, l[k])
k += 1
def click_report(self):
global string, m
pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
i = 0
while i < len(m):
pdf.cell(200, 10, txt = m[i], ln = i + 1)
i += 1
pdf.output('Report.pdf', 'F')
def __init__(self, top=None):
try:
self.db_que = MySQLdb.connect("localhost","shivam","","FARMER")
self.cursor_que = self.db_que.cursor()
except:
print('hi')
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
font9 = "-family gothic -size 15 -weight normal -slant roman " \
"-underline 0 -overstrike 0"
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.configure('.',font="TkDefaultFont")
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("725x573+391+117")
top.minsize(1, 1)
top.maxsize(1351, 738)
top.resizable(1, 1)
top.title("Query Page")
top.configure(cursor="arrow")
'''self.TCombobox1 = ttk.Combobox(top)
self.TCombobox1.place(relx=0.069, rely=0.309, relheight=0.056
, relwidth=0.892)
self.TCombobox1.configure(font=font9)
self.TCombobox1.configure(state='readonly')
self.TCombobox1.configure(textvariable=queries_support.combobox)
self.TCombobox1.configure(takefocus="")'''
self.title = tk.Label(top)
self.title.place(relx=0.317, rely=0.105, height=45, width=259)
self.title.configure(background="#8ad8d5")
self.title.configure(font=font9)
self.title.configure(text='''General Queries''')
self.aadhar = tk.Label(top)
self.aadhar.place(relx=0.067, rely=0.199, height=32, width=150)
self.aadhar.configure(background="#8ad8d5")
self.aadhar.configure(font=font9)
self.aadhar.configure(text='''Aadhaar Number''')
self.Listbox1 = tk.Listbox(top)
self.Listbox1.place(relx=0.069, rely=0.421, relheight=0.451
, relwidth=0.888)
self.Listbox1.configure(background="white")
self.Listbox1.configure(font="Times 15")
'''self.submit = tk.Button(top)
self.submit.place(relx=0.828, rely=0.372, height=32, width=88)
self.submit.configure(background="#a2d89c")
self.submit.configure(font=font9)
self.submit.configure(text=''''''Submit'''''')'''
self.Entry1 = tk.Entry(top)
self.Entry1.place(relx=0.313, rely=0.199,height=32, relwidth=0.345)
self.Entry1.configure(background="white")
self.Entry1.configure(font=font9)
self.Entry1.configure(takefocus="0")
self.search = tk.Button(top)
self.search.place(relx=0.828, rely=0.199, height=32, width=88)
self.search.configure(background="#a2d89c")
self.search.configure(font=font9)
self.search.configure(text='''Search''')
self.search.configure(command=self.click_search)
self.home = tk.Button(top)
self.home.place(relx=0.828, rely=0.925, height=32, width=88)
self.home.configure(activebackground="#f9f9f9")
self.home.configure(background="#a2d89c")
self.home.configure(font="-family {gothic} -size 15")
self.home.configure(text='''Home''')
self.home.configure(command=click_home)
self.d = tk.Button(top)
self.d.place(relx=0.069, rely=0.925, height=32, width=200)
self.d.configure(activebackground="#f9f9f9")
self.d.configure(background="#a2d89c")
self.d.configure(font="-family {gothic} -size 15")
self.d.configure(text='''Download Report''')
self.d.configure(command=self.click_report)
if __name__ == '__main__':
vp_start_gui()