python自动化:uiautomation、pyautogui操作会计记账系统(6):打印会计凭证

python自动化:uiautomation、pyautogui操作会计记账系统(6):打印会计凭证

#coding=utf-8
#Beijia print account document打印会计凭证
import xlrd, xlwt, pyautogui, time, pyperclip, openpyxl,pandas,os, tkinter,\
    datetime, win32gui, uiautomation, subprocess, xlwings,json, easygui
from tkinter.filedialog import askopenfilename
pyautogui.PAUSE = 0.5
mont_list =['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
prin_type_input = easygui.integerbox(msg='打印1凭证,2科目余额表,3三栏明细账,4收支明细表,5序时簿,请输入数字。', lowerbound=1, upperbound=12)
print(prin_type_input)
#year_input = easygui.enterbox(msg='请输入年份')
#year_input = pyautogui.prompt('请输入年份')
year_input = easygui.integerbox(msg='请输入年份', lowerbound=2005, upperbound=2050)
mont_input = easygui.integerbox(msg='请输入月份', lowerbound=1, upperbound=12)

#print(type(mont_input))
year = time.strftime("%Y")
this_mont = int(time.strftime("%m"))

if prin_type_input ==3:
    accnt_code_dict = {"101": "现金", "102": "银行存款", "112": "应收款", "151": "固定资产", "152": "累计折旧", "154": "在建工程",
                       "202": "应付款",

                       "212": "应付福利费", "241": "专项应付款", "311": "公积公益金", "321": "本年收益", "322": "收益分配", "511": "发包及上交收入",
                       "531": "其他收入", "541": "管理费用", "551": "其他支出"}
    # accnt_code_list = ["101", "102", "511", "531", "541"]
    accnt_code_dict = {"101": "现金", "102": "银行存款", "511": "发包及上交收入", "531": "其他收入", "541": "管理费用"}
    accnt_code_dict = {"531": "其他收入"}
    accnt_code_dict = {"101": "现金", "102": "银行存款", "112": "应收款", "202": "应付款",
                       "241": "专项应付款", "511": "发包及上交收入",
                       "531": "其他收入", "541": "管理费用", "551": "其他支出"}
    accnt_code_dict = {"101": "现金", "102": "银行存款", "511": "发包及上交收入", "531": "其他收入", "541": "管理费用", "551": "其他支出"}
    # accnt_code_dict = { "511": "发包及上交收入", "531": "其他收入"}
if prin_type_input == 4:
    deta_or_not = easygui.buttonbox(msg="导出的收支明细表是否包含明细?", title="",
                                    choices=("                是                ", "                否                "))
#print('当前屏幕分辨率宽 X 高:')
screenWidth, screenHeight = pyautogui.size()
# def check_file(folder3_1):
#     # 打开文件
#     path= folder3_1
#     dirs = os.listdir(path)
#     year = time.strftime("%Y")

#     file_accnt_num_list=[]
#     for home, dirs, files in os.walk(path):
#         for file_name in files:
#             #filelist.append(os.path.join(home, file_name))
#             if os.path.splitext(file_name)[1] == '.xls':
#                 #print(file_name)
#                 file_year = file_name[0:4]  # 截取文件名前4个字符
#                 #print(file_year)
#                 # os.rename(file, new)  # 进行重命名
#
#                 if file_year == year:
#                     # 取整方法是可以去除0,但是遇到字符串不能转化为整型会报错
#                     # file_accnt_num=int(file_name[9:12])
#                     s = file_name[9:12]
#                     file_accnt_num = "".join(s[::1]).lstrip("0")
#                     #print(file_accnt_num)
#                 else:
#                     s = file_name[5:8]
#                     file_accnt_num = "".join(s[::1]).lstrip("0")
#                     #print(file_accnt_num)
#                 file_accnt_num_list.append((file_accnt_num))
#
#     #print(filelist)
#     #print(file_accnt_num_list)
#     #print('对列表进行排序,查找时可能减少遍历次数。也便于根据账套号顺序查找')
#     #file_accnt_num_list2=file_accnt_num_list.sort()
#     #print('sort影响列表本身,sorted不影响列表本身,用sort排序')
#     file_exist_list = sorted(file_accnt_num_list)
#     print('已导出的文件列表','file_exist_list:')
#     print(file_exist_list)
#     print('已导出的文件数量',len(file_exist_list))
#     return file_exist_list

def accnt_login(account_Num):
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='帐套登陆')
    # 设置为顶层
    #pyautogui.alert(text="按回车键继续程序", title="提示")  # 窗口前置才能用键盘快捷键
    wc1.SetTopmost(True)  # 置顶能用快捷键
    pc2_1= wc1.PaneControl(searchDepth=1, Name='帐套信息')
    ec3_8=pc2_1.EditControl(searchDepth=1, Name='', foundIndex=2)
    ec3_8.SetFocus()
    #print('ec3_8')
    #print('账套号输入框的位置是:')
    #print(ec3_8.BoundingRectangle)
    pyperclip.copy(account_Num) #account_Num是账套号
    pyautogui.hotkey('ctrl', 'v')  # 再粘贴
    pyautogui.press('enter')



