Диссертация (1167217), страница 77
Текст из файла (страница 77)
Cons.: %s x %s = %s" %(str(vconfPrice),str(addConsQuant), str(vconfPrice*addConsQuant))))# create table in dbtableName = "t" + self.lst[i][6].replace("/", "")#query = conn.execute("CREATE TABLE IF NOT EXISTS fff (ds INT)")conn.execute("CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARYKEY AUTOINCREMENT, month TEXT, vconf INTEGER, opentask INTEGER, managing INTEGER)"% tableName[:-3])conn.commit()self.newTables.append(tableName[:-3])conn.close()# how many monthsmonths = int(duration / 30) + 1 + 6# check if the table is filledconn = sqlite3.connect('cdo.db')quant2 = self.getStrSQL(conn.execute("SELECT COUNT (*) FROM %s"% tableName[:-3]))conn.commit()################### make empty txt files for video conffname = 'videocons/' + '%s_%s_%s_.txt' %(self.lst[i][6].split('/')[0], student[0][1], ' '.join([tutor[0][1], tutor[0][2],tutor[0][3]]))if not isfile(fname):f = open(fname, 'w', encoding='utf-8')f.write('Консультации %s, %s, %s:\n' % (self.lst[i][6], ''.join([student[0][1], student[0][2], student[0][3]]), ' '.join([tutor[0][1],tutor[0][2], tutor[0][3]])))f.close()###################if not quant2:mm = self.getMonths(startdate) - 1yy = self.getYear(startdate)for m in range(0, months):if mm == 12:mm = 0yy += 1conn.execute("INSERT INTO %s VALUES (NULL, '%s-%s',NULL, NULL, NULL)" % (tableName[:-3], yy, self.monthsName[mm]))conn.commit()mm += 1rows = conn.execute("SELECT * FROM %s" % tableName[:-3])lst2 = self.getLstSQL(rows)# adding table to the current tabself.tables.append(QTableWidget())521self.tables[i].setRowCount(months+1)self.tables[i].setColumnCount(5)count = 0headerLst = conn.execute("PRAGMA table_info(%s)" % tableName[:3])for header in headerLst:self.tables[i].setHorizontalHeaderItem(count,QTableWidgetItem(str(header[1])))count += 1# consider add.
conf.vconfAll = 0opentaskAll = 0managingAll = 0for ii in range(0, len(lst2)):for iii in range(0, len(lst2[ii])):# output nothing if the cell is Nullif lst2[ii][iii]:twi = QTableWidgetItem(str(lst2[ii][iii]))self.tables[i].setItem(ii,iii, twi)if iii == 2:vconfAll += lst2[ii][iii]elif iii == 3:opentaskAll += lst2[ii][iii]elif iii == 4:managingAll += lst2[ii][iii]else:twi = QTableWidgetItem("0")self.tables[i].setItem(ii,iii, twi)# Now it is time to insert the last row with the rest of thesummatwi =QTableWidgetItem(str((vconf*vconfPrice+vconfPrice*addConsQuant) vconfAll*vconfPrice))if (vconf*vconfPrice+vconfPrice*addConsQuant) vconfAll*vconfPrice < 0:twi.setBackground(QtGui.QColor(230,99,99))elif (vconf*vconfPrice+vconfPrice*addConsQuant) vconfAll*vconfPrice == 0:twi.setBackground(QtGui.QColor(99,230,99))else:twi.setBackground(QtGui.QColor(230,230,230))self.tables[i].setItem(len(lst2), 2, twi)twi = QTableWidgetItem(str(opentask*opentaskPrice opentaskAll*opentaskPrice))if opentask*opentaskPrice - opentaskAll*opentaskPrice < 0:twi.setBackground(QtGui.QColor(230,99,99))elif opentask*opentaskPrice - opentaskAll*opentaskPrice == 0:twi.setBackground(QtGui.QColor(99,230,99))else:twi.setBackground(QtGui.QColor(230,230,230))self.tables[i].setItem(len(lst2), 3, twi)twi = QTableWidgetItem(str(managing - managingAll))if managing - managingAll < 0:522twi.setBackground(QtGui.QColor(230,99,99))elif managing - managingAll == 0:twi.setBackground(QtGui.QColor(99,230,99))else:twi.setBackground(QtGui.QColor(230,230,230))self.tables[i].setItem(len(lst2), 4, twi)l.addWidget(self.tables[i])self.buttonsSave.append(QPushButton('Save Current Table - %d' %(i+1)))self.buttonsSave[i].released.connect(self.buttonReleased)l.addWidget(self.buttonsSave[i])self.gridItems[i].addWidget(scroll)self.tabItems[i].layout().addWidget(scroll)self.ui.gridLayout_7.addWidget(self.tab)self.buttonSaveTableAll = QPushButton('Save All Tables')self.buttonSaveTableAll.released.connect(self.buttonReleasedAll)self.ui.gridLayout_7.addWidget(self.buttonSaveTableAll)conn.close()self.activeInCST = Trueself.ui.actionShow_Active_Agr.setEnabled(False)self.ui.actionShow_Not_Active_Agr.setEnabled(True)def showTableCSTTablesNotActive(self):self.tab.deleteLater()if self.activeInCST:self.buttonSaveTableAll.deleteLater()conn = sqlite3.connect('cdo.db')rows = conn.execute("SELECT * FROM coursesfortutor WHERE active=0")# here is all table coursesfortutor as a listself.lst = self.getLstSQL(rows)quant = conn.execute("SELECT COUNT (*) FROM coursesfortutor WHEREactive=0")self.tab = QTabWidget() # all tabsself.tabItems = [] # tabs one by oneself.gridItems = [] # tables in each tabself.tables = []self.buttonsSave = []# adding tabs with info one by onerangeFor = self.getStrSQL(quant)conn.close()# new tables namesself.newTables = []for i in range(rangeFor):self.tabItems.append(QTabBar())self.tab.addTab(self.tabItems[i], self.lst[i][6])self.gridItems.append(QtWidgets.QGridLayout(self.tabItems[i]))523scroll = QScrollArea(self.tabItems[i])scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)viewport = QWidget(self.tabItems[i])scroll.setWidget(viewport)scroll.setWidgetResizable(True)l = QGridLayout(viewport)viewport.setLayout(l)# adding info before the table# student nameconn = sqlite3.connect('cdo.db')rows = conn.execute("SELECT * FROM student WHERE id=%d" %self.lst[i][4])student = self.getLstSQL(rows)l.addWidget(QLabel("Student: %s %s %s" % (student[0][1],student[0][2], student[0][3])))# courserows = conn.execute("SELECT * FROM course WHERE id=%d" %self.lst[i][2])course = self.getLstSQL(rows)l.addWidget(QLabel("Course: %s" % (course[0][1])))discount = self.lst[i][14]price = self.lst[i][15]l.addWidget(QLabel("Price: %s (%d %% discount)" % (price,discount)))vconf = course[0][3]vconfPrice = course[0][6]opentask = course[0][4]opentaskPrice = course[0][7]managing = course[0][8]# startdate and durationstartdate = self.lst[i][8]duration = self.lst[i][9]l.addWidget(QLabel("Start: %s" % (startdate)))l.addWidget(QLabel("Duration: %s" % (duration)))# tutorrows = conn.execute("SELECT * FROM tutor WHERE id=%d" %self.lst[i][3])tutor = self.getLstSQL(rows)l.addWidget(QLabel("Tutor: %s %s %s" % (tutor[0][1],tutor[0][2], tutor[0][3])))# examinerrows = conn.execute("SELECT * FROM tutor WHERE id=%d" %self.lst[i][5])examiner = self.getLstSQL(rows)l.addWidget(QLabel("Examiner: %s %s %s" % (examiner[0][1],examiner[0][2], examiner[0][3])))# moneyl.addWidget(QLabel("Video Conferences: %s x %s = %s" %(str(vconf), str(vconfPrice), str(vconf*vconfPrice))))l.addWidget(QLabel("Open Task Ex.: %s x %s = %s" %(str(opentask), str(opentaskPrice), str(opentask*opentaskPrice))))524l.addWidget(QLabel("Managing: %s" % (str(managing))))# additional consultationsaddConsPrice = self.lst[i][16]addConsQuant = self.lst[i][17]l.addWidget(QLabel("Add.
Cons.: %s x %s = %s" %(str(vconfPrice),str(addConsQuant), str(vconfPrice*addConsQuant))))# create table in dbtableName = "t" + self.lst[i][6].replace("/", "")#query = conn.execute("CREATE TABLE IF NOT EXISTS fff (ds INT)")conn.execute("CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARYKEY AUTOINCREMENT, month TEXT, vconf INTEGER, opentask INTEGER, managing INTEGER)"% tableName[:-3])conn.commit()self.newTables.append(tableName[:-3])conn.close()# how many monthsmonths = int(duration / 30) + 1 + 6# check if the table is filledconn = sqlite3.connect('cdo.db')quant2 = self.getStrSQL(conn.execute("SELECT COUNT (*) FROM %s"% tableName[:-3]))conn.commit()################### make empty txt files for video conf, notactive agreementsfname = 'videocons/' + '%s_%s_%s_.txt' %(self.lst[i][6].split('/')[0], student[0][1], ' '.join([tutor[0][1], tutor[0][2],tutor[0][3]]))if not isfile(fname):f = open(fname, 'w', encoding='utf-8')f.write('Консультации %s, %s, %s:\n' % (self.lst[i][6], ''.join([student[0][1], student[0][2], student[0][3]]), ' '.join([tutor[0][1],tutor[0][2], tutor[0][3]])))f.close()###################if not quant2:mm = self.getMonths(startdate) - 1yy = self.getYear(startdate)for m in range(0, months):if mm == 12:mm = 0yy += 1conn.execute("INSERT INTO %s VALUES (NULL, '%s-%s',NULL, NULL, NULL)" % (tableName[:-3], yy, self.monthsName[mm]))conn.commit()mm += 1rows = conn.execute("SELECT * FROM %s" % tableName[:-3])lst2 = self.getLstSQL(rows)# adding table to the current tabself.tables.append(QTableWidget())self.tables[i].setRowCount(months+1)525self.tables[i].setColumnCount(5)count = 0headerLst = conn.execute("PRAGMA table_info(%s)" % tableName[:3])for header in headerLst:self.tables[i].setHorizontalHeaderItem(count,QTableWidgetItem(str(header[1])))count += 1# consider add.
conf.vconfAll = 0opentaskAll = 0managingAll = 0for ii in range(0, len(lst2)):for iii in range(0, len(lst2[ii])):# output nothing if the cell is Nullif lst2[ii][iii]:twi = QTableWidgetItem(str(lst2[ii][iii]))self.tables[i].setItem(ii,iii, twi)if iii == 2:vconfAll += lst2[ii][iii]elif iii == 3:opentaskAll += lst2[ii][iii]elif iii == 4:managingAll += lst2[ii][iii]else:twi = QTableWidgetItem("0")self.tables[i].setItem(ii,iii, twi)# Now it is time to insert the last row with the rest of thesummatwi =QTableWidgetItem(str((vconf*vconfPrice+vconfPrice*addConsQuant) vconfAll*vconfPrice))if (vconf*vconfPrice+vconfPrice*addConsQuant) vconfAll*vconfPrice < 0:twi.setBackground(QtGui.QColor(230,99,99))elif (vconf*vconfPrice+vconfPrice*addConsQuant) vconfAll*vconfPrice == 0:twi.setBackground(QtGui.QColor(99,230,99))else:twi.setBackground(QtGui.QColor(230,230,230))self.tables[i].setItem(len(lst2), 2, twi)twi = QTableWidgetItem(str(opentask*opentaskPrice opentaskAll*opentaskPrice))if opentask*opentaskPrice - opentaskAll*opentaskPrice < 0:twi.setBackground(QtGui.QColor(230,99,99))elif opentask*opentaskPrice - opentaskAll*opentaskPrice == 0:twi.setBackground(QtGui.QColor(99,230,99))else:twi.setBackground(QtGui.QColor(230,230,230))self.tables[i].setItem(len(lst2), 3, twi)twi = QTableWidgetItem(str(managing - managingAll))if managing - managingAll < 0:twi.setBackground(QtGui.QColor(230,99,99))526elif managing - managingAll == 0:twi.setBackground(QtGui.QColor(99,230,99))else:twi.setBackground(QtGui.QColor(230,230,230))self.tables[i].setItem(len(lst2), 4, twi)l.addWidget(self.tables[i])#self.buttonsSave.append(QPushButton('Save Current Table - %d' %(i+1)))#self.buttonsSave[i].released.connect(self.buttonReleased)#l.addWidget(self.buttonsSave[i])self.gridItems[i].addWidget(scroll)self.tabItems[i].layout().addWidget(scroll)self.ui.gridLayout_7.addWidget(self.tab)#self.buttonSaveTableAll = QPushButton('Save All Tables')#self.buttonSaveTableAll.released.connect(self.buttonReleasedAll)#self.ui.gridLayout_7.addWidget(self.buttonSaveTableAll)conn.close()self.ui.tabWidget.setCurrentIndex(5)self.activeInCST = Falseself.ui.actionShow_Active_Agr.setEnabled(True)self.ui.actionShow_Not_Active_Agr.setEnabled(False)def buttonReleased(self):sending_button = self.sender()self.saveCurrentTable(int(sending_button.text().split("")[1].strip()))def buttonReleasedAll(self):self.saveAllTables()def saveCurrentTable(self, tabNum):conn = sqlite3.connect('cdo.db')db_table = "t" + self.tab.tabText(tabNum-1).replace("/", "")[:-3]quant3 = conn.execute("SELECT COUNT (*) FROM %s" % db_table)conn.commit()s = int(self.getStrSQL(quant3))conn.close()tableCells = []for i in range(0, s):cellsInRow = []for ii in range(0, 5):try:a = int(self.tables[tabNum-1].item(i, ii).text())cellsInRow.append(self.tables[tabNum-1].item(i,ii).text())except(ValueError):cellsInRow.append('0')tableCells.append(cellsInRow)for i in range(0, s):527conn = sqlite3.connect('cdo.db')conn.execute("UPDATE %s SET vconf=%d, opentask=%d, managing=%dWHERE id=%d" % (db_table, int(tableCells[i][2]), int(tableCells[i][3]),int(tableCells[i][4]), i+1))conn.commit()conn.close()self.updateOneTableCSTTables(tabNum)self.ui.statusbar.showMessage("Current table has been saved andupdated", 2000)def saveAllTables(self):for q in range(0, len(self.tabItems)):conn = sqlite3.connect('cdo.db')db_table = "t" + self.tab.tabText(q).replace("/", "")[:-3]quant3 = conn.execute("SELECT COUNT (*) FROM %s" % db_table)conn.commit()s = int(self.getStrSQL(quant3))conn.close()tableCells = []for i in range(0, s):cellsInRow = []for ii in range(0, 5):try:a = int(self.tables[q].item(i, ii).text())cellsInRow.append(self.tables[q].item(i, ii).text())except(ValueError):cellsInRow.append('0')tableCells.append(cellsInRow)for i in range(0, s):conn = sqlite3.connect('cdo.db')conn.execute("UPDATE %s SET vconf=%d, opentask=%d,managing=%d WHERE id=%d" % (db_table, int(tableCells[i][2]),int(tableCells[i][3]), int(tableCells[i][4]), i+1))conn.commit()conn.close()self.updateAllTableCSTTables()"""self.tables[tabNum-1].item(s, 2).setText("123")self.tables[tabNum-1].item(s, 3).setText("123")self.tables[tabNum-1].item(s, 4).setText("123")"""def updateOneTableCSTTables(self, tabNum):conn = sqlite3.connect('cdo.db')rows = conn.execute("SELECT * FROM coursesfortutor WHERE active=1")self.tab.deleteLater()self.buttonSaveTableAll.deleteLater()# here is all table coursesfortutor as a listself.lst = self.getLstSQL(rows)528quant = conn.execute("SELECT COUNT (*) FROM coursesfortutor WHEREactive=1")self.tab = QTabWidget() # all tabsself.tabItems = [] # tabs one by oneself.gridItems = [] # tables in each tabself.tables = []self.buttonsSave = []# adding tabs with info one by onerangeFor = self.getStrSQL(quant)conn.close()#for i in range(rangeFor):for i in range(rangeFor):self.tabItems.append(QTabBar())self.tab.addTab(self.tabItems[i], self.lst[i][6])self.gridItems.append(QtWidgets.QGridLayout(self.tabItems[i]))scroll = QScrollArea(self.tabItems[i])scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)viewport = QWidget(self.tabItems[i])scroll.setWidget(viewport)scroll.setWidgetResizable(True)l = QGridLayout(viewport)viewport.setLayout(l)# adding info before the table# student nameconn = sqlite3.connect('cdo.db')rows = conn.execute("SELECT * FROM student WHERE id=%d" %self.lst[i][4])student = self.getLstSQL(rows)l.addWidget(QLabel("Student: %s %s %s" % (student[0][1],student[0][2], student[0][3])))# courserows = conn.execute("SELECT * FROM course WHERE id=%d" %self.lst[i][2])course = self.getLstSQL(rows)l.addWidget(QLabel("Course: %s" % (course[0][1])))discount = self.lst[i][14]price = self.lst[i][15]l.addWidget(QLabel("Price: %s (%d %% discount)" % (price,discount)))vconf = course[0][3]vconfPrice = course[0][6]opentask = course[0][4]opentaskPrice = course[0][7]managing = course[0][8]# startdate and durationstartdate = self.lst[i][8]duration = self.lst[i][9]l.addWidget(QLabel("Start: %s" % (startdate)))l.addWidget(QLabel("Duration: %s" % (duration)))529# tutorrows = conn.execute("SELECT * FROM tutor WHERE id=%d" %self.lst[i][3])tutor = self.getLstSQL(rows)l.addWidget(QLabel("Tutor: %s %s %s" % (tutor[0][1],tutor[0][2], tutor[0][3])))# examinerrows = conn.execute("SELECT * FROM tutor WHERE id=%d" %self.lst[i][5])examiner = self.getLstSQL(rows)l.addWidget(QLabel("Examiner: %s %s %s" % (examiner[0][1],examiner[0][2], examiner[0][3])))# moneyl.addWidget(QLabel("Video Conferences: %s x %s = %s" %(str(vconf), str(vconfPrice), str(vconf*vconfPrice))))l.addWidget(QLabel("Open Task Ex.: %s x %s = %s" %(str(opentask), str(opentaskPrice), str(opentask*opentaskPrice))))l.addWidget(QLabel("Managing: %s" % (str(managing))))# additional consultationsaddConsPrice = self.lst[i][16]addConsQuant = self.lst[i][17]l.addWidget(QLabel("Add.