class PetugasView(QWidget):
    def __init__(self):
        super(PetugasView, self).__init__()
        self.setWindowTitle("Data Petugas")
        self.resize(750, 350)
        self.UI()
        self.disableform()

    def UI(self):
        self.buatform()
        self.buattabelpetugas()
        self.layoutUtama = QVBoxLayout()
        self.layouttabel = QHBoxLayout()
        self.layoutCrud = QHBoxLayout()

        self.btntambah = QPushButtonComponent("Tambah")
        self.btnedit = QPushButtonComponent("Edit")
        self.btnhapus = QPushButtonComponent("Hapus")

        self.layoutCrud.addWidget(self.btntambah)
        self.layoutCrud.addWidget(self.btnedit)
        self.layoutCrud.addWidget(self.btnhapus)
        self.layouttabel.addWidget(self.tablepetugas)

        self.btntambah.clicked.connect(self.enableform)
        # self.btnedit.clicked.connect(lambda: self.editanggota())
        self.btnhapus.clicked.connect(self.hapusAnggotaId)
        self.formpetugas.addRow(self.layouttabel)
        self.formpetugas.addRow(self.layoutCrud)

        self.layoutUtama.addLayout(self.layoutCrud)
        self.setLayout(self.layoutUtama)

    def buatform(self):
        # formlayout
        self.formpetugas = QFormLayout(self)
        # data inputan

        self.nama = QLineEdit(self)
        self.nama.setPlaceholderText("Nama Petugas")
        self.formpetugas.addRow("Nama Petugas", self.nama)

        self.tempatlahir = QLineEdit(self)
        self.tempatlahir.setPlaceholderText("Tempat Lahir")
        self.formpetugas.addRow("Tempat Lahir", self.tempatlahir)

        self.tglLahir = QDateEdit(self)
        self.tglLahir.setDisplayFormat('dd/MM/yyyy')
        self.tglLahir.setCalendarPopup(True)
        self.formpetugas.addRow("Tanggal Lahir", self.tglLahir)

        self.alamat = QTextEdit(self)
        self.alamat.setPlaceholderText("Alamat")
        self.alamat.setFixedHeight(50)
        self.formpetugas.addRow("Alamat", self.alamat)

        self.nohp = QLineEdit(self)
        self.nohp.setInputMask("+62 9999 9999 999")
        self.formpetugas.addRow("No Handphone", self.nohp)

        self.jenkel = QComboBox()
        self.jenkel.addItem("laki-laki")
        self.jenkel.addItem("perempuan")
        self.formpetugas.addRow("Jenis Kelamin ", self.jenkel)
        # button
        self.btn_simpan = QPushButtonComponent("SIMPAN")
        self.btn_simpan.setFixedHeight(45)
        self.btn_simpan.clicked.connect(self.simpan_btn)
        self.formpetugas.addRow(self.btn_simpan)

    def buattabelpetugas(self):
        self.buattabel()

    def buattabel(self):
        self.tablepetugas = QTableWidget()
        self.tablepetugas.cellClicked.connect(self.cek)
        self.tablepetugas.setColumnCount(7)
        self.tablepetugas.setHorizontalHeaderLabels([
            "IdPetugas", "Nama", "TempatLahir", "TanggalLahir", "Alamat",
            "NoHandphone", "JenisKelamin"
        ])
        self.tablepetugas.setFixedSize(900, 350)
        self.tablepetugas.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.isiTable()

    def cek(self, row):
        print(self.tablepetugas.item(row, 0).text())
        print(self.tablepetugas.item(row, 1).text())
        print(self.tablepetugas.item(row, 2).text())
        print(self.tablepetugas.item(row, 3).text())
        print(self.tablepetugas.item(row, 4).text())
        print(self.tablepetugas.item(row, 5).text())
        print(self.tablepetugas.item(row, 6).text())

    def isiTable(self):
        query = OrmPetugas.tampilpetugas()
        self.tablepetugas.setRowCount(len(query))
        for row in range(len(query)):
            self.tablepetugas.setItem(
                row, 0, QTableWidgetItem(str(query[row].idpetugas)))
            self.tablepetugas.setItem(row, 1,
                                      QTableWidgetItem(str(query[row].Nama)))
            self.tablepetugas.setItem(row, 2,
                                      QTableWidgetItem(query[row].TempatLahir))
            self.tablepetugas.setItem(
                row, 3, QTableWidgetItem(query[row].TanggalLahir))
            self.tablepetugas.setItem(row, 4,
                                      QTableWidgetItem(str(query[row].Alamat)))
            self.tablepetugas.setItem(row, 5,
                                      QTableWidgetItem(query[row].NoHandphone))
            self.tablepetugas.setItem(
                row, 6, QTableWidgetItem(str(query[row].JenisKelamin)))

    def simpan_btn(self):
        try:
            Petugas(self.nama.text(), self.tempatlahir.text(),
                    self.tglLahir.text(), self.alamat.toPlainText(),
                    self.nohp.text(), self.jenkel.currentText())

            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Data Telah Disimpan")
            msg.setWindowTitle("Berhasil")
            msg.exec_()
            self.refresh()
            self.disableform()
            self.isiTable()
        except Exception as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("Data tidak berhasil disimpan")
            msg.setInformativeText(f"ERROR : {e}")
            msg.setWindowTitle("Warning")
            msg.exec_()

    def disableform(self):
        self.nama.setReadOnly(True)
        self.tempatlahir.setReadOnly(True)
        self.tglLahir.setReadOnly(True)
        self.alamat.setReadOnly(True)
        self.nohp.setReadOnly(True)
        self.jenkel.setDisabled(True)
        self.btn_simpan.setDisabled(True)

    def enableform(self):
        self.nama.setReadOnly(False)
        self.tempatlahir.setReadOnly(False)
        self.tglLahir.setReadOnly(False)
        self.alamat.setReadOnly(False)
        self.nohp.setReadOnly(False)
        self.jenkel.setDisabled(False)
        self.btn_simpan.setDisabled(False)
        self.nama.setFocus()

    def refresh(self):
        self.nama.clear()
        self.tempatlahir.clear()
        self.tglLahir.clear()
        self.alamat.clear()
        self.nohp.clear()

    def cekid(self, row):
        self.SelectedId = int(self.tablepetugas.item(row, 0).text())
        print(self.SelectedId)

    def hapusAnggotaId(self, row):
        SelectedId = int(self.tablepetugas.item(row, 0).text())
        OrmPetugas.hapusPetugas(SelectedId)
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setText("Data Telah Dihapus")
        msg.setWindowTitle("Berhasil")
        msg.exec_()
        self.isiTable()
Beispiel #2
0
class BukuView(QWidget):

    def __init__(self):
        super(BukuView,self).__init__()
        self.setWindowTitle("Data Buku")
        self.resize(750, 350)
        self.UI()
        self.disableform()

    def UI(self):
        self.buatform()
        self.buattabelbuku()
        self.layoutUtama = QVBoxLayout()
        self.layouttabel = QHBoxLayout()
        self.layoutCrud = QHBoxLayout()

        self.btntambah = QPushButtonComponent("Tambah")
        self.btnedit = QPushButtonComponent("Edit")
        self.btnhapus = QPushButtonComponent("Hapus")

        self.layoutCrud.addWidget(self.btntambah)
        self.layoutCrud.addWidget(self.btnedit)
        self.layoutCrud.addWidget(self.btnhapus)
        self.layouttabel.addWidget(self.tablebuku)

        self.btntambah.clicked.connect(self.enableform)
        # self.btnedit.clicked.connect(lambda: self.editanggota())
        self.btnhapus.clicked.connect(self.hapusid)
        self.formbuku.addRow(self.layouttabel)
        self.formbuku.addRow(self.layoutCrud)

        self.layoutUtama.addLayout(self.layoutCrud)
        self.setLayout(self.layoutUtama)

    def buatform(self):
        # formlayout
        self.formbuku = QFormLayout(self)
        # data inputan

        self.judulb = QLineEdit(self)
        self.judulb.setPlaceholderText("Judul Buku")
        self.formbuku.addRow("Judul Buku        ", self.judulb)

        self.pengarang = QLineEdit(self)
        self.pengarang.setPlaceholderText("Pengarang")
        self.formbuku.addRow("Pengarang        ", self.pengarang)

        self.penerbit = QLineEdit(self)
        self.penerbit.setPlaceholderText("Penerbit")
        self.formbuku.addRow("Penerbit        ", self.penerbit)

        self.tahunterbit = QDateEdit(self)
        self.tahunterbit.setDisplayFormat('yyyy')
        self.tahunterbit.setDate(QDate.currentDate())
        self.formbuku.addRow("Tanggal Terbit        ", self.tahunterbit)

        self.stokbuku = QLineEdit(self)
        self.stokbuku.setPlaceholderText("Stok Buku")
        self.formbuku.addRow("Stok Buku         ", self.stokbuku)

        self.norak = QComboBox()
        self.norak.addItem("Drama")
        self.norak.addItem("Komedi")
        self.norak.addItem("Sejarah")
        self.norak.addItem("Biografi")
        self.formbuku.addRow("Rak           ", self.norak)
        # button
        self.btn_simpan = QPushButtonComponent("SIMPAN")
        self.btn_simpan.setFixedHeight(45)
        self.btn_simpan.clicked.connect(self.simpan_btn)
        self.formbuku.addRow(self.btn_simpan)

    def buattabelbuku(self):
        self.buattabel()

    def buattabel(self):
        self.tablebuku = QTableWidget()
        self.tablebuku.setColumnCount(7)
        self.tablebuku.setHorizontalHeaderLabels(
            ["IdBuku","Judul Buku","Pengarang", "Penerbit","Tahun Terbit", "Stok Buku", "Nama Rak"])
        self.tablebuku.setFixedSize(900, 350)
        self.tablebuku.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.isiTable()

    def isiTable(self):
        query = OrmBuku.tampilbuku()
        self.tablebuku.setRowCount(len(query))
        for row in range(len(query)):
            self.tablebuku.setItem(row, 0, QTableWidgetItem(str(query[row].IdBuku)))
            self.tablebuku.setItem(row, 1, QTableWidgetItem(str(query[row].JudulBuku)))
            self.tablebuku.setItem(row, 2, QTableWidgetItem(str(query[row].Pengarang)))
            self.tablebuku.setItem(row, 3, QTableWidgetItem(query[row].Penerbit))
            self.tablebuku.setItem(row, 4, QTableWidgetItem(query[row].TahunTerbit))
            self.tablebuku.setItem(row, 5, QTableWidgetItem(str(query[row].Stok)))
            self.tablebuku.setItem(row, 6, QTableWidgetItem(query[row].NomorRak))

    def simpan_btn(self):
        try:
            Buku(self.judulb.text(),
                    self.pengarang.text(),
                    self.penerbit.text(),
                    self.tahunterbit.text(),
                    self.stokbuku.text(),
                    self.norak.currentText())

            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Data Telah Disimpan")
            msg.setWindowTitle("Berhasil")
            msg.exec_()
            self.refresh()
            self.disableform()
            self.isiTable()
        except Exception as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("Data tidak berhasil disimpan")
            msg.setInformativeText(f"ERROR : {e}")
            msg.setWindowTitle("Warning")
            msg.exec_()

    def disableform(self):
        self.judulb.setReadOnly(True)
        self.pengarang.setReadOnly(True)
        self.penerbit.setReadOnly(True)
        self.tahunterbit.setDisabled(True)
        self.stokbuku.setReadOnly(True)
        self.norak.setDisabled(True)
        self.btn_simpan.setDisabled(True)

    def enableform(self):
        self.judulb.setReadOnly(False)
        self.pengarang.setReadOnly(False)
        self.penerbit.setReadOnly(False)
        self.tahunterbit.setDisabled(False)
        self.stokbuku.setReadOnly(False)
        self.norak.setDisabled(False)
        self.btn_simpan.setDisabled(False)
        self.judulb.setFocus()

    def refresh(self):
        self.judulb.clear()
        self.pengarang.clear()
        self.penerbit.clear()
        self.tahunterbit.clear()
        self.stokbuku.clear()

    def cekid(self, row):
        self.SelectedId = int(self.tablebuku.item(row, 0).text())
        print(self.SelectedId)

    def hapusid(self, row):
        SelectedId = int(self.tablebuku.item(row, 0).text())
        OrmBuku.hapusBuku(SelectedId)
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setText("Data Telah Dihapus")
        msg.setWindowTitle("Berhasil")
        msg.exec_()
        self.isiTable()
