from main_imports import MDScreen
from ProjectFiles.applibs import utils

utils.load_kv("login.kv")

import mysql.connector


class Login_Screen(MDScreen):


    def LoginButton(self):
        email = format(self.txt1.text)
        password = format(self.txt2.text)
        try:
            connection = mysql.connector.connect(host='localhost',
                                                 database='SystemUser',
                                                 user='root',
                                                 password='')
            cursor = connection.cursor()

            sql_select_query = "SELECT * FROM People WHERE email = '" + email + "' AND password = '" + password + "'"
            cursor.execute(sql_select_query)
            cursor.fetchall()
            rowcount = cursor.rowcount
            if rowcount > 0:
               self.parent.current = "Paddy_Waste"
            else:


                self.l1.text = "Login  Invalid"



        finally:
            if connection.is_connected():
                connection.close()

    def ClearButton(self):
        self.txt1.text = ""
        self.txt2.text = ""
        self.l1.text = ""


    pass