def user_login():
    wc1=uiautomation.WindowControl(searchDepth=1, Name='用户注册')
    # 设置为顶层
    wc1.SetTopmost(True)  # 置顶能用快捷键
    pyautogui.press('down')  # 向下选择超级用户
    pyautogui.press('enter')  # 点击确定
    pyautogui.press('enter')  # 点击确定
    #print('超级用户登录成功')





def  prin_acco_docu(year_input, mont_input): #select year and print account document会计凭证处理界面选择年份
    time.sleep(1)
    #print('选择年份')
    #print('深度1')
    pyautogui.click(screenWidth / 2.9091, screenHeight / 3.7241)  # 点击凭证处理(660, 290)
    time.sleep(1)
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [凭证处理]')
    # 设置为顶层
    #wc1.SetTopmost(True)
    #print(wc1.Name)

    #print('深度2') #isum自创字母后的数字表示深度
    #sbc2_1= wc1.StatusBarControl(searchDepth=1, ClassName= 'TStatusBar')
    pc2_2= wc1.PaneControl(searchDepth=1,ClassName='MDIClient')
    #print(pc2_2.Name)#工作区

    #print('深度3')
    wc3_1= pc2_2.WindowControl(searchDepth=1,Name='凭证处理')
    #print(wc3_1.Name)  # 工作区

    #print('深度4')
    pc4_1= wc3_1.PaneControl(searchDepth=1, ClassName='TPanel',Name= '')
    #print(pc4_1.BoundingRectangle) #Rect: (0,183,311,1013)[311x830]

    #print('深度5')
    #Rect: (1,214,310,442)[309x228]
    pc5_3 = pc4_1.PaneControl(searchDepth=1, ClassName='TPanel',Name= '')
    #print(pc5_3)
    #print('深度6')
    rbc6_6= pc5_3.PaneControl(searchDepth=1, Name='指定年月')
    #print(rbc6_6.Name)
    rbc6_6.Click()
    rbc6_6.Click()
    year = time.strftime("%Y")
    #print("当前年份是:", year)
    # mont = time.strftime(('%M')) #month
    # print('This month is {}'.format(mont))
    pyautogui.press('tab')
    if year_input!=year:

        diff_year = int(year) - int(year_input) # difference year相差年份
        for i in range(diff_year):
            pyautogui.press('Down')

        # pyperclip.copy(year_input)#年份框不能输入,只用用箭头键修改
        # pyautogui.hotkey('ctrl', 'v')
    pyautogui.press('tab')
    for i in range(12):
        pyautogui.press('Up') #返回到1月
    for i in range(mont_input-1):
        pyautogui.press('Down')

    # if mont_input<7:
    #     for i in range(6):
    #         pyautogui.press('Up') #返回到1月
    # # diff_mont = abs(int(mont) - int(mont_input))  # difference year相差年份
    # # print('differ month is {} .'.format(diff_mont))
    #     for i in range(mont_input-1):
    #         pyautogui.press('Down')
    # else:
    #     for i in range(6):
    #         pyautogui.press('Down')  # 返回到12月
    #     # diff_mont = abs(int(mont) - int(mont_input))  # difference year相差年份
    #     # print('differ month is {} .'.format(diff_mont))
    #     for i in range(12 - mont_input):
    #         pyautogui.press('Up')

    time.sleep(3)
    print('点击打印')
    pyautogui.click(screenWidth / 4.0851, screenHeight / 18)  # 点击打印(470, 70)
    time.sleep(1)
    wc1e = uiautomation.WindowControl(searchDepth=1, Name='凭证打印')
    # print(wc1e)
    pc2_4e = wc1e.PaneControl(searchDepth=1, Name='', foundIndex=2)
    # print(pc2_4e)
    cbc3_6 = pc2_4e.CheckBoxControl(searchDepth=1, Name='批打印')
    print(cbc3_6)
    cbc3_6.SetFocus()
    cbc3_6.Click()
    pc2_2e = wc1e.PaneControl(searchDepth=1, Name='确定')
    pc2_2e.SetFocus()
    pc2_2e.Click()

    time.sleep(1)
    # pyautogui.press('enter')
    pyautogui.hotkey('ctrl', 'P')
    time.sleep(3)
    pyautogui.hotkey('shift', 'tab')# tab切换焦点会改变打印的页范围。用'shift', 'tab'回撤切换焦点。选择打印机。

    pyautogui.hotkey('shift', 'tab')

    #pyautogui.press('down') #选择打印机
    pyautogui.press('enter')
    time.sleep(7)
    #pyautogui.press('enter')
    #time.sleep(3)
    pyautogui.hotkey('Alt', 'F4')  # 退出打印界面,返回**凭证处理界面
    time.sleep(1)