Beispiel #3
0
class UserView(QWidget):
    def __init__(self):
        super(UserView, self).__init__()
        self.setWindowTitle("Data User")
        self.resize(750, 350)
        self.UI()
        self.disableform()

    def UI(self):
        self.buatform()
        self.buattabeluser()
        self.layoutUtama = QVBoxLayout()
        self.layouttabel = QHBoxLayout()
        self.layoutCrud = QHBoxLayout()

        self.btntambah = QPushButtonComponent("Tambah")
        self.btnedit = QPushButtonComponent("Edit")
        self.btnhapus = QPushButtonComponent("Hapus")

        self.layoutCrud.addWidget(self.btntambah)
        self.layoutCrud.addWidget(self.btnedit)
        self.layoutCrud.addWidget(self.btnhapus)
        self.layouttabel.addWidget(self.tableuser)

        self.btntambah.clicked.connect(self.enableform)
        # self.btnedit.clicked.connect(lambda: self.editanggota())
        self.btnhapus.clicked.connect(self.hapususer)
        self.formuser.addRow(self.layouttabel)
        self.formuser.addRow(self.layoutCrud)

        # self.layoutUtama.addLayout(self.layouttabel)
        self.layoutUtama.addLayout(self.layoutCrud)
        self.setLayout(self.layoutUtama)

    def buatform(self):
        # formlayout
        self.formuser = QFormLayout(self)

        # data inputab
        self.username = QLineEdit(self)
        self.username.setPlaceholderText("Username")
        self.formuser.addRow("Usename        ", self.username)

        self.passwrd = QLineEdit(self)
        self.passwrd.setPlaceholderText("Password")
        self.formuser.addRow("Password       ", self.passwrd)

        self.hakakses = QComboBox()
        self.hakakses.addItem("Admin")
        self.hakakses.addItem("Petugas")
        self.formuser.addRow("Hak Akses      ", self.hakakses)
        # button
        self.btn_simpan = QPushButtonComponent("SIMPAN")
        self.btn_simpan.setFixedHeight(45)
        self.btn_simpan.clicked.connect(self.simpan_btn)
        self.formuser.addRow(self.btn_simpan)

    def buattabeluser(self):
        self.buattabel()

    def buattabel(self):
        self.tableuser = QTableWidget(self)
        self.tableuser.setColumnCount(4)
        self.tableuser.setHorizontalHeaderLabels(
            ["IdUser", "Username", "Password", "Hak Akses"])
        self.tableuser.setFixedSize(900, 350)
        self.tableuser.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.isiTable()

    def isiTable(self):
        query = OrmUser.tampiluser()

        self.tableuser.setRowCount(len(query))
        for row in range(len(query)):
            self.tableuser.setItem(
                row, 0, QTableWidgetItem(str(query[row].id_username)))
            self.tableuser.setItem(row, 1,
                                   QTableWidgetItem(str(query[row].username)))
            self.tableuser.setItem(row, 2,
                                   QTableWidgetItem(str(query[row].password)))
            self.tableuser.setItem(row, 3,
                                   QTableWidgetItem(str(query[row].hak_akses)))

    def simpan_btn(self):
        try:

            User(self.username.text(), self.passwrd.text(),
                 self.hakakses.currentText())

            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Data Telah Disimpan")
            msg.setWindowTitle("Berhasil")
            msg.exec_()
            self.refresh()
            self.disableform()
            self.isiTable()
        except Exception as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("Data tidak berhasil disimpan")
            msg.setInformativeText(f"ERROR : {e}")
            msg.setWindowTitle("Warning")
            msg.exec_()

    def disableform(self):

        self.username.setReadOnly(True)
        self.passwrd.setReadOnly(True)
        self.hakakses.setDisabled(True)
        self.btn_simpan.setDisabled(True)

    def enableform(self):
        self.username.setReadOnly(False)
        self.passwrd.setReadOnly(False)
        self.hakakses.setDisabled(False)
        self.btn_simpan.setDisabled(False)
        self.username.setFocus()

    def refresh(self):
        self.username.clear()
        self.passwrd.clear()

    def cekid(self, row):
        self.SelectedId = int(self.tableuser.item(row, 0).text())
        print(self.SelectedId)

    def hapususer(self, row):
        SelectedId = int(self.tableuser.item(row, 0).text())
        OrmUser.hapususer(SelectedId)
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setText("Data Telah Dihapus")
        msg.setWindowTitle("Berhasil")
        msg.exec_()
        self.isiTable()
