-
Notifications
You must be signed in to change notification settings - Fork 0
/
crops.py
228 lines (199 loc) · 8.44 KB
/
crops.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.26
# in conjunction with Tcl version 8.6
# Oct 26, 2019 12:02:49 AM IST platform: Linux
import os
import sys
from subprocess import call
import MySQLdb
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 crops_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()
crops_support.set_Tk_var()
top = Crop (root)
crops_support.init(root, top)
root.mainloop()
w = None
def create_Crop(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
crops_support.set_Tk_var()
top = Crop (w)
crops_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Crop():
global w
w.destroy()
w = None
class Crop:
def store_crop(self):
l = []
crop_name = self.cropdata.get()
aadhar = self.adhar.get()
sector = self.cropdata_7.get()
season = self.Season.get()
irri = self.irri.get()
l.append(crop_name)
l.append(aadhar)
l.append(sector)
l.append(season)
l.append(irri)
for i in l:
if len(i) == 0:
messagebox.showerror("Enrollment failure", "All fields are mandatory")
return
if not len(aadhar) == 12:
messagebox.showerror("Enrollment Error", "12 Digit Aadhaar Number is required")
return
self.cursor_crop.execute("SELECT aid FROM farmer WHERE aid = {}".format(aadhar))
result = self.cursor_crop.fetchone()
try:
if result is None:
messagebox.showerror("Search Error", "Farmer not registered")
return
except:
messagebox.showerror("Search Error", "Incorrect Aadhaar Number")
return
try:
self.cursor_crop.execute("INSERT INTO field (crop_name, irrogation, season) VALUES (%s, %s, %s)", (crop_name, irri, season))
self.cursor_crop.execute("SELECT fid FROM field WHERE crop_name = %s and irrogation = %s and season = %s", (crop_name, irri, season))
except:
self.cursor_crop.execute("SELECT fid FROM field WHERE crop_name = %s and irrogation = %s and season = %s", (crop_name, irri, season))
result = self.cursor_crop.fetchone()
try:
self.cursor_crop.execute("INSERT INTO sector (aid, fid, sector_no) VALUES ('{}', {}, '{}')".format(aadhar, int(result[0]), sector))
self.db_crop.commit()
messagebox.showinfo("Crop Info", "Crop is Successfully enrolled")
except:
messagebox.showerror("Crop Error", "Crop is already enrolled")
def __init__(self, top=None):
try:
self.db_crop = MySQLdb.connect("localhost","shivam","","FARMER")
self.cursor_crop = self.db_crop.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("Crop Management")
top.configure(background="#adab91")
top.configure(highlightcolor="black")
self.crop = tk.Label(top)
self.crop.place(relx=0.317, rely=0.052, height=72, width=254)
self.crop.configure(background="#5fd877")
self.crop.configure(font=font9)
self.crop.configure(text='''How is Your Farm''')
self.crop = tk.Label(top)
self.crop.place(relx=0.097, rely=0.349, height=35, width=219)
self.crop.configure(background="#6559d8")
self.crop.configure(font=font9)
self.crop.configure(text='''Name of the Crop''')
self.cropdata = tk.Entry(top)
self.cropdata.place(relx=0.579, rely=0.349,height=37, relwidth=0.257)
self.cropdata.configure(background="white")
self.cropdata.configure(font=font9)
self.Aadhaar = tk.Label(top)
self.Aadhaar.place(relx=0.097, rely=0.244, height=35, width=219)
self.Aadhaar.configure(activebackground="#f9f9f9")
self.Aadhaar.configure(background="#6559d8")
self.Aadhaar.configure(font="-family {gothic} -size 15")
self.Aadhaar.configure(text='''Aadhaar No''')
self.adhar = tk.Entry(top)
self.adhar.place(relx=0.579, rely=0.244,height=37, relwidth=0.312)
self.adhar.configure(background="white")
self.adhar.configure(font=font9)
self.adhar.configure(selectbackground="#c4c4c4")
self.irrigation = tk.Label(top)
self.irrigation.place(relx=0.097, rely=0.471, height=35, width=219)
self.irrigation.configure(activebackground="#f9f9f9")
self.irrigation.configure(background="#6559d8")
self.irrigation.configure(font="-family {gothic} -size 15")
self.irrigation.configure(text='''Irrigation Method''')
self.season = tk.Label(top)
self.season.place(relx=0.097, rely=0.593, height=35, width=219)
self.season.configure(activebackground="#f9f9f9")
self.season.configure(background="#6559d8")
self.season.configure(font="-family {gothic} -size 15")
self.season.configure(text='''Season Preffered''')
self.sector = tk.Label(top)
self.sector.place(relx=0.097, rely=0.716, height=35, width=219)
self.sector.configure(activebackground="#f9f9f9")
self.sector.configure(background="#6559d8")
self.sector.configure(font="-family {gothic} -size 15")
self.sector.configure(text='''Sector No''')
self.cropdata_7 = tk.Entry(top)
self.cropdata_7.place(relx=0.579, rely=0.716,height=37, relwidth=0.257)
self.cropdata_7.configure(background="white")
self.cropdata_7.configure(font=font9)
self.cropdata_7.configure(selectbackground="#c4c4c4")
self.home = tk.Button(top)
self.home.place(relx=0.083, rely=0.873, height=35, width=90)
self.home.configure(background="#d8329b")
self.home.configure(font=font9)
self.home.configure(text='''Home''')
self.home.configure(command=click_home)
self.submit = tk.Button(top)
self.submit.place(relx=0.745, rely=0.873, height=35, width=90)
self.submit.configure(activebackground="#f9f9f9")
self.submit.configure(background="#d8329b")
self.submit.configure(font=font9)
self.submit.configure(text='''Submit''')
self.submit.configure(command=self.store_crop)
self.Season = ttk.Combobox(top)
self.Season.place(relx=0.579, rely=0.593, relheight=0.061
, relwidth=0.341)
self.value_list = ['Fall','Automn','Winter','Summer',]
self.Season.configure(values=self.value_list)
self.Season.configure(font=font9)
self.Season.configure(state='readonly')
#self.Season.configure(textvariable=crops_support.combobox)
self.Season.configure(takefocus="")
self.irri = ttk.Combobox(top)
self.irri.place(relx=0.579, rely=0.489, relheight=0.061, relwidth=0.341)
self.value_list = ['Drip/Micro','Surface','Sprinkler',]
self.irri.configure(values=self.value_list)
self.irri.configure(font=font9)
self.irri.configure(state='readonly')
self.irri.configure(textvariable=crops_support.combobox)
self.irri.configure(takefocus="")
if __name__ == '__main__':
vp_start_gui()