示例#1
0
    def go_holiday(self):
        data = f.read_data()
        go_rest = self.e2.get()

        # 将go_rest保存,再次大开始调用

        if go_rest not in self.name_nomal and len(go_rest) != 0:
            tk.messagebox.showinfo(title="输入有误",
                                   message="您输入的名称错误或其正在休假(或出公差)中,"
                                           "请重新输入即将休假(或公差)人员")
        elif go_rest in self.name_nomal:
            go = tk.messagebox.askyesno(title='提示',
                                        message='休假人员是否本周值完班再休假?'
                                                '(选择【是】,本周继续值班,下周开始休假|选择【否】,本周不值班,开始休假)')
            # 本周值完班后再休假
            if go:
                # 如果执行本周值完班再休假,将此情况写入缓存,本周再次打开时(today<=date),再一次自动调用本周值完班再离队,当下周或
                # 下几周(today>date)打开时,首先将after_work_go改为false(这样 update时间后,不会再次跳入,本周值完班再休假),
                # 如果是下周打开,直接读入第二周离队状态,如果是下几周后,读入离队状态从第二周开始loop
                data["go_rest_after_work"].append(go_rest)
                f.write_data(data)
                self.after_work_go()
                self.v1.set("当前可值班人员更改为:%s" % self.name_nomal)
                self.v2.set("当前休假人更改员为:%s" % self.name_holiday)
                self.t.insert("end", "下周值班人员:\r\n")
                self.list_duty()
                if data['back_work_next']:
                    self.work_next()
                    self.back_work_next_due_to_name()

            else:
                # 重新读入初始值班顺序
                self.name_nomal, self.name_weekend = f.read_curent()
                # 清空文本
                self.t.delete(1.0, "end")
                self.a = 0
                self.t.insert("end", "本周值班人员:\r\n")
                self.name_nomal.remove(go_rest)
                self.name_weekend.remove(go_rest)
                f.write_curent(self.name_nomal, self.name_weekend)
                self.name_holiday.append(go_rest)
                data = f.read_data()
                data['name_holiday'] = self.name_holiday
                f.write_data(data)
                self.v1.set("当前可值班人员更改为:%s" % self.name_nomal)
                self.v2.set("当前休假人更改员为:%s" % self.name_holiday)
                self.list_duty()
                self.to = self.curduty + self.today_duty_name()
                self.v3.set(self.to)
                self.t.insert("end", "下周值班人员:\r\n")
                self.list_duty()

        else:
            pass
示例#2
0
 def write_current_reset(self):
     if e2.get() == '' or e3.get() == '':
         tk.messagebox.showinfo(title='错误', message='本周一或本周六值班人员未输入,初始化失败,请按照要求输入相应人员!')
     else:
         data = f.read_data()
         data['re_back'] = []
         data['go_rest_after_work'] = []
         data['after_work_go'] = False
         data['back_work_next'] = False
         data['name_holiday'] = self.name_holiday
         f.write_data(data)
         f.write_curent(self.name_nomal, self.name_weekend)
         self.reset()
示例#3
0
 def back_work_next_due_to_name(self):
     self.name_nomal = f.read_data()['cache_name_nomal']
     self.name_weekend = f.read_data()['cache_name_weekend']
     self.name_holiday = f.read_data()['name_holiday']
     for i in f.read_data()['re_back']:
         self.name_holiday.remove(i)
         f.add_list(i, self.name_nomal, self.name_weekend, self.name_holiday)
     self.v1.set("当前休假人更改员为:%s" % self.name_holiday)
     self.v2.set("当前可值班人员更改为:%s" % self.name_nomal)
     self.t.insert("end", "下周值班人员:\r\n")
     # 此时为值班列表为休假返回第一周未参加值班,第二周参加值班的值班序列列表
     data = f.read_data()
     data['back_work_next_name_nomal'] = self.name_nomal
     data['back_work_next_name_weekend'] = self.name_weekend
     f.write_data(data)
     self.list_duty()
