예제 #1
0
    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 1
        tk.Label(w, text="Actions:").grid(row=r, sticky=tk.W)
        self.cbActions = ttk.Combobox(w, )
        self.cbActions.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Description:").grid(row=r, sticky=tk.W)
        self.txDescription = ttk.Entry(
            w,
            textvariable=self.description,
        )
        self.txDescription.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Modified:").grid(row=r, column=0, sticky=tk.W)
        self.modified_date = Calendarium(self, "")
        self.modified_date.get_calendarium(w, r, c)

        r += 1
        ttk.Label(w, text="Enable:").grid(row=r, sticky=tk.W)
        chk = ttk.Checkbutton(w, onvalue=1, offvalue=0, variable=self.enable)
        chk.grid(row=r, column=c, sticky=tk.W)

        if self.index is not None:
            self.engine.get_save_cancel_delete(self, w)
        else:
            self.engine.get_save_cancel(self, w)
예제 #2
0
파일: counts.py 프로젝트: dxdinh/Biovarase
    def init_ui(self):

        w = self.nametowidget(".").engine.get_init_ui(self)

        self.export_date = Calendarium(self, "Export From")
        self.export_date.get_calendarium(w, 0, 0)

        self.nametowidget(".").engine.get_export_cancel(self, self)
예제 #3
0
    def init_ui(self):

        w = self.nametowidget(".").engine.get_init_ui(self)

        r = 0
        self.start_date = Calendarium(self, "Start Date")
        self.start_date.get_calendarium(w, r)

        self.nametowidget(".").engine.get_export_cancel(self, w)
예제 #4
0
    def init_ui(self):

        w = self.nametowidget(".").engine.get_init_ui(self)

        r = 0
        c = 0

        self.analysis_date = Calendarium(self, "Set a date")
        self.analysis_date.get_calendarium(w, r, c)

        self.nametowidget(".").engine.get_export_cancel(self, self)
예제 #5
0
class UI(tk.Toplevel):
    def __init__(self, parent, *args, **kwargs):
        super().__init__(name='quick_data_analysis')

        self.attributes('-topmost', True)
        self.transient(parent)
        self.resizable(0, 0)
        self.parent = parent
        self.engine = kwargs['engine']
        self.engine.center_me(self)
        self.init_ui()

    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 0

        self.analysis_date = Calendarium(self, "Set a date")
        self.analysis_date.get_calendarium(w, r, c)

        self.engine.get_export_cancel(self, self)

    def on_open(self):

        sql = "SELECT date(recived) FROM results WHERE enable= 1 ORDER BY recived DESC LIMIT 1;"

        rs = self.engine.read(
            False,
            sql,
        )

        msg = "Quick Data Analysis last data {0}".format(rs[0])

        self.analysis_date.year.set(int(rs[0][0:4]))
        self.analysis_date.month.set(int(rs[0][5:7]))
        self.analysis_date.day.set(int(rs[0][8:10]))

        self.title(msg)

    def on_export(self, evt=None):

        if self.analysis_date.get_date(self) == False: return

        args = (self.analysis_date.get_date(self), )
        self.engine.get_quick_data_analysis(args)
        self.on_cancel()

    def on_cancel(self, evt=None):
        self.destroy()
예제 #6
0
파일: result.py 프로젝트: ra2003/Biovarase
    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 1
        ttk.Label(w, text="Test:").grid(row=r, sticky=tk.W)
        lbl = ttk.Label(w, style='Data.TLabel', textvariable=self.test)
        lbl.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Batch:").grid(row=r, sticky=tk.W)
        lbl = ttk.Label(w, style='Data.TLabel', textvariable=self.batch)
        lbl.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Result:").grid(row=r, sticky=tk.W)
        self.txtResult = ttk.Entry(w,
                                   width=8,
                                   justify=tk.CENTER,
                                   validate='key',
                                   validatecommand=self.vcmd,
                                   textvariable=self.result)
        self.txtResult.grid(row=r, column=1, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Recived:").grid(row=r, sticky=tk.N + tk.W)

        self.recived_date = Calendarium(self, "")
        self.recived_date.get_calendarium(w, r, c)

        r += 1
        lbl = ttk.Label(w, text="Time:").grid(row=r, sticky=tk.W)
        lbl = ttk.Label(w, style='Data.TLabel', textvariable=self.recived_time)
        lbl.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Enable:").grid(row=r, sticky=tk.W)
        chk = ttk.Checkbutton(
            w,
            onvalue=1,
            offvalue=0,
            variable=self.enable,
        )
        chk.grid(row=r, column=c, sticky=tk.W)

        if self.index is not None:
            self.engine.get_save_cancel_delete(self, w)
        else:
            self.engine.get_save_cancel(self, w)
예제 #7
0
    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 1
        ttk.Label(w, text="Batch:").grid(row=r, sticky=tk.W)
        self.txtBatch = ttk.Entry(w, textvariable=self.batch)
        self.txtBatch.grid(row=r, column=c, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Expiration:").grid(row=r, sticky=tk.N+tk.W)
        self.expiration_date = Calendarium(self, "")
        self.expiration_date.get_calendarium(w, r, c)


        r += 1
        ttk.Label(w, text="Target:").grid(row=r, sticky=tk.W)
        self.txtTarget = ttk.Entry(w,
                                   width=8,
                                   justify=tk.CENTER,
                                   validate='key',
                                   validatecommand=self.vcmd,
                                   textvariable=self.target)
        self.txtTarget.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="SD:").grid(row=r, sticky=tk.W)
        self.txtSD = ttk.Entry(w,
                               width=8,
                               justify=tk.CENTER,
                               validate='key',
                               validatecommand=self.vcmd,
                               textvariable=self.sd)
        self.txtSD.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Enable:").grid(row=r, sticky=tk.W)
        chk = ttk.Checkbutton(w, onvalue=1, offvalue=0, variable=self.enable)
        chk.grid(row=r, column=c, sticky=tk.W)

        self.engine.get_save_cancel(self, w)
예제 #8
0
    def init_ui(self):

        self.pack(fill=tk.BOTH, expand=1)

        f = ttk.Frame()

        self.start_date = Calendarium(self, "Start Date")
        self.end_date = Calendarium(self, "End Date")

        self.start_date.get_calendarium(f, )
        self.end_date.get_calendarium(f, )

        w = ttk.Frame()

        ttk.Button(w, text="Print Date", command=self.on_callback).pack()
        ttk.Button(w, text="Set Today", command=self.on_reset).pack()
        ttk.Button(w, text="Compare", command=self.on_compare).pack()
        ttk.Button(w, text="Close", command=self.on_close).pack()

        f.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
        w.pack(side=tk.RIGHT, fill=tk.BOTH, expand=1)
예제 #9
0
파일: counts.py 프로젝트: ra2003/Biovarase
class UI(tk.Toplevel):
    def __init__(self, parent, engine, index=None):
        super().__init__(name='counts')

        self.resizable(0, 0)
        self.parent = parent
        self.engine = engine
        self.index = index
        self.center_me()
        self.init_ui()

    def center_me(self):

        #center window
        x = (self.winfo_screenwidth() - self.winfo_reqwidth()) / 2
        y = (self.winfo_screenheight() - self.winfo_reqheight()) / 2
        self.geometry("+%d+%d" % (x, y))

    def init_ui(self):

        w = self.engine.get_init_ui(self)

        self.export_date = Calendarium(self, "Export From")
        self.export_date.get_calendarium(w, 0, 0)

        self.engine.get_export_cancel(self, self)

    def on_open(self):

        self.export_date.set_today()

        self.title("Export Counts")

    def on_export(self, evt=None):

        if self.export_date.get_date(self) == False: return
        if messagebox.askyesno(self.engine.title, "Export data?",
                               parent=self) == True:
            args = (self.export_date.get_date(self), )
            self.engine.get_counts(args)
            self.on_cancel()

    def on_cancel(self, evt=None):
        self.destroy()
예제 #10
0
class UI(tk.Toplevel):
    def __init__(self, parent):
        super().__init__(name='export_rejection')

        self.parent = parent
        self.resizable(0, 0)
        self.transient(parent)

        self.init_ui()
        self.nametowidget(".").engine.center_me(self)

    def init_ui(self):

        w = self.nametowidget(".").engine.get_init_ui(self)

        r = 0
        self.start_date = Calendarium(self, "Start Date")
        self.start_date.get_calendarium(w, r)

        self.nametowidget(".").engine.get_export_cancel(self, w)

    def on_open(self):

        self.start_date.set_today()

        self.title("Export Rejections Data")

    def on_export(self, evt=None):

        if self.start_date.get_date(self) == False: return

        if messagebox.askyesno(self.nametowidget(".").title(),
                               "Export data?",
                               parent=self) == True:
            args = (self.start_date.get_date(self), )
            self.nametowidget(".").engine.get_rejections(args)
            self.on_cancel()

    def on_cancel(self, evt=None):
        self.destroy()
예제 #11
0
파일: counts.py 프로젝트: dxdinh/Biovarase
class UI(tk.Toplevel):
    def __init__(self, parent):
        super().__init__(name='counts')

        self.parent = parent
        self.attributes('-topmost', True)
        self.resizable(0, 0)
        self.init_ui()
        self.nametowidget(".").engine.center_me(self)

    def init_ui(self):

        w = self.nametowidget(".").engine.get_init_ui(self)

        self.export_date = Calendarium(self, "Export From")
        self.export_date.get_calendarium(w, 0, 0)

        self.nametowidget(".").engine.get_export_cancel(self, self)

    def on_open(self):

        self.export_date.set_today()

        self.title("Export Counts")

    def on_export(self, evt=None):

        if self.export_date.get_date(self) == False: return
        if messagebox.askyesno(self.nametowidget(".").title(),
                               "Export data?",
                               parent=self) == True:
            args = (self.export_date.get_date(self), )
            self.nametowidget(".").engine.get_counts(args)
            self.on_cancel()

    def on_cancel(self, evt=None):
        self.destroy()
예제 #12
0
파일: batch.py 프로젝트: ra2003/Biovarase
class UI(tk.Toplevel):
    def __init__(self, parent, *args, **kwargs):
        super().__init__(name='batch')

        self.attributes('-topmost', True)
        self.transient(parent)
        self.resizable(0, 0)

        self.parent = parent
        self.engine = kwargs['engine']
        self.index = kwargs['index']

        self.batch = tk.StringVar()
        self.target = tk.DoubleVar()
        self.sd = tk.DoubleVar()
        self.enable = tk.BooleanVar()

        self.vcmd = self.engine.get_validate_float(self)
        self.engine.center_me(self)
        self.init_ui()

    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 1
        ttk.Label(w, text="Batch:").grid(row=r, sticky=tk.W)
        self.txtBatch = ttk.Entry(w, textvariable=self.batch)
        self.txtBatch.grid(row=r, column=c, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Expiration:").grid(row=r, sticky=tk.N + tk.W)
        self.expiration_date = Calendarium(self, "")
        self.expiration_date.get_calendarium(w, r, c)

        r += 1
        ttk.Label(w, text="Target:").grid(row=r, sticky=tk.W)
        self.txtTarget = ttk.Entry(w,
                                   width=8,
                                   justify=tk.CENTER,
                                   validate='key',
                                   validatecommand=self.vcmd,
                                   textvariable=self.target)
        self.txtTarget.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="SD:").grid(row=r, sticky=tk.W)
        self.txtSD = ttk.Entry(w,
                               width=8,
                               justify=tk.CENTER,
                               validate='key',
                               validatecommand=self.vcmd,
                               textvariable=self.sd)
        self.txtSD.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Enable:").grid(row=r, sticky=tk.W)
        chk = ttk.Checkbutton(w, onvalue=1, offvalue=0, variable=self.enable)
        chk.grid(row=r, column=c, sticky=tk.W)

        self.engine.get_save_cancel(self, w)

    def on_open(self, selected_test, selected_batch=None):

        self.selected_test = selected_test

        if self.index is not None:
            self.selected_batch = selected_batch
            msg = "Update {0} for {1}".format(self.winfo_name(),
                                              selected_test[1])
            self.set_values()
        else:
            msg = "Insert {0} for {1}".format(self.winfo_name(),
                                              selected_test[1])
            self.expiration_date.set_today()
            self.target.set('')
            self.sd.set('')
            self.enable.set(1)

        self.title(msg)
        self.txtBatch.focus()

    def on_save(self, evt=None):

        if self.engine.on_fields_control(self) == False: return
        if self.expiration_date.get_date(self) == False: return
        if messagebox.askyesno(self.engine.title,
                               self.engine.ask_to_save,
                               parent=self) == True:

            args = self.get_values()

            if self.index is not None:

                sql = self.engine.get_update_sql('batches', 'batch_id')

                args = (*args, self.selected_batch[0])

            else:

                sql = self.engine.get_insert_sql('batches', len(args))

            self.engine.write(sql, args)
            self.parent.set_batches()

            if self.index is not None:
                if self.parent.winfo_name() == 'data':
                    self.parent.lstBatches.focus(self.index)
                    self.parent.lstBatches.selection_set(self.index)

                else:
                    self.parent.lstBatches.see(self.index)
                    self.parent.lstBatches.selection_set(self.index)
                    self.parent.lstBatches.event_generate("<<ListboxSelect>>")

            self.on_cancel()

        else:
            messagebox.showinfo(self.engine.title,
                                self.engine.abort,
                                parent=self)

    def get_values(self, ):

        return (self.selected_test[0], self.batch.get(),
                self.expiration_date.get_date(self), self.target.get(),
                self.sd.get(), self.enable.get())

    def set_values(self, ):

        self.batch.set(self.selected_batch[2])
        self.expiration_date.year.set(int(self.selected_batch[3][0:4]))
        self.expiration_date.month.set(int(self.selected_batch[3][5:7]))
        self.expiration_date.day.set(int(self.selected_batch[3][8:10]))
        self.target.set(self.selected_batch[4])
        self.sd.set(self.selected_batch[5])
        self.enable.set(self.selected_batch[6])

    def on_cancel(self, evt=None):
        self.destroy()
예제 #13
0
class Main(ttk.Frame):
    def __init__(self, parent):
        super().__init__()

        self.parent = parent

        self.text = tk.StringVar()

        self.init_ui()

    def init_ui(self):

        self.pack(fill=tk.BOTH, expand=1)

        f = ttk.Frame()

        self.start_date = Calendarium(self, "Start Date")
        self.end_date = Calendarium(self, "End Date")

        self.start_date.get_calendarium(f, )
        self.end_date.get_calendarium(f, )

        w = ttk.Frame()

        ttk.Button(w, text="Print Date", command=self.on_callback).pack()
        ttk.Button(w, text="Set Today", command=self.on_reset).pack()
        ttk.Button(w, text="Compare", command=self.on_compare).pack()
        ttk.Button(w, text="Close", command=self.on_close).pack()

        f.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
        w.pack(side=tk.RIGHT, fill=tk.BOTH, expand=1)

    def on_open(self):
        pass
        #self.start_date.set_today()
        #self.end_date.set_today()

    def on_callback(self, ):

        if self.start_date.get_date(self) == False: return

        if self.end_date.get_date(self) == False:
            return
        else:
            msg = "{0}: {1}\n{2}: {3}".format(self.start_date.name,
                                              self.start_date.get_date(self),
                                              self.end_date.name,
                                              self.end_date.get_date(self))

        messagebox.showinfo(self.parent.title(), msg, parent=self)

    def on_reset(self):
        self.start_date.set_today()
        self.end_date.set_today()

    def on_compare(self):

        if self.start_date.get_date(self) == False:
            return
        else:
            d1 = self.start_date.get_date(self)

        if self.end_date.get_date(self) == False:
            return

        else:
            d2 = self.end_date.get_date(self)

        if d1 > d2:
            msg = "{0} is greater than {1} :".format(self.start_date.name,
                                                     self.end_date.name)
        elif d1 < d2:
            msg = "{0} is less than {1} :".format(self.start_date.name,
                                                  self.end_date.name)
        else:
            msg = "{0} is equal than {1} :".format(self.start_date.name,
                                                   self.end_date.name)

        messagebox.showinfo(self.parent.title(), msg, parent=self)

    def on_close(self):
        self.parent.on_exit()
예제 #14
0
class UI(tk.Toplevel):
    def __init__(self, parent, *args, **kwargs):
        super().__init__(name='rejection')

        self.parent = parent
        self.engine = kwargs['engine']
        self.index = kwargs['index']
        self.resizable(0, 0)
        self.transient(parent)
        self.description = tk.StringVar()
        self.enable = tk.BooleanVar()
        self.init_ui()
        self.engine.center_me(self)

    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 1
        tk.Label(w, text="Actions:").grid(row=r, sticky=tk.W)
        self.cbActions = ttk.Combobox(w, )
        self.cbActions.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Description:").grid(row=r, sticky=tk.W)
        self.txDescription = ttk.Entry(
            w,
            textvariable=self.description,
        )
        self.txDescription.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Modified:").grid(row=r, column=0, sticky=tk.W)
        self.modified_date = Calendarium(self, "")
        self.modified_date.get_calendarium(w, r, c)

        r += 1
        ttk.Label(w, text="Enable:").grid(row=r, sticky=tk.W)
        chk = ttk.Checkbutton(w, onvalue=1, offvalue=0, variable=self.enable)
        chk.grid(row=r, column=c, sticky=tk.W)

        if self.index is not None:
            self.engine.get_save_cancel_delete(self, w)
        else:
            self.engine.get_save_cancel(self, w)

    def on_open(self,
                selected_test,
                selected_batch,
                selected_result,
                selected_rejection=None):

        self.selected_test = selected_test
        self.selected_batch = selected_batch
        self.selected_result = selected_result

        self.set_actions()

        if self.index is not None:
            self.selected_rejection = selected_rejection
            msg = "Update rejection"
            self.set_values()
        else:
            msg = "Add rejection"
            self.enable.set(1)
            self.modified_date.set_today()

        self.title(msg)
        self.cbActions.focus()

    def on_save(self, evt=None):

        if self.engine.on_fields_control(self) == False: return
        if self.modified_date.get_date(self) == False: return
        if messagebox.askyesno(self.engine.title,
                               self.engine.ask_to_save,
                               parent=self) == True:

            args = self.get_values()

            if self.index is not None:

                sql = self.engine.get_update_sql('rejections', 'rejection_id')

                args = (*args, self.selected_rejection[0])

            else:
                sql = self.engine.get_insert_sql('rejections', len(args))

            self.engine.write(sql, args)
            self.parent.on_open(self.selected_test, self.selected_batch,
                                self.selected_result)

            if self.index is not None:
                self.parent.lstItems.see(self.index)
                self.parent.lstItems.selection_set(self.index)

            self.on_cancel()

    def on_delete(self, evt=None):

        if self.index is not None:
            if messagebox.askyesno(self.engine.title,
                                   self.engine.delete,
                                   parent=self) == True:

                sql = "DELETE FROM rejections WHERE rejection_id =?"
                args = (self.selected_rejection[0], )
                self.engine.write(sql, args)
                self.parent.on_open(self.selected_test, self.selected_batch,
                                    self.selected_result)

                if self.index is not None:
                    self.parent.lstItems.see(self.index)
                    self.parent.lstItems.selection_set(self.index)

                self.on_cancel()

            else:
                messagebox.showinfo(self.engine.title,
                                    self.engine.abort,
                                    parent=self)

    def set_actions(self):

        index = 0
        values = []
        self.dict_actions = {}

        sql = "SELECT action_id, action FROM actions ORDER BY action ASC"
        rs = self.engine.read(True, sql, ())

        for i in rs:
            self.dict_actions[index] = i[0]
            index += 1
            values.append(i[1])

        self.cbActions['values'] = values

    def get_values(self, ):

        return (self.selected_result[0],
                self.dict_actions[self.cbActions.current()],
                self.description.get(), self.modified_date.get_timestamp(),
                self.enable.get())

    def set_values(self, ):

        key = next(key for key, value in self.dict_actions.items()
                   if value == self.selected_rejection[2])
        self.cbActions.current(key)

        self.description.set(self.selected_rejection[3])

        self.modified_date.year.set(int(self.selected_rejection[4].year))
        self.modified_date.month.set(int(self.selected_rejection[4].month))
        self.modified_date.day.set(int(self.selected_rejection[4].day))

        self.enable.set(self.selected_rejection[5])

    def on_cancel(self, evt=None):
        self.destroy()
예제 #15
0
파일: result.py 프로젝트: ra2003/Biovarase
class UI(tk.Toplevel):
    def __init__(self, parent, *args, **kwargs):
        super().__init__(name='result')

        self.parent = parent
        self.engine = kwargs['engine']
        self.index = kwargs['index']
        self.transient(parent)
        self.resizable(0, 0)

        self.test = tk.StringVar()
        self.batch = tk.StringVar()
        self.result = tk.DoubleVar()
        self.recived_time = tk.StringVar()
        self.enable = tk.BooleanVar()

        self.vcmd = self.engine.get_validate_float(self)
        self.set_style()
        self.init_ui()
        self.engine.center_me(self)

    def set_style(self):

        s = ttk.Style()

        s.configure('Data.TLabel', font=('Helvetica', 12, 'bold'))

    def init_ui(self):

        w = self.engine.get_init_ui(self)

        r = 0
        c = 1
        ttk.Label(w, text="Test:").grid(row=r, sticky=tk.W)
        lbl = ttk.Label(w, style='Data.TLabel', textvariable=self.test)
        lbl.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Batch:").grid(row=r, sticky=tk.W)
        lbl = ttk.Label(w, style='Data.TLabel', textvariable=self.batch)
        lbl.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Result:").grid(row=r, sticky=tk.W)
        self.txtResult = ttk.Entry(w,
                                   width=8,
                                   justify=tk.CENTER,
                                   validate='key',
                                   validatecommand=self.vcmd,
                                   textvariable=self.result)
        self.txtResult.grid(row=r, column=1, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Recived:").grid(row=r, sticky=tk.N + tk.W)

        self.recived_date = Calendarium(self, "")
        self.recived_date.get_calendarium(w, r, c)

        r += 1
        lbl = ttk.Label(w, text="Time:").grid(row=r, sticky=tk.W)
        lbl = ttk.Label(w, style='Data.TLabel', textvariable=self.recived_time)
        lbl.grid(row=r, column=c, sticky=tk.W, padx=5, pady=5)

        r += 1
        ttk.Label(w, text="Enable:").grid(row=r, sticky=tk.W)
        chk = ttk.Checkbutton(
            w,
            onvalue=1,
            offvalue=0,
            variable=self.enable,
        )
        chk.grid(row=r, column=c, sticky=tk.W)

        if self.index is not None:
            self.engine.get_save_cancel_delete(self, w)
        else:
            self.engine.get_save_cancel(self, w)

    def on_open(self, selected_test, selected_batch, selected_result=None):

        self.selected_batch = selected_batch
        self.test.set(selected_test[1])
        self.batch.set(self.selected_batch[2])

        if self.index is not None:
            self.selected_result = selected_result
            msg = "Update {0} for {1}".format(self.winfo_name(),
                                              selected_test[1])
            self.set_values()
        else:
            msg = "Insert {0} for {1}".format(self.winfo_name(),
                                              selected_test[1])
            self.enable.set(1)
            self.result.set('')
            self.recived_date.set_today()

        self.title(msg)
        self.txtResult.focus()

    def on_save(self, evt=None):

        if self.engine.on_fields_control(self) == False: return
        if self.recived_date.get_date(self) == False: return

        if messagebox.askyesno(self.engine.title,
                               self.engine.ask_to_save,
                               parent=self) == True:

            args = self.get_values()

            if self.index is not None:

                sql = self.engine.get_update_sql('results', 'result_id')

                args = (*args, self.selected_result[0])

            else:
                sql = self.engine.get_insert_sql('results', len(args))

            self.engine.write(sql, args)
            self.parent.set_results()

            if self.index is not None:
                if self.parent.winfo_name() == 'data':
                    self.parent.lstResults.focus(self.index)
                    self.parent.lstResults.see(self.index)
                    self.parent.lstResults.selection_set(self.index)
                else:
                    self.parent.lstResults.see(self.index)
                    self.parent.lstResults.selection_set(self.index)

            self.on_cancel()

    def on_delete(self, evt=None):

        if self.index is not None:
            if messagebox.askyesno(self.engine.title,
                                   self.engine.delete,
                                   parent=self) == True:
                sql = "DELETE FROM results WHERE result_id =?"
                args = (self.selected_result[0], )
                self.engine.write(sql, args)
                sql = "DELETE FROM rejections WHERE result_id =?"
                args = (self.selected_result[0], )
                self.engine.write(sql, args)
                self.parent.set_results()
                self.on_cancel()
            else:
                messagebox.showinfo(self.engine.title,
                                    self.engine.abort,
                                    parent=self)

    def get_values(self, ):

        return (self.selected_batch[0], self.result.get(),
                self.recived_date.get_timestamp(), self.enable.get())

    def set_values(self, ):

        try:
            self.recived_date.year.set(int(self.selected_result[3].year))
            self.recived_date.month.set(int(self.selected_result[3].month))
            self.recived_date.day.set(int(self.selected_result[3].day))

            t = "{0}:{1}:{0}".format(self.selected_result[3].hour,
                                     self.selected_result[3].minute,
                                     self.selected_result[3].second)

            self.recived_time.set(t)

        except:
            print(sys.exc_info()[0])
            print(sys.exc_info()[1])
            print(sys.exc_info()[2])

        self.result.set(self.selected_result[2])
        self.enable.set(self.selected_result[4])

    def on_cancel(self, evt=None):
        self.destroy()