class PengembalianView(QWidget):
    def __init__(self):
        super(PengembalianView, self).__init__()
        self.setWindowTitle("Data Pengembalian Buku")
        self.resize(750, 350)
        self.UI()
        self.disableform()

    def UI(self):
        self.buatform()
        self.buattabelpinjam()
        self.layoutUtama = QVBoxLayout()
        self.layouttabel = QHBoxLayout()
        self.layoutCrud = QHBoxLayout()

        self.btntambah = QPushButtonComponent("Tambah")
        self.btnedit = QPushButtonComponent("Edit")
        self.btnhapus = QPushButtonComponent("Hapus")

        self.layoutCrud.addWidget(self.btntambah)
        self.layoutCrud.addWidget(self.btnedit)
        self.layoutCrud.addWidget(self.btnhapus)

        self.layouttabel.addWidget(self.tablepinjam)

        self.btntambah.clicked.connect(self.enableform)
        # self.btnedit.clicked.connect(lambda: self.editanggota())
        self.btnhapus.clicked.connect(self.hapusid)
        self.formpinjam.addRow(self.layouttabel)
        self.formpinjam.addRow(self.layoutCrud)

        self.layoutUtama.addLayout(self.layoutCrud)
        self.setLayout(self.layoutUtama)

    def buatform(self):
        # formlayout
        self.formpinjam = QFormLayout(self)
        # data inputan

        self.idpinjam = QLineEdit(self)
        self.idpinjam.setPlaceholderText("Id Peminjaman")
        self.formpinjam.addRow("Id Peminjaman      ", self.idpinjam)

        self.idanggota = QLineEdit(self)
        self.idanggota.setPlaceholderText("Id Anggota")
        self.formpinjam.addRow("Id Anggota      ", self.idanggota)

        self.idpetugas = QLineEdit(self)
        self.idpetugas.setPlaceholderText("Id Petugas")
        self.formpinjam.addRow("Id Petugas      ", self.idpetugas)

        self.idbuku = QLineEdit(self)
        self.idbuku.setPlaceholderText("Id Buku")
        self.formpinjam.addRow("Id Buku     ", self.idbuku)

        self.tglpinjam = QDateEdit(self)
        self.tglpinjam.setDisplayFormat('dd/MM/yyyy')
        self.tglpinjam.setCalendarPopup(True)
        self.formpinjam.addRow("Tanggal Peminjaman      ", self.tglpinjam)

        self.tglkembali = QDateEdit(self)
        self.tglkembali.setDisplayFormat('dd/MM/yyyy')
        self.tglkembali.setCalendarPopup(True)
        self.formpinjam.addRow("Tanggal Kembalikan       ", self.tglkembali)

        self.tgldikembali = QDateEdit(self)
        self.tgldikembali.setDisplayFormat('dd/MM/yyyy')
        self.tgldikembali.setCalendarPopup(True)
        self.tgldikembali.setDate(QDate.currentDate())
        self.formpinjam.addRow("Tanggal Dikembalikan      ", self.tgldikembali)

        self.status = QComboBox()
        self.status.addItem("Dipinjam")
        self.status.addItem("Selesai")
        self.formpinjam.addRow("Status      ", self.status)

        self.denda = QComboBox()
        self.denda.addItem("NolRb")
        self.denda.addItem("DuaRb")
        self.denda.addItem("LimaRb")
        self.formpinjam.addRow("Denda      ", self.denda)

        # button
        self.btn_simpan = QPushButtonComponent("SIMPAN")
        self.btn_simpan.setFixedHeight(45)
        self.btn_simpan.clicked.connect(self.simpan_btn)
        self.formpinjam.addRow(self.btn_simpan)

    def buattabelpinjam(self):
        self.buattabel()

    def buattabel(self):
        self.tablepinjam = QTableWidget(self)

        self.tablepinjam.setColumnCount(9)
        self.tablepinjam.setHorizontalHeaderLabels([
            "Id Pengembalian", "Id Peminjaman", "Id Anggota", "Id Petugas",
            "Id Buku", "Tanggal Peminjaman", "Tanggal Kembalikan",
            "Tanggal Dikembalikan", "Status"
        ])
        self.tablepinjam.setFixedSize(900, 350)
        self.tablepinjam.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.isiTable()

    def isiTable(self):
        query = OrmPengembalian.tampilpengembaian()

        self.tablepinjam.setRowCount(len(query))
        for row in range(len(query)):
            self.tablepinjam.setItem(
                row, 0, QTableWidgetItem(str(query[row].idpengembalian)))
            self.tablepinjam.setItem(
                row, 1, QTableWidgetItem(str(query[row].idpeminjaman)))
            self.tablepinjam.setItem(
                row, 2, QTableWidgetItem(str(query[row].idanggota)))
            self.tablepinjam.setItem(
                row, 3, QTableWidgetItem(str(query[row].idpetugas)))
            self.tablepinjam.setItem(row, 4,
                                     QTableWidgetItem(str(query[row].idbuku)))
            self.tablepinjam.setItem(
                row, 5, QTableWidgetItem(str(query[row].tglPinjam)))
            self.tablepinjam.setItem(
                row, 6, QTableWidgetItem(str(query[row].tglKembali)))
            self.tablepinjam.setItem(
                row, 7, QTableWidgetItem(str(query[row].tglDikembalikan)))
            self.tablepinjam.setItem(row, 8,
                                     QTableWidgetItem(str(query[row].Status)))
            self.tablepinjam.setItem(row, 9,
                                     QTableWidgetItem(str(query[row].Denda)))

    def simpan_btn(self):
        try:

            Pengembalian(self.idpinjam.text(), self.idanggota.text(),
                         self.idpetugas.text(), self.idbuku.text(),
                         self.tglpinjam.text(), self.tglkembali.text(),
                         self.tgldikembali.text(), self.status.currentText(),
                         self.denda.currentText())

            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Data Telah Disimpan")
            msg.setWindowTitle("Berhasil")
            msg.exec_()
            self.refresh()
            self.disableform()
            self.isiTable()
        except Exception as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("Data tidak berhasil disimpan")
            msg.setInformativeText(f"ERROR : {e}")
            msg.setWindowTitle("Warning")
            msg.exec_()

    def disableform(self):
        self.idpinjam.setReadOnly(True)
        self.idanggota.setReadOnly(True)
        self.idpetugas.setReadOnly(True)
        self.idbuku.setReadOnly(True)
        self.tglpinjam.setReadOnly(True)
        self.tglkembali.setReadOnly(True)
        self.tgldikembali.setReadOnly(True)
        self.status.setDisabled(True)
        self.denda.setDisabled(True)
        self.btn_simpan.setDisabled(True)

    def enableform(self):
        self.idpinjam.setReadOnly(False)
        self.idanggota.setReadOnly(False)
        self.idpetugas.setReadOnly(False)
        self.idbuku.setReadOnly(False)
        self.tglpinjam.setReadOnly(False)
        self.tglkembali.setReadOnly(False)
        self.tgldikembali.setReadOnly(False)
        self.status.setDisabled(False)
        self.denda.setDisabled(False)
        self.btn_simpan.setDisabled(False)
        self.idpinjam.setFocus()

    def refresh(self):
        self.idpinjam.clear()
        self.idanggota.clear()
        self.idpetugas.clear()
        self.idbuku.clear()

    def cekid(self, row):
        self.SelectedId = int(self.tablepinjam.item(row, 0).text())
        print(self.SelectedId)

    def hapusid(self, row):
        SelectedId = int(self.tablepinjam.item(row, 0).text())
        OrmPengembalian.hapuspengembalian(SelectedId)
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setText("Data Telah Dihapus")
        msg.setWindowTitle("Berhasil")
        msg.exec_()
        self.isiTable()
