def CheckForUpdatesFromController(self): if not self.Queue.empty(): queue = self.Queue.get() blPr = BLProject.BLProject(self.dbConnection) project = blPr.GetByButton(queue) if project is not None: print(project.Description) recordType = 1 blTr = BLTimeRecord.BLTimeRecord(self.dbConnection) for record in self.Cache.TimeRecords: if record.StatusID == TimeRecordStatusEnum.TimeRecordStatusEnum.Gestart.value: record.StatusID = TimeRecordStatusEnum.TimeRecordStatusEnum.Gestopt.value record.EndHour = Globals.GetCurrentTime() blTr.Update(record) timeRecord = TimeRecord.TimeRecord( None, Globals.GetCurrentTime(), None, project.ID, recordType, 'Automatically generated', TimeRecordStatusEnum.TimeRecordStatusEnum.Gestart.value, 0, None, None) valid = TimeRecordValidation.TimeRecordValidation() validationMessage = valid.ValidateOnCreation(timeRecord) if not len(validationMessage) == 0: errorMessage = '' for i in validationMessage: errorMessage = errorMessage + i + '\n' messagebox.showerror('Error', errorMessage) else: index = self.DaysCombo.current() blTr.Create(timeRecord) self.Cache.RefreshAllStaticData() self.FillCombos() if index == -1: index = 0 self.DaysCombo.current(index) self.RefreshTimeRecords() self.Master.after(500, self.CheckForUpdatesFromController)
def CopyTimeRecord(self, timeRecord): timeRecord.ID = None timeRecord.StartHour = Globals.GetCurrentTime() timeRecord.EndHour = None timeRecord.StatusID = TimeRecordStatusEnum.TimeRecordStatusEnum.Gestart.value timeRecord.Minutes = 0 self.Create(timeRecord)
def CopyToCodex(self): self.Master.clipboard_clear() index = self.DaysCombo.current() date = self.Cache.DayViews[index].Date self.Master.clipboard_append( Globals.CopyToCodex(self.dbConnection, date)) self.RefreshTimeRecords()
def StartRecording(self): recordIndex = self.RecordTypeCombo.current() projectIndex = self.ProjectsCombo.current() if recordIndex == -1: recordType = '' else: recordType = self.Cache.RecordTypes[recordIndex].ID if projectIndex == -1: project = None else: project = self.Cache.ActiveProjects[projectIndex].ID timeRecord = TimeRecord.TimeRecord( None, Globals.GetCurrentTime(), None, project, recordType, self.DescriptionValue.get(), TimeRecordStatusEnum.TimeRecordStatusEnum.Gestart.value, 0, None, None) valid = TimeRecordValidation.TimeRecordValidation() validationMessage = valid.ValidateOnCreation(timeRecord) if not len(validationMessage) == 0: errorMessage = '' for i in validationMessage: errorMessage = errorMessage + i + '\n' messagebox.showerror('Error', errorMessage) else: index = self.DaysCombo.current() blTr = BLTimeRecord.BLTimeRecord(self.dbConnection) blTr.Create(timeRecord) self.Cache.RefreshAllStaticData() self.FillCombos() if index == -1: index = 0 self.DaysCombo.current(index) self.RefreshTimeRecords()
def Confirm(self): # projectID = self.conn.GetProjectID(self.ProjectValue.get()) # recordTypeID = self.conn.GetRecordTypeID(self.RecordTypeValue.get()) # self.conn.UpdateSelectedRecord(self.RecordID,projectID,recordTypeID,self.StartDate.get(),self.EndDate.get(),self.DescriptionValue.get()) blTr = BLTimeRecord.BLTimeRecord(self.Connection) blPr = BLProject.BLProject(self.Connection) blRt = BLRecordType.BLRecordType(self.Connection) Tr = blTr.GetById(self.RecordID) Tr.Description = self.DescriptionValue.get() timeString = Globals.ConvertToAmericanDate(self.TimeRecord.Date) + ' 00:00' Tr.StartHour = self.GetDate(timeString,self.StartDate.get()) if not self.EndDate.get() =='': Tr.EndHour = self.GetDate(Tr.StartHour,self.EndDate.get()) Tr.ProjectID = blPr.GetProjectIDFromDescription(self.ProjectValue.get()) Tr.RecordTypeID = blRt.GetRecordTypeIDFromDescription(self.RecordTypeValue.get()) Tr.Km = self.KmValue.get() oneNoteLink = self.OneNoteValue.get() try: if not oneNoteLink=="" and not oneNoteLink.startswith("onenote"): secondPart = oneNoteLink.split("onenote")[1] oneNoteLink = "onenote"+secondPart except: oneNoteLink = "" messagebox.showerror('Error',"No valid link found") return Tr.OneNoteLink = oneNoteLink if not self.IsNew: blTr.Update(Tr) else: Tr.StatusID = TimeRecordStatusEnum.TimeRecordStatusEnum.Gestopt.value blTr.Create(Tr) self.Master.quit()
def Confirm(self): blE = BLExcel.BLExcel(self.Connection) fromDate = self.DateFrom.get() toDate = self.DateTo.get() blTrV = BLTimeRecordView.BLTimeRecordView(self.Connection) timeRecords = blTrV.GetAllBetweenDates(fromDate, toDate) result = messagebox.askquestion( "Validatie", "{0} records geselecteerd. Doorgaan?".format(len(timeRecords)), icon='warning') if result == 'yes': file_path = filedialog.askdirectory() file_path = file_path + "/" + Globals.GetCurrentDay() blE.ExportToExcel(timeRecords, file_path) self.Master.quit()
def StopRecording(self): blTr = BLTimeRecord.BLTimeRecord(self.dbConnection) sel = self.RecordsListBox.curselection()[0] timeRecordView = self.Cache.TimeRecordViews[sel] timeRecord = blTr.GetById(timeRecordView.ID) timeRecord.EndHour = Globals.GetCurrentTime() timeRecord.StatusID = TimeRecordStatusEnum.TimeRecordStatusEnum.Gestopt.value blTr.Update(timeRecord) index = self.DaysCombo.current() self.DaysCombo.current(0) self.Cache.RefreshAllStaticData() self.FillCombos() self.DaysCombo.current(index) self.RefreshTimeRecords() self.SetButtonsEnabled()
def SetButtonsEnabled(self): enableStop = True enableCopyToCodex = True enableDelete = True enableCopyRecord = True enableOpenOneNote = True indexDaysCombo = self.DaysCombo.current() indexRecordsListBox = self.RecordsListBox.curselection() current = Globals.GetCurrentDay() if indexDaysCombo == -1: enableStop = False enableCopyToCodex = False else: date = self.Cache.DayViews[indexDaysCombo].Date if not current == date: enableStop = False bl = BLTimeRecord.BLTimeRecord(self.dbConnection) records = bl.GetAllForDate(date) for record in records: if record.StatusID == TimeRecordStatusEnum.TimeRecordStatusEnum.Gestart.value: enableCopyToCodex = False if len(indexRecordsListBox) == 0: enableStop = False enableDelete = False enableCopyRecord = False enableOpenOneNote = False else: trView = self.Cache.TimeRecordViews[indexRecordsListBox[0]] if trView.OneNoteLink == 'None' or trView.OneNoteLink == "": enableOpenOneNote = False self.SetButton(enableStop, self.StopRecordButton) self.SetButton(enableCopyToCodex, self.CopyToCodexButton) self.SetButton(enableDelete, self.DeleteRecordButton) self.SetButton(enableCopyRecord, self.CopyRecordButton) self.SetButton(enableOpenOneNote, self.OneNoteButton)
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()