示例#4
0
 def after_work_go(self):
     data = f.read_data()
     data['after_work_go'] = True
     # 重新读入初始值班顺序
     self.name_nomal, self.name_weekend = f.read_curent()
     self.name_holiday = copy.deepcopy(data['name_holiday'])
     self.a = 0
     # 清空文本
     self.t.delete(1.0, "end")
     self.t.insert("end", "本周值班人员:\r\n")
     self.list_duty()  # 此处会更改当前值班序列
     for i in data['go_rest_after_work']:
         self.name_nomal.remove(i)
         self.name_weekend.remove(i)
         self.name_holiday.append(i)
     data['after_work_go_name_nomal'] = self.name_nomal
     data['after_work_go_name_weekend'] = self.name_weekend
     f.write_data(data)
示例#5
0
    def back_work(self):
        re_back = self.e1.get()
        data = f.read_data()
        data['re_back'].append(re_back)
        f.write_data(data)
        if re_back not in self.name_holiday and len(re_back) != 0:
            tk.messagebox.showinfo(title="输入有误", message="您输入的名称错误或其已在值班人员列表,请重新输入正确的返回人员")
            re_back = ''
        elif re_back in self.name_holiday:
            accept_re = tk.messagebox.askyesno(title='提示',
                                               message='休假(或公差)返回人员是否从本周开始值班?'
                                                       '(【是】:本周开始值班|【否】:下周开始值班)')
            # 休假归队人员本周开始值班
            if accept_re:
                self.back_work_current(re_back)

            # 休假归队人员下周开始值班
            else:
                self.work_next()
                self.back_work_next_due_to_name()
示例#6
0
 def work_next(self):
     data = f.read_data()
     data['back_work_next'] = True
     f.write_data(data)
     data = f.read_data()
     # 重新读入初始值班顺序
     self.name_nomal, self.name_weekend = f.read_curent()
     # 清空文本
     self.t.delete(1.0, "end")
     self.t.insert("end", "本周值班人员:\r\n")
     # 程序打开时,已经调用了一次排班,self.a变为7,这里重新排班需要重置回0
     self.a = 0
     self.list_duty()
     if data['after_work_go']:
         self.name_nomal = data['after_work_go_name_nomal']
         self.name_weekend = data['after_work_go_name_weekend']
     # (还未返回的下一次序列)将当前序列写入缓存(下次试试能不能用多进程解决这个问题)
     data = f.read_data()
     data['cache_name_nomal'] = self.name_nomal
     data['cache_name_weekend'] = self.name_weekend
     f.write_data(data)
示例#7
0
 def today_duty_name(self):
     global today_duty
     data = f.read_data()
     data['name_nomal'] = self.name_nomal
     data['name_weekend'] = self.name_weekend
     f.write_data(data)
     for i in range(self.a, self.a + 5):
         day = self.monday + datetime.timedelta(days=i)
         duty = self.name_nomal.pop(0)
         if day == self.today:
             today_duty = self.week[i - self.a] + ",今日值班员为【%s】,祝您生活愉快!!! ^=^ " % duty
         self.name_nomal.append(duty)
     for i in range(self.a + 5, self.a + 7):
         day = self.monday + datetime.timedelta(days=i)
         duty = self.name_weekend.pop(0)
         if day == self.today:
             today_duty = self.week[i - self.a] + ",今日值班员为【%s】,祝您生活愉快!!! ^=^ " % duty
         self.name_weekend.append(duty)
     date = f.read_data()
     self.name_nomal = date['name_nomal']
     self.name_weekend = date['name_weekend']
     return today_duty
示例#8
0
    def add_holiday(self):
        h_name = e1.get()
        if h_name not in self.name_nomal_sequence and h_name != '':
            tk.messagebox.showinfo(title='输入错误', message='您输入的名称错误,请重新输入!')
        elif h_name == '':
            current_holiday_name.set("当前休假人员:" + str(self.name_holiday))
            self.name_nomal = self.name_nomal_sequence
            self.name_weekend = self.name_weekend_sequence
            current_duty_name.set('当前值班人员为:' + str(self.name_nomal))
            data = f.read_data()
            data['name_holiday'] = self.name_holiday
            f.write_data(data)

        elif h_name in self.name_nomal_sequence:
            self.name_holiday.append(h_name)
            current_holiday_name.set("当前休假人员:" + str(self.name_holiday))
            self.name_nomal_sequence.remove(h_name)
            self.name_weekend_sequence.remove(h_name)
            self.name_nomal = self.name_nomal_sequence
            self.name_weekend = self.name_weekend_sequence
            current_duty_name.set('当前值班人员为:' + str(self.name_nomal))
            data = f.read_data()
            data['name_holiday'] = self.name_holiday
            f.write_data(data)
