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 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')
- #*******************************************************************************#
- 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 update in price by id
- # call edited by person
- elif op==7 :
- writeProduct(Id)
- else :
- return
- ch=input('\nIf you want to continue press [ Y / N ] : ')
- #*******************************************************************************#
- def Main():
- op1 = int(input('1) Employee.\n2) Customer.\nEnter Your choice : '))
- if op1 == 1 : # Employee
- newPass=input('Enter the password for employees : ') # str
- 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 op2==2 : # Customer
- # # phone , name -> get them from funtion writeCustomer
- # menuCustomer(Phone , Name)
- else :
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement