def delete_barang(): sys.path.append('module/') from read import tampil1 tampil1() nomor = input('%s Pilih id barang : %s' % (ungu,putih)) with conn.cursor() as cursor: sql = "DELETE FROM barang WHERE `id` =%s" try: cursor.execute(sql, (nomor)) print('\n') print('\t\t%sSukses Menghapus DATA %sTabel Barang' % (putih,kuning)) print('\n') tampil1() except pymysql.Error as e: print("Error here", e)
def tampil1(): with conn.cursor() as cursor: sql = "SELECT `id`, `nama_barang`, `kategori`, `harga` FROM barang" try: cursor.execute(sql) result = cursor.fetchall() print("%s\t\t\t TABEL BARANG" % (merah)) print("%s +-------------------------------------------------------------+ " % (putih)) print("%s | Id_brg\t| Nama Barang\t| Kategori\t| Harga |" %(putih)) print("%s +-------------------------------------------------------------+ " % (putih)) for row in result: print(" "+str(row[0]) + "\t" + row[1] + "\t\t" + row[2] + "\tRp " + str(row[3])) print("%s +-------------------------------------------------------------+ " % (putih)) except pymysql.Error as e: print("Oops! Something Wrong", e)
def tampil(): with conn.cursor() as cursor: sql = "SELECT `id`, `nama`, `username`, `password` FROM user" try: cursor.execute(sql) result = cursor.fetchall() print("%s\t\t\t TABEL USER" % (merah)) print("%s +-------------------------------------------------------------+ " % (putih)) print("%s | Id_user\t| Nama\t\t| Username\t| Password |" %(putih)) print("%s +-------------------------------------------------------------+ " % (putih)) for row in result: print(" "+str(row[0]) + "\t" + row[1] + "\t\t" + row[2] + "\t " + row[3]) print("%s +-------------------------------------------------------------+ " % (putih)) except pymysql.Error as e: print("Oops! Something Wrong", e)
def ubahusr(): sys.path.append('module/') from read import tampil tampil() nomor = input('%s Pilih id user : %s' % (ungu,putih)) nm = input('%s Update Nama User : %s' % (ungu,putih)) usr = input('%s Update Username : %s' % (ungu,putih)) pswd = input('%s Update Password : %s' % (ungu,putih)) with conn.cursor() as cursor: sql = "UPDATE user SET `nama`=%s, `username`=%s, `password`=%s WHERE `id`=%s" try: cursor.execute(sql, (nm, usr, pswd, nomor)) print('\n') print("%s\t\t\t TABEL USER" % (merah)) print("%s +-------------------------------------------------------------+ " % (putih)) print("%s Sukses Update Nama : %s%s" % (ungu,putih,nm)) print("%s Sukses Update Username : %s%s" % (ungu,putih,usr)) print("%s Sukses Update Password : %s%s" % (ungu,putih,pswd)) print("%s +-------------------------------------------------------------+ " % (putih)) print('\n') except pymysql.Error as e: print("Error here", e)
def ubahbrg(): sys.path.append('module/') from read import tampil1 tampil1() nomor = input('%s Pilih id barang : %s' % (ungu,putih)) nm = input('%s Update Nama Barang : %s' % (ungu,putih)) ktg = input('%s Update Kategori : %s' % (ungu,putih)) hrg = input('%s Update Harga Barang : %sRp ' % (ungu,putih)) with conn.cursor() as cursor: sql = "UPDATE barang SET `nama_barang`=%s, `kategori`=%s, `harga`=%s WHERE `id`=%s" try: cursor.execute(sql, (nm, ktg, hrg, nomor)) print('\n') print("%s\t\t\t TABEL BARANG" % (merah)) print("%s +-------------------------------------------------------------+ " % (putih)) print("%s Sukses Update Nama Barang : %s%s" % (ungu,putih,nm)) print("%s Sukses Update Kategori Barang : %s%s" % (ungu,putih,ktg)) print("%s Sukses Update Harga Barang : %sRp %s" % (ungu,putih,hrg)) print("%s +-------------------------------------------------------------+ " % (putih)) print('\n') except pymysql.Error as e: print("Error here", e)
def tableuser(): print("%s\t\t\t TABEL USER" % (merah)) print( "%s +-------------------------------------------------------------+ " % (putih)) nm = input("%s Masukan Nama : %s" % (nila, putih)) usr = input("%s Masukan Username : %s" % (nila, putih)) pswd = input("%s Masukan Password : %s" % (nila, putih)) print( "%s +-------------------------------------------------------------+ " % (putih)) with conn.cursor() as cursor: sql = "INSERT INTO user (`nama`, `username`, `password`) VALUES (%s, %s, %s)" try: cursor.execute(sql, (nm, usr, pswd)) print('\n') print("%s Sukses Menambahkan Nama : %s%s" % (nila, putih, nm)) print("%s Sukses Menambahkan Username : %s%s" % (nila, putih, usr)) print("%s Sukses Menambahkan Password : %s%s" % (nila, putih, pswd)) except pymysql.Error as e: print("Error here", e)
def tablebrg(): print("%s\t\t\t TABEL BARANG" % (merah)) print( "%s +-------------------------------------------------------------+ " % (putih)) nm = input("%s Masukan Nama Barang : %s" % (kuning, putih)) ktg = input("%s Masukan Kategori : %s" % (kuning, putih)) hrg = input("%s Masukan Harga : %sRp " % (kuning, putih)) print( "%s +-------------------------------------------------------------+ " % (putih)) with conn.cursor() as cursor: sql = "INSERT INTO barang (`nama_barang`, `kategori`, `harga`) VALUES (%s, %s, %s)" try: cursor.execute(sql, (nm, ktg, hrg)) print('\n') print("%s Sukses Menambahkan Nama Barang : %s%s" % (kuning, putih, nm)) print("%s Sukses Menambahkan Kategori : %s%s" % (kuning, putih, ktg)) print("%s Sukses Menambahkan Harga : %sRp %s" % (kuning, putih, hrg)) except pymysql.Error as e: print("Error here", e)