Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- passWord='Zainab'
- def writeEmployee():
- with open('Employee.txt','a') as file :
- c = 'y'
- while c =='y' or c=='Y' :
- Id=input('Enter id : ')
- Name=input('Enter name : ')
- file.write(Id+'\t\t'+Name+'\n')
- c=input('Do you want to enter records again ? (y or n) ')
- #*******************************************************************************#*******************************************************************************#
- def readEmployee():
- with open('Employee.txt','r') as file :
- print('Employee_ID\tEmployee_Name')
- print('------------------------------------------')
- for line in file:
- print(line, end='')
- #*******************************************************************************#*******************************************************************************#
- def writeCustomer():
- with open('Customer.txt','a') as file :
- namecustomer=input('Enter your name : ')
- customerphone=input('Enter your phone number : ')
- file.write(namecustomer+'\t\t'+customerphone+'\n')
- #*******************************************************************************#*******************************************************************************#
- def readCustomer():
- with open('Customer.txt','r') as file :
- print('Customer_Name\tCustomer_PhoneNum')
- print('------------------------------------------')
- for line in file:
- print(line, end='')
- #*******************************************************************************#*******************************************************************************#
- def writeProduct(Employee_ID):
- with open('Product.txt', 'a')as file:
- c='y'
- while c=='y' or c=='Y':
- ID=input('Enter the product id: ')
- Name=input('Enter the product name: ')
- Price=input('Enter the product price: ')
- file.write(ID+'\t'+Name+'\t'+Price+'\t'+Employee_ID+'\n')
- c=input('Enter records of product again (y/n)? ')
- #*******************************************************************************#*******************************************************************************#
- def readProduct():
- with open('Product.txt', 'r')as file:
- print('ID\tName\tPrice\tEmployee_ID')
- print('-----------------------------------')
- for line in file:
- print(line , end='')
- #*******************************************************************************#*******************************************************************************#
- def readProduct2():
- with open('Product.txt', 'r')as file:
- print('ID\tName\tPrice')
- print('-----------------------------------')
- for line in file:
- l=line.split('\t')
- print(l[0] + '\t' + l[1] + '\t' + l[2])
- #*******************************************************************************#*******************************************************************************#
- def searchProduct():
- Name=input('Enter the name for the product to search: ')
- flag=False
- with open('Product.txt', 'r') as file:
- for line in file:
- pr=line.split('\t')
- if Name==pr[1]:
- flag=True
- print('ID:',pr[0],'\tName:',pr[1],'\tPrice:',pr[2])
- if not flag:
- print('\n"Sorry, The product is not found!"\n')
- #*******************************************************************************#*******************************************************************************#
- def deleteProduct():
- import os
- ID=input('Enter the id for the product: ')
- flag=False
- file=open('Product.txt', 'r')
- tempProduct=open('TempProduct.txt', 'w')
- for line in file:
- pr=line.split('\t')
- if ID==pr[0]:
- flag=True
- else:
- tempProduct.write(line)
- file.close()
- tempProduct.close()
- os.remove('Product.txt')
- os.rename('TempProduct.txt','Product.txt')
- if flag:
- print('\n"Product record deleted successfuly"\n')
- if not flag:
- print('\n"Sorry, The product is not found!"\n')
- #*******************************************************************************#*******************************************************************************#
- #update hereeeeeeeeeeeeeeeeee
- #*******************************************************************************#*******************************************************************************#
- def menuEmpolyee(Id , Name) :
- ch='Y'
- while ch=='Y' or ch=='y' :
- print('1) add new Employees')
- print('2) read all Employees')
- print('3) read all products')
- print('4) search about product by name')
- print('5) delete product by it\'s id')
- # op 6 and 7 need update autometically in field edited by
- print('6) update at price of product by it\'s id ')
- print('7) add new product')
- print('press any key to exit ')
- op=int(input('\n\nEnter your choice : \n'))
- if op== 1 :
- writeEmployee()
- elif op==2 :
- readEmployee()
- elif op==3 :
- readProduct()
- elif op==4 :
- searchProduct()
- elif op==5 :
- deleteProduct()
- elif op==6 :
- print('update in price soon ........ ')
- # call updateProduct(Id)
- # call edited by person
- elif op==7 :
- writeProduct(Id)
- else :
- return
- ch=input('\nIf you want to continue press [ Y / N ] : ')
- #*******************************************************************************#*******************************************************************************#
- def menuCustomer(Name , Phone):
- # countVis= # call cnt no of exiting the same customer in the file already
- ch='Y' ; totalPrice =0;
- with open("Sales.txt" ,'w' ) as sale:
- while ch=='Y' or ch=='y' :
- print('\n1) read all products to buy from them ')
- print('2) search about product by name \'if you want to buy it call \'read all products\' \'')
- print('if you want to exit press any key ')
- opt= int(input('\n\nEnter your choice : \t\n'))
- if opt== 1:
- readProduct2()
- wantedID=input('Enter id of the needed product : ')
- with open("Product.txt" ,'r' ) as file :
- for line in file :
- L = line.split('\t')
- if wantedID== L[0] :
- sale.write(line)
- totalPrice+=int(L[2])
- break
- elif opt == 2 :
- searchProduct()
- else :
- break
- ch= input('If you want to continue press [ Y / N ] : ')
- # the customer not buy anything
- if totalPrice==0 :
- print( 'thanks for using our system')
- return
- print('=========== id of sales & name & their prices =========== \n')
- with open("Sales.txt" ,'r' ) as sale:
- for line in sale :
- l=line.split('\t')
- print(l[0] + '\t' + l[1] + '\t' + l[2] )
- print('\nYour total price = ' , totalPrice)
- # check if count function > 0 then there exist discount
- print('\n\n*********************************** thanks for using our system ***********************************')
- #*******************************************************************************#*******************************************************************************#
- def Main():
- op1 = int(input('1) Employee.\n2) Customer.\nEnter Your choice : '))
- if op1 == 1 : # Employee
- newPass=input('Enter the password for employees : ')
- cnt=1
- while newPass != passWord and cnt < 3 :
- newPass=input('Invalid password !\nplease try again : ')
- cnt+=1
- if newPass !=passWord :
- return
- print('\n************* Welcome *************\n')
- with open('Employee.txt','a') as file :
- Id=input('Enter your id : ')
- Name=input('Enter your name : ')
- file.write(Id+'\t\t'+Name+'\n') # suppose that they always true
- print('\n************* logged in *************\n')
- menuEmpolyee(Id , Name)
- elif op1==2 : # Customer
- # phone , name -> get them from funtion writeCustomer
- with open('Customer.txt','a') as File :
- Name=input('Enter your name : ')
- Phone=input('Enter your phone number : ')
- File.write(Name+'\t\t'+Phone+'\n')
- menuCustomer(Name , Phone)
- else :
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement