Диссертация (1167217), страница 78
Текст из файла (страница 78)
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()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()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 tab530self.tables.append(QTableWidget())self.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 += 1vconfAll = 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:531twi.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.ui.gridLayout_7.addWidget(self.buttonSaveTableAll)self.buttonSaveTableAll.released.connect(self.buttonReleasedAll)self.tab.setCurrentIndex(tabNum-1)conn.close()def updateAllTableCSTTables(self):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)quant = 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):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)532# 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))))l.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)")533conn.execute("CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARYKEY AUTOINCREMENT, month TEXT, vconf INTEGER, opentask INTEGER, managing INTEGER)"% tableName[:-3])conn.commit()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()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)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 += 1vconfAll = 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)534# 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))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.ui.gridLayout_7.addWidget(self.buttonSaveTableAll)self.tab.setCurrentIndex(0)conn.close()self.ui.statusbar.showMessage("All tables have been saved andupdated", 3000)def dateExtr(self, date):date = datetime.strptime(date,'%Y-%m-%d')today = date.today()return (date - today).days + 1def getStrSQL(self, rows):for row in rows:s = row[0]return sdef getLstSQL(self, rows):535lst = []for row in rows:cells = []for cell in row:cells.append(cell) # cellslst.append(cells) # rowsreturn lstdef getMonths(self, startdate):firstMonth = startdate.split("-")[1]return int(firstMonth)def getYear(self, startdate):firstYear = startdate.split("-")[0]return int(firstYear)if __name__ == "__main__":app = QtWidgets.QApplication(sys.argv)myapp = MyWin()myapp.show()sys.exit(app.exec_()).