Advertisement
Zeinab_Hamdy

final1

May 8th, 2023 (edited)
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.64 KB | None | 0 0
  1. passWord='Zainab'
  2.  
  3. def writeEmployee():  
  4.     with open('Employee.txt','a') as file :
  5.         c = 'y'
  6.         while c =='y' or c=='Y' :
  7.             Id=input('Enter id : ')
  8.             Name=input('Enter name : ')
  9.             file.write(Id+'\t\t'+Name+'\n')
  10.             c=input('Do you want to enter records again ? (y or n) ')
  11.  
  12.  
  13. #*******************************************************************************#
  14.  
  15.            
  16.            
  17.  
  18.  
  19. def readEmployee():
  20.     with open('Employee.txt','r') as file :
  21.         print('Employee_ID\tEmployee_Name')
  22.         print('------------------------------------------')
  23.         for line in file:
  24.             print(line, end='')
  25.  
  26.  
  27. #*******************************************************************************#
  28.  
  29.  
  30.  
  31. def writeCustomer():
  32.     with open('Customer.txt','a') as file :
  33.         namecustomer=input('Enter your  name : ')
  34.         customerphone=input('Enter your phone number : ')
  35.         file.write(namecustomer+'\t\t'+customerphone+'\n')
  36.  
  37.  
  38. #*******************************************************************************#
  39.  
  40.        
  41.        
  42. def readCustomer():
  43.     with open('Customer.txt','r') as file :
  44.         print('Customer_Name\tCustomer_PhoneNum')
  45.         print('------------------------------------------')
  46.         for line in file:
  47.             print(line, end='')
  48.  
  49.  
  50.  
  51. #*******************************************************************************#
  52.  
  53.            
  54. def writeProduct(Employee_ID):
  55.     with open('Product.txt', 'a')as file:
  56.         c='y'
  57.         while c=='y' or c=='Y':
  58.             ID=input('Enter the product id: ')
  59.             Name=input('Enter the product name: ')
  60.             Price=input('Enter the product price: ')
  61.             file.write(ID+'\t'+Name+'\t'+Price+'\t'+Employee_ID+'\n')
  62.             c=input('Enter records of product again (y/n)? ')
  63.  
  64.            
  65. #*******************************************************************************#
  66.  
  67.  
  68.            
  69. def readProduct():
  70.     with open('Product.txt', 'r')as file:
  71.         print('ID\tName\tPrice\tEmployee_ID')
  72.         print('-----------------------------------')
  73.         for line in file:
  74.             print(line , end='')
  75.  
  76.  
  77. #*******************************************************************************#
  78.  
  79.            
  80. def searchProduct():
  81.     Name=input('Enter the name for the product to search: ')
  82.     flag=False
  83.     with open('Product.txt', 'r') as file:
  84.         for line in file:
  85.             pr=line.split('\t')
  86.             if Name==pr[1]:
  87.                 flag=True
  88.                 print('ID:',pr[0],'\tName:',pr[1],'\tPrice:',pr[2])
  89.         if not flag:
  90.             print('\n"Sorry, The product is not found!"\n')
  91.  
  92.  
  93.  
  94. #********************************************************************************#
  95.  
  96.  
  97.  
  98. def deleteProduct():
  99.     import os
  100.     ID=input('Enter the id for the product: ')
  101.     flag=False
  102.     file=open('Product.txt', 'r')
  103.     tempProduct=open('TempProduct.txt', 'w')
  104.     for line in file:
  105.         pr=line.split('\t')
  106.         if ID==pr[0]:
  107.             flag=True
  108.         else:
  109.             tempProduct.write(line)
  110.     file.close()
  111.     tempProduct.close()
  112.     os.remove('Product.txt')
  113.     os.rename('TempProduct.txt','Product.txt')
  114.     if flag:
  115.         print('\n"Product record deleted successfuly"\n')
  116.     if not flag:
  117.         print('\n"Sorry, The product is not found!"\n')
  118.  
  119.  
  120.  
  121. #*******************************************************************************#
  122.  
  123.  
  124. def menuEmpolyee(Id , Name) :
  125.     ch='Y'
  126.     while ch=='Y' or ch=='y' :
  127.         print('1) add new Employees')
  128.         print('2) read all Employees')
  129.         print('3) read all products')
  130.         print('4) search about product by name')
  131.         print('5) delete product by it\'s id')
  132.         # op 6 and 7 need update autometically in field edited by
  133.         print('6) update at price of product by it\'s id ')
  134.         print('7) add new product')
  135.         print('press any key to exit ')
  136.         op=int(input('\n\nEnter your choice : \n'))
  137.  
  138.        
  139.         if  op== 1 :
  140.             writeEmployee()
  141.         elif op==2 :
  142.             readEmployee()
  143.         elif op==3 :
  144.             readProduct()
  145.         elif op==4 :
  146.             searchProduct()
  147.         elif op==5 :
  148.             deleteProduct()
  149.         elif op==6 :
  150.             print('update in price soon ........ ')
  151.             # call update in price by id
  152.             # call edited by person
  153.         elif op==7 :
  154.             writeProduct(Id)
  155.         else :
  156.             return
  157.  
  158.         ch=input('\nIf you want to continue press [ Y / N ] : ')
  159.        
  160.  
  161.  
  162. #*******************************************************************************#
  163.  
  164.        
  165.  
  166.  
  167.  
  168.      
  169. def Main():
  170.     op1 = int(input('1) Employee.\n2) Customer.\nEnter Your choice : '))
  171.     if op1 == 1 : # Employee
  172.         newPass=input('Enter the password for employees : ') # str
  173.         cnt=1
  174.         while  newPass != passWord and  cnt < 3  :
  175.             newPass=input('Invalid password !\nplease try again : ')
  176.             cnt+=1
  177.         if newPass !=passWord :
  178.           return
  179.         print('\n*************  Welcome  *************\n')
  180.        
  181.         with open('Employee.txt','a') as file :
  182.             Id=input('Enter your id : ')
  183.             Name=input('Enter your  name : ')
  184.             file.write(Id+'\t\t'+Name+'\n')   # suppose that they always true
  185.            
  186.         print('\n************* logged in *************\n')
  187.        
  188.         menuEmpolyee(Id , Name)
  189.        
  190.  #   elif op2==2 : # Customer
  191.  #       # phone , name -> get them from funtion writeCustomer
  192.  #       menuCustomer(Phone , Name)
  193.     else :
  194.         return
  195.        
  196.        
  197.  
  198.  
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement