# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'create_project.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from project import Ui_ProjectWindow

import MySQLdb as mdb

class Ui_EditProjectInfoWindow(object):
    def setupUi(self, EditProjectInfoWindow):
        EditProjectInfoWindow.setObjectName("EditProjectInfoWindow")
        EditProjectInfoWindow.setFixedSize(570, 818)
        self.centralwidget = QtWidgets.QWidget(EditProjectInfoWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(40, 10, 591, 51))
        self.label.setObjectName("label")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(0, 80, 1161, 16))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(30, 100, 481, 51))
        self.label_2.setObjectName("label_2")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(30, 210, 481, 51))
        self.label_4.setObjectName("label_4")
        font = QtGui.QFont()
        font.setPointSize(14)
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(30, 160, 481, 41))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit.setFont(font)
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(30, 270, 481, 101))
        self.textEdit.setObjectName("textEdit")
        self.textEdit.setFont(font)
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(30, 380, 481, 51))
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(30, 420, 481, 51))
        self.label_6.setObjectName("label_6")
        self.textEdit_2 = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit_2.setGeometry(QtCore.QRect(30, 480, 481, 211))
        self.textEdit_2.setObjectName("textEdit_2")
        self.textEdit_2.setFont(font)
        self.saveBtn = QtWidgets.QPushButton(self.centralwidget)
        self.saveBtn.setGeometry(QtCore.QRect(230, 720, 89, 25))
        self.saveBtn.clicked.connect(self.create_project)
        self.saveBtn.clicked.connect(EditProjectInfoWindow.close)
        self.saveBtn.setFont(font)
        self.saveBtn.setObjectName("saveBtn")
        EditProjectInfoWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(EditProjectInfoWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 553, 22))
        self.menubar.setObjectName("menubar")
        self.menuInteractive_System_Modelling = QtWidgets.QMenu(self.menubar)
        self.menuInteractive_System_Modelling.setObjectName("menuInteractive_System_Modelling")
        EditProjectInfoWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(EditProjectInfoWindow)
        self.statusbar.setObjectName("statusbar")
        EditProjectInfoWindow.setStatusBar(self.statusbar)
        self.menubar.addAction(self.menuInteractive_System_Modelling.menuAction())
        self.origin_name = ''
        self.retranslateUi(EditProjectInfoWindow)
        QtCore.QMetaObject.connectSlotsByName(EditProjectInfoWindow)

    def create_project(self):
        db = mdb.connect('127.0.0.1', 'root', '', 'interSys')
        with db:
            cur = db.cursor()
            
            cur.execute("UPDATE projects SET name = '%s', short_descr = '%s', long_descr = '%s' WHERE name = '%s'"
                                                 % (''.join(self.lineEdit.text()),
                                                  ''.join(self.textEdit.toPlainText()),
                                                  ''.join(self.textEdit_2.toPlainText()),
                                                  ''.join(self.origin_name)))
            cur.execute("UPDATE versions SET project_name = '%s' WHERE project_name = '%s'"
                                                 % (''.join(self.lineEdit.text()),
                                                  ''.join(self.origin_name)))

            #cur_name = 'Project: ' + self.lineEdit.text()
            #cur_vers = 'Version #1.0: New '
 
            db.commit()
            QtWidgets.QMessageBox.about(self.centralwidget,'Connection', 'Data Edited Successfully')
        


    def retranslateUi(self, EditProjectInfoWindow):
        _translate = QtCore.QCoreApplication.translate
        EditProjectInfoWindow.setWindowTitle(_translate("EditProjectInfoWindow", "MainWindow"))
        self.label.setText(_translate("EditProjectInfoWindow", "<html><head/><body><p><span style=\" font-size:28pt;\">Edit Project Information</span></p></body></html>"))
        self.label_2.setText(_translate("EditProjectInfoWindow", "<html><head/><body><p><span style=\" font-size:20pt;\">Project Name</span></p></body></html>"))
        self.label_4.setText(_translate("EditProjectInfoWindow", "<html><head/><body><p><span style=\" font-size:20pt;\">Short Description</span></p></body></html>"))
        self.label_5.setText(_translate("EditProjectInfoWindow", "<html><head/><body><p><span style=\" font-size:20pt;\">Long Description</span></p></body></html>"))
        self.label_6.setText(_translate("EditProjectInfoWindow", "<html><head/><body><p><span style=\" font-size:16pt; color:#888a85;\">Optional</span></p></body></html>"))
        self.saveBtn.setText(_translate("EditProjectInfoWindow", "Save"))
        self.menuInteractive_System_Modelling.setTitle(_translate("EditProjectInfoWindow", "1"))

