-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_project.py
52 lines (43 loc) · 2.16 KB
/
new_project.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
from PyQt6 import QtWidgets, uic, QtCore
from PyQt6.QtCore import QDate, QTimer
from PyQt6.QtWidgets import QApplication, QMainWindow, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget, QHeaderView
import sys
import pyodbc
import connectionString
class NewProject(QtWidgets.QMainWindow):
def __init__(self, ngoID):
super().__init__()
uic.loadUi('Screens/AddProject.ui',self)
self.projectStartDate.setDate(QDate.currentDate())
self.projectDoneBtn.clicked.connect(lambda: self.ProjectAdded(ngoID))
self.projectCancelBtn.clicked.connect(lambda: self.close())
def ProjectAdded(self, ngoID):
# get projectName, prjectScale, projectStartDate, projectEndDate
projectName = self.projectName.text()
projectScale = self.projectScale.text()
projectStartDate = self.projectStartDate.date()
connection = pyodbc.connect(connectionString.connection_string)
cursor = connection.cursor()
cursor.execute("SELECT projectName FROM Project")
projectNames = [x[0] for x in cursor.fetchall()]
if projectScale.isdigit() == False:
Dialog = QtWidgets.QMessageBox()
Dialog.setWindowTitle("Error")
Dialog.setText("Project Scale Must Be An Integer")
Dialog.exec()
return
if projectName in projectNames:
Dialog = QtWidgets.QMessageBox()
Dialog.setWindowTitle("Error")
Dialog.setText("Project Name Already Exists \n Please Enter A Different Project Name")
Dialog.exec()
return
Dialog = QtWidgets.QMessageBox()
Dialog.setWindowTitle("Confirmation Box")
Dialog.setText("Project Is Successfully Added To Yor NGO Data")
Option = Dialog.exec()
if Option == QtWidgets.QMessageBox.StandardButton.Ok:
cursor.execute("INSERT INTO Project(ngoID, projectName, scale, startDate) VALUES(?, ?, ?, ?)", ngoID, projectName, projectScale, projectStartDate.toString("yyyy-MM-dd"))
connection.commit()
connection.close()
self.close()