#
# def chag_acco_acco_docu(): #change account account document凭证处理界面另选账套
#     #print('深度1')
#     wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [凭证处理]')
#     # 设置为顶层
#     #wc1.SetTopmost(True)
#     #print(wc1.Name)
#
#     #print('深度2') #isum自创字母后的数字表示深度
#     #sbc2_1= wc1.StatusBarControl(searchDepth=1, ClassName= 'TStatusBar')
#     pc2_2= wc1.PaneControl(searchDepth=1,ClassName='MDIClient')
#     #print(pc2_2.Name)#工作区
#
#     mbc2=wc1.MenuBarControl(searchDepth=1, Name= '应用程序')
#     #print('mbc2')
#     #print(mbc2.Name)
#
#     mic3_9=mbc2.MenuItemControl(searchDepth=1, Name='', foundIndex=9)
#     #print('mic3_9')
#     #print(mic3_9.BoundingRectangle)#(700,27,788,51)[88x24]
#     print('点击另选账套')
#     mic3_9.Click()
#
#     #另选账套的坐标:Rect: (700,27,788,51)
#     #这四个 参数 分别代表的意思是: left   top   right   bottom   是 左 上 右 下。





def prin_inco(year_input, mont_input):
    #select year and print income expenditure,收支明细表
    time.sleep(1)
    # print('选择年份')
    pyautogui.click(screenWidth / 3.9587, screenHeight / 1.125)  # 系统小字体显示,点击收支明细表(485,960)
    time.sleep(1)
    # print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [收支明细表]')
    # 设置为顶层
    # wc1.SetTopmost(True)
    wc1.SetActive(True)
    # print(wc1.Name)

    # print('深度2') #isum自创字母后的数字表示深度
    # sbc2_1= wc1.StatusBarControl(searchDepth=1, ClassName= 'TStatusBar')
    pc2_2 = wc1.PaneControl(searchDepth=1, ClassName='MDIClient')
    # print(pc2_2.Name)#工作区

    # print('深度3')
    wc3_1 = pc2_2.WindowControl(searchDepth=1, Name='收支明细表')
    # print(wc3_1.Name)  # 工作区

    # print('深度4')
    pc4_2 = wc3_1.PaneControl(searchDepth=1, ClassName='TPanel', Name='')
    # print(pc4_2.BoundingRectangle) #Rect: (0,183,311,1013)[311x830]
    # print('深度5')
    # Rect: (1,214,310,442)[309x228]
    pc5_1 = pc4_2.PaneControl(searchDepth=1, ClassName='TPanel', Name='')
    if deta_or_not == '                否                ':
        # print('导出不包含明细')
        cbc6_2 = pc5_1.ComboBoxControl(searchDepth=1, Name='')
        cbc6_2.SetFocus()
        pyautogui.press('down')

    # print('深度6')

    rbc6_14 = pc5_1.RadioButtonControl(searchDepth=1, Name='指定年月')
    # print('点击:' + rbc6_14.Name)
    rbc6_14.Click()
    pyautogui.press('tab')
    pyperclip.copy(year_input)
    pyautogui.hotkey('ctrl', 'v')

    cbc6_3 = pc5_1.ComboBoxControl(searchDepth=1, ClassName='TComboBox', foundIndex=2)
    mont_show = cbc6_3.GetValuePattern().Value  # month show会计系统4
    # 显示月份
    #print(mont_show)
    pyautogui.press('tab')
    for c in range(len(mont_list)):
        if mont_show == mont_list[c]:  # 一月对应的i是0
            # print('c+1')
            # print(c+1)
            print(mont_list[c])
            if mont_input > c + 1:
                for t in range(abs(mont_input - (c + 1))):
                    pyautogui.press('down')
            else:
                for t in range(abs(mont_input - (c + 1))):
                    pyautogui.press('up')

    # print(mont_show.Value)
    #tc7_1d = cbc6_3.TextControl(searchDepth=1, Name='')
    # print(tc7_1d)
    # mont_show = tc7_1d.GetValuePattern() #month show显示月份
    # print(mont_show)
    # print('按tab键切换到月份下拉菜单,按向下按钮,一直到十二月')

    # if mont_input != this_mont:
    #     print('按tab键切换到月份下拉菜单,按向下或向上按钮,一直到十二月或一月')
    #     pyautogui.press('tab')
    #     if mont_input > 6 and this_mont > 6:
    #         print('mont_input > 6 and this_mont > 6')
    #         for i in range(0, 6):
    #             pyautogui.press('down')
    #         time.sleep(1)
    #         for i in range(0, 12 - mont_input):
    #             pyautogui.press('up')
    #     elif mont_input <= 6 and this_mont <= 6 and this_mont != 1:  # 1月份显示12月份数已经入账。所以this_mont 大于6
    #         print('mont_input <= 6 and this_mont <= 6 and this_mont != 1')
    #         for i in range(0, 6):
    #             pyautogui.press('up')
    #         time.sleep(1)
    #         for i in range(0, mont_input - 1):
    #             pyautogui.press('down')
    #     else:
    #         print('Else')
    #         for i in range(0, 12):
    #             pyautogui.press('up')
    #             #print('pyautogui.press(up)')
    #         time.sleep(1)
    #         for i in range(0, mont_input - 1):
    #             pyautogui.press('down')
    #             #print('pyautogui.press(up)')


    # for i in range(12):
    #     pyautogui.press('Up') #返回到1月
    # for i in range(mont_input-1):
    #     pyautogui.press('Down')


    # diff_mont = this_mont - mont_input
    # print(diff_mont)
    # for i in range(diff_mont - 1):
    #     pyautogui.press('Down')
    # print(type(mont_input))
    # print(type(this_mont))
    # print(mont_input)
    # print(this_mont)
    # diff_mont = abs(mont_input - this_mont)
    # print(diff_mont)
    # for i in range(diff_mont):
    #     time.sleep(1)
    #     pyautogui.press('Down')
    # if mont_input >= this_mont:
    #     print('输入月份大于当前月份')
    #     diff_mont = mont_input - this_mont
    #     print(diff_mont)
    #     for i in range(diff_mont-1):
    #         time.sleep(1)
    #         pyautogui.press('Down')
    # if mont_input <= this_mont:
    #     print('输入月份小于当前月份')
    #     diff_mont =  this_mont - mont_input
    #     print(diff_mont)
    #     for i in range(diff_mont-1):
    #         time.sleep(1)
    #         pyautogui.press('Up')

    # year = time.strftime("%Y")
    # # print("当前年份是:", year)
    # if year_input != year:
    #     # print('深度6')
    #     rbc6_14 = pc5_1.RadioButtonControl(searchDepth=1, Name='指定年月')
    #     # print('点击:' + rbc6_14.Name)
    #     rbc6_14.Click()
    #     pyautogui.press('tab')
    #     pyperclip.copy(year_input)
    #     pyautogui.hotkey('ctrl', 'v')
    #     # print('按tab键切换到月份下拉菜单,按向下按钮,一直到十二月')
    #     pyautogui.press('tab')
    #     for i in range(0, 12):
    #         pyautogui.press('down')
    # else:
    #
    #     rbc6_13 = pc5_1.RadioButtonControl(searchDepth=1, Name='当前年月')
    #     # print('点击:' + rbc6_13.Name)
    #     rbc6_13.Click()
    time.sleep(1)
    pyautogui.click(screenWidth/25.6 , screenHeight/18 ) #点击(75,60 )刷新,入账审核过帐后,第一次查询收支明细表需要刷新。否则只能查询到上个月的数据。
    time.sleep(2)
    pyautogui.click(screenWidth/14.7692, screenHeight/18) #点击打印(130, 60)
    time.sleep(2)
    pyautogui.click(screenWidth/15.36, screenHeight/27)# 点击预览界面中的打印(125, 40)
    time.sleep(2)
    pyautogui.press('Enter')
    time.sleep(2)
    pyautogui.hotkey('Alt', 'F4')  # 退出打印界面,返回**凭证处理界面
    time.sleep(1)

def sele_year_san_lan(year_input, mont_input): #select year and print san lan ming xi zhang,三栏明细账
    time.sleep(1)
    # print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
    # 设置为顶层
    print(wc1.Name)

    # print('深度2') #isum自创字母后的数字表示深度
    pc2 = wc1.PaneControl(searchDepth=1, Name='工作区')
    # print(pc2.Name)

    # print('深度3')
    wc3 = pc2.WindowControl(searchDepth=1, Name='三栏明细帐')
    # print(wc3.Name)

    # print('深度4')
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=2)
    # print(pc4.Name) #Name: 'Panel6' #搜索的是第一个

    # pc = wc.PaneControl(searchDepth=1, ClassName='TPanel', AutomationId= '9701258') #AutomationId是动态变化的不能用
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', Name='')
    # print(pc4.Name) #Name: 'Panel6' #搜索的是第一个
    # print(pc4.AutomationId)

    # print('深度5')
    pc5_2 = pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=2)
    # print(pc5_2.Name)
    # print(pc5_2.AutomationId)

    pc5_4 = pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=4)
    # print('pc5_4')
    # print(pc5_4.Name)
    # print(pc5_4.AutomationId)

    pc5_5 = pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=5)
    # print('pc5_5')
    # print(pc5_5.Name)
    # print(pc5_5.AutomationId)

    # print('深度6')
    pc6 = pc5_2.PaneControl(searchDepth=1, ClassName='TPanel')
    # print('pc6')
    # print(pc6.Name)
    # print(pc6.AutomationId)

    # 全部数据上层
    cbc6_1 = pc5_4.ComboBoxControl(searchDepth=1, ClassName='TComboBox', foundIndex=2)
    # print('cbc6_1')
    # print(cbc6_1.Name) #
    # print(cbc6_1.AutomationId)
    cbc6_1.Click()
    pyautogui.press('down')
    pyautogui.press('down')

    # #全部数据下层
    # tc7_1=cbc6_1.TextControl(searchDepth=1,Name='')
    # print('tc7_1')
    # print(tc7_1)
    # print(tc7_1.AutomationId)

    ec6_1 = pc5_4.EditControl(searchDepth=1, ClassName='TEdit')
    # print('先获取焦点,否则不能写入年份')
    ec6_1.SetFocus()
    # ec6_1.SendKey('2020')不能写入
    pyperclip.copy(year_input)
    pyautogui.hotkey('ctrl', 'v')
    # print(ec6_1.AutomationId)

    # print('深度7')
    pc7 = pc6.PaneControl(searchDepth=1, ClassName='TdxCheckbox')
    # print(pc7.Name) #方式二科目范围
    # print(pc7.AutomationId)




def select_accnt_code(accnt_code):
    #print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
    # 设置为顶层
    #print(wc1.Name)

    #print('深度2') #isum自创字母后的数字表示深度
    pc2 = wc1.PaneControl(searchDepth=1, Name='工作区')
    #print(pc2.Name)

    #print('深度3')
    wc3= pc2.WindowControl(searchDepth=1, Name='三栏明细帐')
    #print('定位到',end='')
    #print(wc3.Name)


    #print('深度4')
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=2)
    #print(pc4.Name) #Name: 'Panel6' #搜索的是第一个

    #pc = wc.PaneControl(searchDepth=1, ClassName='TPanel', AutomationId= '9701258') #AutomationId是动态变化的不能用
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', Name= '')
    #print(pc4.Name) #Name: 'Panel6' #搜索的是第一个
    #print(pc4.AutomationId)


    pc5_3= pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=3)
    #print(pc5_3.Name)
    #print(pc5_3.AutomationId)

    pc6_2= pc5_3.PaneControl(searchDepth=1, ClassName='TPanel')
    #print('pc6_2')
    #print(pc6_2.Name) # Name: '方式一:特定科目'
    #print(pc6_2.AutomationId)

    pc7_2= pc6_2.PaneControl(searchDepth=1, ClassName='TdxCheckbox')
    #print(pc7_2.Name) # Name: '方式一:特定科目'
    #print(pc7_2.AutomationId)
    #pc7_2.SendKey('101') 不能用,因为PaneControl是不能输入值的
    #pc7_2.SetFocus()#不用setfocus也可以的
    time.sleep(2)
    pc7_2.Click()

    time.sleep(1)
    #print('定位到方式一:特定科目,tab建切换到文本输入框。')
    pyautogui.press('tab')
    pyperclip.copy(accnt_code) #101现金科目代码
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(1)
    pyautogui.press('tab')









def prin_bala_shee(year_input, mont_input): #打印科目余额表
    time.sleep(1)
    # print('点击科目余额表')
    pyautogui.click(screenWidth / 2.7826, screenHeight / 1.125)  # 系统小字体显示,点击科目余额表(690,960)
    time.sleep(1)
    # print('选择年份')
    # print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [科目余额表]')
    # 设置为顶层
    # wc1.SetTopmost(True)
    # print(wc1.Name)

    # print('深度2') #isum自创字母后的数字表示深度
    # sbc2_1= wc1.StatusBarControl(searchDepth=1, ClassName= 'TStatusBar')
    pc2_2 = wc1.PaneControl(searchDepth=1, ClassName='MDIClient')
    # print(pc2_2.Name)#工作区

    # print('深度3')
    wc3_1 = pc2_2.WindowControl(searchDepth=1, Name='科目余额表')
    # print(wc3_1.Name)  # 工作区

    # print('深度4')
    pc4_2 = wc3_1.PaneControl(searchDepth=1, ClassName='TPanel', Name='')
    # print(pc4_2.BoundingRectangle) #Rect: (0,183,311,1013)[311x830]

    # print('深度5')
    # Rect: (1,214,310,442)[309x228]
    pc5_2 = pc4_2.PaneControl(searchDepth=1, ClassName='TPanel', Name='', foundIndex=2)
    # print(pc5_2.BoundingRectangle)

    # print('深度6')
    rbc6_12b = pc5_2.RadioButtonControl(searchDepth=1, Name='指定区间')
    rbc6_13b = pc5_2.RadioButtonControl(searchDepth=1, Name='当前年月')
    rbc6_14b = pc5_2.RadioButtonControl(searchDepth=1, Name='指定年份')
    rbc6_18b = pc5_2.RadioButtonControl(searchDepth=1, Name='指定年月')
    # print('点击:'+rbc6_14.Name)

    year = time.strftime("%Y")
    # print("当前年份是:", year)
    list_time_quan = ['当前年月', '指定年月', '指定年份', '指定区间']  # time quantum时间段
    time_quan = list_time_quan[1]
    if time_quan == '指定年月':
        rbc6_18b.Click()
        if year_input != year:
            pyautogui.press('tab')
            pyperclip.copy(year_input)
            pyautogui.hotkey('ctrl', 'v')
        cbc6_21b =pc5_2.ComboBoxControl(searchDepth=1, ClassName = 'TComboBox', foundIndex=3)
        mont_show = cbc6_21b.GetValuePattern().Value  # month show会计系统4
        # 显示月份
        # print(mont_show)
        pyautogui.press('tab')
        for c in range(len(mont_list)):
            if mont_show == mont_list[c]:  # 一月对应的c是0
                # print('c+1')
                # print(c+1)
                print(mont_list[c])
                if mont_input > c + 1:
                    for t in range(abs(mont_input - (c + 1))):
                        pyautogui.press('down')
                else:
                    for t in range(abs(mont_input - (c + 1))):
                        pyautogui.press('up')

        # if mont_input != this_mont:
        #     print('按tab键切换到月份下拉菜单,按向下或向上按钮,一直到十二月或一月')
        #     pyautogui.press('tab')
        #     if mont_input > 6 and this_mont > 6:
        #         for i in range(0,6):
        #             pyautogui.press('down')
        #         time.sleep(1)
        #         for i in range(0, 12-mont_input):
        #             pyautogui.press('up')
        #     elif mont_input <= 6 and this_mont <= 6 and this_mont != 1: #1月份显示12月份数已经入账。所以this_mont 大于6
        #         for i in range(0,6):
        #             pyautogui.press('up')
        #         time.sleep(1)
        #         for i in range(0, mont_input-1):
        #             pyautogui.press('down')
        #     else:
        #         for i in range(0, 12):
        #             pyautogui.press('up')
        #         time.sleep(1)
        #         for i in range(0, mont_input - 1):
        #             pyautogui.press('down')
        #         #不用下面这么复杂,下面两种情况是一样耗时的
        #         # if this_mont > 6:
        #         #     for i in range(0,6):
        #         #         pyautogui.press('down')
        #         #     for i in range(0, 12-mont_input):
        #         #         pyautogui.press('up')
        #         # else:
        #         #     for i in range(0, 6):
        #         #         pyautogui.press('up')
        #         #     for i in range(0, mont_input - 1):
        #         #         pyautogui.press('down')
    if time_quan == '指定年份':
        rbc6_14b.Click()
        if year_input != year:
            pyautogui.press('tab')
            pyperclip.copy(year_input)
            pyautogui.hotkey('ctrl', 'v')
            # print('按tab键切换到月份下拉菜单,按向下按钮,一直到十二月')
            # pyautogui.press('tab')
            # for i in range(0,12):
            #     pyautogui.press('down')

    cbc6_21 = pc5_2.ComboBoxControl(searchDepth=1, ClassName='TComboBox', foundIndex=4)#排除零项
    # print(cbc6_21)
    tc7_1 = cbc6_21.TextControl(searchDepth=1, Name='', )
    tc7_1.SetFocus()
    pyautogui.press('down')
    time.sleep(2)
    pyautogui.click(220,80)
    time.sleep(2)
    pyautogui.click(screenWidth/15.36, screenHeight/27)# 点击预览界面中的打印(125, 40)
    time.sleep(2)

    # pyautogui.press('enter')
    pyautogui.hotkey('ctrl', 'P')


    time.sleep(3)
    pyautogui.hotkey('shift', 'tab')# tab切换焦点会改变打印的页范围。用'shift', 'tab'回撤切换焦点。选择打印机。

    pyautogui.hotkey('shift', 'tab')

    #pyautogui.press('down') #选择打印机
    pyautogui.press('enter') #确定打印
    time.sleep(3)
    #pyautogui.press('enter')
    time.sleep(3)
    pyautogui.hotkey('Alt', 'F4')  # 退出打印界面,返回**凭证处理界面
    time.sleep(1)



def prin_chro_book(year_input, mont_input): #select year and print chronological book,序时簿
    time.sleep(1)
    pyautogui.click(screenWidth / 7.2453, screenHeight / 1.1676)  # 系统小字体显示,点击凭证查询(265,925)
    time.sleep(1)
    print('序时簿')
    pyautogui.click(screenWidth/ 14.7692, screenHeight/15.4286)  # (130,70)
    # print('选择年份')
    # print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [凭证查询]')
    # 设置为顶层
    # wc1.SetTopmost(True)
    # print(wc1.Name)

    # print('深度2') #isum自创字母后的数字表示深度
    # sbc2_1= wc1.StatusBarControl(searchDepth=1, ClassName= 'TStatusBar')
    pc2_2 = wc1.PaneControl(searchDepth=1, ClassName='MDIClient')
    # print(pc2_2.Name)#工作区

    # print('深度3')
    wc3_1 = pc2_2.WindowControl(searchDepth=1, Name='凭证查询')
    # print(wc3_1.Name)  # 工作区

    # print('深度4')
    pc4_2 = wc3_1.PaneControl(searchDepth=1, ClassName='TPanel', Name='')
    # print(pc4_2.BoundingRectangle) #Rect: (0,183,311,1013)[311x830]

    # print('深度5')
    # Rect: (1,214,310,442)[309x228]
    pc5_1 = pc4_2.PaneControl(searchDepth=1, ClassName='TPanel', Name='')

    # print('深度6')
    rbc6_14 = pc5_1.RadioButtonControl(searchDepth=1, Name='指定年份')
    # print('点击:'+rbc6_14.Name)
    rbc6_14.Click()
    year = time.strftime("%Y")
    # print("当前年份是:", year)
    if year_input != year:
        pyautogui.press('tab')
        pyperclip.copy(year_input)
        pyautogui.hotkey('ctrl', 'v')
        # 选项出现较慢,需要等待
        print('点击生成')
        # pyautogui.click(screenWidth/8.3478, screenHeight /13.5)  # 系统中等字体显示,点击生成按钮(230,80)
        pyautogui.click(screenWidth / 10.6667, screenHeight / 15.4286)  # 系统小字体显示,点击生成按钮(180,70)
        time.sleep(2)
        #点击打印
        pyautogui.click(screenWidth / 5.0526, screenHeight / 16.6154)  # 系统小字体显示,点击生成按钮(380,60)
    time.sleep(2)
    pyautogui.click(screenWidth/15.36, screenHeight/27)# 点击预览界面中的打印(125, 40)
    time.sleep(1)
    pyautogui.press('Enter')
    time.sleep(2)
    pyautogui.hotkey('Alt', 'F4')
    time.sleep(2)


