def __init__(self, window): self.wn = window self.wn.title("Login") self.wn.geometry("400x500+600+100") self.con = Queries() #Images self.login_img = ImageTk.PhotoImage(Image.open("Icons\Login.png").resize((100, 100))) #Frames self.frame1 = Frame(self.wn, relief=GROOVE, bd=5) self.frame1.place(x=10,y=10, height=480, width=380) #Lables self.login_image = Label(self.frame1, image=self.login_img) self.login_image.place(x=140, y=20) self.login_lbl = Label(self.frame1, text="Login", font=('verdana', 15)) self.login_lbl.place(x=165, y=120) self.uname_lbl = Label(self.frame1, text="Username :"******"Password :"******"Login", font=('arial', 15), width=10, command=self.login) self.login_btn.place(x=50, y=300) self.register_btn = Button(self.frame1, text="Reset", font=('arial', 15), width=10, command=self.reset) self.register_btn.place(x=200, y=300) self.register_btn = Button(self.frame1, text="Register", font=('arial', 15), width=10, command=self.register) self.register_btn.place(x=130, y=360)
def mainMenu(): currentuser = session['username'] cursor.execute(Queries.getPopulation(currentuser)) g.population = cursor.fetchone() if g.population > 0: g.population = g.population[0] cursor.execute(Queries.getJurisdiction(currentuser)) g.jurisdiction = cursor.fetchone() if g.jurisdiction > 0: g.jurisdiction = g.jurisdiction[0] cursor.execute(Queries.getHQLocation(currentuser)) g.hqlocation = cursor.fetchone() if g.hqlocation > 0: g.hqlocation = g.hqlocation[0] return render_template('menu.html')
def __init__(self, notes): self.con = Queries() self.note_id_val = StringVar() # Images self.add_image = ImageTk.PhotoImage(Image.open("Icons/Add.png").resize((50, 50))) self.update_image = ImageTk.PhotoImage(Image.open("Icons/Update.png").resize((50, 50))) self.delete_image = ImageTk.PhotoImage(Image.open("Icons/Delete.png").resize((50, 50))) self.reset_image = ImageTk.PhotoImage(Image.open("Icons/Reset.png").resize((50, 50))) # Frames self.frame1 = Frame(notes, relief=RIDGE, bd=8) self.frame1.place(x=10, y=10, width=1235, height=500) self.frame2 = Frame(self.frame1, relief=RIDGE, bd=5) self.frame2.place(x=0, y=0, width=200, height=485) # Label self.note_id_lbl = Label(self.frame1, text="Note ID:", font=('verdana', 12)) self.note_id_lbl.place(x=230, y=10) self.note_lbl = Label(self.frame1, text="Note:", font=('verdana', 12)) self.note_lbl.place(x=230, y=50) # Entry self.note_id_ent = Entry(self.frame1, font=('arial', 12), textvariable=self.note_id_val, state="readonly") self.note_id_ent.place(x=320, y=12) self.note_ent = Text(self.frame1, width=100, height=20, font=('arial', 12)) self.note_ent.place(x=300, y=55) # Buttons self.add_btn = Button(self.frame1, relief=FLAT, image=self.add_image, command=self.add_note) self.add_btn.place(x=550, y=420) self.update_btn = Button(self.frame1, relief=FLAT, image=self.update_image, command=self.update_note) self.update_btn.place(x=650, y=420) self.delete_btn = Button(self.frame1, relief=FLAT, image=self.delete_image, command=self.delete_note) self.delete_btn.place(x=750, y=420) self.reset_btn = Button(self.frame1, relief=FLAT, image=self.reset_image, command=self.reset_note) self.reset_btn.place(x=850, y=420) # TreeView self.scroll_y = Scrollbar(self.frame2, orient=VERTICAL) self.note_tbl = ttk.Treeview(self.frame2, columns=("note"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.note_tbl.yview, bg='#9BC01C') self.note_tbl.heading("note", text="Note Number") self.note_tbl['show'] = 'headings' self.note_tbl.column("note") self.note_tbl.pack(fill=BOTH, expand='1') self.insert_note()
class Login: def __init__(self, window): self.wn = window self.wn.title("Login") self.wn.geometry("400x500+600+100") self.con = Queries() #Images self.login_img = ImageTk.PhotoImage(Image.open("Icons\Login.png").resize((100, 100))) #Frames self.frame1 = Frame(self.wn, relief=GROOVE, bd=5) self.frame1.place(x=10,y=10, height=480, width=380) #Lables self.login_image = Label(self.frame1, image=self.login_img) self.login_image.place(x=140, y=20) self.login_lbl = Label(self.frame1, text="Login", font=('verdana', 15)) self.login_lbl.place(x=165, y=120) self.uname_lbl = Label(self.frame1, text="Username :"******"Password :"******"Login", font=('arial', 15), width=10, command=self.login) self.login_btn.place(x=50, y=300) self.register_btn = Button(self.frame1, text="Reset", font=('arial', 15), width=10, command=self.reset) self.register_btn.place(x=200, y=300) self.register_btn = Button(self.frame1, text="Register", font=('arial', 15), width=10, command=self.register) self.register_btn.place(x=130, y=360) #Methods def login(self): data = self.con.fetch_user() for i, j in data: if i == self.uname_ent.get() and j == self.pass_ent.get(): tkinter.messagebox.showinfo('Success', 'Welcome to Data Storage System.') self.wn.withdraw() self.login = Toplevel(self.wn) Notebook.Notebook(self.login) return else: tkinter.messagebox.showerror('Login Failed', 'Invalid Username or Password') def reset(self): self.uname_ent.delete(0, END) self.pass_ent.delete(0, END) def register(self): self.wn.withdraw() self.login = Toplevel(self.wn) Register(self.login)
def reportGenerator(): currentuser = session['username'] cursor.execute(Queries.generateReport(currentuser)) data = cursor.fetchall() newList = [] for r in data: obj = GenerateReport_Item(r[0], r[1], r[2], r[3]) newList.append(obj) g.table = GenerateReport_Table(newList) return render_template('reportGenerator.html')
def addResource(): #grab ESFs cursor.execute(Queries.getESFs()) esfs = cursor.fetchall() g.esf = esfs #grab COST_PER cursor.execute("SELECT COSTPER from COST_PER" ) #T49 - Use above example to put this into Queries g.costper = cursor.fetchall() #grab no of resources to generate ID: cursor.execute(Queries.getNextResourceID()) try: autoInc = cursor.fetchone()[10] except: autoInc = 1 #cursor.execute("SELECT 'auto_increment' FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'RESOURCE'") #T49 - Use above example to put this into Queries g.resourceID = autoInc return render_template('addResource.html')
class Server(BaseHTTPRequestHandler): q = Queries() """ Handles a single index page """ def do_GET(self): results = '' try: query = urlparse(self.path).query params = dict(qc.split("=") for qc in query.split("&")) results = self.handle_request(params) except: print "Error in parameters" # Read the index file f = open('index.html') content = f.read() f.close() # Send back response self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(content % results) """ Splits query parameters and supplies them to the query class. The results are rendered and returned to user """ def handle_request(self, params): response = '' if "query" in params: results = self.q.query_to_urls(params['query'].split('+')) response = self.render_results(results) return response """ Returns the results as html """ def render_results(self, results): if not results: return '<p>No Results</p>' r = '<div id="results"><ul>' for url in results: r += '<li><a href="%s">%s</a></li>' % (url, url) r += '</ul></div>' return r
def addIncident(): form = AddIncidentForm() if form.validate_on_submit(): #add this to DB currentuser = session['username'] cursor.execute( Queries.addIncident(currentuser, form.description.data, form.latitude.data, form.longitude.data)) flash("Successfully Added Incident!", "success") return redirect(url_for('mainMenu')) flash_errors(form) return render_template("addIncident.html", form=form)
def __init__(self, window): self.wn = window self.wn.title("Register") self.wn.geometry("500x500+600+100") self.con = Queries() #Images self.lbl = Label(self.wn, text="test") self.lbl.place(x=10, y=10) self.reg_image = ImageTk.PhotoImage(Image.open("Icons\Register.png").resize((100, 100))) #Frames self.frame1 = Frame(self.wn, relief=GROOVE, bd=5) self.frame1.place(x=10,y=10, height=480, width=480) # Lables self.reg_img = Label(self.wn, image=self.reg_image) self.reg_img.place(x=200, y=20) self.register_lbl = Label(self.frame1, text="Register", font=('verdana', 15)) self.register_lbl.place(x=190, y=120) self.uname_lbl = Label(self.frame1, text="Username :"******"E-Mail :", font=('verdana', 15)) self.email_lbl.place(x=20, y=240) self.cpass_lbl = Label(self.frame1, text="Password :"******"Register", font=('arial', 15), width=10, command=self.register_user) self.reg_btn.place(x=100, y=360) self.reset_btn = Button(self.frame1, text="Reset", font=('arial', 15), width=10, command=self.reset) self.reset_btn.place(x=260, y=360) self.login_btn = Button(self.frame1, text="Login", font=('arial', 15), width=10, command=self.login) self.login_btn.place(x=180, y=420)
def resourceStatus(): currentuser = session['username'] cursor = mysql.connect().cursor() #FIRST ONE #return Queries.resourceStatus_getResourcesInUse(currentuser) query = Queries.resourceStatus_getResourcesInUse(currentuser) #return query cursor.execute(query) results = cursor.fetchall() resourceInUseList = [] for r in results: print r obj = ResourcesInUseStatus_Item(r[0], r[1], r[2], r[3], r[4], r[5], r[6]) #, r[6], r[7]) resourceInUseList.append(obj) g.resourceInUsetable = ResourcesInUseStatus(resourceInUseList) ''' try: cursor.execute(Queries.resourceStatus_getResourcesInUse(currentuser)) results = cursor.fetchall() resourceInUseList = [] for r in results: obj = ResourcesInUseWithDistance_Item(r[0], r[1], r[2], r[3], r[4], r[5]) resourceInUseList.append(obj) g.resourceInUsetable = ResourceStatus_ResourcesInUse(resourceInUseList) except TypeError: print "No data to display..." g.resourceInUsetable = None ''' #SECOND ONE #return Queries.resourceStatus_getResourcesRequestedByMe(currentuser) cursor.execute( Queries.resourceStatus_getResourcesRequestedByMe(currentuser)) results = cursor.fetchall() resourcesRequestedByMe = [] for r in results: obj = GeneResourceStatus_ResourcesRequestedByMe_Item( r[0], r[1], r[2], r[3], r[4], r[5], r[6]) resourcesRequestedByMe.append(obj) g.resourcesRequestedByMeTable = ResourceStatus_ResourcesRequestedByMe( resourcesRequestedByMe) #THIRD query = Queries.resourceStatus_getResourcesReceivedByMe(currentuser) cursor.execute(query) #return query results = cursor.fetchall() resourcesReceivedByMe = [] for r in results: print r obj = ResourceStatus_ResourceRequestsReceivedByMe_Item( r[0], r[1], r[2], r[3], r[4], r[5]) resourcesReceivedByMe.append(obj) g.resourcesReceivedByMeTable = ResourceStatus_ResourceRequestsReceivedByMe( resourcesReceivedByMe) #FOURTH cursor.execute( Queries.resoureceStatus_getRepairsScheduledAndInProgress(currentuser)) results = cursor.fetchall() resourcesInUse = [] for r in results: obj = ResourceStatus_RepairsScheduledAndInProgress_Item( r[0], r[1], r[2], r[3], "cancel") resourcesInUse.append(obj) g.resourcesReceivedByMe = ResourceStatus_RepairsScheduledAndInProgress( resourcesInUse) return render_template('resourceStatus.html')
# -*- coding:utf-8 -*- from Queries import Queries myQuery = Queries()
class PasswordManager: def __init__(self, password): self.con = Queries() self.count = 0 #Images self.show_image = ImageTk.PhotoImage( Image.open("Icons/Show.png").resize((20, 20))) self.add_image = ImageTk.PhotoImage( Image.open("Icons/Add.png").resize((50, 50))) self.update_image = ImageTk.PhotoImage( Image.open("Icons/Update.png").resize((50, 50))) self.delete_image = ImageTk.PhotoImage( Image.open("Icons/Delete.png").resize((50, 50))) self.reset_image = ImageTk.PhotoImage( Image.open("Icons/Reset.png").resize((50, 50))) #Frames self.frame1 = Frame(password, relief=RIDGE, bd=8) self.frame1.place(x=10, y=10, width=430, height=500) self.frame2 = Frame(password, relief=RIDGE, bd=1) self.frame2.place(x=650, y=10, width=600, height=500) self.frame3 = Frame(password, relief=RIDGE, bd=1) self.frame3.place(x=450, y=10, width=200, height=500) self.category_frame = Frame(self.frame1, relief=RIDGE, bd=1) self.category_frame.place(x=0, y=0, width=415, height=200) self.entry_frame = Frame(self.frame1, relief=RIDGE, bd=1) self.entry_frame.place(x=0, y=200, width=415, height=285) #Lables self.create_lbl = Label(self.category_frame, text="Create Category", font=('verdana', 12)) self.create_lbl.place(x=140, y=10) self.account_lbl = Label(self.entry_frame, text="Account Name:", font=('verdana', 12)) self.account_lbl.place(x=20, y=20) self.category_lbl = Label(self.entry_frame, text="Category :", font=('verdana', 12)) self.category_lbl.place(x=20, y=60) self.username_lbl = Label(self.entry_frame, text="Username\n/E-mail :", font=('verdana', 12)) self.username_lbl.place(x=20, y=100) self.passowrd_lbl = Label(self.entry_frame, text="Password :"******"category"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.category_tbl.yview, bg='#9BC01C') self.category_tbl.heading("category", text="Category") self.category_tbl['show'] = 'headings' self.category_tbl.column("category", width=30) self.category_tbl.pack(fill=BOTH, expand='1') self.insert_category() #Treeview2 self.scroll_y = Scrollbar(self.frame2, orient=VERTICAL) self.password_tbl = ttk.Treeview(self.frame2, columns=("account", "category", "username"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.password_tbl.yview, bg='#9BC01C') self.password_tbl.heading("account", text="Account") self.password_tbl.heading("category", text="Category") self.password_tbl.heading("username", text="Username / Email") self.password_tbl['show'] = 'headings' self.password_tbl.column("account", width=30) self.password_tbl.column("category", width=30) self.password_tbl.column("username", width=30) self.password_tbl.pack(fill=BOTH, expand='1') self.insert_password() #Methods def add_category(self): data = self.con.fetch_category() category = self.create_ent.get() result = self.binary_search(data, category) if result != -1: tkinter.messagebox.showerror('Error', 'Category already exists') else: if self.create_ent.get() == '': tkinter.messagebox.showerror('Error', 'Category cannot be left empty.') else: self.con.add_category(self.create_ent.get()) self.category() self.insert_category() self.reset_category() def add_password(self): if self.account_ent.get()=='' or self.category_ent.get()=='' or self.username_ent.get()=='' or \ self.password_ent.get()=='': tkinter.messagebox.showerror('Error', 'Dont leave the fields empty.') else: self.con.add_password(self.account_ent.get(), self.category_ent.get(), self.username_ent.get(), self.password_ent.get()) self.insert_password() self.reset_password() def update_password(self): if self.account_ent.get() == '' or self.category_ent.get() == '' or self.username_ent.get() == '' or \ self.password_ent.get() == '': tkinter.messagebox.showerror('Error', 'Dont leave the fields empty.') else: self.con.update_password(self.account_ent.get(), self.category_ent.get(), self.username_ent.get(), self.password_ent.get(), self.id) self.insert_password() self.reset_password() def delete_category(self): self.con.delete_category(self.create_ent.get()) self.category() self.category_ent.set('') self.insert_category() self.insert_password() self.reset_category() def delete_password(self): self.con.delete_password(self.id) self.insert_password() self.reset_password() def reset_category(self): self.create_ent.delete(0, END) def reset_password(self): self.account_ent.delete(0, END) self.category_ent.set('') self.username_ent.delete(0, END) self.password_ent.delete(0, END) def insert_category(self): data = self.con.fetch_category() self.category_tbl.delete(*self.category_tbl.get_children()) for i in data: self.category_tbl.insert("", "end", value=(i[0])) self.category_tbl.bind('<Double-1>', self.select_category) def select_category(self, event): self.row = self.category_tbl.item(self.category_tbl.selection(), "values") self.fill_category() def fill_category(self): self.reset_category() self.create_ent.insert(0, self.row[0]) def insert_password(self): data = self.con.fetch_password() self.password_tbl.delete(*self.password_tbl.get_children()) for i in data: self.password_tbl.insert("", "end", value=(i[1], i[2], i[3], i[4]), text=(i[0])) self.password_tbl.bind('<Double-1>', self.select_password) def select_password(self, event): self.row = self.password_tbl.item(self.password_tbl.selection(), "values") self.id = self.password_tbl.item(self.password_tbl.selection(), "text") self.fill_password() def fill_password(self): self.reset_password() self.account_ent.insert(0, self.row[0]) self.category_ent.set(self.row[1]) self.username_ent.insert(0, self.row[2]) self.password_ent.insert(0, self.row[3]) def category(self): data = self.con.fetch_category() self.category_ent['values'] = data def show(self): self.count += 1 if self.count % 2 == 0: self.password_ent.configure(show="*") else: self.password_ent.configure(show='') def binary_search(self, list, key): start = 0 end = len(list) - 1 while start <= end: mid = (start + end) // 2 if list[mid][0] == key: return mid elif list[mid][0] > key: end = mid - 1 else: start = mid + 1 return -1
def __init__(self, password): self.con = Queries() self.count = 0 #Images self.show_image = ImageTk.PhotoImage( Image.open("Icons/Show.png").resize((20, 20))) self.add_image = ImageTk.PhotoImage( Image.open("Icons/Add.png").resize((50, 50))) self.update_image = ImageTk.PhotoImage( Image.open("Icons/Update.png").resize((50, 50))) self.delete_image = ImageTk.PhotoImage( Image.open("Icons/Delete.png").resize((50, 50))) self.reset_image = ImageTk.PhotoImage( Image.open("Icons/Reset.png").resize((50, 50))) #Frames self.frame1 = Frame(password, relief=RIDGE, bd=8) self.frame1.place(x=10, y=10, width=430, height=500) self.frame2 = Frame(password, relief=RIDGE, bd=1) self.frame2.place(x=650, y=10, width=600, height=500) self.frame3 = Frame(password, relief=RIDGE, bd=1) self.frame3.place(x=450, y=10, width=200, height=500) self.category_frame = Frame(self.frame1, relief=RIDGE, bd=1) self.category_frame.place(x=0, y=0, width=415, height=200) self.entry_frame = Frame(self.frame1, relief=RIDGE, bd=1) self.entry_frame.place(x=0, y=200, width=415, height=285) #Lables self.create_lbl = Label(self.category_frame, text="Create Category", font=('verdana', 12)) self.create_lbl.place(x=140, y=10) self.account_lbl = Label(self.entry_frame, text="Account Name:", font=('verdana', 12)) self.account_lbl.place(x=20, y=20) self.category_lbl = Label(self.entry_frame, text="Category :", font=('verdana', 12)) self.category_lbl.place(x=20, y=60) self.username_lbl = Label(self.entry_frame, text="Username\n/E-mail :", font=('verdana', 12)) self.username_lbl.place(x=20, y=100) self.passowrd_lbl = Label(self.entry_frame, text="Password :"******"category"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.category_tbl.yview, bg='#9BC01C') self.category_tbl.heading("category", text="Category") self.category_tbl['show'] = 'headings' self.category_tbl.column("category", width=30) self.category_tbl.pack(fill=BOTH, expand='1') self.insert_category() #Treeview2 self.scroll_y = Scrollbar(self.frame2, orient=VERTICAL) self.password_tbl = ttk.Treeview(self.frame2, columns=("account", "category", "username"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.password_tbl.yview, bg='#9BC01C') self.password_tbl.heading("account", text="Account") self.password_tbl.heading("category", text="Category") self.password_tbl.heading("username", text="Username / Email") self.password_tbl['show'] = 'headings' self.password_tbl.column("account", width=30) self.password_tbl.column("category", width=30) self.password_tbl.column("username", width=30) self.password_tbl.pack(fill=BOTH, expand='1') self.insert_password()
# --------------------------------------------------------------------------------------------------- # Author: Hany Hamed # Description: Main code that add using the queries and executing them [for Assignment 1 for DMD2 course] # Sources: # - https://blog.exploratory.io/an-introduction-to-mongodb-query-for-beginners-bd463319aa4c # - https://www.w3schools.com/python/python_mongodb_query.asp # --------------------------------------------------------------------------------------------------- from Queries import Queries from utils import * import time settings = get_settings() client_mngdb, db_mngdb = init_mongodb(settings["host"], settings["database"]) q = Queries(db_mngdb) while(True): q_num = int(input("Enter number of the query:")) if(q_num == -1 or q_num > 5): print("Finish !!") break params = {} if(q_num == 4): params["customer_id"] = int(input("Enter Cutomer_id: ")) if(q_num == 5): params["source_actor_id"] = int(input("Enter Actor_id: ")) time1 = time.time() q.query(q_num, params=params) print("############ Statistics ############") print("Time taken to finish to {:}th query ::: {:.4f}s".format(q_num,time.time()-time1))
class Register: def __init__(self, window): self.wn = window self.wn.title("Register") self.wn.geometry("500x500+600+100") self.con = Queries() #Images self.lbl = Label(self.wn, text="test") self.lbl.place(x=10, y=10) self.reg_image = ImageTk.PhotoImage(Image.open("Icons\Register.png").resize((100, 100))) #Frames self.frame1 = Frame(self.wn, relief=GROOVE, bd=5) self.frame1.place(x=10,y=10, height=480, width=480) # Lables self.reg_img = Label(self.wn, image=self.reg_image) self.reg_img.place(x=200, y=20) self.register_lbl = Label(self.frame1, text="Register", font=('verdana', 15)) self.register_lbl.place(x=190, y=120) self.uname_lbl = Label(self.frame1, text="Username :"******"E-Mail :", font=('verdana', 15)) self.email_lbl.place(x=20, y=240) self.cpass_lbl = Label(self.frame1, text="Password :"******"Register", font=('arial', 15), width=10, command=self.register_user) self.reg_btn.place(x=100, y=360) self.reset_btn = Button(self.frame1, text="Reset", font=('arial', 15), width=10, command=self.reset) self.reset_btn.place(x=260, y=360) self.login_btn = Button(self.frame1, text="Login", font=('arial', 15), width=10, command=self.login) self.login_btn.place(x=180, y=420) #Methods def register_user(self): data = self.con.fetch_user() username = self.uname_ent.get() result = self.binary_search(data, username) if result != -1: tkinter.messagebox.showerror('Error', 'Username already exists') else: if self.uname_ent.get() == '' or self.email_ent.get() == '' or self.pass_ent.get() == '': tkinter.messagebox.showerror('Error', 'Dont leave the fields empty.') else: self.con.add_user(self.uname_ent.get(), self.email_ent.get(), self.pass_ent.get()) tkinter.messagebox.showinfo('Success', 'User registered sucessfully') self.reset() def reset(self): self.uname_ent.delete(0, END) self.email_ent.delete(0, END) self.pass_ent.delete(0, END) def binary_search(self, list, key): start = 0 end = len(list) - 1 while start <= end: mid = (start + end) // 2 if list[mid][0] == key: return mid elif list[mid][0] > key: end = mid - 1 else: start = mid + 1 return -1 def login(self): self.wn.withdraw() self.login = Toplevel(self.wn) Login(self.login)
def __init__(self, contacts): self.con = Queries() self.contact_id_val = StringVar() #Images self.add_image = ImageTk.PhotoImage( Image.open("Icons/Add.png").resize((50, 50))) self.update_image = ImageTk.PhotoImage( Image.open("Icons/Update.png").resize((50, 50))) self.delete_image = ImageTk.PhotoImage( Image.open("Icons/Delete.png").resize((50, 50))) self.reset_image = ImageTk.PhotoImage( Image.open("Icons/Reset.png").resize((50, 50))) #Frames self.frame1 = Frame(contacts, relief=RIDGE, bd=8) self.frame1.place(x=10, y=10, width=430, height=500) self.frame2 = Frame(contacts) self.frame2.place(x=450, y=10, width=800, height=500) #Labels self.id_lbl = Label(self.frame1, text="Contact ID:", font=('verdana', 12)) self.id_lbl.place(x=10, y=10) self.fname_lbl = Label(self.frame1, text="First Name:", font=('verdana', 12)) self.fname_lbl.place(x=10, y=50) self.lname_lbl = Label(self.frame1, text="Last Name:", font=('verdana', 12)) self.lname_lbl.place(x=10, y=90) self.group_lbl = Label(self.frame1, text="Group:", font=('verdana', 12)) self.group_lbl.place(x=10, y=130) self.number_lbl = Label(self.frame1, text="Phone:", font=('verdana', 12)) self.number_lbl.place(x=10, y=170) self.email_lbl = Label(self.frame1, text="E-mail:", font=('verdana', 12)) self.email_lbl.place(x=10, y=210) self.address_lbl = Label(self.frame1, text="Address:", font=('verdana', 12)) self.address_lbl.place(x=10, y=250) #Entries self.contact_id_ent = Entry(self.frame1, font=('arial', 12), width=22, textvariable=self.contact_id_val, state="readonly") self.contact_id_ent.place(x=120, y=10) self.fname_ent = Entry(self.frame1, font=('arial', 12), width=22) self.fname_ent.place(x=120, y=50) self.lname_ent = Entry(self.frame1, font=('arial', 12), width=22) self.lname_ent.place(x=120, y=90) self.group_ent = ttk.Combobox(self.frame1, font=('arial', 12), width=20, state='readonly') self.group_ent['values'] = ('Work', "Home", "College") self.group_ent.place(x=120, y=130) self.number_ent = Entry(self.frame1, font=('arial', 12), width=22) self.number_ent.place(x=120, y=170) self.email_ent = Entry(self.frame1, font=('arial', 12), width=22) self.email_ent.place(x=120, y=210) self.address_ent = Entry(self.frame1, font=('arial', 12), width=22) self.address_ent.place(x=120, y=250) #Buttons self.add_btn = Button(self.frame1, relief=FLAT, image=self.add_image, command=self.add_contact) self.add_btn.place(x=100, y=320) self.edit_btn = Button(self.frame1, relief=FLAT, image=self.update_image, command=self.update_contact) self.edit_btn.place(x=240, y=320) self.delete_btn = Button(self.frame1, relief=FLAT, image=self.delete_image, command=self.delete_contact) self.delete_btn.place(x=100, y=400) self.reset_btn = Button(self.frame1, relief=FLAT, image=self.reset_image, command=self.reset_contact) self.reset_btn.place(x=240, y=400) #Treeview self.scroll_y = Scrollbar(self.frame2, orient=VERTICAL) self.contact_tbl = ttk.Treeview(self.frame2, columns=("fname", "lname", "group", "number", "email", "address"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.contact_tbl.yview, bg='#9BC01C') self.contact_tbl.heading("fname", text="First Name") self.contact_tbl.heading("lname", text="Last Name") self.contact_tbl.heading("group", text="Group") self.contact_tbl.heading("number", text="Phone No") self.contact_tbl.heading("email", text="E-mail") self.contact_tbl.heading("address", text="Address") self.contact_tbl['show'] = 'headings' self.contact_tbl.column("fname", width=30) self.contact_tbl.column("lname", width=30) self.contact_tbl.column("group", width=30) self.contact_tbl.column("number", width=30) self.contact_tbl.column("email", width=60) self.contact_tbl.column("address", width=60) self.contact_tbl.pack(fill=BOTH, expand='1') self.insert_contact()
class ContactManager: def __init__(self, contacts): self.con = Queries() self.contact_id_val = StringVar() #Images self.add_image = ImageTk.PhotoImage( Image.open("Icons/Add.png").resize((50, 50))) self.update_image = ImageTk.PhotoImage( Image.open("Icons/Update.png").resize((50, 50))) self.delete_image = ImageTk.PhotoImage( Image.open("Icons/Delete.png").resize((50, 50))) self.reset_image = ImageTk.PhotoImage( Image.open("Icons/Reset.png").resize((50, 50))) #Frames self.frame1 = Frame(contacts, relief=RIDGE, bd=8) self.frame1.place(x=10, y=10, width=430, height=500) self.frame2 = Frame(contacts) self.frame2.place(x=450, y=10, width=800, height=500) #Labels self.id_lbl = Label(self.frame1, text="Contact ID:", font=('verdana', 12)) self.id_lbl.place(x=10, y=10) self.fname_lbl = Label(self.frame1, text="First Name:", font=('verdana', 12)) self.fname_lbl.place(x=10, y=50) self.lname_lbl = Label(self.frame1, text="Last Name:", font=('verdana', 12)) self.lname_lbl.place(x=10, y=90) self.group_lbl = Label(self.frame1, text="Group:", font=('verdana', 12)) self.group_lbl.place(x=10, y=130) self.number_lbl = Label(self.frame1, text="Phone:", font=('verdana', 12)) self.number_lbl.place(x=10, y=170) self.email_lbl = Label(self.frame1, text="E-mail:", font=('verdana', 12)) self.email_lbl.place(x=10, y=210) self.address_lbl = Label(self.frame1, text="Address:", font=('verdana', 12)) self.address_lbl.place(x=10, y=250) #Entries self.contact_id_ent = Entry(self.frame1, font=('arial', 12), width=22, textvariable=self.contact_id_val, state="readonly") self.contact_id_ent.place(x=120, y=10) self.fname_ent = Entry(self.frame1, font=('arial', 12), width=22) self.fname_ent.place(x=120, y=50) self.lname_ent = Entry(self.frame1, font=('arial', 12), width=22) self.lname_ent.place(x=120, y=90) self.group_ent = ttk.Combobox(self.frame1, font=('arial', 12), width=20, state='readonly') self.group_ent['values'] = ('Work', "Home", "College") self.group_ent.place(x=120, y=130) self.number_ent = Entry(self.frame1, font=('arial', 12), width=22) self.number_ent.place(x=120, y=170) self.email_ent = Entry(self.frame1, font=('arial', 12), width=22) self.email_ent.place(x=120, y=210) self.address_ent = Entry(self.frame1, font=('arial', 12), width=22) self.address_ent.place(x=120, y=250) #Buttons self.add_btn = Button(self.frame1, relief=FLAT, image=self.add_image, command=self.add_contact) self.add_btn.place(x=100, y=320) self.edit_btn = Button(self.frame1, relief=FLAT, image=self.update_image, command=self.update_contact) self.edit_btn.place(x=240, y=320) self.delete_btn = Button(self.frame1, relief=FLAT, image=self.delete_image, command=self.delete_contact) self.delete_btn.place(x=100, y=400) self.reset_btn = Button(self.frame1, relief=FLAT, image=self.reset_image, command=self.reset_contact) self.reset_btn.place(x=240, y=400) #Treeview self.scroll_y = Scrollbar(self.frame2, orient=VERTICAL) self.contact_tbl = ttk.Treeview(self.frame2, columns=("fname", "lname", "group", "number", "email", "address"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.contact_tbl.yview, bg='#9BC01C') self.contact_tbl.heading("fname", text="First Name") self.contact_tbl.heading("lname", text="Last Name") self.contact_tbl.heading("group", text="Group") self.contact_tbl.heading("number", text="Phone No") self.contact_tbl.heading("email", text="E-mail") self.contact_tbl.heading("address", text="Address") self.contact_tbl['show'] = 'headings' self.contact_tbl.column("fname", width=30) self.contact_tbl.column("lname", width=30) self.contact_tbl.column("group", width=30) self.contact_tbl.column("number", width=30) self.contact_tbl.column("email", width=60) self.contact_tbl.column("address", width=60) self.contact_tbl.pack(fill=BOTH, expand='1') self.insert_contact() #Methods def add_contact(self): if self.fname_ent.get()=='' or self.lname_ent.get()=='' or self.group_ent.get()=='' or \ self.number_ent.get()=='' or self.email_ent.get()=='' or self.address_ent.get()=='': tkinter.messagebox.showerror('Error', 'Dont leave the fields empty.') else: self.con.add_contact(self.fname_ent.get(), self.lname_ent.get(), self.group_ent.get(), self.number_ent.get(), self.email_ent.get(), self.address_ent.get()) self.insert_contact() self.reset_contact() def update_contact(self): if self.fname_ent.get()=='' or self.lname_ent.get()=='' or self.group_ent.get()=='' or \ self.number_ent.get()=='' or self.email_ent.get()=='' or self.address_ent.get()=='': tkinter.messagebox.showerror('Error', 'Dont leave the fields empty.') else: self.con.update_contact(self.fname_ent.get(), self.lname_ent.get(), self.group_ent.get(), self.number_ent.get(), self.email_ent.get(), self.address_ent.get(), self.contact_id_ent.get()) self.insert_contact() self.reset_contact() def delete_contact(self): self.con.delete_contact(self.contact_id_ent.get()) self.insert_contact() self.reset_contact() def reset_contact(self): self.contact_id_val.set('') self.fname_ent.delete(0, END) self.lname_ent.delete(0, END) self.group_ent.set('') self.number_ent.delete(0, END) self.email_ent.delete(0, END) self.address_ent.delete(0, END) def insert_contact(self): data = self.con.fetch_contact() self.contact_tbl.delete(*self.contact_tbl.get_children()) for i in data: self.contact_tbl.insert("", "end", value=(i[1], i[2], i[3], i[4], i[5], i[6], i[0])) self.contact_tbl.bind('<Double-1>', self.select_contact) def select_contact(self, event): self.row = self.contact_tbl.item(self.contact_tbl.selection(), "values") self.fill_contact() def fill_contact(self): self.reset_contact() self.contact_id_val.set(self.row[6]) self.fname_ent.insert(0, self.row[0]) self.lname_ent.insert(0, self.row[1]) self.group_ent.set(self.row[2]) self.number_ent.insert(0, self.row[3]) self.email_ent.insert(0, self.row[4]) self.address_ent.insert(0, self.row[5])
def search(): currentuser = session['username'] cursor = mysql.connect().cursor() tableList = [] if request.method == "POST": keyword = request.form["keyword"] esf = request.form["primary-esf-form"] loc = request.form["location"] incident = request.form[ "incident"] #fix this...might not always be there... incident_lat = None incident_long = None useIntersection = False #checks to see if they are not blank if incident != "": cursor.execute(Queries.getIncidentNameFromID(incident)) incidentName = cursor.fetchone() g.tableTitle = "Search Results for Incident: %s" % incidentName cursor.execute(Queries.getLatLongOfIncident(incident)) result = cursor.fetchone() incident_lat = result[0] incident_long = result[1] #Option 1 - if NO field is selected if keyword == "" and esf == "" and loc == "" and incident == "": cursor.execute(Queries.searchResourcesNothingSelected()) results = cursor.fetchall() #print "RESULT:", results[1] rlist = [] for r in results: #DRY THIS UP -- BUTTON PART button = None #if r[5] == "Available": #or IN USE # button = "request" obj = ResourcesInUse_Item(r[0], r[1], r[2], r[3], r[4], r[5], r[6]) #, button) rlist.append(obj) tableList = rlist removeDupesFromList(tableList) g.table = ResourcesInUse(tableList) #print g.table.distance useIntersection = True #Option2 - search by Keyword if keyword != "": cursor.execute(Queries.searchResourcesbyKeyword(keyword)) results = cursor.fetchall() rlist = [] for r in results: obj = ResourcesInUse_Item(r[0], r[1], r[2], r[3], r[4], r[5], r[6]) rlist.append(obj) if useIntersection: intersection = [] for o in tableList: for p in rlist: if o == p: intersection.append(o) tableList = intersection else: tableList = rlist removeDupesFromList(tableList) g.table = ResourcesInUse(tableList) useIntersection = True #Option 3 - search by ESF if esf != "": cursor.execute(Queries.searchResourcesbyESF(esf)) results = cursor.fetchall() rlist = [] for r in results: obj = ResourcesInUse_Item(r[0], r[1], r[2], r[3], r[4], r[5], r[6]) rlist.append(obj) if useIntersection: intersection = [] for o in tableList: for p in rlist: if o == p: print "ADDED!" intersection.append(o) tableList = intersection else: tableList = rlist removeDupesFromList(tableList) g.table = ResourcesInUse(tableList) useIntersection = True #Option 4 - search by Location (include condition for table) -- make sure form knows both field have to be populated (distance AND incident) if incident != "": cursor.execute( Queries.searchResourcesbyIncidentAndDistance( incident_lat, incident_long)) results = cursor.fetchall() #print "results are:", results rlist = [] for r in results: owner = r[7] button = None repairButton = None if r[4] == "Available" or r[4] == "In Use": #or IN USE button = "request" if owner == currentuser: button = "deploy" repairButton = "repair" #cursor.execute(Queries.getIncidentNameFromID(incident)) #incidentName = cursor.fetchone() obj = ResourcesInUseWithDistance_Item(r[0], r[1], r[2], r[3], r[4], r[5], r[6], incident, r[7], button, repairButton) rlist.append(obj) if useIntersection: intersection = [] for o in tableList: for p in rlist: if o == p: print "ADDED!" intersection.append(o) tableList = intersection else: tableList = rlist #filter out things > than loc if loc != "": filteredList = [] for q in tableList: if q.distance <= float(loc): print "added!", q filteredList.append(q) print "got some stuff:", filteredList tableList = filteredList #g.table = tableList removeDupesFromList(tableList) g.table = ResourcesInUseWithDistance(tableList) useIntersection = True print "*****" print "keyword: ", keyword print "esf: ", esf print "loc: ", loc print "incident: ", incident print "incidents", incident_lat, incident_long #test = request.form["test"] print "Proccess postes" print "The keyword is:", request.form["keyword"] cursor.execute("SELECT ESF_ID, DESCRIPTION from ESF") esf = cursor.fetchall() g.esf = esf #get incidents cursor.execute(Queries.getUserIncidents(currentuser)) g.incidents = cursor.fetchall() return render_template("searchresource.html")
def parseAction(): if request.method == "POST": print "**************************swwsaw" _type = request.args.get('type') print "TYPE IS", _type if _type == "cancel": _resourceid = request.args.get('id') query = Queries.deleteRepairRequest(_resourceid) cursor.execute(query) flash("Successfully Cancelled Repair Request!", "success") return redirect(url_for('mainMenu')) if _type == "repair": _resourceid = request.args.get('id') query = Queries.submitRepairRequest(_resourceid) cursor.execute(query) flash("Successfully Requested Resource Repair!", "success") return redirect(url_for('mainMenu')) #return query if _type == "return": #1 check for repair requests _resourceid = request.args.get('id') query = Queries.checkForRepairRequests(_resourceid) cursor.execute(query) rowcount = cursor.rowcount #if its in there, set status to in repair and delete it from rep req if rowcount > 0: results = cursor.fetchone() query = Queries.setStatusToInRepair(results[1], _resourceid) cursor.execute(query) #delete from rep requests query = Queries.deteFromRepairRequests(_resourceid) cursor.execute(query) #if its not, set status to available else: print "SETTING STATUS TO AVAILABLE" _incidentID = request.args.get('incidentID') query = Queries.setStatusToAvailable(_resourceid) cursor.execute(query) #delete from requests query = Queries.deleteResourceFromRequestsTable( _resourceid, _incidentID) cursor.execute(query) flash("Successfully Returned Resource!", "success") return redirect(url_for('mainMenu')) if _type == "deleteResourceRequest": _incidentID = request.args.get('resourceID') _resourceid = request.args.get('incidentID') #_id = request.args.get('id') #_incidentID = request.args.get('incidentID') query = Queries.deletePendingResourceRequests( _resourceid, _incidentID) #return query cursor.execute(query) flash("Successfully Deleted Resource Request!", "success") print "eee" return redirect(url_for('mainMenu')) if _type == "request": print "its a request" _id = request.args.get('id') _incidentID = request.args.get('incidentID') #DO IT try: query = Queries.requestResource(_id, _incidentID) cursor.execute(Queries.requestResource(_id, _incidentID)) except: print "error" pass print "hiiii" flash("Successfully Requested Resource!", "success") return redirect(url_for('mainMenu')) if _type == "deploy": _resourceid = request.args.get('resourceID') _incidentID = request.args.get('incidentID') _returnBy = request.args.get('returnBy') #updates status query = Queries.deployResource(_resourceid, _incidentID) cursor.execute(query) #deploys query2 = Queries.deployingResourceStatus(_returnBy, _resourceid) #return query2 cursor.execute(query2) flash("Successfully Deployed Resource Request!", "success") return redirect(url_for('mainMenu'))
class NotesManager: def __init__(self, notes): self.con = Queries() self.note_id_val = StringVar() # Images self.add_image = ImageTk.PhotoImage(Image.open("Icons/Add.png").resize((50, 50))) self.update_image = ImageTk.PhotoImage(Image.open("Icons/Update.png").resize((50, 50))) self.delete_image = ImageTk.PhotoImage(Image.open("Icons/Delete.png").resize((50, 50))) self.reset_image = ImageTk.PhotoImage(Image.open("Icons/Reset.png").resize((50, 50))) # Frames self.frame1 = Frame(notes, relief=RIDGE, bd=8) self.frame1.place(x=10, y=10, width=1235, height=500) self.frame2 = Frame(self.frame1, relief=RIDGE, bd=5) self.frame2.place(x=0, y=0, width=200, height=485) # Label self.note_id_lbl = Label(self.frame1, text="Note ID:", font=('verdana', 12)) self.note_id_lbl.place(x=230, y=10) self.note_lbl = Label(self.frame1, text="Note:", font=('verdana', 12)) self.note_lbl.place(x=230, y=50) # Entry self.note_id_ent = Entry(self.frame1, font=('arial', 12), textvariable=self.note_id_val, state="readonly") self.note_id_ent.place(x=320, y=12) self.note_ent = Text(self.frame1, width=100, height=20, font=('arial', 12)) self.note_ent.place(x=300, y=55) # Buttons self.add_btn = Button(self.frame1, relief=FLAT, image=self.add_image, command=self.add_note) self.add_btn.place(x=550, y=420) self.update_btn = Button(self.frame1, relief=FLAT, image=self.update_image, command=self.update_note) self.update_btn.place(x=650, y=420) self.delete_btn = Button(self.frame1, relief=FLAT, image=self.delete_image, command=self.delete_note) self.delete_btn.place(x=750, y=420) self.reset_btn = Button(self.frame1, relief=FLAT, image=self.reset_image, command=self.reset_note) self.reset_btn.place(x=850, y=420) # TreeView self.scroll_y = Scrollbar(self.frame2, orient=VERTICAL) self.note_tbl = ttk.Treeview(self.frame2, columns=("note"), xscrollcommand=self.scroll_y.set) self.scroll_y.pack(side=RIGHT, fill='y') self.scroll_y.config(command=self.note_tbl.yview, bg='#9BC01C') self.note_tbl.heading("note", text="Note Number") self.note_tbl['show'] = 'headings' self.note_tbl.column("note") self.note_tbl.pack(fill=BOTH, expand='1') self.insert_note() #Methods def add_note(self): print(self.note_ent.get("1.0","end")) if self.note_ent.get("1.0","end")=='': tkinter.messagebox.showerror('Error','Dont leave the field empty.') else: self.con.add_note(self.note_ent.get("1.0","end")) self.insert_note() self.reset_note() def update_note(self): if self.note_ent.get("1.0","end")=='': tkinter.messagebox.showerror('Error','Dont leave the field empty.') else: self.con.update_note(self.note_ent.get("1.0","end"), self.note_id_ent.get()) self.insert_note() self.reset_note() def delete_note(self): self.con.delete_note(self.note_id_ent.get()) self.insert_note() self.reset_note() def reset_note(self): self.note_id_val.set('') self.note_ent.delete("1.0","end") def insert_note(self): data = self.con.fetch_note() self.note_tbl.delete(*self.note_tbl.get_children()) for i in data: self.note_tbl.insert("","end", value=(i[0],i[1])) self.note_tbl.bind('<Double-1>',self.select_note) def select_note(self, event): self.row = self.note_tbl.item(self.note_tbl.selection(), "values") self.fill_note() def fill_note(self): self.reset_note() self.note_id_val.set(self.row[0]) self.note_ent.insert("0.0",self.row[1])