class PengunjungView(QDialog):
    def __init__(self):
        super(PengunjungView, self).__init__()
        self.setWindowTitle("Form Pengunjung")
        self.resize(750, 350)
        self.UI()
        self.disableform()

    def UI(self):
        self.buatform()
        self.buattabelpengunjung()

        self.layoutUtama = QVBoxLayout()
        self.layouttabel = QHBoxLayout()
        self.layoutCrud = QHBoxLayout()

        self.btntambah = QPushButtonComponent("Berkunjung")
        self.btntambah.clicked.connect(self.enableform)

        self.layoutCrud.addWidget(self.btntambah)
        self.layouttabel.addWidget(self.tablepengunjung)
        self.btntambah.clicked.connect(self.enableform)
        self.formpengunjung.addRow(self.layouttabel)
        self.formpengunjung.addRow(self.layoutCrud)

        self.layoutUtama.addLayout(self.layoutCrud)
        self.setLayout(self.layoutUtama)

    def buatform(self):
        # formlayout
        self.formpengunjung = QFormLayout(self)
        # data inputan

        self.nama = QLineEdit(self)
        self.nama.setPlaceholderText("Nama")
        self.formpengunjung.addRow("Nama      ", self.nama)

        self.alamat = QTextEdit(self)
        self.alamat.setPlaceholderText("Alamat")
        self.alamat.setFixedHeight(50)
        self.formpengunjung.addRow("Alamat        ", self.alamat)

        self.nohp = QLineEdit(self)
        self.nohp.setInputMask("+62 9999 9999 999")
        self.formpengunjung.addRow("No Handphone      ", self.nohp)

        self.tglberkunjung = QDateEdit(self)
        self.tglberkunjung.setDisplayFormat('dd/MM/yyyy')
        self.tglberkunjung.setDate(QDate.currentDate())
        self.tglberkunjung.setReadOnly(True)
        self.formpengunjung.addRow("Tanggal Berkunjung        ",
                                   self.tglberkunjung)

        # button
        self.btn_simpan = QPushButtonComponent("SIMPAN")
        self.btn_simpan.setFixedHeight(45)
        self.btn_simpan.clicked.connect(self.submit_btn)
        self.formpengunjung.addRow(self.btn_simpan)

    def buattabelpengunjung(self):
        self.buattabel()

    def buattabel(self):
        self.tablepengunjung = QTableWidget()
        self.tablepengunjung.cellClicked.connect(self.isiForm)
        self.tablepengunjung.setColumnCount(5)
        self.tablepengunjung.setHorizontalHeaderLabels([
            "Id Pengunjung", "Nama", "Alamat", "NoHandphone",
            "Tanggal Berkunjung"
        ])
        self.tablepengunjung.setFixedSize(900, 350)
        self.tablepengunjung.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.isiTable()

    def isiForm(self, row):
        self.nama.setText(self.tablepengunjung.item(row, 1).text())
        self.alamat.setText(self.tablepengunjung.item(row, 2).text())
        dataTgl = self.tablepengunjung.item(row, 4).text().split('/')
        dd = int(dataTgl[0])
        mm = int(dataTgl[1])
        yy = int(dataTgl[2])
        self.tglberkunjung.setDate(QDate(yy, mm, dd))
        self.nohp.setText(str(self.tablepengunjung.item(row, 3).text()))

    def isiTable(self):
        query = OrmPengunjung.tampilpengunjung()
        self.tablepengunjung.setRowCount(len(query))
        for row in range(len(query)):
            self.tablepengunjung.setItem(
                row, 0, QTableWidgetItem(str(query[row].IdPengunjung)))
            self.tablepengunjung.setItem(
                row, 1, QTableWidgetItem(str(query[row].Nama)))
            self.tablepengunjung.setItem(
                row, 2, QTableWidgetItem(str(query[row].Alamat)))
            self.tablepengunjung.setItem(row, 3,
                                         QTableWidgetItem(query[row].NoHp))
            self.tablepengunjung.setItem(
                row, 4, QTableWidgetItem(query[row].TanggalBerkunjung))

    def submit_btn(self):
        try:
            Pengunjung(self.nama.text(), self.alamat.toPlainText(),
                       self.nohp.text(), self.tglberkunjung.text())

            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Data Telah Disimpan")
            msg.setWindowTitle("Berhasil")
            msg.exec_()
            self.refresh()
            self.disableform()
            self.isiTable()
        except Exception as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("Data tidak berhasil disimpan")
            msg.setInformativeText(f"ERROR : {e}")
            msg.setWindowTitle("Warning")
            msg.exec_()

    def disableform(self):
        self.nama.setReadOnly(True)
        self.alamat.setReadOnly(True)
        self.nohp.setReadOnly(True)
        self.btn_simpan.setDisabled(True)

    def enableform(self):
        self.nama.setReadOnly(False)
        self.alamat.setReadOnly(False)
        self.nohp.setReadOnly(False)
        self.btn_simpan.setDisabled(False)
        self.nama.setFocus()

    def refresh(self):
        self.nama.clear()
        self.alamat.clear()
        self.nohp.clear()