def open_fold():
    # #open folder,打开文件夹,用win+E快捷键
    pyautogui.hotkey('win', 'e')
    pyautogui.press('tab')
    #pyautogui.press('insert')
    pyautogui.press('enter')
    pyperclip.copy('D:\**会计系统导出数据')
    pyautogui.hotkey('ctrl', 'v')
    pyautogui.press('enter')



def func(year_input, mont_input, prin_type_input):



    #print(screenWidth, screenHeight)  # 屏幕分辨率1920 1080,导出的按钮595,80
    msg = '浏览需要导出的村委会Excel表格文件并打开'
    title = '打开文件'
    filePath = easygui.fileopenbox(msg, title)
    #print(filePath)
    df = pandas.read_excel(filePath)

    #df=pandas.read_excel('**电脑端账套号pandas.xlsx')
    #df = pd.read_excel(src_file, header=1, usecols='B:F')
    #header参数为一个整数,从0开始索引,其为选择的行,比如1表示Excel中的第2行。
    #usecols参数设定选择的Excel列范围范围(A-…),例如,B:F表示读取B到F列。

    accnt_dict=dict(zip(df['账套号'],df['账套号加单位简称']))

    #print('获取字典的键,要转化为列表。第一个键是:',end='')

    account_Num= list(accnt_dict)[0]
    print(account_Num)





    year = time.strftime("%Y")
    #print("当前年份是:", year)
    #year_input = pyautogui.prompt('请输入账套查询的年份:')
    #print('弹窗输入年份:' + year_input)


    #print('Excel文件上要导出的文件数量及文件列表是:','list_accnt_dict(要先将字典的键转化为字符串格式,两个列表的元素都是字符串才能做减法)')
    list_accnt_dict= [str(t) for t in list(accnt_dict)]




    file_numb = 0
    for i in list_accnt_dict:
        #print('i在之前转化为字符串,要重新转化为数值格式')
        i=int(i)
        #print('直接用遍历字典的键值循环,i就是账套号')
        accnt_Num_name=accnt_dict[i]
        print('账套号是:' + str(i)+',账套名称是:'+accnt_Num_name)
        time.sleep(1)
        #账套号登录自定义函数
        accnt_login(i)
        time.sleep(1)
        #用户登录自定义函数
        user_login()

        time.sleep(1)

        # 选项出现较慢,需要等待
        # print('深度1') 依次点击总账报表--凭证处理--凭证处理
        wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [主界面]')
        # 设置为顶层
        # wc1.SetTopmost(True)
        # print(wc1.Name)
        # print('深度2') #isum自创字母后的数字表示深度
        # pc2_2d = wc1.PaneControl(searchDepth=1, Name='工作区')
        # print(pc2_2d)

        # wc3_1d = pc2_2d.WindowControl(searchDepth=1,  Name='主界面')
        # pc4_2d = wc3_1d.PaneControl(searchDepth=1, ClassName ='TPanel', foundIndex=2)
        # print(pc4_2d)
        # pc5_6d = pc4_2d.PaneControl(searchDepth=1, Name ='总帐报表')
        # pc5_6d.Click()
        if prin_type_input == 1:
            print('打印会计凭证。')
            prin_acco_docu(year_input=year_input,mont_input=mont_input)
        if prin_type_input ==2:
            print('科目余额表。')
            prin_bala_shee(year_input=year_input,mont_input=mont_input)
        if prin_type_input == 3:
            print('三栏明细账。')
            time.sleep(1)

            # pyautogui.click(700, 925)  # 点击三栏明细账
            pyautogui.click(screenWidth / 2.7429, screenHeight / 1.1676)
            sele_year_san_lan(year_input=year_input, mont_input=mont_input)
            for accnt_code in list(accnt_code_dict.keys()):
                # for accnt_code in accnt_code_list:
                select_accnt_code(accnt_code)  # 填写科目代码,会弹窗提示: Name: '601科目不存在,系统跳过!'
                time.sleep(1)
                # 科目代码不存在时会弹窗
                wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
                # 设置为顶层
                # print(wc1.Name)
                wc1.SetActive(True)
                try:
                    # print('深度2')  # simon自创字母后的数字表示深度
                    wc2_1_1 = wc1.WindowControl(searchDepth=1, Name='提示')
                    # print('提示')
                    # print(wc2_1_1.Name)
                    bc3_1_1 = wc2_1_1.ButtonControl(searchDepth=1, Name='确定')
                    # print('bc3_1_1确定')
                    # print(bc3_1_1.Name)
                    bc3_1_1.SetFocus()
                    pyautogui.press('enter')  # 点击确定
                    # pyautogui.keyDown('backspace')  # 长摁删除键
                    # time.sleep(1)
                    # pyautogui.keyUp('backspace')


                except:
                    if wc2_1_1.Exists():
                        pass
                    else:
                        pyautogui.click(screenWidth / 4.5714, screenHeight / 18)  # 点击打印按钮坐标(420, 60)
                        pyautogui.press('down')  # 按向下键,选择当前科目
                        pyautogui.press('enter')  # 点击确定
                        time.sleep(2)
                        pyautogui.click(screenWidth / 16, screenHeight / 30.8571)  # 点击(120, 35)
                        # 默认打印机是提前设定好的打印机,输出PDF默认打印机是PDF虚拟打印机。
                        pyautogui.press('enter')  # 点击确定打印
                        time.sleep(3)
                        pyautogui.hotkey('alt', 'f4')  # 关闭对话框
                        time.sleep(2)

        if prin_type_input == 4:
            print('打印收支明细表。')
            prin_inco(year_input=year_input,mont_input=mont_input)


        if prin_type_input == 5:
            print('打印序时簿。')
            prin_chro_book(year_input=year_input,mont_input=mont_input)



        #print('导出Excel表涉及到创建文件夹,创建文件,需要输入屏幕长宽、年份、账套号、账套名称、账套所在村委会字典')

        #print('系统中等字体显示点击另选账套')
        #pyautogui.click(722,37)  #另选账套
        #account_Num+=1
        #print('系统小字体显示点击另选账套坐标135,36')
        pyautogui.click(screenWidth/3.2,screenHeight/30)  #另选账套
        time.sleep(3)#另选账套必须足够长时间,因为窗口切换幅度大
        file_numb+=1
        print('已打印账套数:{}个'.format(file_numb))
    #pyautogui.alert(text=r"文件保存在D:\**会计系统导出数据", title="提示")  #
