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

# Form implementation generated from reading ui file 'dlg1.ui'
#
# Created by: PyQt5 UI code generator 5.12.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_vit(object):
    def setupUi(self, vit):
        vit.setObjectName("vit")
        vit.resize(1052, 862)
        self.label = QtWidgets.QLabel(vit)
        self.label.setGeometry(QtCore.QRect(460, 20, 191, 101))
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(28)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.custlist = QtWidgets.QTableWidget(vit)
        self.custlist.setGeometry(QtCore.QRect(40, 430, 551, 431))
        self.custlist.setRowCount(11)
        self.custlist.setColumnCount(4)
        self.custlist.setObjectName("custlist")
        self.label_9 = QtWidgets.QLabel(vit)
        self.label_9.setGeometry(QtCore.QRect(930, 790, 111, 16))
        self.label_9.setText("")
        self.label_9.setObjectName("label_9")
        self.about = QtWidgets.QPushButton(vit)
        self.about.setGeometry(QtCore.QRect(950, 10, 75, 23))
        self.about.setObjectName("about")
        self.widget = QtWidgets.QWidget(vit)
        self.widget.setGeometry(QtCore.QRect(100, 410, 491, 25))
        self.widget.setObjectName("widget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label_12 = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setFamily("Segoe Print")
        self.label_12.setFont(font)
        self.label_12.setObjectName("label_12")
        self.horizontalLayout.addWidget(self.label_12)
        self.label_13 = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setFamily("Segoe Print")
        self.label_13.setFont(font)
        self.label_13.setObjectName("label_13")
        self.horizontalLayout.addWidget(self.label_13)
        self.label_14 = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setFamily("Segoe Print")
        self.label_14.setFont(font)
        self.label_14.setObjectName("label_14")
        self.horizontalLayout.addWidget(self.label_14)
        self.label_15 = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setFamily("Segoe Print")
        self.label_15.setFont(font)
        self.label_15.setObjectName("label_15")
        self.horizontalLayout.addWidget(self.label_15)
        self.widget1 = QtWidgets.QWidget(vit)
        self.widget1.setGeometry(QtCore.QRect(620, 440, 391, 111))
        self.widget1.setObjectName("widget1")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.widget1)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.clr = QtWidgets.QPushButton(self.widget1)
        self.clr.setObjectName("clr")
        self.verticalLayout.addWidget(self.clr)
        self.srchre = QtWidgets.QPushButton(self.widget1)
        self.srchre.setObjectName("srchre")
        self.verticalLayout.addWidget(self.srchre)
        self.widget2 = QtWidgets.QWidget(vit)
        self.widget2.setGeometry(QtCore.QRect(40, 130, 471, 30))
        self.widget2.setObjectName("widget2")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.widget2)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(self.widget2)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(10)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.custid = QtWidgets.QLineEdit(self.widget2)
        self.custid.setObjectName("custid")
        self.horizontalLayout_2.addWidget(self.custid)
        self.addcust = QtWidgets.QPushButton(self.widget2)
        self.addcust.setObjectName("addcust")
        self.horizontalLayout_2.addWidget(self.addcust)
        self.widget3 = QtWidgets.QWidget(vit)
        self.widget3.setGeometry(QtCore.QRect(40, 170, 461, 25))
        self.widget3.setObjectName("widget3")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.widget3)
        self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.label_4 = QtWidgets.QLabel(self.widget3)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(9)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_3.addWidget(self.label_4)
        self.custnm = QtWidgets.QLineEdit(self.widget3)
        self.custnm.setObjectName("custnm")
        self.horizontalLayout_3.addWidget(self.custnm)
        self.label_3 = QtWidgets.QLabel(self.widget3)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(9)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.horizontalLayout_3.addWidget(self.label_3)
        self.custag = QtWidgets.QLineEdit(self.widget3)
        self.custag.setObjectName("custag")
        self.horizontalLayout_3.addWidget(self.custag)
        self.widget4 = QtWidgets.QWidget(vit)
        self.widget4.setGeometry(QtCore.QRect(40, 215, 182, 25))
        self.widget4.setObjectName("widget4")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.widget4)
        self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.label_16 = QtWidgets.QLabel(self.widget4)
        font = QtGui.QFont()
        font.setFamily("Segoe Print")
        font.setBold(True)
        font.setWeight(75)
        self.label_16.setFont(font)
        self.label_16.setObjectName("label_16")
        self.horizontalLayout_4.addWidget(self.label_16)
        self.date = QtWidgets.QLineEdit(self.widget4)
        self.date.setObjectName("date")
        self.horizontalLayout_4.addWidget(self.date)
        self.widget5 = QtWidgets.QWidget(vit)
        self.widget5.setGeometry(QtCore.QRect(40, 250, 371, 30))
        self.widget5.setObjectName("widget5")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.widget5)
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.label_5 = QtWidgets.QLabel(self.widget5)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(9)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.horizontalLayout_5.addWidget(self.label_5)
        self.medi = QtWidgets.QLineEdit(self.widget5)
        self.medi.setObjectName("medi")
        self.horizontalLayout_5.addWidget(self.medi)
        self.addmedi = QtWidgets.QPushButton(self.widget5)
        self.addmedi.setObjectName("addmedi")
        self.horizontalLayout_5.addWidget(self.addmedi)
        self.widget6 = QtWidgets.QWidget(vit)
        self.widget6.setGeometry(QtCore.QRect(40, 290, 217, 25))
        self.widget6.setObjectName("widget6")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.widget6)
        self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.label_6 = QtWidgets.QLabel(self.widget6)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(9)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.horizontalLayout_6.addWidget(self.label_6)
        self.qnty = QtWidgets.QLineEdit(self.widget6)
        self.qnty.setObjectName("qnty")
        self.horizontalLayout_6.addWidget(self.qnty)
        self.widget7 = QtWidgets.QWidget(vit)
        self.widget7.setGeometry(QtCore.QRect(40, 330, 188, 25))
        self.widget7.setObjectName("widget7")
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.widget7)
        self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.label_7 = QtWidgets.QLabel(self.widget7)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(9)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.horizontalLayout_7.addWidget(self.label_7)
        self.prc = QtWidgets.QLineEdit(self.widget7)
        self.prc.setObjectName("prc")
        self.horizontalLayout_7.addWidget(self.prc)
        self.widget8 = QtWidgets.QWidget(vit)
        self.widget8.setGeometry(QtCore.QRect(40, 370, 400, 30))
        self.widget8.setObjectName("widget8")
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.widget8)
        self.horizontalLayout_8.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.pushButton_3 = QtWidgets.QPushButton(self.widget8)
        self.pushButton_3.setObjectName("pushButton_3")
        self.horizontalLayout_8.addWidget(self.pushButton_3)
        self.pushButton = QtWidgets.QPushButton(self.widget8)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout_8.addWidget(self.pushButton)
        self.label_8 = QtWidgets.QLabel(self.widget8)
        font = QtGui.QFont()
        font.setFamily("Segoe Script")
        font.setPointSize(9)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.horizontalLayout_8.addWidget(self.label_8)
        self.total = QtWidgets.QLineEdit(self.widget8)
        self.total.setObjectName("total")
        self.horizontalLayout_8.addWidget(self.total)

        self.addcust.clicked.connect(self.createtb)
        self.addmedi.clicked.connect(self.addmedicine)
        self.pushButton_3.clicked.connect(self.viewitem)
        self.clr.clicked.connect(self.clear)
        self.srchre.clicked.connect(self.search)
        self.about.clicked.connect(self.info)

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

    def retranslateUi(self, vit):
        _translate = QtCore.QCoreApplication.translate
        vit.setWindowTitle(_translate("vit", "Dialog"))
        self.label.setText(_translate("vit", "ENTRY"))
        self.about.setText(_translate("vit", "ABOUT"))
        self.label_12.setText(_translate("vit", "DATE"))
        self.label_13.setText(_translate("vit", "MEDICINE"))
        self.label_14.setText(_translate("vit", "QUANTITY"))
        self.label_15.setText(_translate("vit", "PRICE"))
        self.clr.setText(_translate("vit", "CLEAR"))
        self.srchre.setText(_translate("vit", "Search records"))
        self.label_2.setText(_translate("vit", "Customer Id"))
        self.addcust.setText(_translate("vit", "ADD CUSTOMER"))
        self.label_4.setText(_translate("vit", "Name"))
        self.label_3.setText(_translate("vit", "Age"))
        self.label_16.setText(_translate("vit", "DATE"))
        self.label_5.setText(_translate("vit", "Medicine"))
        self.addmedi.setText(_translate("vit", "ADD MEDICINE"))
        self.label_6.setText(_translate("vit", "Quantity"))
        self.label_7.setText(_translate("vit", "Price"))
        self.pushButton_3.setText(_translate("vit", "VIEW ITEMS"))
        self.pushButton.setText(_translate("vit", "PRINT"))
        self.label_8.setText(_translate("vit", "TOTAL"))

    def createtb(self,text):
        import sqlite3
        customerid=self.custid.text()
        name=self.custnm.text()
        age=self.custag.text()
        entities=(customerid,name,age)
        conn = sqlite3.connect('MRECORD.db')
        curconn=conn.cursor()
        curconn.execute('''CREATE TABLE {}(Date,Medicine,Quantity,Price)'''.format(customerid))
        conn.commit()
        curconn.close()
        conn1=sqlite3.connect('CRECORD.db')
        curconn1=conn1.cursor()
        curconn1.execute('''INSERT INTO Record(CustId,Name,Age)VALUES(?,?,?)''',entities)
        conn1.commit()
        curconn1.close()
        self.total.setText('0')
        

    def addmedicine(self,text):
        date1=self.date.text()
        medicine=self.medi.text()
        quantity=self.qnty.text()
        price=self.prc.text()
        customerid=self.custid.text()
        medi_price=int(quantity)*int(price)
        total_int=self.total.text()
        total_price=int(total_int)+medi_price
        total_price=str(total_price)
        self.total.setText(total_price)
        entities1=(date1,medicine,quantity,price)
        import sqlite3
        conn2= sqlite3.connect('MRECORD.db')
        curconn=conn2.cursor()
        curconn.execute('''INSERT INTO {}(Date,Medicine,Quantity,Price)VALUES(?,?,?,?)'''.format(customerid),entities1)
        conn2.commit()
        curconn.close()
        


    def viewitem(self,text):
        import sqlite3
        customerid=self.custid.text()
        connection=sqlite3.connect('MRECORD.db')
        result=connection.execute('''SELECT * FROM {}'''.format(customerid))
        self.custlist.setRowCount(0)
        for row_number,row_data in enumerate(result):
            self.custlist.insertRow(row_number)
            for column_number,data in enumerate(row_data):
                self.custlist.setItem(row_number,column_number,QtWidgets.QTableWidgetItem(str(data)))

        connection.close()

    def clear(self,text):
        self.custid.setText('')
        self.custnm.setText('')
        self.custag.setText('')
        self.medi.setText('')
        self.prc.setText('')
        self.qnty.setText('')

    def search(self,text):
        from dlg2 import Ui_Dialog2
        Dialog2 = QtWidgets.QDialog()
        ui = Ui_Dialog2()
        ui.setupUi(Dialog2)
        Dialog2.show()
        ret=Dialog2.exec_()

    def info(self,text):
        from About import Ui_ABOUT
        ABOUT = QtWidgets.QDialog()
        ui = Ui_ABOUT()
        ui.setupUi(ABOUT)
        ABOUT.show()
        ret=ABOUT.exec_()







if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    vit = QtWidgets.QDialog()
    ui = Ui_vit()
    ui.setupUi(vit)
    vit.show()
    sys.exit(app.exec_())
