
import time
import sys
import os
# print('根据当前文件获取当前文件所在目录的路径', os.path.dirname(__file__))
from airtest.core.helper import using

from common.common_func import commonFuc
from common.db.sql.sql_del_branch_info import delData

curPath = os.path.abspath(os.path.dirname(__file__))  # 获取当前文件的所在目录的绝对路径
# print('将路径中的/换成\\', curPath)  # C:\Users\Administrator\Desktop\temp\dbshop99\main
# # #将当前文件的所在目录的绝对路径进行分离,分离成 ('C:\\Users\\Administrator\\Desktop\\temp\\dbshop99', 'main'),存到元组中
# print('切割路径,切割成一个元组,将路径分离', os.path.split(curPath))
rootPath = os.path.split(curPath)[0]  # [0]表示元组中的为一个元素
# print('当前项目的根目录', rootPath)
sys.path.append(rootPath)  # 将项目的根目录路径添加到环境变量中,然后在cmd命令行中就可以正常运行脚本
import tkinter as tk
from tkinter import *
import tkinter.messagebox
from common.run_cmd_script import execute_command
pro_path = commonFuc().get_pro_path2()
sys.path.append(pro_path + r'/air_case/b5_spd3_core_business_flow/execute.air')
using(pro_path + r'//air_case/b5_spd3_core_business_flow/execute.air')
def main_text():
    # 创建窗口
    root = tk.Tk()
    # 获取屏幕宽高
    window_width = root.winfo_screenwidth()
    window_height = root.winfo_screenheight()
    # 设置窗口大小
    root.geometry('395x280')
    # 刷新窗口参数
    root.update()
    # 计算窗口居中时左上角的坐标
    x = (window_width - root.winfo_width()) // 2
    y = (window_height - root.winfo_height()) // 2
    # 设置窗口左上角的坐标
    root.geometry("+{}+{}".format(x, y))
    root.title (string ="核心业务流")
    root.resizable(False,False)
    # for a in ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw']:
    #     Button(root,
    #            text='anchor',
    #            anchor=a,
    #            width=30,
    #            height=4).pack()
    def flow1():
        print('调用流程一')
        from execute import flow1
        flow1()
        # execute_command("python runner_test.py tag id2302-1 debug mdm3")
        # sys.exit(0)
    def flow2():
        print('调用流程二')
        from execute import flow2
        flow2()
        # execute_command("python runner_test.py tag id2302-2 debug mdm3")
        # sys.exit(0)
    def flow3():
        from execute import flow3
        flow3()
        # execute_command("python runner_test.py tag id2302-3 debug mdm3")
        # sys.exit(0)
    def flow4():
        # execute_command("python runner_test.py tag id2302-4 debug mdm3")
        from execute import flow4
        flow4()
        # sys.exit(0)
    def flow5():
        # execute_command("python runner_test.py tag id2302-5,id2302-6,id2302-7,id2302-8 debug mdm3")
        from execute import flow5,flow6,flow7,flow8
        flow5()
        flow6()
        flow7()
        flow8()
        # sys.exit(0)
    def flow6():
        from execute import flow9
        flow9()
        # sys.exit(0)
    def flow7():
        from execute import flow10
        flow10()
        # sys.exit(0)
    def flow8():
        from execute import flow11
        flow11()
        print('流程十一执行完毕','流程十一执行完毕')
        # sys.exit(0)
    def flow9():
        from execute import flow12
        flow12()
        print('流程十二执行完毕','流程十二执行完毕')
        # sys.exit(0)
    def flow10():
        from execute import flow13
        flow13()
        print('流程十三执行完毕','流程十三执行完毕')
        # sys.exit(0)
    def flow11():
        from execute import flow14
        flow14()
        print('流程十四执行完毕','flow14执行完毕')
        # sys.exit(0)
    def flow12():
        from execute import flow15
        flow15()
        # sys.exit(0)
    def flow13():
        from execute import flow16
        flow16()
        # sys.exit(0)
    def flow14():
        from execute import flow17
        flow17()
        # sys.exit(0)
    def flow15():
        from execute import flow18
        flow18()
        tkinter.messagebox.showinfo('流程十五执行完毕')
        # sys.exit(0)
    def flow16():
        from execute import flow19
        flow19()
        tkinter.messagebox.showinfo('流程十六执行完毕')
        # sys.exit(0)
    def flow17():
        from execute import flow20
        flow20()
        tkinter.messagebox.showinfo('流程十七执行完毕')
        # sys.exit(0)
    def flow18():
        from execute import flow21
        flow21()
        tkinter.messagebox.showinfo('流程十八执行完毕')
        # sys.exit(0)
    def flow0():
        execute_command("python runner_test.py tag id2302-23 debug mdm3")
        sys.exit(0)
    def exit():
        print('退出')
        sys.exit(0)
    def del_data():
        # 删除自动化脚本产生的数据
        result=confirm()
        if result==True:
            result1 = confirm1()
            if result1 == True:
                delData().Delete_branch_by_id()
                delData().Delete_goods_change_info()
                delData().Delete_probeInfo_other()
                delData().Del_supply_relation()
                delData().Delete_business_Data()
                delData().Del_reporter_data()
                delData().Delete_business_Data_All()
                delData().Delete_business_Data_All2()
                print('===================删除垃圾数据完毕============================')
        else:
            print('Cancel')


    def confirm():
        result = tkinter.messagebox.askokcancel("确认", "您确定要执行此操作吗？")
        # print(result)
        print("用户选择了:", "OK" if result else "Cancel")
        return result
    def confirm1():
        result = tkinter.messagebox.askokcancel("再次确认", "您确定要执行此删除操作吗？数据删除后不可逆.")
        # print(result)
        print("用户选择了:", "OK" if result else "Cancel")
        return result

    # 文本显示的位置。
    Button(root, text='流程一', width=8, height=4,command=flow1).grid(row=2,column=0)
    Button(root, text='流程二', anchor='center', width=8, height=4,command=flow2).grid(row=2,column=2)
    Button(root, text='流程三', anchor='center', width=8, height=4,command=flow3).grid(row=2,column=4)
    Button(root, text='流程四', anchor='center', width=8, height=4,command=flow4).grid(row=2,column=6)
    Button(root, text='流程五', anchor='center', width=8, height=4,command=flow5).grid(row=2,column=8)
    Button(root, text='流程六', anchor='center', width=8, height=4,command=flow6).grid(row=2,column=10)
    Button(root, text='流程七', anchor='center', width=8, height=4,command=flow7).grid(row=3,column=0)
    Button(root, text='流程八', anchor='center', width=8, height=4,command=flow8).grid(row=3,column=2)
    Button(root, text='流程九', anchor='center', width=8, height=4,command=flow9).grid(row=3,column=4)
    Button(root, text='流程十', anchor='center', width=8, height=4,command=flow10).grid(row=3,column=6)
    Button(root, text='流程十一', anchor='center', width=8, height=4,command=flow11).grid(row=3,column=8)
    Button(root, text='流程十二', anchor='center', width=8, height=4,command=flow12).grid(row=3,column=10)
    Button(root, text='流程十三', anchor='center', width=8, height=4,command=flow13).grid(row=4,column=0)
    Button(root, text='流程十四', anchor='center', width=8, height=4,command=flow14).grid(row=4,column=2)
    Button(root, text='流程十五', anchor='center', width=8, height=4,command=flow15).grid(row=4,column=4)
    Button(root, text='流程十六', anchor='center', width=8, height=4,command=flow16).grid(row=4,column=6)
    Button(root, text='流程十七', anchor='center', width=8, height=4,command=flow17).grid(row=4,column=8)
    Button(root, text='流程十八', anchor='center', width=8, height=4,command=flow18).grid(row=4,column=10)
    Button(root, text='一键执行', anchor='center', width=8, height=2,command=flow0).grid(row=5,column=2)
    Button(root, text='删除垃圾数据', anchor='center', width=8, height=2,command=del_data).grid(row=5,column=4)
    Button(root, text='退  出', anchor='center', width=8, height=2,command=exit).grid(row=5,column=8)

    # Button(root, text='anchor', anchor='e', width=30, height=4).pack()
    # Button(root, text='anchor', anchor='w', width=30, height=4).pack()
    # Button(root, text='anchor', anchor='ne', width=30, height=4).pack()
    # Button(root, text='anchor', anchor='nw', width=30, height=4).pack()
    # Button(root, text='anchor', anchor='se', width=30, height=4).pack()
    # Button(root, text='anchor', anchor='sw', width=30, height=4).pack()

    root.mainloop()
main_text()