0% found this document useful (0 votes)
22 views

Prelimcode

The document contains code for an electricity billing system that allows users to create consumer profiles, view consumer details, edit consumer details, enter meter readings and billing details, and view a home menu. The code includes functions for connecting to a MySQL database and performing CRUD operations on consumer and billing data.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Prelimcode

The document contains code for an electricity billing system that allows users to create consumer profiles, view consumer details, edit consumer details, enter meter readings and billing details, and view a home menu. The code includes functions for connecting to a MySQL database and performing CRUD operations on consumer and billing data.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

from time import sleep

def createconsumer():
import mysql.connector as m
mysql= m.connect(host="localhost", user="root",passwd="Vrushant14"
,database="consumer")
if mysql.is_connected():
print("Connected")

mycursor=mysql.cursor()
#The name of the database is consumer

con_no=int(input("Enter no: "))


name= input("Enter your full name:")
areacode=int(input("Enter areacode:"))
address=input("Enter address")
mobno=int(input("Enter your mobile number"))
email=input("Enter your email address")

sqlform="Insert into consumerinfo values(%s,%s,%s, %s,%s, %s)"

consumerinfo=[(con_no,name,areacode,address,mobno,
email)]
mycursor.executemany(sqlform, consumerinfo)

mysql.commit()
sleep(2.6)
print("\n\nData stored Successfully!")
home()

def meterreadings():
pread=float(input("Enter the previous reading: "))
cread=float(input("Enter the current readings: "))
units=cread-pread
billamt=int(input("Enter amount: "))
date=input("Enter date in dd/mm/yyyy format: ")

sqlform="Insert into meterreadings values(%s,%s,%s,%s,%s,%s)"

meter=[(con_no,pread,cread,units,billamt,
date)]
mycursor.executemany(sqlform, meter)

mysql.commit()

def viewconsumer():
import mysql.connector as m
mysql= m.connect(host="localhost", user="root",passwd="Vrushant14"
,database="consumer")
if mysql.is_connected():
print("Connected")

mycursor=mysql.cursor()

mycursor.execute("Select * from consumerinfo")


res=mycursor.fetchall()
inp=int(input("Enter your consumer number: "))
d=0
for row in res:
if row[0]==inp:
print("Consumer No:\t",row[0],
"\nName: \t",row[1],
"\nAreaCode: \t",row[2],
"\nAddress: \t",row[3],
"\nMobile: \t",row[4],
"\nEmailID: \t",row[5])
d=1
else:
continue
if d==0:
print("User not registered!")

sleep(1)
home()

def editconsumer():
import mysql.connector as m
mysql= m.connect(host="localhost", user="root",passwd="Vrushant14"
,database="consumer")
if mysql.is_connected():
print("Connected")

mycursor=mysql.cursor()
con=input("Enter your consumer number: ")
print("What do you wish to edit?: ")
print("1. areacode\n2. address\n3. mobile number\n4. Email\
\n5. Go back to home")
c=int(input("Enter your choice: "))
if c==1:
new=input("Enter new area code: ")
sql="Update consumerinfo set areacode="+new+" where ConsumerNo="+con
mycursor.execute(sql)
mysql.commit()
if c==2:
new=input("Enter new address: ")
sql="Update consumerinfo set address="+new+" where ConsumerNo="+con
mycursor.execute(sql)
mysql.commit()
if c==3:
new=input("Enter new mobile number: ")
sql="Update consumerinfo set mobno="+new+" where ConsumerNo="+con
mycursor.execute(sql)
mysql.commit()
if c==4:
new=input("Enter new email: ")
sql="Update consumerinfo set email="+new+" where ConsumerNo="+con
mycursor.execute(sql)
mysql.commit()
if c==5:
home()
def home():
print("\n\t\t\tELECTRICITY BILLING SYSTEM")
print("\nWhat do you wish to do?:")
print("1. Create Consumer\n2. View Consumer Details\n3. Edit Consumer Details\
n4. Billing Details\n5. Exit")

input1=int(input("Enter your choice: "))


if input1==1:
createconsumer()
if input1==2:
viewconsumer()
if input1==3:
editconsumer()

home()

You might also like