def setChPw(self): if len(self.entUid.get()) <= 0 : return sql = "SELECT * FROM acct WHERE uid = %s" val = (self.entUid.get(),) data = getdata_one(sql,val) if data != None : uid = data[0] password = data[2] matchpw = verify_password(self.entCurPw.get(),password) if matchpw == False: messagebox.showerror(title="Error",message="Password lama tidak sesuai") self.entCurPw.focus_set() elif (len(self.entNewPw.get()) <= 0) or (str(self.entNewPw.get()) != str(self.entConfPw.get())): messagebox.showerror(title="Error",message="Konfirmasi Password tidak sesuai") self.entConfPw.focus_set() elif messagebox.askokcancel('Change Password','Anda yakin akan mengganti Password?') == True: storepw = generate_hash(self.entNewPw.get()) sql = "UPDATE acct SET passhash=%s WHERE uid=%s" val = (storepw,uid) if (insert_data(sql,val)) == True: messagebox.showinfo(title="Change Password", \ message="Password baru sudah berhasil diupdate.") self.cancelChPw(0) else: self.cancelChPw(0)
def onSave(self): cWo = self.checkwo( self.entWo.get()) # self.checkwo, jika salah return False cIfca = self.entIfca.get() cTglBuat = store_date(self.entTglbuat.get()) #check tgl dulu cJamBuat = self.entJambuat.get() cUnit = self.entUnit.get().upper().strip() cWorkReq = self.entWorkReq.get('1.0', 'end').upper().strip() cStaff = self.entStaff.get().upper().strip() cIfca = self.entIfca.get() if cWo == False: #check WO messagebox.showerror(title="Error", \ message="WO sudah terdaftar atau Input WO salah") elif self.checkifca(cIfca) == False: #check IFCA messagebox.showerror(title="Error", \ message="IFCA sudah terdaftar atau Input IFCA salah") self.entIfca.focus_set() elif len(cTglBuat) == 0 or len( cJamBuat.strip()) != 5: #check tgl jika kosong, batalkan save messagebox.showerror(title="Error", message="Format tanggal salah") elif len(cUnit) == 0: messagebox.showwarning(title="Peringatan", message="Unit harus diisi.") self.entUnit.focus_set() self.entUnit.delete(0, END) else: sql = "INSERT INTO logbook (no_wo,no_ifca,date_create,time_create,unit,work_req,staff,auth_login)"+\ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s)" val = (cWo, cIfca, cTglBuat, cJamBuat, cUnit, cWorkReq, cStaff, self.user) if (insert_data(sql, val)) == True: messagebox.showinfo(title="Informasi", message="Data sudah di tersimpan.") self.onClear()
def onDelete(self): cIfca = self.entIfca.get() if messagebox.askokcancel( 'Delete Data', 'WO dengan no {} akan dihapus?'.format(cIfca)) == True: sql = "DELETE FROM logbook WHERE no_ifca =%s" val = (cIfca, ) if (insert_data(sql, val)) == True: sql = "DELETE FROM onprogress WHERE no_ifca =%s" val = (cIfca, ) if (insert_data(sql, val)) == True: self.onSearch() #update received sesuai tabel yg dicari messagebox.showinfo(title="Delete {}".format(cIfca), \ message="Data sudah di hapus.") else: pass
def setLock(self): if len(self.entUid.get()) <= 0: return if self.entSts.get() == "Locked": sql = "UPDATE acct SET `lock`=%s, date_lock=%s WHERE uid=%s" val = (False, datetime.now(), self.entUid.get()) if (insert_data(sql, val)) == True: messagebox.showinfo(title="Locking System", \ message="Unlock success.") elif self.entSts.get() == "Usage": sql = "UPDATE acct SET `lock`=%s, date_lock=%s WHERE uid=%s" val = (True, datetime.now(), self.entUid.get()) if (insert_data(sql, val)) == True: messagebox.showinfo(title="Locking System", \ message="Lock success.") else: pass self.refresh()
def doReceive(self, data): receiver = self.user + "." + self.dept tsekarang = datetime.now() sql = "UPDATE logbook SET date_received=%s,received=%s,wo_receiver=%s WHERE no_ifca =%s" val = (tsekarang, True, receiver, data) if (insert_data(sql, val)) == True: # messagebox.showinfo(title="Informasi", \ # message="Wo {} sudah diterima.".format(data)) self.onSearch() #update received sesuai tabel yg dicari
def updateUser(self): try: sql = "UPDATE acct SET last_logout=%s WHERE uid=%s" val = (datetime.now(),self.page3.entUid.get()) if (insert_data(sql,val)) == True: return True else: return False except: # ijinkan exit saat login page (uid undefined) return True
def setDept(self): if len(self.entUid.get()) <= 0: return if messagebox.askokcancel('Setting Department','Set Username: {0} - Dept: {1}?'\ .format(self.entName.get(),self.entDept.get())) == True: sql = "UPDATE acct SET dept=%s, activated=%s WHERE uid=%s" val = (self.entDept.get(), True, self.entUid.get()) if (insert_data(sql, val)) == True: messagebox.showinfo(title="Setting Department", \ message="Data sudah diupdate.") self.refresh()
def proses(self, event=None): sql = "SELECT * FROM acct WHERE username = %s" val = (self.entryUsername.get(), ) data = getdata_one(sql, val) if data != None: uid = data[0] user = data[1] password = data[2] dept = data[4] datecreate = GetSeconds(str(data[5])) matchpw = verify_password(self.entryPassword.get(), password) host_name = socket.gethostname() host_ip = socket.gethostbyname(host_name) # login username samakan saja menjadi lower if (str(self.entryUsername.get()).lower().strip() == user.lower()) \ and (matchpw == True): if data[6] != True: # bagian ceking aktivasi + remove acct datetodrop = datecreate.value + 604800 # 86400*7 (7 hari). Lebih baik buat custom duration = GetDuration(datetodrop - time.time()) messagebox.showerror(title="Belum Aktivasi", \ message="Tidak dapat menggunakan program.\r\nsilahkan hubungi Administrator\r\nuntuk Aktivasi Departement.\ \r\n \ \r\nSisa waktu: {}" .format(duration.value)) # bagian remove account if ((datetodrop - time.time()) <= 0 and RemoveAcct(uid).result == True): messagebox.showwarning( title="Account Info", message="Account Deleted successfully") return if data[7] == True: messagebox.showerror(title="Account dikunci", \ message="Tidak dapat menggunakan program.\r\nAccount anda telah dikunci.") return if data[12] == None: messagebox.showerror(title="Double Login Warning!", \ message="Tidak dapat login program.\r\nAccount anda sedang digunakan.") return sql = "UPDATE acct SET last_login=%s,last_host=%s,last_ip=%s,last_logout=%s WHERE uid=%s" val = (datetime.now(), host_name, host_ip, "", data[0]) if (insert_data(sql, val)) == True: self.user = user self.dept = dept self.top.destroy() else: return else: #untuk salah password self.entryPassword.delete(0, END) self.entryPassword.focus_set() else: self.entryUsername.delete(0, END) self.entryPassword.delete(0, END) self.entryUsername.focus_set()
def proses(self): sql = "SELECT * FROM acct WHERE username = %s" val = (self.entUser.get(), ) data = getdata_one(sql, val) if (self.entUser.get() == ""): self.entUser.focus_set() elif (self.entPass.get() == ""): self.entPass.focus_set() elif (self.entConf.get() == ""): self.entConf.focus_set() elif (self.entEmail.get() == ""): self.entEmail.focus_set() elif data == None: if str(self.entPass.get()).lower() != str( self.entConf.get()).lower(): # parent=self.top karena msgbox with toplevel messagebox.showerror(title="Error",parent=self.top,\ message="Konfirmasi Password tidak sesuai") self.entConf.focus_set() elif len(self.entUser.get()) < 3: messagebox.showerror(title="Error",parent=self.top,\ message="Username harus antara 3 - 10 karakter") self.entUser.focus_set() elif self.entUser.get().isalnum() == False: messagebox.showerror(title="Error",parent=self.top,\ message="Username yang diperbolehkan hanya kombinasi huruf dan angka") self.entUser.focus_set() else: storepw = generate_hash(self.entPass.get()) sql = "INSERT INTO acct (username,passhash,email,dept,date_create,last_logout)"+\ "VALUES(%s,%s,%s,%s,%s,%s)" val = (self.entUser.get().strip(), storepw, self.entEmail.get(), "USER", datetime.now(), datetime.now()) if (insert_data(sql, val)) == True: messagebox.showinfo( title="Account Info", message="Account registration is successful") self.value = self.entUser.get() self.top.destroy() else: user = data[1] password = data[2] dept = data[3] if str(self.entUser.get()).lower().strip() == user.lower(): # parent=self.top karena msgbox with toplevel messagebox.showerror(title="Error",parent=self.top, \ message="User {} sudah terdaftar.\nSilahkan pilih yang lain".format(self.entUser.get())) self.entUser.focus_set()
def __init__(self, uid): sql = "DELETE FROM acct WHERE uid =%s" val = (uid, ) self.result = False if (insert_data(sql, val)) == True: self.result = True
def onUpdate(self): #panel kiri cWo = self.entWo.get() cIfca = self.entIfca.get() cTglBuat = store_date(self.entTglbuat.get()) #check tgl dulu cWorkReq = self.entWorkReq.get('1.0', 'end').upper().strip() cStaff = self.entStaff.get().upper().strip() cStatus = self.opsiStatus.get() cTimeAcc = datetime.now() #panel kanan cWorkAct = self.entWorkAct.get('1.0', 'end').upper().strip() cTglDone = store_date(self.entTgldone.get()) #check tgl dulu jamdone = self.entJamdone.get() #eksekusi sql if len(cWorkReq) <= 0: messagebox.showwarning(title="Peringatan", message="Work Request harus diisi.") self.entWorkReq.focus_set() self.entWorkReq.delete('1.0', 'end') return # stop aja karena cWorkAct tidak diisi if cStatus == "DONE": if len(cStaff) <= 0: messagebox.showwarning(title="Peringatan", message="Staff ENG harus diisi.") self.entStaff.focus_set() self.entStaff.delete(0, END) return # stop aja karena cStaff tidak diisi elif len(cWorkAct) <= 0: messagebox.showwarning(title="Peringatan", message="Work Action harus diisi.") self.entWorkAct.focus_set() self.entWorkAct.delete('1.0', 'end') return # stop aja karena cWorkAct tidak diisi elif len(cTglDone) == 0 or len(jamdone.strip()) != 5: messagebox.showerror(title="Error", message="Format tanggal salah") return # stop aja karena tanggal tidak diisi else: pass elif cStatus == "PENDING": cTglDone = "" jamdone = "" com_auth_by = cStaff + "@" + self.user if len(cStaff) <= 0: messagebox.showwarning(title="Peringatan", message="Staff ENG harus diisi.") self.entStaff.focus_set() self.entStaff.delete(0, END) return # stop aja karena cStaff tidak diisi elif len(cWorkAct) <= 0: messagebox.showwarning(title="Peringatan", message="Work Action harus diisi.") self.entWorkAct.focus_set() self.entWorkAct.delete('1.0', 'end') return # stop aja karena cWorkAct tidak diisi else: ### jgn eksekusi sekarang mungkin? sql = "INSERT INTO onprogress (no_ifca,date_update,commit_update,auth_by,auth_login,auth_dept)"+\ "VALUES(%s,%s,%s,%s,%s,%s)" val = (cIfca, cTimeAcc, cWorkAct, com_auth_by, self.user, self.dept) print("Pending store data,", insert_data(sql, val)) elif cStatus == "CANCEL": cTglDone = "" jamdone = "" if len(cWorkAct) <= 0: messagebox.showwarning(title="Peringatan", message="Work Action harus diisi.") self.entWorkAct.focus_set() self.entWorkAct.delete('1.0', 'end') return # stop aja karena cWorkAct tidak diisi else: # UPDATE tidak perlu tanggal cTglDone = "" jamdone = "" curItem = self.tabelIfca.item(self.tabelIfca.focus()) if cWorkReq == curItem['values'][4] and \ cStaff == curItem['values'][5] and cWorkAct == curItem['values'][6]: print("Tidak ada aktivitas perubahan") else: sql = "UPDATE logbook SET no_wo=%s,no_ifca=%s,date_create=%s,work_req=%s,staff=%s,\ status_ifca=%s,date_done=%s,time_done=%s,work_act=%s,auth_login=%s WHERE no_ifca =%s" val = (cWo, cIfca, cTglBuat, cWorkReq, cStaff, cStatus, cTglDone, jamdone, cWorkAct, self.user, cIfca) if (insert_data(sql, val)) == True: messagebox.showinfo(title="Informasi", \ message="Data sudah di terupdate.") self.onSearch()
def proses_import(self): # section return (abort) if (self.dept != "ROOT"): messagebox.showerror(title="Prohibited", \ message="This command is reserved for Administrator") self.btnImportCsv.grid_forget() return fnames = filedialog.askopenfilename(filetypes=[("Excel CSV", "*.csv")]) if not fnames: print("open file canceled") return with open(fnames) as cek_header: reader = csv.reader(cek_header) for row in reader: if row == header_csv: break else: messagebox.showerror(title="Import File Error", \ message="The header file is invalid!") return with open(fnames) as countrow: reader = csv.reader(countrow) next(reader) # skip the heading lines = len(list(reader)) # jumlah baris dalam file setelah header # lines = sum(1 for row in reader) # ini juga bisa hitung jumlah baris if lines > 5000: messagebox.showerror(title="Import File Error", \ message="Row count: {}. Maximum is 5000".format(lines)) return # section processing start = time.perf_counter() progbar = SetProgBar(self.parent, lines) with open(fnames) as input_file: reader = csv.reader(input_file) next(reader) # skip the heading update = 0 insert = 0 for rowno, row in enumerate(reader): if (row[0].isdigit() == False): # abaikan selain index=digit continue if self.checkifca( row[2]) == False: #check IFCA, jika ada update aja # print("IFCA",row[2],"Sudah terdaftar") sql = "UPDATE logbook SET date_create=%s,time_create=%s,unit=%s,work_req=%s WHERE no_ifca =%s" val = (store_date(row[3]), row[4], row[5], row[6], row[2]) if (insert_data(sql, val)) == True: update += 1 else: messagebox.showerror(title="Import File Error", \ message="Fail on Update {}".format(row[2])) else: # insert baru sql = "INSERT INTO logbook (no_wo,no_ifca,date_create,time_create,unit,work_req,staff,\ work_act,date_done,time_done,status_ifca,received,wo_receiver,date_received,auth_login)" +\ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" # val = (row) val = (row[1],row[2],store_date(row[3]),row[4],row[5],row[6],row[7],row[8],\ store_date(row[9]),row[10],row[11],row[12],row[13],store_date(row[14]),row[15]) if (insert_data(sql, val)) == True: insert += 1 else: messagebox.showerror(title="Import File Error", \ message="Fail on New Insert {}".format(row[2])) progbar.bytes = rowno + 1 finish = time.perf_counter() usedsecs = finish - start if usedsecs > 60: usedsecs = GetDuration(usedsecs).value messagebox.showinfo(title="Import File Result", \ message="Update IFCA: {0}\r\nNew Record: {1}\r\nTime Used: {2}"\ .format(update,insert,usedsecs)) self.onSearch() #Refresh table by search