示例#9
0
 def back_work_current(self, re_back):
     data = f.read_data()
     data['back_work_next'] = False
     f.write_data(data)
     # 重新读入初始值班顺序
     self.name_nomal, self.name_weekend = f.read_curent()  # 当休假返回时,重复读入
     self.name_holiday.remove(re_back)
     data = f.read_data()
     data['name_holiday'] = self.name_holiday
     f.write_data(data)
     f.add_list(re_back, self.name_nomal, self.name_weekend, self.name_holiday)
     self.v1.set("当前休假人更改员为:%s" % self.name_holiday)
     self.v2.set("当前可值班人员更改为:%s" % self.name_nomal)
     # 重写本周列表
     f.write_curent(self.name_nomal, self.name_weekend)
     self.a = 0
     # 清空文本
     self.t.delete(1.0, "end")
     self.t.insert("end", "本周值班人员:\r\n")
     self.list_duty()
     self.to = self.curduty + self.today_duty_name()
     self.v3.set(self.to)
     self.t.insert("end", "下周值班人员:\r\n")
     self.list_duty()
示例#10
0
    def __init__(self):
        # a每周正常值班和周末值班的控制循环次数
        self.a = 0
        self.name_nomal_sequence = ['张旭辉', '钟晓东', '邹堪芳', '刘鹏辉', '王海涛', '苏伟健', '李琦学', '弯海峰', '李泽杰']
        self.name_weekend_sequence = ['刘鹏辉', '王海涛', '钟晓东', '张旭辉', '邹堪芳', '苏伟健', '李琦学', '弯海峰', '李泽杰']
        self.week = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
        self.today = datetime.date.today()
        self.monday = datetime.date.today()
        self.sunday = datetime.date.today()
        self.one_day = datetime.timedelta(days=1)
        self.date, self.curduty = self.read_date()
        self.name_holiday = f.read_data()['name_holiday']
        while self.monday.weekday() != 0:
            self.monday -= self.one_day
        while self.sunday.weekday() != 6:
            self.sunday += self.one_day

        # 创建root
        self.root = tk.Tk()
        self.root.title("自动排班系统")
        width = 800
        height = 600
        screenwidth = self.root.winfo_screenwidth()
        screenheight = self.root.winfo_screenheight()
        alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - 700) / 2)

        # 设置窗口大小不可改变
        self.root.resizable(width=False, height=False)
        self.root.geometry(alignstr)
        # 创建文本框
        self.t = tk.Text(self.root)
        self.t.insert("end", '\r\n    我值班,我快乐,吼吼吼~~~~~~~~~    ^=^    !!!'
                             '\r\n\r\n@Author:{Jason}  @Contact:{[email protected]}  @History:'
                             '{20/11/21(First release)}\r\n***********************************'
                             '*********************************************\r\n本周值班人员:\r\n')

        if self.today <= self.date:
            after_work_go = f.read_data()["after_work_go"]
            back_work_next = f.read_data()['back_work_next']
            if after_work_go:
                # go_rest = f.read_data()['go_rest']

                tk.messagebox.showinfo(title="提示",
                                       message="%s已经列入休假名单,将在本周值完班后,下周开始休假"
                                               % f.read_data()['go_rest_after_work'])
                # 执行本周未离队,下周离队打印输出
                self.after_work_go()

                self.t.insert("end", "下周值班人员:\r\n")
                self.list_duty()
            if back_work_next:
                re_back = f.read_data()['re_back']
                tk.messagebox.showinfo(title="提示", message="归队人员%s,将在下周开始值班" % re_back)
                self.work_next()
                # 读入第一周排班后的顺序,加入调入的人员,就是第二周的
                self.name_nomal = f.read_data()['cache_name_nomal']
                self.name_weekend = f.read_data()['cache_name_weekend']
                for i in re_back:
                    self.name_holiday.remove(i)
                    f.add_list(i, self.name_nomal, self.name_weekend, self.name_holiday)
            elif not back_work_next and not after_work_go:
                self.name_nomal, self.name_weekend = f.read_curent()
                self.list_duty()
        elif self.today > self.date:
            after_work_go = f.read_data()["after_work_go"]
            back_work_next = f.read_data()['back_work_next']
            if not after_work_go and not back_work_next:
                self.name_nomal, self.name_weekend = f.read_curent()

                # 计算过去了几周
                how_many_days = str(self.today - self.date)
                how_many_days = re.match('\d+', how_many_days)
                how_many_days = int(how_many_days.group())
                how_many_week = how_many_days // 7
                # 将时间更新为本周星期日的时间
                f.update_date(self.sunday)
                # 判断是隔了几周,隔了几周,就掉几次list
                for i in range(how_many_week + 1):
                    self.loop_list()
                f.write_curent(self.name_nomal, self.name_weekend)

                # 经过loop后,需要再次将初始化self.a
                self.a = 0
                self.list_duty()
            elif after_work_go and not back_work_next:
                data = f.read_data()
                data['after_work_go'] = False
                for i in data['go_rest']:
                    self.name_holiday.append(i)
                data['name_holiday'] = self.name_holiday
                data['go_rest'] = []
                f.write_data(data)
                # 读入第一周值班,第二周离队的状态,判断当前情况是过了一周,还是过了大于一周,如果一周,输出第二周离队状态,如果n周,loop
                # n次
                how_many_days = str(self.today - self.date)
                how_many_days = re.match('\d+', how_many_days)
                how_many_days = int(how_many_days.group())
                how_many_week = how_many_days // 7
                # 将时间更新为本周星期日的时间
                f.update_date(self.sunday)
                if how_many_week <= 1:
                    self.name_nomal = f.read_data()['after_work_go_name_nomal']
                    self.name_weekend = f.read_data()['after_work_go_name_weekend']
                    f.write_curent(self.name_nomal, self.name_weekend)
                    self.list_duty()
                elif how_many_week > 1:
                    for i in range(how_many_week):
                        self.loop_list()
            elif back_work_next and not after_work_go:
                data = f.read_data()
                re_back = data['re_back']
                data['back_work_next'] = False
                data['name_holiday'] = self.name_holiday
                self.name_nomal = f.read_data()['cache_name_nomal']
                self.name_weekend = f.read_data()['cache_name_weekend']
                for i in re_back:
                    self.name_holiday.remove(i)
                    f.add_list(i, self.name_nomal, self.name_weekend, self.name_holiday)
                f.write_data(data)
                f.write_curent(self.name_nomal, self.name_weekend)
                # 计算过去了几周
                how_many_days = str(self.today - self.date)
                how_many_days = re.match('\d+', how_many_days)
                how_many_days = int(how_many_days.group())
                how_many_week = how_many_days // 7
                # 将时间更新为本周星期日的时间
                f.update_date(self.sunday)
                if how_many_week <= 1:
                    self.a = 0
                    self.list_duty()
                elif how_many_week > 1:
                    for i in range(how_many_week):
                        self.loop_list()
                    # 经过loop后,需要再次将初始化self.a
                    self.a = 0
                    self.list_duty()
            elif back_work_next and after_work_go:
                data = f.read_data()
                re_back = data['re_back']
                data['after_work_go'] = False
                data['back_work_next'] = False

                for i in data['go_rest_after_work']:
                    self.name_holiday.append(i)
                for i in re_back:
                    self.name_holiday.remove(i)
                data['re_back'] = []
                data['name_holiday'] = self.name_holiday
                self.name_nomal = f.read_data()['back_work_next_name_nomal']
                self.name_weekend = f.read_data()['back_work_next_name_weekend']
                f.write_data(data)
                f.write_curent(self.name_nomal, self.name_weekend)
                # 计算过去了几周
                how_many_days = str(self.today - self.date)
                how_many_days = re.match('\d+', how_many_days)
                how_many_days = int(how_many_days.group())
                how_many_week = how_many_days // 7
                # 将时间更新为本周星期日的时间
                f.update_date(self.sunday)
                if how_many_week <= 1:
                    self.a = 0
                    self.list_duty()
                elif how_many_week > 1:
                    for i in range(how_many_week):
                        self.loop_list()
                    # 经过loop后,需要再次将初始化self.a
                    self.a = 0
                    self.list_duty()
        #  创建几个子菜单
        # 文件子菜单
        self.file = tk.Menu(self.root, tearoff=False)
        self.file_1 = self.file.add_command(label='将当前排班内容另存为', command=self.save)
        self.file_2 = self.file.add_command(label='退出', command=self.quit_program)
        # 编辑子菜单
        self.edit = tk.Menu(self.root, tearoff=False)
        self.edit1 = self.edit.add_command(label="初始化", command=self.init_name)
        self.edit2 = self.edit.add_command(label="重置", command=self.reset)
        # 帮助子菜单
        self.help = tk.Menu(self.root, tearoff=False)
        self.help1 = self.help.add_command(label="帮助文档", command=self.open_help_file)
        self.help2 = self.help.add_command(label="联系方式", command=self.cotact)
        # 主菜单
        self.menubar = tk.Menu(self.root)
        self.menubar.add_cascade(label='文件', menu=self.file)
        self.menubar.add_cascade(label='操作', menu=self.edit)
        self.menubar.add_cascade(label='帮助', menu=self.help)
        self.menubar.add_command(label='关于', command=self.about)

        self.root.config(menu=self.menubar)
        # 欢迎标签
        tk.Label(self.root, text="欢迎使用排班系统", font='Arial 15 bold', height=2, anchor='ne'
                 ).place(x=300, y=20, anchor='nw')
        self.v3 = tk.StringVar()
        self.l1 = tk.Label(self.root, textvariable=self.v3, width=70, font='Arial 10 bold')
        self.l2 = tk.Label(self.root,
                           text="请输入休假或公差结束归队人员(输入人员将加入到本周或下周值班:)",
                           width=60,
                           bg='SpringGreen')
        self.l3 = tk.Label(self.root,
                           text='请输入即将休假或公差人员(输入人员将在本周或下周从值班人员中剔除) :',
                           width=60,
                           bg='LightPink')
        self.v1 = tk.StringVar()
        self.v2 = tk.StringVar()
        # 用于显示值班人员或者调整后得标签
        self.l4 = tk.Label(self.root, textvariable=self.v1, bg='cyan', font='Arial 10', anchor='nw')
        self.l5 = tk.Label(self.root, textvariable=self.v2, bg='gold', font='Arial 10', anchor='nw')
        self.v1.set("当前可值班人员为:%s" % self.name_nomal)
        self.v2.set("当前休假人员为:%s" % self.name_holiday)
        # 两个文本输入框,返回和休假
        self.e1 = tk.Entry(self.root, width=15)
        self.e2 = tk.Entry(self.root, width=15)
        # 人员变动后必须及时调整curent值班序列,否则多周后将变动后持续出错
        self.b1 = tk.Button(self.root, text="确 定", width=6, command=self.back_work)
        self.b2 = tk.Button(self.root, text="确 定", width=6, command=self.go_holiday)
        self.b3 = tk.Button(self.root, text='排 班', font='Arial 18 bold', width=6, height=3, command=self.arr_duty)

        # 标签l1的显示内容:今日值班人员

        self.to = self.curduty + self.today_duty_name()

        self.scroll = tk.Scrollbar()
        self.scroll.place(x=590, y=195, width=20, height=316)
        # 关联文本框
        self.scroll.config(command=self.t.yview)
        self.t.config(yscrollcommand=self.scroll.set)

        self.v3.set(self.to)
        self.l1.place(x=20, y=60, anchor='nw')
        self.l2.place(x=20, y=85, anchor='nw')
        self.l3.place(x=20, y=110, anchor='nw')
        self.l5.place(x=20, y=135, anchor='nw')
        self.l4.place(x=20, y=162, anchor='nw')

        self.b1.place(x=550, y=80, anchor='nw')
        self.b2.place(x=550, y=110, anchor='nw')
        self.b3.place(x=650, y=400, anchor='nw')

        self.e1.place(x=450, y=85, anchor='nw')
        self.e2.place(x=450, y=110, anchor='nw')

        self.t.place(x=30, y=195)
        self.t.see('end')
        self.t.update()

        self.root.mainloop()