if __name__ == "__main__":
    #creat_file('2019')
    print('桌面不能打开其他程序,程序在左下角运行。程序运行时不能操作鼠标和键盘,不能打开word和WPS。文件保存在D:\**会计系统导出数据.')
    #pyautogui.alert(text="桌面不能打开其他程序,程序在左下角运行。程序运行时不能操作鼠标和键盘。文件保存在D:\**会计系统导出数据",title="提示")
    time.sleep(1)
    # year_input = easygui.multchoicebox('2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023')
    # mont_input = easygui.multchoicebox('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12')

    #time.sleep(20)
    # 打开程序
    proc_list = ['D:\**经营管理系统2007版\BJACCOUNT.EXE', 'E:\**经营管理系统2007版\BJACCOUNT.EXE', 'C:\**经营管理系统2007版\BJACCOUNT.EXE',
                 'F:\**经营管理系统2007版\BJACCOUNT.EXE', 'G:\**经营管理系统2007版\BJACCOUNT.EXE','H:\**经营管理系统2007版\BJACCOUNT.EXE',
                 'I:\**经营管理系统2007版\BJACCOUNT.EXE', 'J:\**经营管理系统2007版\BJACCOUNT.EXE', 'K:\**经营管理系统2007版\BJACCOUNT.EXE',
                 'D:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'E:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'C:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'F:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'G:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'H:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'I:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'J:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'K:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'D:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'E:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'C:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'F:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'G:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'H:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'I:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'J:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'K:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 ]
    for i in range(len(proc_list)):
        try:
            subprocess.Popen(proc_list[i])
            #print('程序在:{}'.format(proc_list[i]))
            break
        except:
            #print('程序不在:{}'.format(proc_list[i]))
            pass

    time.sleep(3)
    wc = uiautomation.WindowControl(searchDepth=1, Name='帐套登陆')
    # 设置为顶层
    # pyautogui.alert(text="按回车键继续程序", title="提示")  # 窗口前置才能用键盘快捷键
    #print('窗口前置才能用键盘快捷键')
    wc.SetTopmost(True)  # 置顶能用快捷键
    # accnt_Num_txt = wc.EditControl()
    # print('accnt_Num_txt',accnt_Num_txt)
    # for year_input in range(2021, 2020, -1):
    #     year_input=str(year_input)
    #     print(year_input)
    #     func(year_input=year_input, mont_input=mont_input)
    func(year_input=year_input, mont_input=mont_input, prin_type_input=prin_type_input)
    open_fold()









  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值