def Confirm(self): try: if self.BusinessEntity == None: project = Project.Project(None, self.ProjectOmschrijvingVar.get(), self.ProjectIDVar.get(), self.Button.get(), True) if project.Button == '': project.Button = None bl = BLProject.BLProject(self.Connection) bl.Create(project) else: project = self.BusinessEntity project.Description = self.ProjectOmschrijvingVar.get() project.ExterneId = self.ProjectIDVar.get() project.Button = self.Button.get() if project.Button == '': project.Button = None bl = BLProject.BLProject(self.Connection) bl.Update(project) except sqlite3.IntegrityError as e: messagebox.showerror('Error', 'Button must be unique') Logger.LogError(str(e)) return except Exception as e: Logger.LogError(str(e)) return finally: self.Quit()
def RefreshAllStaticData(self): Logger.LogInfo('Refreshing all static data') self.DayViews = self.blVwD.GetAll() self.ActiveProjects = self.blPr.GetAll(False) self.AllProjects = self.blPr.GetAll() self.RecordTypes = self.blRt.GetAll() Logger.LogInfo('Done refreshing all static data')
def __init__(self): config = configparser.ConfigParser() config.read('config.ini') try: self.Connection = sqlite3.connect( config['DEFAULT']['DataBaseName']) Logger.LogInfo('DataBase Connection Established') except Exception as e: Logger.LogError(str(e))
def __init__(self, conn): Logger.LogInfo('Cache: Initializing Cache') self.blTrv = BLTimeRecordView.BLTimeRecordView(conn) self.blVwD = BLDayView.BLDayView(conn) self.blPr = BLProject.BLProject(conn) self.blRt = BLRecordType.BLRecordType(conn) self.blTr = BLTimeRecord.BLTimeRecord(conn) self.DayViews = self.blVwD.GetAll() self.ActiveProjects = self.blPr.GetAll(False) self.AllProjects = self.blPr.GetAll() self.RecordTypes = self.blRt.GetAll() self.TimeRecordViews = [] self.TimeRecords = [] Logger.LogInfo('Cache: Cache initialized')
def ConvertToEuropeanTime(dateString): try: timeArray = dateString.split('-') year = timeArray[0] month = timeArray[1] day = timeArray[2] return year + '-' + month + '-' + day except Exception as e: Logger.LogError(e)
def CopyToCodex(dbConn, date): try: blTr = BLTimeRecord.BLTimeRecord(dbConn) timeRecords = blTr.GetAllForDate(date) blPr = BLProject.BLProject(dbConn) blRt = BLRecordType.BLRecordType(dbConn) sequence = '' for item in timeRecords: item1 = blPr.GetProjectExterneID(item.ProjectID) item2 = blRt.GetRecordTypeExterneID(item.RecordTypeID) s1Time = time.strptime(item.StartHour, "%Y-%m-%d %H:%M") s2Time = time.strptime(item.EndHour, "%Y-%m-%d %H:%M") item3 = time.strftime("%H:%M", s1Time) item4 = time.strftime("%H:%M", s2Time) item5 = item.Description s = "" string1 = "" string2 = "" item.StatusID = TimeRecordStatusEnum.TimeRecordStatusEnum.Gekopieerd.value blTr.Update(item) if len(item5) > 30: items = item5.split(" ") countChar = 0 indexToSplit = 0 for i in range(0, len(items)): countChar = countChar + len(items[i]) if i > 30: indexToSplit = i - 1 break filler = " " if indexToSplit == 0: indexToSplit = 30 filler = "" list1 = item5[0:indexToSplit] list2 = item5[indexToSplit:] string1 = filler.join(list1) string2 = filler.join(list2) else: string1 = item5 km = "\t" if not item.Km is None: km = str(item.Km) + "\t" line = (item1, "\t", "\t", "\t", item2, "\t", "\t", "\t", km, "\t", item3, "\t", item4, "\t", string1, "\t", string2, "\n") sequence = sequence + s.join(line) return sequence except Exception as e: Logger.LogError(str(e))
def Confirm(self): try: if self.BusinessEntity == None: recordType = RecordType.RecordType( None, self.RecordTypeOmschrijving.get(), self.RecordTypeExterneID.get()) bl = BLRecordType.BLRecordType(self.Connection) bl.Create(recordType) else: recordType = self.BusinessEntity recordType.Description = self.RecordTypeOmschrijving.get() recordType.ExterneId = self.RecordTypeExterneID.get() bl = BLRecordType.BLRecordType(self.Connection) bl.Update(recordType) self.Master.quit() except Exception as e: Logger.LogError(str(e)) return
def GetLastLogon(): try: user = getpass.getuser() start_date = datetime.datetime.now() + datetime.timedelta(days=-1) end_date = start_date + datetime.timedelta(days=2) dtmStartDate = datetime.datetime.strftime(start_date, '%Y%m%d000000.000000-480') #dtmStartDate = '20180512000000.000000-480' dtmEndDate = datetime.datetime.strftime(end_date, '%Y%m%d000000.000000-480') # Initialize WMI objects and query. wmi_o = wmi.WMI('.') wql = ("Select * from Win32_NTLogEvent Where TimeWritten > '" + dtmStartDate + "' and TimeWritten < '" + dtmEndDate + "'" + "and EventCode =" + str(4672)) # Query WMI object. wql_r = wmi_o.query(wql) t = None for i in wql_r: if i.InsertionStrings[1] == user: t = i.TimeGenerated break # year = t[:4] # month = t[4:6] # day = t[6:8] hour = "" minutes = "" if not t is None: hour = str(int(t[8:10]) + 2) minutes = t[10:12] return hour + ":" + minutes # + " " + day + "-" + month + "-" + year except Exception as e: Logger.LogError(e)
def CloseConnection(self): Logger.LogInfo('DataBase Connection Closed') self.Connection.close()
def __init__(self, master, connection): #Reset Database if necessary Globals.ClearUserTables(connection) self.Config = configparser.ConfigParser() self.Config.read('config.ini') #Main Window self.Master = master self.Master.title("Hour Registration") #Database connection self.dbConnection = connection #Initialize Cache self.Cache = Cache.Cache(connection) #Initialize String Vars self.RecordTypeValue = StringVar() self.ProjectValue = StringVar() self.DescriptionValue = StringVar() self.LastLogon = StringVar() self.LastLogon.set(Globals.GetLastLogon()) #Designer self.DaysCombo = ttk.Combobox(master) self.DaysCombo.grid(row=0, column=0, sticky='NSEW', columnspan=3) self.RecordButton = Button(master, text="Start Recording", command=self.StartRecording) self.RecordButton.grid(row=1, column=0, sticky='NSEW') self.RecordIcon = PhotoImage(file=".\\Resources\\add.png") self.RecordButton.config(image=self.RecordIcon, width="32", height="32") self.DeleteRecordButton = Button(master, text="Delete Record", command=self.DeleteRecord) self.DeleteRecordButton.grid(row=1, column=1, sticky='NSEW') self.DeleteRecordIcon = PhotoImage(file=".\\Resources\\delete.png") self.DeleteRecordButton.config(image=self.DeleteRecordIcon, width="32", height="32") self.StopRecordButton = Button(master, text="Stop Recording", command=self.StopRecording) self.StopRecordButton.grid(row=1, column=2, sticky='NSEW') self.StopRecordIcon = PhotoImage(file=".\\Resources\\stop.png") self.StopRecordButton.config(image=self.StopRecordIcon, width="32", height="32") self.CopyToCodexButton = Button(master, text="Copy To Codex", command=self.CopyToCodex) self.CopyToCodexButton.grid(row=2, column=0, sticky='NSEW') self.CopyIcon = PhotoImage(file=".\\Resources\\copyCodex.png") self.CopyToCodexButton.config(image=self.CopyIcon, width="32", height="32") self.ExcelButton = Button(master, text="Export", command=self.ExportToExcel) self.ExcelButton.grid(row=2, column=1, sticky='NSEW') self.ExcelIcon = PhotoImage(file=".\\Resources\\excel.png") self.ExcelButton.config(image=self.ExcelIcon, width="32", height="32") self.ProjectButton = Button(master, text="Project", command=self.OpenProjectListForm) self.ProjectButton.grid(row=2, column=2, sticky='NSEW') self.ProjectIcon = PhotoImage(file=".\\Resources\\add_project.png") self.ProjectButton.config(image=self.ProjectIcon, width="32", height="32") self.CopyRecordButton = Button(master, text="CopyRecord", command=self.CopyRecord) self.CopyRecordButton.grid(row=3, column=0, sticky='NSEW') self.CopyRecordIcon = PhotoImage(file=".\\Resources\\copy.png") self.CopyRecordButton.config(image=self.CopyRecordIcon, width="32", height="32") self.OneNoteButton = Button(master, text="OneNote", command=self.OpenInOneNote) self.OneNoteButton.grid(row=3, column=1, sticky='NSEW') self.OneNoteIcon = PhotoImage(file=".\\Resources\\onenote.png") self.OneNoteButton.config(image=self.OneNoteIcon, width="32", height="32") self.AddTimeRecordButton = Button(master, text="AddTimeRecordButton", command=self.ShowNewEditForm) self.AddTimeRecordButton.grid(row=3, column=2, sticky="NSEW") self.AddTimeRecordIcon = PhotoImage( file=".\\Resources\\application_add.png") self.AddTimeRecordButton.config(image=self.AddTimeRecordIcon, width="32", height="32") self.BackupButton = Button(master, text="BackupButton", command=self.DatabaseBackup) self.BackupButton.grid(row=4, column=0, sticky="NSEW") self.BackupButtonIcon = PhotoImage(file=".\\Resources\\angel.png") self.BackupButton.config(image=self.BackupButtonIcon, width="32", height="32") self.RecordTypeButton = Button(master, text="RecordType", command=self.OpenRecordTypeListForm) self.RecordTypeButton.grid(row=4, column=1, sticky="NSEW") self.RecordTypeButtonIcon = PhotoImage( file=".\\Resources\\recordType.png") self.RecordTypeButton.config(image=self.RecordTypeButtonIcon, width="32", height="32") self.ExportToGraphsButton = Button(master, text="ExportToGraphs", command=self.ExportToGraph) self.ExportToGraphsButton.grid(row=4, column=2, sticky="NSEW") self.ExportToGraphsButtonIcon = PhotoImage( file=".\\Resources\\chart.png") self.ExportToGraphsButton.config(image=self.ExportToGraphsButtonIcon, width="32", height="32") self.ProjectsCombo = ttk.Combobox(master, textvariable=self.ProjectValue) self.ProjectsCombo.grid(row=0, column=3, columnspan=2, sticky='NSEW') self.RecordTypeCombo = ttk.Combobox(master, textvariable=self.RecordTypeValue) self.RecordTypeCombo.grid(row=1, column=3, columnspan=2, sticky='NSEW') self.DescriptionTextBox = Entry(master, textvariable=self.DescriptionValue) self.DescriptionTextBox.grid(row=2, column=3, columnspan=2, sticky='NSEW') self.RecordsListBox = Listbox(master, width=50) self.RecordsListBox.grid(row=3, column=3, rowspan=7, columnspan=1, sticky='NSEW') self.CommentListBox = Listbox(master, width=70) self.CommentListBox.grid(row=3, column=4, rowspan=7, columnspan=2, sticky='NSEW') self.CommentListBox.bindtags((self.CommentListBox, master, "all")) self.EventLogExplanationLabel = Label(master, text="Laatst aangemeld op: ") self.EventLogExplanationLabel.grid(row=0, column=5) self.EventLogLabel = Label(master, textvariable=self.LastLogon) self.EventLogLabel.grid(row=1, column=5) self.DaysCombo.bind("<<ComboboxSelected>>", self.DaysCombo_SelectedItemChanged) self.RecordsListBox.bind("<<ListboxSelect>>", self.RecordsListBox_SelectedItemChanged) self.RecordsListBox.bind('<Double-1>', lambda x: self.ShowEditForm()) #End Designer #Set Form Controls self.FillCombos() self.SetButtonsEnabled() self.Queue = queue.Queue(10) self.KillEvent = threading.Event() self.ControllerThread = threading.Thread(target=self.ctrl, args=(self.Queue, self.KillEvent)) self.ControllerThread.start() Logger.LogInfo(self.ControllerThread.getName() + ' started.') self.CheckForUpdatesFromController()
def RefreshRecordTypes(self): Logger.LogInfo('Refresh RecordTypes') self.RecordTypes = self.blRt.GetAll() Logger.LogInfo('Done refreshing recordtypes')
def RefreshProjects(self): Logger.LogInfo('Refreshing Projects') self.ActiveProjects = self.blPr.GetAll(False) self.AllProjects = self.blPr.GetAll() Logger.LogInfo('Done refreshing projects')
def RefreshDayViews(self): Logger.LogInfo('Refreshing DayViews') self.DayViews = self.blVwD.GetAll() Logger.LogInfo('Done refreshing DayViews')
def RefreshTimeRecordsForDate(self, date): Logger.LogInfo('Refreshing TimeRecords for date: ' + date) self.TimeRecordViews = self.blTrv.GetAllForDate(date) self.TimeRecords = self.blTr.GetAllForDate(date) Logger.LogInfo('Done refreshing TimeRecords')
from DataAccess.DataBaseConnection import DataBaseConnection from BusinessEntities import * from DataAccess.DAProject import DAProject from DataAccess.DAController import DAController from GUI.MainScreen import MainScreen from DataAccess.Log import Logger from tkinter import Tk, ttk #Handle Project Initialisations root = Tk() databaseConnection = DataBaseConnection() mainScreen = MainScreen(root, databaseConnection) try: Logger.LogInfo('Application Starting...') mainScreen.Show() except Exception as e: Logger.LogError(str(e), True) finally: mainScreen.KillEvent.set() mainScreen.ControllerThread.join() Logger.LogInfo('Application Stopping...') databaseConnection.CloseConnection()