-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainWin.py
777 lines (692 loc) · 36.7 KB
/
mainWin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# coding:utf-8
# 界面的逻辑功能函数
# import sys
import os
# sys.path.append(r'..\.')
import pandas as pd
# import json
# import traceback
from mainWinUI import Ui_MainWindow
import myLogging as mylogger
from PyQt5.QtWidgets import QFileDialog,QTableWidgetItem,QMainWindow
# from PyQt5.QtCore import Qt
from PyQt5.Qt import QHeaderView
import cgitb
cgitb.enable( format = 'text',logdir=mylogger.err_path)
# Ui_MainWindow
class MyMainWindow(QMainWindow,Ui_MainWindow):
def __init__(self,parent=None):
super(MyMainWindow,self).__init__(parent)
# self.logger = myLogging()
mylogger.logger.debug('mainWin>init..')
self.setupUi(self)
self.initUI()
self.deal_taizhang = '' # deal_taizhang()
self.fileList = {}
# self.townList = ''
self.workPath = os.getcwd()
self.A = ''
self.A_flag = False
self.B = ''
self.B_flag = False
self.xiaoqu = ''
self.xiaoqu_flag = False
self.zhuzhai = ''
self.zhuzhai_flag = False
self.zhuhu = ''
self.zhuhu_flag = False
self.zy = ''
self.zy_flag = False
self.codes = ''
self.codes_flag =False
self.tz = ''
self.tz_flag = False
self.townTable = ''
self.location = ''
self.page_break_row = []
#A、B、D审核结果输出表的表头
self.A_table_head = {'year':[],'sid':[],'scode':[],'name':[],'code':[],'核实内容':[],'核实说明':[],'townname':[],'vname':[]}
A_head = ['year','sid', 'scode', 'name', 'code', '核实内容','核实说明', 'townname', 'vname']
self.An_check_result = pd.DataFrame(self.A_table_head)
self.An_check_result = self.An_check_result[A_head]
self.As_check_result = pd.DataFrame(self.A_table_head)
self.As_check_result = self.As_check_result[A_head]
self.B_table_head = {'year':[], 'sid': [], 'scode': [], 'code': [], '核实内容': [],'核实说明':[], 'townname': [], 'vname': []}
B_head = ['year', 'sid', 'scode', 'code', '核实内容','核实说明', 'townname', 'vname']
self.Bn_check_result = pd.DataFrame(self.B_table_head)
self.Bn_check_result = self.Bn_check_result[B_head]
self.Bs_check_result = pd.DataFrame(self.B_table_head)
self.Bs_check_result = self.Bs_check_result[B_head]
self.Bi_check_result = pd.DataFrame(self.B_table_head)
self.Bi_check_result = self.Bi_check_result[B_head]
self.zy_table_head = {'sid': [],'coun':[],'scode': [],'task': [],'year': [], 'month': [], 'person': [], 'name': [], 'code': [],'核实内容': [],'核实说明':[],'townname': [], 'vname': []}
zy_head = ['sid', 'coun', 'scode','year', 'month', 'task', 'person', 'name', 'code', '核实内容','核实说明','townname', 'vname']
self.zs_check_result = pd.DataFrame(self.zy_table_head)
self.zs_check_result = self.zs_check_result[zy_head]
self.zn_check_result = pd.DataFrame(self.zy_table_head)
self.zn_check_result = self.zn_check_result[zy_head]
self.za_check_result = pd.DataFrame(self.zy_table_head)
self.za_check_result = self.za_check_result[zy_head]
self.zi_check_result = pd.DataFrame(self.zy_table_head)
self.zi_check_result = self.zi_check_result[zy_head]
self.now_show_table = ''
# self.openTownList()
self.connectSlot()
mylogger.logger.debug('mainWin>init ok')
# 重新设置UI界面
def initUI(self):
self.splitter.setStretchFactor(1,3)
self.splitter_2.setStretchFactor(0,1)
# self.tableData.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.tableData.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
# self.setWindowFlags(Qt.FramelessWindowHint)
# 为组件绑定事件
def connectSlot(self):
# self.actionimportFile = QtWidgets.QAction("导入文件", self, triggered=self.openFile)
self.actionimportFile.triggered.connect(self.showInTable)
self.actionworkspace.triggered.connect(self.selectWorkDirecory)
self.actionIntroduce.triggered.connect(self.helpText)
self.open_tableA.clicked.connect(self.setTableA)
self.open_zy.clicked.connect(self.setZy)
self.xz_comboBox.currentIndexChanged.connect(self.townSelectChange)
self.generateTz.clicked.connect(self.genTz)
self.import_townList.clicked.connect(self.openTownList)
self.export_taizhang.clicked.connect(self.save_to_csv)
# self.importTable.clicked.connect(self.importTableFiles)
self.importTable.clicked.connect(self.openImportFileDialog)
self.questionCheck.clicked.connect(self.openQuestionCheckDialog)
self.zyCheck.clicked.connect(self.openzyCheckDialog)
self.file_list.itemClicked.connect(self.listSelection)
self.searchButton.clicked.connect(self.search)
def selectWorkDirecory(self):
self.workPath = QFileDialog.getExistingDirectory(self,"选择工作目录",os.getcwd())
def helpText(self):
mylogger.logger.debug("help")
with open("使用帮助.txt","r",encoding="utf-8") as f:
# print("open")
txt = f.read()
# print("txt",txt)
self.textEdit.setText(txt)
# print("打开使用帮助")
self.statusbar.showMessage("打开使用帮助",3000)
def showMaximized(self):
desktop = QApplication.desktop()
rect = desktop.availableGeometry()
self.setGeometry(rect)
# self.show()
def search(self):
sid = self.searchlineEdit.text()
if sid == "":
self.statusbar.showMessage("请在输入框中填入要搜索户的SID")
else:
if self.A_flag == False:
self.statusbar.showMessage("请先导入A表")
else:
family = self.A[self.A["SID"] == sid]
if family.empty == False:
# 按照人码进行排序
family = family.sort_values(by='A100')
family.fillna('')
# print(family)
res = self.setFamily(family)
self.showData(res)
self.statusbar.showMessage("查找成功",3000)
else:
self.statusbar.showMessage("A表中无此户数据")
def setFamily(self,family):
zhibiao_arr = ["成员编码","姓名","本期住户成员变动情况","与本户户主的关系","性别","出生年月","民族","户口登记地","户口性质","健康状况","参加何种医疗保险","是否在校学生","受教育程度","婚姻状况","是否持证残疾人","在本住宅居住时间","是否每月到其他住宅居住","是否每月到本住宅居住一天以上","是否打算居住本宅超过一个半月","是否常住人口", "成员编码","是否离退休人员","参加何种养老保险","是否丧失劳动能力","是否从业过","主要就业状况","主要行业","主要职业","工作总时间","工作地点","最远去哪里工作或学习(上大学)过","您认为自己主要属于下列哪个群体","您认为自己还属于下列哪个群体","您拥有的与当前职业相关的最高技能等级证书或职业技能证书","您拥有的与当前职业相关的最高技术职称"]
code_arr = ["A100","A101","A102","A103","A104","A105","A107","A108","A109","A110","A111","A112","A113","A114","A120","A115","A116","A117","A118","A119", "A200","A201","A202","A203","A204","A205","A206","A207","A208","A209","A210","A211","A212","A213","A214"]
index_arr = ['一', '二', '三', '四', '五', '六', '七', '八','九']
data = {'指标': [], '编码': [], '一': [], '二': [], '三': [], '四': [], '五': [], '六': [], '七': [], '八': [],'九': []}
result = pd.DataFrame(data)
result = result[['指标', '编码', '一', '二', '三', '四', '五', '六', '七', '八','九']]
# 一户总人数
rowCount = family.iloc[:, 0].size
for (zhibiao, code) in zip(zhibiao_arr, code_arr):
dict = {"指标":zhibiao,"编码":code}
code_data = family[code]
# print("code_data",code_data,type(code_data))
for i in range(rowCount):
key = index_arr[i]
# print(key,code_data.values[i])
dict[key] = code_data.values[i]
result = result.append(dict, ignore_index=True)
return result
# list点击触发事件
def listSelection(self,index):
try:
tb = self.fileList[index.text()]
if tb.empty == False:
self.now_show_table = tb
# print(tb)
self.statusbar.showMessage("正在切换至表" + index.text() + ",请稍等...")
self.showData(tb)
self.statusbar.showMessage("切换成功",3000)
else:
self.statusbar.showMessage(index.text() + "为空?请确认")
except Exception as e:
self.statusbar.showMessage("程序异常,请重新操作")
# 向列表中添加项
def addToList(self,key,value):
self.file_list.addItem(key)
self.fileList[key] = value
# 文件List选择
def listSelect(self,item):
if item.text() == "A表":
self.showData(self.A)
if item.text() == "B表":
self.showData(self.B)
if item.text() == "住宅名录":
self.showData(self.zhuzhai)
if item.text() == "小区名录":
self.showData(self.xiaoqu)
if item.text() == "住户名录":
self.showData(self.zhuhu)
if item.text() == "账页表":
self.showData(self.zy)
if item.text() == "台账结果":
self.showData(self.now_show_table)
# 打开csv文件 返回DataFrame对象
def read_csv(self,path):
with open(path, 'r') as f:
mylogger.logger.debug('mainWin>openFile:' + path)
file = pd.read_csv(f, header=0,low_memory=False)
return file
#导入相关文件
def importTableFiles(self):
if self.A_flag == False:
self.A,self.A_flag = self.openFile("请导入A表")
# if self.A_flag == True:
# self.file_list.addItem("A表")
# self.fileList.append(self.A)
if self.B_flag == False:
self.B,self.B_flag = self.openFile("请导入B表")
# if self.B_flag == True:
# self.file_list.addItem("B表")
# self.fileList.append(self.B)
if self.zhuzhai_flag == False:
self.zhuzhai,self.zhuzhai_flag = self.openFile("请导入住宅名录")
# if self.zhuzhai_flag == True:
# self.file_list.addItem("住宅名录")
# self.fileList.append(self.zhuzhai)
if self.xiaoqu_flag == False:
self.xiaoqu,self.xiaoqu_flag = self.openFile("请导入小区名录")
# if self.xiaoqu_flag == True:
# self.file_list.addItem("小区名录")
# self.fileList.append(self.xiaoqu)
if self.zhuhu_flag == False:
self.zhuhu,self.zhuhu_flag = self.openFile("请导入住户名录")
# if self.zhuhu_flag == True:
# self.file_list.addItem("住户名录")
# self.fileList.append(self.zhuhu)
if self.zy_flag == False:
self.zy,self.zy_flag = self.openFile("请导入账页数据")
col = self.colUpper(self.zy.columns.values.tolist())
self.zy = self.zy.rename(columns=col)
# print(self.zy)
# if self.zy_flag == True:
# self.file_list.addItem("账页表")
# self.fileList.append(self.zy)
# 打开审核问卷对话框
def openQuestionCheckDialog(self):
try:
from questionCheckDialog import QuestionCheckDialog
qcd = QuestionCheckDialog(self)
# 获取对话框返回值
result = qcd.exec_()
if result:
from A_necessity_check import A_necessity_check
from A_suggestion_check import A_suggestion_check
from B_necessity_check import B_necessity_check
from B_suggestion_check import B_suggestion_check
from B_independent_check import B_independent_check
An, As, Bn, Bs, Bi,range = qcd.getData()
# print(An, As, Bn, Bs, Bi)
if An + As + Bn + Bs + Bi == 0:
self.statusbar.showMessage("请先选择审核方式")
if An == True or As == True:
if self.A_flag == True and self.xiaoqu_flag == True:
if An == True and self.zhuhu_flag == True:
self.statusbar.showMessage("正在进行问卷A必要性审核,请稍等...")
An_outcome = A_necessity_check(self.A,self.zhuhu,self.xiaoqu,self.An_check_result)
# print(type(An_outcome))
Anfilename = '问卷A必要性审核结果.xlsx'
An_outcome.to_excel('./问卷A必要性审核结果.xlsx',encoding="utf-8",index=False,sheet_name='Sheet')
self.addToList(Anfilename,An_outcome)
self.showData(An_outcome,100)
self.statusbar.showMessage("审核完毕")
if As == True:
self.statusbar.showMessage("正在进行问卷A提示性审核,请稍等...")
As_outcome = A_suggestion_check(self.A,self.xiaoqu,self.As_check_result)
Asfilename = '问卷A提示性审核结果.xlsx'
As_outcome.to_excel('./问卷A提示性审核结果.xlsx', encoding="utf-8", index=False,sheet_name='Sheet')
self.addToList(Asfilename, As_outcome)
self.showData(As_outcome, 100)
self.statusbar.showMessage("审核完毕")
else:
if self.A_flag == False:
self.statusbar.showMessage("请先导入A表")
if self.xiaoqu_flag == False:
self.statusbar.showMessage("请先导入小区表")
if self.zhuhu_flag == False and An == True:
self.statusbar.showMessage("请先导入住户表")
if Bn == True or Bs == True:
if self.B_flag == True and self.zhuhu_flag == True and self.zhuzhai_flag == True and self.xiaoqu_flag == True:
if Bn == True:
self.statusbar.showMessage("正在进行问卷B必要性审核,请稍等...")
Bn_outcome = B_necessity_check(self.B,self.zhuhu,self.zhuzhai,self.xiaoqu,self.Bn_check_result)
Bnfilename = '问卷B必要性审核结果.xlsx'
Bn_outcome.to_excel('./问卷B必要性审核结果.xlsx',encoding="utf-8",index=False,sheet_name='Sheet')
self.addToList(Bnfilename,Bn_outcome)
self.showData(Bn_outcome,100)
self.statusbar.showMessage("审核完毕")
if Bs == True:
self.statusbar.showMessage("正在进行问卷B提示性审核,请稍等...")
Bs_outcome = B_suggestion_check(self.B, self.zhuhu, self.zhuzhai, self.xiaoqu,self.Bs_check_result)
Bsfilename = '问卷B提示性审核结果.xlsx'
Bs_outcome.to_excel('./问卷B提示性审核结果.xlsx', encoding="utf-8", index=False,sheet_name='Sheet')
self.addToList(Bsfilename, Bs_outcome)
self.showData(Bs_outcome, 100)
self.statusbar.showMessage("审核完毕")
else:
if self.B_flag == False:
self.statusbar.showMessage("请先导入B表")
if self.zhuhu_flag == False:
self.statusbar.showMessage("请先导入住户表")
if self.zhuzhai_flag == False:
self.statusbar.showMessage("请先导入住宅表")
if self.xiaoqu_flag == False:
self.statusbar.showMessage("请先导入小区表")
if Bi == True:
if self.B_flag == True and self.xiaoqu_flag == True:
self.statusbar.showMessage("正在进行问卷B独立审核,请稍等...")
Bi_outcome = B_independent_check(self.B,self.xiaoqu,self.Bi_check_result)
Bi_filename = '问卷B独立审核结果.xlsx'
Bi_outcome.to_excel('./问卷B独立审核结果.xlsx', encoding="utf-8", index=False,sheet_name='Sheet')
self.addToList(Bi_filename, Bi_outcome)
self.showData(Bi_outcome, 100)
self.statusbar.showMessage("审核完毕")
else:
if self.B_flag == False:
self.statusbar.showMessage("请先导入B表")
if self.xiaoqu_flag == False:
self.statusbar.showMessage("请先导入小区表")
except Exception as e:
mylogger.logger.error(e)
self.statusbar.showMessage("审核问卷出错,请检查使用数据是否正确")
# print(An,As,Bn,Bs,range)
# print("result:",result)
# qcd.show()
# 打开导入相关文件对话框
def openImportFileDialog(self):
from importFileDialog import importFileDialog
importFile = importFileDialog(self,self.workPath)
result = importFile.exec_()
res_path = importFile.getPath()
info = "打开"
# print(res_path)
if res_path["A"] != "":
info += "A,"
self.A,self.A_flag = self.openFileByPath(res_path["A"])
if res_path["B"] != "":
self.B, self.B_flag = self.openFileByPath(res_path["B"])
info += "B,"
if res_path["住户"] != "":
self.zhuhu, self.zhuhu_flag = self.openFileByPath(res_path["住户"])
info += "住户,"
if res_path["住宅"] != "":
self.zhuzhai, self.zhuzhai_flag = self.openFileByPath(res_path["住宅"])
info += "住宅,"
if res_path["小区"] != "":
self.xiaoqu, self.xiaoqu_flag = self.openFileByPath(res_path["小区"])
info += "住宅,"
if res_path["账页表"] != "":
self.zy, self.zy_flag = self.openFileByPath(res_path["账页表"])
info += "账页表,"
# if res_path["编码手册"] != "":
# self.codes, self.codes_flag = self.openFileByPath(res_path["编码手册"])
# info += "编码手册,"
info += "成功"
if info == "打开成功":
self.statusbar.showMessage("未选择打开新文件")
else:
self.statusbar.showMessage(info)
# 打开审核账页对话框
def openzyCheckDialog(self):
try:
from zyCheckDialog import zyCheckDialog
zcd = zyCheckDialog(self)
result = zcd.exec_()
# print(result)
if result:
from zy_check_necessity import zy_check_necessity
from zy_check_suggestion import zy_check_suggestion
from zy_check_addition import zy_check_addition
from independent_check import independent_check
Zn,Zs,Za,Zi,townRange,monthRange,directory = zcd.getData()
if Zs == True or Zn == True or Za == True or Zi == True:
if self.zy_flag == True and self.A_flag == True and self.B_flag == True and self.zhuhu_flag == True and self.xiaoqu_flag == True:
# 账页逻辑关系独立审核
if Zi == True:
self.statusbar.showMessage("正在进行账页逻辑关系独立审核,请稍等...")
zi_outcome = independent_check(self.A, self.B, self.zy, self.zhuhu, self.xiaoqu,self.zi_check_result)
zi_filename = '账页逻辑关系独立审核.xlsx'
zi_outcome.to_excel(directory + '/' + zi_filename, encoding="utf-8", index=False,sheet_name='Sheet')
self.addToList(zi_filename, zi_outcome)
self.showData(zi_outcome, 100)
self.statusbar.showMessage("审核完毕")
# 账页逻辑关系提示性审核
if Zs == True:
if self.zhuzhai_flag == True:
self.statusbar.showMessage("正在进行账页关系逻辑提示性审核,请稍等...")
Zs_outcome = zy_check_suggestion(self.A, self.B, self.zy, self.zhuzhai, self.zhuhu,
self.xiaoqu, self.zs_check_result)
Zs_filename = '账页逻辑提示性审核.xlsx'
Zs_outcome.to_excel(directory + '/' + Zs_filename, encoding="utf-8", index=False,
sheet_name='Sheet')
self.addToList(Zs_filename, Zs_outcome)
self.showData(Zs_outcome)
self.statusbar.showMessage("审核完毕")
else:
if self.zhuzhai_flag == False:
self.statusbar.showMessage("请先导入住宅表")
# 账页逻辑关系必要性审核
if Zn == True:
if self.zhuzhai_flag == True:
self.statusbar.showMessage("正在进行账页逻辑关系必要性审核,请稍等...")
Zn_outcome = zy_check_necessity(self.A, self.B, self.zy, self.zhuzhai, self.zhuhu, self.xiaoqu,
self.zn_check_result)
Zn_filename = '账页逻辑必要性审核.xlsx'
Zn_outcome.to_excel(directory + '/' + Zn_filename, encoding="utf-8", index=False,
sheet_name='Sheet')
self.addToList(Zn_filename, Zn_outcome)
self.showData(Zn_outcome, 100)
self.statusbar.showMessage("审核完毕")
else:
if self.zhuzhai_flag == False:
self.statusbar.showMessage("请先导入住宅表")
# 账页逻辑关系附加性审核
if Za == True:
if self.zhuzhai_flag == True:
self.statusbar.showMessage("正在进行账页逻辑关系附加性审核,请稍等...")
za_outcome = zy_check_addition(self.A, self.B, self.zy, self.zhuzhai, self.zhuhu, self.xiaoqu,
self.za_check_result)
za_filename = '账页逻辑附加性审核结果.xlsx'
za_outcome.to_excel(directory + '/' + za_filename, encoding="utf-8", index=False,
sheet_name='Sheet')
self.addToList(za_filename, za_outcome)
self.showData(za_outcome, 100)
self.statusbar.showMessage("审核完毕")
else:
if self.zhuzhai_flag == False:
self.statusbar.showMessage("请先导入住宅表")
else:
if self.zy_flag == False:
self.statusbar.showMessage("请先导入账页表")
if self.A_flag == False:
self.statusbar.showMessage("请先导入A表")
if self.B_flag == False:
self.statusbar.showMessage("请先导入B表")
if self.zhuhu_flag == False:
self.statusbar.showMessage("请先导入住户表")
if self.zhuzhai_flag == False:
self.statusbar.showMessage("请先导入住宅表")
if self.xiaoqu_flag == False:
self.statusbar.showMessage("请先导入小区表")
except Exception as e:
mylogger.logger.error(e)
self.statusbar.showMessage("审核账页逻辑关系出错,请检查使用数据是否正确")
def openFileByPath(self,filePath):
try:
mylogger.logger.debug("mainWin>function:openFile:try")
df = self.read_csv(filePath)
filepath, name = os.path.split(filePath)
self.addToList(name, df)
col = self.colUpper(df.columns.values.tolist())
df = df.rename(columns=col)
return df, True
except Exception as e:
mylogger.logger.error("openFileByPath() exception")
mylogger.logger.error(e)
# print("openFile Error",e)
return '', False
# 将所有列名换成大写
def colUpper(self,col):
dict = {}
for key in col:
value = key.upper()
# print(value)
dict[key] = value
return dict
# 打开文件
# 输入:打开文件的提示信息
# 返回值:
# 若选中文件,返回:已打开文件的pandas对象,是否打开文件标志位-True
# 未选中文件,返回:空,False
def openFile(self,tip="选取文件"):
# print("openFile")
fileName1, filetype = QFileDialog.getOpenFileName(self,
tip,
self.workPath,
"All Files (*);;Text Files (*.txt)") # 设置文件扩展名过滤,注意用双分号间隔
# print("filename>",fileName1,"<",type(fileName1),"len:",fileName1)
mylogger.logger.debug("mainWin>function:openFile:%s"%fileName1)
# 若没有选中文件
if fileName1.strip() != "":
# print(fileName1, filetype)
try:
# print("try")
mylogger.logger.debug("mainWin>function:openFile:try")
df = self.read_csv(fileName1)
# fileName = fileName1.split("/")[-1]
filpath,name = os.path.split(fileName1)
# print(fileName,name)
self.addToList(name,df)
col = self.colUpper(df.columns.values.tolist())
df = df.rename(columns=col)
return df,True
except Exception as e:
mylogger.logger.error("mainWin>function:openFile:exception")
mylogger.logger.error(e)
# print("openFile Error",e)
return '',False
else:
self.statusbar.showMessage("未选择文件",3000)
return '',False
#导入相关表后提取小区范围(审核问卷)
def get_community_range(self):
mylogger.logger.debug("get_community_range:")
if self.xiaoqu_flag == False:
mylogger.logger.debug("get_community_range 未选择小区表")
else:
xiaoqu_arr = list(self.xiaoqu['VNAME'].drop_duplicates())
# 导入小区名录时触发
def openTownList(self):
# file_path = "D:/Document/Code/Python/AuditingApp/src/输入文件夹/小区名录310151.18.csv"
# self.read_csv(file_path)
self.townTable,flag = self.openFile("请导入小区名录")
mylogger.logger.debug("openTownList openFile")
if flag == False:
mylogger.logger.debug("openTownList 未选中文件")
else:
mylogger.logger.debug("in openTownList else")
# try:
if self.townTable["TOWNNAME"].values[0].strip() == "乡镇名称":
self.townTable = self.townTable.drop(0)
# townList = self.townTable["townName"].drop_duplicates()
townList = ["所有乡镇"]
arr = list(self.townTable["TOWNNAME"].drop_duplicates())
for i in arr:
townList.append(i)
self.xz_comboBox.clear()
self.xz_comboBox.addItems(townList)
# communityList = ["所有居委会"]
# self.xq_comboBox.clear()
# self.xq_comboBox.addItems(communityList)
self.townSelectChange()
# print("townList:",townList)
mylogger.logger.debug('mainWin>function:openTownList')
self.statusbar.showMessage("打开文件成功",5000)
# except Exception as e:
# print(e)
# mylogger.logger.debug('mainWin>function:openTownList exception')
# self.statusbar.showMessage("打开的文件有误,请重新选择文件",5000)
# 选取生成台账的小区触发函数
def townSelectChange(self):
mylogger.logger.debug("in townSelectChange")
town = self.xz_comboBox.currentText()
if town == "所有乡镇":
communityList = ["所有居委会"]
self.xq_comboBox.clear()
self.xq_comboBox.addItems(communityList)
else:
# community = self.townTable[self.townTable["townName"] == town]
community = self.townTable[self.townTable["TOWNNAME"] == town]
# communityList = community["vName"].drop_duplicates()
communityList = ["所有居委会"]
arr = list(community["VNAME"].drop_duplicates())
for i in arr:
communityList.append(i)
self.xq_comboBox.clear()
self.xq_comboBox.addItems(communityList)
def getCommunityCode(self):
townName = self.xz_comboBox.currentText()
communityName = self.xq_comboBox.currentText()
code = str(self.townTable["VID"].values[0])
if townName == "所有乡镇":
# 310151101027001
# 151101101214001
communityCode = code[0:3]
# self.location = townName
else:
code = str(self.townTable[self.townTable["TOWNNAME"] == townName]["VID"].values[0])
if communityName == "所有居委会":
if code[3:6] == code[6:9]:
communityCode = code[0:6]
else:
communityCode = code[0:9]
else:
# communityList = self.townTable[self.townTable["vName"] == communityName]
communityList = self.townTable[self.townTable["VNAME"] == communityName]
# communityCode = str(communityList["vID"].values[0])
communityCode = str(communityList["VID"].values[0])
mylogger.logger.debug('mainWin>function:getCommunityCode')
self.location = townName + communityName
# location = townName + " " + communityName
return communityCode
def setTableA(self):
# print('setA')
mylogger.logger.debug('mainWin>function:setTableA')
self.A,self.A_flag = self.openFile("请导入A表")
def setZy(self):
# print('setzy')
mylogger.logger.debug('mainWin>function:setTableZy')
self.zy,self.zy_flag = self.openFile("请导入账页表")
def genTz(self):
try:
from deal_taizhang import deal_taizhang
self.deal_taizhang = deal_taizhang()
if self.xq_comboBox.currentText() == '':
self.statusbar.showMessage("请先导入小区名录")
else:
if self.A_flag == False or self.zy_flag == False:
# print("请先导入A表与账页表")
self.statusbar.showMessage("请先导入A表与账页表")
else:
# print('生成台账')
self.statusbar.showMessage("生成台账中...")
communityCode = self.getCommunityCode()
# print("communityCode:",communityCode)
# print("mainWin type:", type(communityCode))
self.now_show_table = self.deal_taizhang.getCommunity(communityCode,self.townTable,self.A,self.zy)
if self.now_show_table.empty == False:
# if self.tz_flag == False:
key = self.location + "台账"
self.addToList(key,self.now_show_table)
self.statusbar.showMessage("生成台账成功")
mylogger.logger.debug("获取到生成台账结果")
# self.clearTable()
self.showData(self.now_show_table,False)
# deal_taizhang.spliteFamily(self.A,self.zy)
else:
self.statusbar.showMessage("生成台账无数据,请确认是否正确选择对应乡镇")
except Exception as e:
# print(e)
mylogger.logger.error(e)
self.statusbar.showMessage("生成台账出错,请检查使用数据是否正确")
def showInTable(self):
self.statusbar.showMessage("正在打开文件")
df,flag = self.openFile()
# print(pd.isnull(df))
if flag == False:
print("空文件")
self.statusbar.showMessage("空文件")
else:
self.statusbar.showMessage("获取数据中,请稍等")
print('getData')
# 获取表头
df = df.fillna('')
header = df.columns.values.tolist() # [str(col) for col in df]
# 获取表的行列数
colCount = df.columns.size
rowCount = df.iloc[:, 0].size
# 设置表行数
self.tableData.setRowCount(rowCount)
# 设置表列数
self.tableData.setColumnCount(colCount)
self.tableData.clear()
# 重新设置表头
self.tableData.setHorizontalHeaderLabels(header)
for r in range(rowCount):
for c in range(colCount):
item = df.iat[r, c]
self.tableData.setItem(r, c, QTableWidgetItem(str(item)))
self.statusbar.showMessage("打开文件成功")
def clearTable(self):
self.tableData.clear()
rowCount = self.tableData.rowCount()
# print(rowCount)
for row in range(0,rowCount):
self.tableData.removeRow(row)
def showData(self,df,max=True):
df = df.fillna('')
mylogger.logger.debug("将结果显示在表上")
header = df.columns.values.tolist() # [str(col) for col in df]
# 获取表的行列数
colCount = df.columns.size
rowCount = df.iloc[:, 0].size
if max == True:
if rowCount > 100:rowCount = 100
# 设置表行数
self.tableData.setRowCount(rowCount)
# 设置表列数
self.tableData.setColumnCount(colCount)
self.tableData.clear()
# 重新设置表头
self.tableData.setHorizontalHeaderLabels(header)
for r in range(0,rowCount):
for c in range(colCount):
item = df.iat[r, c]
self.tableData.setItem(r, c, QTableWidgetItem(str(item)))
def save_to_csv(self):
try:
from page_break_print import page_break_print
path = './' + self.location + '台账结果.xlsx'
self.now_show_table.to_excel(path,encoding="utf-8",index=False,sheet_name='Sheet')
self.statusbar.showMessage("正在添加分页符...")
page_break_print(path)
self.statusbar.showMessage("生成文件" + path + "成功")
# self.now_show_table.to_csv("台账结果.csv",encoding="utf-8",index=False)
mylogger.logger.debug("生成台账结果成功")
except Exception as e:
self.statusbar.showMessage("生成台账出错,请检查操作步骤是否正确?")
def saveFile(self):
filename = QFileDialog.getSaveFileName(self, 'save file', '/home/jm/study')
with open(filename[0], 'w') as f:
my_text = self.textEdit.toPlainText()
f.write(my_text)
if __name__ == '__main__':
app = QApplication(sys.argv)
mywin = MyMainWindow()
mywin.show()
sys.exit(app.exec_())