-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJNBToolV3(0411).py
1969 lines (1487 loc) · 58.7 KB
/
JNBToolV3(0411).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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from PyQt5.QtCore import QFile, QIODevice, Qt, QTextStream
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (QDialog, QFileDialog, QGridLayout, QHBoxLayout, QMessageBox,
QLabel, QLineEdit, QPushButton, QTextEdit, QVBoxLayout, QComboBox, QRadioButton, QCheckBox,
QWidget)
import os
import shutil
import openpyxl
from openpyxl.styles import Font
from openpyxl import styles
from openpyxl.styles import Alignment
from openpyxl.styles import Border, Side, PatternFill, colors
import random
import datetime
import webbrowser
import ctypes
import requests
import pyodbc
#AutoRun
import pyautogui as au
import pyperclip
import time
import subprocess
#Use module
# import ActiveHDForm
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
dateSubmit = str(datetime.date.today())
print(dateSubmit)
listDesAV = {' Choose a designer... ':'','Trung': '중A', 'Kieu': '끼우',
'Thuy': '튀B', 'Chinh': '찐', 'Hai': '하이B', 'Dong': '돔', 'Quan': '꾸언', 'Thinh': '타잉'}
try :
desDic = {}
desPathFile = ""
if os.path.exists(".\sampleFiles\\DesignerList.txt") == False:
desPathFile = "C:\\JNBtool\\SampleFiles\\DesignerList.txt"
desFile = open(desPathFile)
for line in desFile:
if line.count("|") == 2:
desDic[line.split('|')[0]] = line.split('|')[1]
if len(desDic) != 0:
listDesAV = desDic
print(listDesAV)
except:
print("Load default desList")
pass
ListDesV = list(listDesAV.keys())
ListDesV.sort()
#Active HD-Form 2015:
def adminMode():
re = requests.get("http://textuploader.com/dh47h/raw")
pW = re.text
while True:
pWinput = au.password(text = "Bạn cần nhập mật khẩu để sử dụng chức năng này:", title = "Login")
if pWinput == pW:
cf = au.alert(text = "Đăng nhập thành công, nhấn OK để kích hoạt!")
print("Login success")
if cf == 'OK':
return True
else:
return False
break
elif pWinput == None:
return False
break
else:
au.alert(text = "Mật khẩu sai!")
print("Wrong password!")
def runCrack(modeAdmin = False):
if modeAdmin == True:
os.startfile('C:/HD-FORM2015/HD-FORM2015License(Admin).exe')
res = au.size()
# au.moveTo(res[0]/2, res[1]/2)
time.sleep(0.5)
# au.click(res[0]/2, res[1]/2)
au.press('tab')
au.press('tab')
au.press('tab')
au.press('tab')
time.sleep(0.2)
au.typewrite('HDFORM2016PW')
au.press('tab')
au.press('enter')
au.press('tab')
au.press('tab')
au.press('enter')
au.press('enter')
au.hotkey('alt', 'F4')
au.alert(text = "HD-FORM2015 được kích hoạt thành công.")
else:
pass
#autofic Function
### CHUOI HAM SU LI FILE MDB
def saveAsMdbFile(oldname,newname ):
old = open(oldname, 'rb')
content = old.read()
new = open(newname, 'wb')
new.write(content)
new.close()
def updateMdb(mdbPath, toa, kV):
conn_str = (
r'DRIVER={agr};'
r'DBQ={path};'
).format(agr = "{Microsoft Access Driver (*.mdb, *.accdb)}", path = str(mdbPath))
cnxn = pyodbc.connect(conn_str)
crsr = cnxn.cursor()
#Update toa
sql = '''UPDATE TBALB02 SET DONG_NM_KOR=? WHERE ORDCNT=?'''
para = (toa, 1)
crsr.execute(sql, para)
#update kv
sql = '''UPDATE TBALB03 SET HOUD_NM_KOR=? WHERE ORDCNT=?'''
para = (kV, 1)
crsr.execute(sql, para)
#Luu file
cnxn.commit()
cnxn.close()
def autoMakeMdb(mdbSource, lsBlock, info= ("None", "None", "중A", "None","None","None")):
lsBlock = makeList(lsBlock)
lsMdb = []
for block in lsBlock:
info[0] = block[0]
info[1] = block[1]
saveName = "C:\Tempfile\\%s동%s_계단_%s(%s%s).mdb" %(block[0], block[1],info[2],info[3],info[4])
# Copy file nguon thanh file tempMdb.mdb
os.makedirs('C:\Tempfile', exist_ok = True)
shutil.copy2(os.path.abspath(mdbSource), "C:\Tempfile\\tempMdb.mdb")
# Update file mdb
updateMdb("C:\Tempfile\\tempMdb.mdb", block[0], block[1])
# Doi ten file mdb
shutil.copy2("C:\Tempfile\\tempMdb.mdb",saveName)
# Them ten file mdb vua tao:
lsMdb.append(saveName)
# Ham tra ve la danh sach cac file mdb vua tao
return lsMdb
def removeMdb():
os.makedirs('C:\Tempfile', exist_ok = True)
dirProject = str('C:\\tempfile\\')
mdbList = []
for fileMdb in os.listdir(dirProject):
if fileMdb.endswith('.mdb'):
os.remove(dirProject + fileMdb)
print("Have been remove%s " % fileMdb)
return dirProject
def moveMdb(curDir, projCode, newDir = "C:\Tempfile"):
# Move new mdb File
dirProject = curDir
mdbList = []
for fileMdb in os.listdir(dirProject):
if fileMdb.endswith('.mdb') and fileMdb != str(projCode + '.mdb'):
mdbList.append(dirProject + fileMdb)
shutil.copy2(dirProject + fileMdb, newDir)
print("Have been copy%s " % fileMdb)
return newDir
## CHUỖI HÀM XỬ LÍ FILE EXCEL
def autoCorrectEx(filename, toa, kv, dateSub = dateSubmit):
# Load mot workBook
# wbNamwe = filename
wb = openpyxl.load_workbook(filename)
sheet = wb.active
# Lay gioi han cua bang tinh
max_row = sheet.max_row
max_column = sheet.max_column
if max_column != 14:
raise TypeError
else:
pass
# Nhap ten toa va khu vu
tenToa = str(toa).upper()
khuVuc = (str(kv)).upper()
# dat ten cho bang thong ke (title)
sheet.merge_cells('A2:N2')
titFont = Font(bold = True, size = 20)
sheet['A2'].font = titFont
sheet['A2'].alignment = Alignment(horizontal = 'center')
title = "물량집계표(%s 동%s_계단)" %(tenToa.upper(), khuVuc.upper())
sheet['A2'] = title
#Sua ten toa
sheet['L5'].value = tenToa
sheet['L6'].value = khuVuc
# Sua project name cell
boldFont = Font(bold = True, size = 11)
sheet['A4'].font = boldFont
sheet['A4'].alignment = Alignment(horizontal = 'left')
# Sua date cell
sheet['N4'].font = boldFont
sheet['N4'].alignment = Alignment(horizontal = 'right')
sheet['N4'].value = dateSub
# Sua Head row
thin_border = Border(left=Side(style='thin'),
right=Side(style='thin'),
top=Side(style='thin'),
bottom=Side(style='thin'))
for col in 'ABCDEFGHIJKLMN':
for row in range(5, 7):
sheet[str(col) + str(row)].font = boldFont
sheet[str(col) + str(row)].alignment = Alignment(horizontal = 'center', vertical = 'center')
sheet[str(col) + str(row)].border = thin_border
# Sua total row
for col in 'ABCDEFGHIJKLMN':
sheet[str(col) + str(max_row)].font = boldFont
# merge cells
sheet.merge_cells('K5:K6')
print("01.Dinh dang file: OK")
### PART2: EDIT CONTENT:
# SUA STT TRONG EXCEL:
for row in range(7, max_row + 1):
row = str(row)
sheet['F' + row].value = sheet['A' + row].value
print("02.Sua cot STT : OK")
# Sua ten tam:
platesWrong = ['SDH', 'SP0', 'SP', 'SSP', 'D-', 'D(','SB-','SB(' ]
for row in range(7, max_row + 1):
row = str(row)
cellVal = str(sheet['B' + row].value)
if cellVal[0:3] in platesWrong or cellVal[0:2] in platesWrong:
if cellVal[0:2] == 'SP':
sheet['B' + row].value = cellVal[:2] + cellVal[-3:]
elif cellVal[0:2] == 'D(' or cellVal[0:2] == 'D-':
sheet['B' + row].value = "D" + str(sheet['C' + row].value)
elif cellVal[0:3] == 'SB-' or cellVal[0:3] == 'SB(':
sheet['B' + row].value = "SB" + sheet['C' + row].value
else:
sheet['B' + row].value = cellVal[:3] + cellVal[-3:]
else:
pass
# Sua dien tich SA, SCP
AREA1Wrong = ['SA-', 'SCP']
for row in range(7, max_row + 1):
row = str(row)
cellValName = str(sheet['E' + row].value)
cellValVol = (sheet['I' + row].value)
cellValArea = (sheet['G' + row].value)
if cellValName[0:3] in AREA1Wrong and (cellValVol < 3.5 or cellValArea < 0.1):
if cellValName[0:2] == 'SA':
sheet['G' + row].value = round(int(cellValName[3:6]) * int(cellValName[cellValName.find("*") + 1:])/1000000, 3)
sheet['I' + row].value = sheet['G' + row].value * 35
else:
pass
sheet['G' + row].value = round(int(cellValName[4:7]) * int(cellValName[cellValName.find("*") + 1:])/1000000, 3)
sheet['I' + row].value = sheet['G' + row].value * 15
# sheet['G' + row].value = cellValName[4:7] + cellValName[-4:]
# print("SCPs fixed")
# print(cellValName)
else:
pass
# Sua dien tich va khoi luong SDH, SP, SSP
AREA2Wrong = ['SDH', 'SP-', 'SP', 'SSP']
for row in range(7, max_row + 1):
row = str(row)
cellValName = str(sheet['B' + row].value)
cellValVol = (sheet['I' + row].value)
cellValArea = (sheet['G' + row].value)
if cellValName[0:3] in AREA2Wrong or cellValName[0:2] in AREA2Wrong :
if cellValName[0:2] == 'SP' and (cellValVol < 3.5 or cellValArea < 0.1):
sheet['G' + row].value = round(random.uniform(0.564, 0.695), 3)
sheet['I' + row].value = sheet['G' + row].value * 17
elif cellValName[0:3] == 'SDH' and cellValName[-1] == '1' and (cellValVol < 2 or cellValArea < 0.1):
sheet['G' + row].value = round(random.uniform(0.191, 0.235), 3)
sheet['I' + row].value = sheet['G' + row].value * 35
elif cellValName[0:3] == 'SDH' and cellValName[-1] == '2' and (cellValVol < 1.5 or cellValArea < 0.05):
sheet['G' + row].value = round(random.uniform(0.065, 0.101), 3)
sheet['I' + row].value = sheet['G' + row].value * 54
elif cellValName[0:3] == 'SSP' and (cellValVol < 3.5 or cellValArea < 0.1):
sheet['G' + row].value = round(random.uniform(0.891, 1.095), 3)
sheet['I' + row].value = sheet['G' + row].value * 20
else:
pass
else:
pass
### PART 3: DINH DANG IN AN.
# Dinh dang cot
wN = sheet.column_dimensions['N']
wN.width = 55
# Dinh dang in
sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
print("04.Dinh dang in A4: OK")
# Luu sang file khac
saveName = "C:\\Tempfile\\autoCorrected Output File.xlsx"
wb.save(saveName)
# Mo file sau khi sua
# os.startfile(saveName)
return saveName
#autofic Function
def saveFileEx(fileIn, info, fileOut = "None"):
# Load mot workBook
wbI = openpyxl.load_workbook(fileIn)
sheet = wbI.active
# Nhan ban excel(sua toa, title):
title = "물량집계표(%s 동%s_계단)" %(info[0].upper(), info[1].upper())
sheet['A2'] = title
# Sua ten toa:
sheet['L5'].value = info[0]
sheet['L6'].value = info[1]
# Sua ngay trinh:
sheet['N4'].value = info[5]
# Sua Head row
thin_border = Border(left=Side(style='thin'),
right=Side(style='thin'),
top=Side(style='thin'),
bottom=Side(style='thin'))
noneFill = PatternFill(fill_type=None)
for col in 'ABCDEFGHIJKLMN':
for row in range(5, 7):
sheet[str(col) + str(row)].border = thin_border
for row in sheet.iter_rows():
for cell in row:
cell.fill = noneFill
# Save file
wbI.save(fileOut)
# Mo file sau khi sua
os.startfile(fileOut)
def saveFilesEx(fileIn, info, fileOut = "None"):
# Load mot workBook
wbI = openpyxl.load_workbook(fileIn)
sheet = wbI.active
# Nhan ban excel(sua toa, title):
title = "물량집계표(%s 동%s_계단)" %(info[0].upper(), info[1].upper())
sheet['A2'] = title
# Sua ten toa:
sheet['L5'].value = info[0]
sheet['L6'].value = info[1]
# Sua ngay trinh:
sheet['N4'].value = info[5]
# Sua Head row
thin_border = Border(left=Side(style='thin'),
right=Side(style='thin'),
top=Side(style='thin'),
bottom=Side(style='thin'))
noneFill = PatternFill(fill_type=None)
for col in 'ABCDEFGHIJKLMN':
for row in range(5, 7):
sheet[str(col) + str(row)].border = thin_border
for row in sheet.iter_rows():
for cell in row:
cell.fill = noneFill
# Save file
wbI.save(fileOut)
# Mo file sau khi sua
# os.startfile(fileOut)
def removeEx():
# Remove old excel File
mdbList = []
for fileEx in os.listdir():
if fileEx.endswith('.xlsx') and fileEx != str('autoCorrected Output File.xlsx') and fileEx != str('outCompare.xlsx'):
os.remove(fileEx)
print("Have been remove%s " % fileEx)
# Compare 2 files:
def compareEx(fileIn, fileOut):
wbI = openpyxl.load_workbook(fileIn)
wbO = openpyxl.load_workbook(fileOut)
wsI = wbI.active
wsO = wbO.active
max_row = wsI.max_row
max_col = wsI.max_column
# Warn!!
greenFill = PatternFill(start_color='91189431',
end_color='91189431',
fill_type='solid')
for row in wsI.iter_rows():
for cell in row:
col = str(cell.column)
row = str(cell.row)
if wsI[str(col + row)].value == wsO[str(col + row)].value:
pass
else:
wsO[str(col + row)].fill = greenFill
wbO.save("C:\\Tempfile\outCompare.xlsx")
os.startfile("C:\\Tempfile\outCompare.xlsx")
def autoMakeEx(fileNameTxt, info = ("None", "None", "중A", "None","None","None")):
fileIn = open(fileNameTxt)
lsFiles = []
ls = []
for row in fileIn:
subls = []
if row.count('|') == 2:
subls = row.split('|')
if list(subls[0:2]) not in ls:
ls.append(subls[0:2])
else:
print("already exist!!")
else:
pass
print(ls)
for block in ls:
info[0] = block[0]
info[1] = block[1]
name = "C:\\Tempfile\%s동%s_계단_%s(%s%s).xlsx" %(block[0], block[1],info[2],info[3],info[4])
saveFilesEx("C:\\Tempfile\outCompare.xlsx", info, name)
lsFiles.append(os.path.abspath(name))
print(lsFiles)
return lsFiles
# cHUỖI HÀM XỬ LÍ FILE MOL
# Update file MOL, BOM
def updateMOL(mol, kl ='KL.xlsx',modeBj = True):
# Mo file MOL len va copy noi dung cua file ra 1 list input
molInputFile = open(mol, 'r')
listInputMol = []
for line in molInputFile:
if line.count('|') == 7:
listInputMol.append(line)
molInputFile.close()
# Load file excel mau
klwb = openpyxl.load_workbook(kl, data_only = True)
IPws = klwb['INPUT']
CODEws = klwb['PASTE CODE']
listPaste = []
updateMolFile = open(mol,'w+')
# Load file excel Mau, lay paste code,
listPlate = []
for row in range(2, CODEws.max_row):
row = str(row)
if (str(CODEws['B' + row].value)).count('|') == 7:
updateMolFile.write(str(CODEws['B' + row].value)+ "\n")
listRow = str(CODEws['B' + row].value).split('|')
if (listRow[1] + listRow[2]) in listPlate:
pass
else:
listPlate.append(listRow[1] + listRow[2])
else:
pass
# Luon them listplate BJ350
listPlate.append('BJ350')
# Da tao duoc list plate already existed
# load more from original .MOL:
for line in listInputMol:
match = line.split('|')
if (match[1] + match[2]) in listPlate:
pass
else:
updateMolFile.writelines(line) # Ghi file mol
if modeBj == True:
updateMolFile.writelines("\n000000BJ035003500000000000000000000+00000|BJ350|||AF-BJ001A|350||1")
print("Included BJ350")
else:
print('Not Included BJ350')
pass
updateMolFile.close()
# os.startfile(mol)
def updateBom(bomFile, kl ='KL.xlsx', modeBj = True):
# Mo file Bom len va copy noi dung cua file ra 1 list input
BomInputFile = open(bomFile, 'r')
listInputBom = []
for line in BomInputFile:
if line.count(",") == 35:
listInputBom.append(line.split(','))
BomInputFile.close()
# Tới đây chúng ta được một danh sách các tấm nguyên bản từ file BOM
# Load file excel mau
klwb = openpyxl.load_workbook(kl, data_only = True)
IPws = klwb['INPUT']
CODEws = klwb['PASTE CODE']
# Tao 1 dict match:
dictMatch = {}
for row in range(2, CODEws.max_row + 3):
row = str(row)
if (str(CODEws['F' + row].value)).count('|') == 1:
subList = str(CODEws['F' + row].value).split('|')
dictMatch[subList[0]] = str(subList[1])
# print(dictMatch)
# Tới đây chúng ta được 1 dic lưu {tên tấm: Diện tích}
# Đếm số tấm DP = 1/2 Số tấm BJ
amountDp = 0
for i in listInputBom:
if (i[1]+i[2]+i[3]) in dictMatch.keys():
i[6] = dictMatch[str(i[1]+i[2]+i[3])]
elif i[1] == 'DP-':
amountDp +=1
elif i[1]+i[2] == 'BJ350':
del listInputBom[listInputBom.index(i)]
else:
pass
# print(listInputBom[0])
# print("So tam Dp co la: %d" % amountDp)
try:
block = listInputBom[0][0]
except:
print("BOM file is empty")
amountBj350 = str(2*amountDp)
rowBj350 = [block, 'BJ', '350', '', '', amountBj350, '', 'ALFORM', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'ALFORM', 'BJ', 'M2', 'H', 'BJ01\n']
# print(rowBj350)
if modeBj:
if rowBj350 not in listInputBom:
listInputBom.append(rowBj350)
print("Included BJ350")
else:
print("The BJ350 already exists")
else:
if rowBj350 in listInputBom:
print("chỉ số BJ350 = " + list.index(rowBj350))
print("Not Included BJ")
pass
# Ghi File:
outBomFile = open(bomFile, 'w+')
try:
for i in listInputBom:
line = ','.join(i)
outBomFile.write(line)
except:
print("Loi! Khong them duoc BJ")
finally :
outBomFile.close()
# Autorun BOM command:
def makeList(fileNameTxt = '.\sampleFiles\\list.txt'):
fileIn = open(fileNameTxt)
ls = []
for row in fileIn:
subls = []
if row.count('|') == 2:
subls = row.split('|')
if list(subls[0:2]) not in ls:
ls.append(subls[0:2])
else:
print("already exist!!")
else:
pass
return ls
# Tao UI:
class EditExcelFile(QWidget):
filename = "None"
report = "None"
def __init__(self, parent = None):
super(EditExcelFile, self).__init__(parent)
#Icon Window:
self.setWindowIcon(QIcon("Icon.ico"))
self.setWindowTitle("JNB Tool - 계단 ")
# Set mode:
self.modeBom = True
self.modeMdb = False
self.modeEx = False
self.isBjchecked = True
# UI:
# Other button:
# Movie Button
self.warnLine = QTextEdit()
self.warnLine.setFixedSize(450, 75)
self.warnLine.setReadOnly(True)
self.warnLine.setText("""<html><b> WARNING: </b>.<BR>
- Tool chỉ dùng cho các trường hợp thông thường.<BR>
- Các mẫu bảng biểu, tên tấm theo mẫu hiện tại (2018-02-03).<BR>
- ..... !!!</html> """)
self.clipButton = QPushButton('&Link F...')
self.clipButton.setMinimumHeight(30)
self.clipButton.setToolTip('18+.')
self.docButton = QPushButton('&Link V.')
self.docButton.setMinimumHeight(30)
self.docButton.setToolTip('Black&White Beautiful Girl <3.')
self.helpLayout = QHBoxLayout()
self.helpLayout.addWidget(self.warnLine)
self.helpLayout.addSpacing(20)
self.helpLayout.addWidget(self.clipButton)
self.helpLayout.addWidget(self.docButton)
self.helpLayout.addSpacing(50)
# self.helpLayout.addSpacing(50)
# self.helpLayout.addStretch()
# self.helpMainLayout = QHBoxLayout()
# self.helpMainLayout.addLayout(self.helpLayout)
# self.helpMainLayout.addSpacing(200)
# active HD-Form
self.activeButton = QPushButton('''Activate HD-FORM2015''')
self.activeButton.setMinimumHeight(25)
self.activeButton.setToolTip('AutoActivate HD-FORM2015.')
self.activeButton.clicked.connect(self.activeClicked)
# Choose mode:
# Open data setting (command BOM cad)
self.openDataSet = QPushButton('''Open Data Setting''')
self.openDataSet.setMinimumHeight(80)
self.openDataSet.setToolTip('Run Data Setting.')
# check box include BJ350
self.incBjCheckBox = QCheckBox("BJ350")
self.incBjCheckBox.setEnabled(True)
self.incBjCheckBox.setChecked(True)
self.incBjCheckBox.setEnabled(True)
self.amountBj = QLineEdit()
self.amountBj.setEnabled(False)
self.incBjLayout = QHBoxLayout()
self.incBjLayout.addWidget(self.incBjCheckBox)
self.incBjLayout.addWidget(self.amountBj)
self.incBjCheckBox.stateChanged.connect(self.checkBj)
# Choose mode layout
self.modeLayout = QVBoxLayout()
self.modeLayout.addWidget(self.openDataSet)
self.modeLayout.addSpacing(75)
self.modeRB = QRadioButton('Edit BOM, MOL File')
self.modeRB.setChecked(True)
self.modeRB.mode = "Edit BOM, MOL File"
self.modeRB.toggled.connect(self.setMode)
self.modeLayout.addWidget(self.modeRB)
self.modeLayout.addLayout(self.incBjLayout)
self.modeLayout.addSpacing(58)
self.modeRB = QRadioButton('Edit MDB File')
self.modeRB.mode = "Edit MDB File"
self.modeRB.toggled.connect(self.setMode)
self.modeLayout.addWidget(self.modeRB)
self.modeLayout.addSpacing(27)
self.modeRB = QRadioButton('Edit Excel File')
self.modeRB.mode = "Edit Excel File"
self.modeRB.toggled.connect(self.setMode)
self.modeLayout.addWidget(self.modeRB)
self.modeLayout.addSpacing(63)
self.modeLayout.addStretch()
# Edit Excel File:
self.editExlable = QLabel("Edit Excel File:")
self.editExlable.setEnabled(self.modeEx)
self.pathExLable = QLabel('Path Excel File:')
self.pathExLine = QLineEdit()
self.pathExLine.setReadOnly(True)
self.pathExLine.setPlaceholderText("Nhấn 'Load Excel File...' để lựa chọn file Excel cần chỉnh sửa.")
self.pathExLine.setEnabled(self.modeEx)
self.loadExButton = QPushButton('&Load Excel File ...')
self.loadExButton.setToolTip('Load input file .xlsx from harddisk.')
self.loadExButton.setEnabled(self.modeEx)
self.correctExButton = QPushButton('AutoCorrect')
self.correctExButton.setToolTip('AutoCorrect input file xlsx.')
self.correctExButton.setEnabled(self.modeEx)
self.saveExButton = QPushButton('Save')
self.saveExButton.setToolTip('Save the file xlsx.')
self.saveExButton.setEnabled(self.modeEx)
self.makeExButton = QPushButton('Make Excel')
self.makeExButton.setToolTip('Autorun to clone file excel files.')
self.makeExButton.setEnabled(self.modeEx)
# Edit Mdb File:
self.editMdblable = QLabel("Edit MDB File:")
self.editMdblable.setEnabled(self.modeMdb)
self.pathMdbLable = QLabel('Path MDB File:')
self.pathMdbLine = QLineEdit()
self.pathMdbLine.setReadOnly(True)
self.pathMdbLine.setPlaceholderText("Nhấn 'Load MDB File...' để lựa chọn file MDB cần chỉnh sửa.")
self.pathMdbLine.setEnabled(self.modeMdb)
self.loadMdbButton = QPushButton('&Load MDB File ...')
self.loadMdbButton.setToolTip('Load input file .MDBfrom harddisk.')
self.loadMdbButton.setEnabled(self.modeMdb)
self.correctMdbButton = QPushButton('Manually Edit')
self.correctMdbButton.setToolTip('Edit input file mdb with Access.')
self.correctMdbButton.setEnabled(self.modeMdb)
self.saveMdbButton = QPushButton('Save')
self.saveMdbButton.setToolTip('Save the file mdb.')
self.saveMdbButton.setEnabled(self.modeMdb)
self.makeMdbButton = QPushButton('Make MDB')
self.makeMdbButton.setToolTip('Autorun to clone file mdb.')
self.makeMdbButton.setEnabled(self.modeMdb)
# import Txt:
# self.editMdblable = QLabel("Edit MDB File:")
# self.editMdblable.setEnabled(self.modeEx)
self.pathTxtLable = QLabel('Path Txt File:')
self.pathTxtLine = QLineEdit()
self.pathTxtLine.setReadOnly(True)
self.pathTxtLine.setPlaceholderText("Nhấn 'Import Txt File...' để lựa chọn file Txt chứa danh sách tòa và khu vực.")
self.pathTxtLine.setEnabled(True)
self.loadTxtButton = QPushButton('&Import Txt File ...')
self.loadTxtButton.setToolTip('import data from file .Txt.')
self.loadTxtButton.setEnabled(True)
self.defaultTxtButton = QPushButton('&Load Sample List')
self.defaultTxtButton.setToolTip('import data from file .Txt.')
self.defaultTxtButton.setEnabled(True)
#run Mdb Layout
autoRunLayout = QHBoxLayout()
autoRunLayout.addWidget(self.pathTxtLable)
autoRunLayout.addWidget(self.pathTxtLine)
autoRunLayout.addWidget(self.loadTxtButton)
autoRunLayout.addWidget(self.defaultTxtButton)
# autoRunLayout.addWidget(self.makeMdbButton)
# Info:
infoLable = QLabel('General Infor:')
toaLable = QLabel('Block:')
self.toaLine = QLineEdit()
self.toaLine.setReadOnly(False)
self.toaLine.setPlaceholderText("Tên tòa...")
kvLable = QLabel('Zone: ') # kv = Khu vuc
self.kvLine = QLineEdit()
self.kvLine.setReadOnly(False)
self.kvLine.setPlaceholderText("Tên khu vực...")
dateLable= QLabel('Date (yyyy-mm-dd):')
self.dateLine = QLineEdit()
self.dateLine.setPlaceholderText("Ngày trình...")
self.dateLine.setText(dateSubmit)
Des2Lable= QLabel('Designer:')
self.Des2Combo = QComboBox()
self.Des2Combo.addItems(ListDesV)
DesLable= QLabel('Designer:')
self.DesLine = QLineEdit()
self.DesLine.setPlaceholderText("Tên Designer...")
# MessageBox Confirm:
self.contMesBox = QMessageBox
#Edit .MOL:
self.pathKlLable = QLabel('KL file:')
self.pathKlLine = QLineEdit()
if os.path.exists(".\SampleFiles\KL.xlsx"):
self.pathKlLine.setText(os.path.abspath(".\SampleFiles\KL.xlsx"))
elif os.path.exists("C:\JNBtool\SampleFiles\KL.xlsx"):
self.pathKlLine.setText(os.path.abspath("C:\JNBtool\SampleFiles\KL.xlsx"))
else:
pass
self.pathKlLine.setReadOnly(True)
self.pathKlLine.setPlaceholderText("Nhấn 'Load File KL...' để chọn file.")
self.loadKlButton = QPushButton('&Load KL File...')
self.loadKlButton.setToolTip('Load input file .kl from harddisk.')
self.editKlButton = QPushButton('&Edit KL File...')
self.editKlButton.setToolTip('Edit file .kl')
self.pathMolLable = QLabel('MOL file:')
self.pathMolLine = QLineEdit()
self.pathMolLine.setReadOnly(True)
self.pathMolLine.setPlaceholderText("Nhấn 'Load File MOL...' để chọn file.")
self.loadMolButton = QPushButton('&Load MOL File...')
self.loadMolButton.setToolTip('Load input file .MOL from harddisk.')
self.updateMolButton = QPushButton('&Update MOL...')
self.updateMolButton.setToolTip('Update file MOL.')
self.pathBomLable = QLabel('BOM file:')
self.pathBomLine = QLineEdit()
self.pathBomLine.setReadOnly(True)
self.pathBomLine.setPlaceholderText("Nhấn 'Load File Bom...' để chọn file.")
self.loadBomButton = QPushButton('&Load Bom File...')
self.loadBomButton.setToolTip('Load input file .BOM from harddisk.')
self.updateBomButton = QPushButton('&Update BOM...')
self.updateBomButton.setToolTip('Update file BOM.')
statusLable = QLabel("Notice:")
self.statusBox = QTextEdit()
report = "Các thông báo trạng thái sẽ xuất hiện ở đây!"
self.statusBox.setText(report)
self.statusBox.setReadOnly(True)
self.checkButton = QPushButton('Check')
self.checkButton.setToolTip('Highlight the Error cells.')
self.checkButton.hide()
self.quitButton = QPushButton('Quit')
self.quitButton.setToolTip('Quit only.')
self.quitReButton = QPushButton('Remove temp files.')
self.quitReButton.setToolTip('Remove temp files and Quit.')
# layout
buttonLayout1 = QVBoxLayout()
buttonLayout1.addStretch()
buttonLayout1.addWidget(self.quitReButton)
buttonLayout1.addWidget(self.quitButton)
#info Layout
infoLayout = QGridLayout()