import sys

from PyQt5.QtWidgets import QMessageBox

from service.MainMenu import *
from service import globalValue

class Ui_MainWindow1(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui_MainWindow1, self).__init__()
        self.setupUi(self)
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        font.setBold(False)
        font.setWeight(50)
        MainWindow.setFont(font)
        MainWindow.setStyleSheet("\n"
                                 "*{\n"
                                 "font-size:24px;\n"
                                 "font-family:Century Gothic;\n"
                                 "}\n"
                                 "QFrame{\n"
                                 "background:rgba(0,0,0,0.8);\n"
                                 "border-radius:15px;\n"
                                 "}\n"
                                 "#centralwidget{\n"
                                 "border-image:url(./pictures/login3.jpg) strectch；\n"
                                 "}\n"
                                 "\n"
                                 "#toolButton{\n"
                                 "background:red;\n"
                                 "border-radius:60px;\n"
                                 "}\n"
                                 "QLabel{\n"
                                 "color:white;\n"
                                 "background:transparent;\n"
                                 "}\n"
                                 "QPushButton{\n"
                                 "background:red;;\n"
                                 "border-radius:15px;\n"
                                 "}\n"
                                 "QPushButton:hover{\n"
                                 "background:#333;\n"
                                 "border-radius:15px;\n"
                                 "background:#49ebff;\n"
                                 "}\n"
                                 "QLineEdit{\n"
                                 "background:transparent;\n"
                                 "border:none;\n"
                                 "color:#717072;\n"
                                 "border-bottom:1px solid #717072;\n"
                                 "}")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        font.setStyleStrategy(QtGui.QFont.PreferAntialias)
        self.centralwidget.setFont(font)
        self.centralwidget.setFocusPolicy(QtCore.Qt.WheelFocus)
        self.centralwidget.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
        self.centralwidget.setObjectName("centralwidget")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(140, 80, 491, 461))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.frame.setFont(font)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(180, 70, 151, 41))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.lineEdit_user = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_user.setGeometry(QtCore.QRect(70, 160, 361, 31))
        self.lineEdit_user.setText("")
        self.lineEdit_user.setObjectName("lineEdit_user")
        self.lineEdit_password = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_password.setGeometry(QtCore.QRect(70, 260, 361, 31))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        self.lineEdit_password.setFont(font)
        self.lineEdit_password.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
        self.lineEdit_password.setLocale(QtCore.QLocale(QtCore.QLocale.Chinese, QtCore.QLocale.China))
        self.lineEdit_password.setText("")
        self.lineEdit_password.setEchoMode(QtWidgets.QLineEdit.Password)
        self.lineEdit_password.setObjectName("lineEdit_password")
        self.pushButton = QtWidgets.QPushButton(self.frame)
        self.pushButton.setGeometry(QtCore.QRect(40, 380, 421, 51))
        self.pushButton.setObjectName("pushButton")

        self.label_2 = QtWidgets.QLabel(self.frame)
        self.label_2.setGeometry(QtCore.QRect(70, 120, 121, 31))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        font.setBold(False)
        font.setWeight(50)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.frame)
        self.label_3.setGeometry(QtCore.QRect(70, 220, 121, 31))
        self.label_3.setObjectName("label_3")
        self.toolButton = QtWidgets.QToolButton(self.centralwidget)
        self.toolButton.setGeometry(QtCore.QRect(330, 20, 121, 121))
        self.toolButton.setLocale(QtCore.QLocale(QtCore.QLocale.Chinese, QtCore.QLocale.China))
        self.toolButton.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("./pictures/login.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.toolButton.setIcon(icon)
        self.toolButton.setIconSize(QtCore.QSize(150, 150))
        self.toolButton.setObjectName("toolButton")
        self.forgetPasswd = QtWidgets.QToolButton(self.centralwidget)
        self.forgetPasswd.setGeometry(QtCore.QRect(660, 520, 131, 71))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(-1)
        font.setBold(False)
        font.setWeight(50)
        self.forgetPasswd.setFont(font)
        self.forgetPasswd.setStyleSheet("border:none;\n"
                                        "color:white;\n"
                                        "background:rgba(0,0,0,0.8)\n"
                                        "")
        self.forgetPasswd.setObjectName("forgetPasswd")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(660, 560, 121, 31))
        self.label_4.setObjectName("label_4")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "登录"))
        self.label.setText(_translate("MainWindow", "LOGIN HERE"))
        self.lineEdit_user.setPlaceholderText(_translate("MainWindow", "username"))
        self.lineEdit_password.setPlaceholderText(_translate("MainWindow", "password"))
        self.pushButton.setText(_translate("MainWindow", "登 录"))
        self.pushButton.clicked.connect(self.password)
        self.label_2.setText(_translate("MainWindow", "账户名"))
        self.label_3.setText(_translate("MainWindow", "密码"))
        self.forgetPasswd.setText(_translate("MainWindow", "忘记密码?"))
        self.forgetPasswd.clicked.connect(self.forgetPwd)

    def password(self):
        username = self.lineEdit_user.text()
        password = self.lineEdit_password.text()
        global staff
        staff = globalValue._initStaff()
        role = staff.userLogin(username,password)

        if role:
            from service.mainControl import MainWindow
            self.Main = MainWindow()
            self.close()
            self.Main.show()
        else:
            reply = QMessageBox.warning(self, "警告", "账户或密码错误，请重新输入！")

    def forgetPwd(self):
        from service.forgetPwd import fpWindow
        self.fpWindow = fpWindow()
        self.close()
        self.fpWindow.show()

if __name__=='__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = Ui_MainWindow1()
    Ui_MainWindow = Ui_MainWindow()
    window.show()
    sys.exit(app.exec_())
