Advertisement
Zeinab_Hamdy

ff

May 8th, 2023
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.35 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.  
  20. def readEmployee():
  21.     with open('Employee.txt','r') as file :
  22.         print('Employee_ID\tEmployee_Name')
  23.         print('------------------------------------------')
  24.         for line in file:
  25.             print(line, end='')
  26.  
  27.  
  28.  
  29. #*******************************************************************************#*******************************************************************************#
  30.  
  31.  
  32.  
  33.  
  34. def writeCustomer():
  35.     with open('Customer.txt','a') as file :
  36.         namecustomer=input('Enter your  name : ')
  37.         customerphone=input('Enter your phone number : ')
  38.         file.write(namecustomer+'\t\t'+customerphone+'\n')
  39.  
  40.  
  41. #*******************************************************************************#*******************************************************************************#
  42.  
  43.        
  44.        
  45. def readCustomer():
  46.     with open('Customer.txt','r') as file :
  47.         print('Customer_Name\tCustomer_PhoneNum')
  48.         print('------------------------------------------')
  49.         for line in file:
  50.             print(line, end='')
  51.  
  52.  
  53.  
  54. #*******************************************************************************#*******************************************************************************#
  55.  
  56.            
  57.  
  58.            
  59. def writeProduct(Employee_ID):
  60.     with open('Product.txt', 'a')as file:
  61.         c='y'
  62.         while c=='y' or c=='Y':
  63.             ID=input('Enter the product id: ')
  64.             Name=input('Enter the product name: ')
  65.             Price=input('Enter the product price: ')
  66.             file.write(ID+'\t'+Name+'\t'+Price+'\t'+Employee_ID+'\n')
  67.             c=input('Enter records of product again (y/n)? ')
  68.            
  69.  
  70.            
  71. #*******************************************************************************#*******************************************************************************#
  72.  
  73.  
  74.            
  75. def readProduct():
  76.     with open('Product.txt', 'r')as file:
  77.         print('ID\tName\tPrice\tEmployee_ID')
  78.         print('-----------------------------------')
  79.         for line in file:
  80.             print(line , end='')
  81.  
  82.            
  83.  
  84.  
  85. #*******************************************************************************#*******************************************************************************#
  86.  
  87.  
  88.  
  89.  
  90. def readProduct2():
  91.     with open('Product.txt', 'r')as file:
  92.         print('ID\tName\tPrice')
  93.         print('-----------------------------------')
  94.         for line in file:
  95.              l=line.split('\t')
  96.              print(l[0] + '\t' + l[1] + '\t' + l[2])
  97.  
  98.  
  99.            
  100.  
  101.  
  102.  
  103.  
  104. #*******************************************************************************#*******************************************************************************#
  105.  
  106.            
  107. def searchProduct():
  108.     Name=input('Enter the name for the product to search: ')
  109.     flag=False
  110.     with open('Product.txt', 'r') as file:
  111.         for line in file:
  112.             pr=line.split('\t')
  113.             if Name==pr[1]:
  114.                 flag=True
  115.                 print('ID:',pr[0],'\tName:',pr[1],'\tPrice:',pr[2])
  116.         if not flag:
  117.             print('\n"Sorry, The product is not found!"\n')
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. #*******************************************************************************#*******************************************************************************#
  127.        
  128.  
  129. def deleteProduct():
  130.     import os
  131.     ID=input('Enter the id for the product: ')
  132.     flag=False
  133.     file=open('Product.txt', 'r')
  134.     tempProduct=open('TempProduct.txt', 'w')
  135.     for line in file:
  136.         pr=line.split('\t')
  137.         if ID==pr[0]:
  138.             flag=True
  139.         else:
  140.             tempProduct.write(line)
  141.     file.close()
  142.     tempProduct.close()
  143.     os.remove('Product.txt')
  144.     os.rename('TempProduct.txt','Product.txt')
  145.     if flag:
  146.         print('\n"Product record deleted successfuly"\n')
  147.     if not flag:
  148.         print('\n"Sorry, The product is not found!"\n')
  149.  
  150.  
  151.  
  152. #*******************************************************************************#*******************************************************************************#
  153.  
  154.  
  155.  
  156. #update hereeeeeeeeeeeeeeeeee
  157.        
  158.  
  159.  
  160.        
  161.  
  162. #*******************************************************************************#*******************************************************************************#
  163.  
  164.  
  165.  
  166. def menuEmpolyee(Id , Name) :
  167.     ch='Y'
  168.     while ch=='Y' or ch=='y' :
  169.         print('1) add new Employees')
  170.         print('2) read all Employees')
  171.         print('3) read all products')
  172.         print('4) search about product by name')
  173.         print('5) delete product by it\'s id')
  174.        
  175.         # op 6 and 7 need update autometically in field edited by
  176.         print('6) update at price of product by it\'s id ')
  177.         print('7) add new product')
  178.         print('press any key to exit ')
  179.         op=int(input('\n\nEnter your choice : \n'))
  180.  
  181.        
  182.         if  op== 1 :
  183.             writeEmployee()
  184.         elif op==2 :
  185.             readEmployee()
  186.         elif op==3 :
  187.             readProduct()
  188.         elif op==4 :
  189.             searchProduct()
  190.         elif op==5 :
  191.             deleteProduct()
  192.         elif op==6 :
  193.             print('update in price soon ........ ')
  194.             # call updateProduct(Id)
  195.             # call edited by person
  196.         elif op==7 :
  197.             writeProduct(Id)
  198.         else :
  199.             return
  200.  
  201.         ch=input('\nIf you want to continue press [ Y / N ] : ')
  202.        
  203.  
  204.  
  205. #*******************************************************************************#*******************************************************************************#
  206.  
  207.        
  208.  
  209.  
  210.  
  211. def  menuCustomer(Name , Phone):
  212.    # countVis= # call cnt no of exiting the same customer in the file already
  213.    
  214.      ch='Y' ; totalPrice =0;
  215.      
  216.      with open("Sales.txt" ,'w' ) as sale:
  217.           while ch=='Y' or ch=='y' :
  218.              
  219.                print('\n1) read all products to buy from them ')
  220.                print('2) search about product by name \'if you want to buy it call \'read all products\' \'')
  221.                print('if you want to exit press any key ')
  222.                opt= int(input('\n\nEnter your choice : \t\n'))
  223.  
  224.                
  225.                if opt== 1:
  226.                    readProduct2()
  227.                    wantedID=input('Enter id of the needed product : ')  
  228.                    with open("Product.txt" ,'r' ) as file :
  229.                         for line in file :
  230.                             L = line.split('\t')
  231.                             if wantedID== L[0] :
  232.                                 sale.write(line)
  233.                                 totalPrice+=int(L[2])
  234.                                 break
  235.  
  236.            
  237.                elif opt == 2 :
  238.                     searchProduct()
  239.    
  240.                else :
  241.                     break
  242.                ch= input('If you want to continue press [ Y / N ] : ')
  243.  
  244.  
  245.  
  246.   # the customer not buy anything
  247.      if totalPrice==0 :
  248.         print( 'thanks for using our system')
  249.         return
  250.        
  251.      print('===========    id of sales &  name & their prices   =========== \n')
  252.      with open("Sales.txt" ,'r' ) as sale:
  253.          for line in sale :
  254.              l=line.split('\t')
  255.              print(l[0] + '\t' + l[1] + '\t' + l[2] )
  256.      print('\nYour total price = ' , totalPrice)
  257.      # check if count function > 0 then there exist discount
  258.  
  259.  
  260.      print('\n\n***********************************   thanks for using our system   ***********************************')
  261.  
  262.  
  263.        
  264. #*******************************************************************************#*******************************************************************************#
  265.  
  266.      
  267.  
  268.      
  269. def Main():
  270.     op1 = int(input('1) Employee.\n2) Customer.\nEnter Your choice : '))
  271.    
  272.     if op1 == 1 : # Employee
  273.         newPass=input('Enter the password for employees : ')
  274.         cnt=1
  275.        
  276.         while  newPass != passWord and  cnt < 3  :
  277.             newPass=input('Invalid password !\nplease try again : ')
  278.             cnt+=1
  279.            
  280.         if newPass !=passWord :
  281.           return
  282.        
  283.         print('\n*************  Welcome  *************\n')
  284.        
  285.         with open('Employee.txt','a') as file :
  286.             Id=input('Enter your id : ')
  287.             Name=input('Enter your  name : ')
  288.             file.write(Id+'\t\t'+Name+'\n')   # suppose that they always true
  289.            
  290.         print('\n************* logged in *************\n')
  291.        
  292.         menuEmpolyee(Id , Name)
  293.        
  294.     elif op1==2 : # Customer
  295.        # phone , name -> get them from funtion writeCustomer
  296.        with open('Customer.txt','a') as File :
  297.         Name=input('Enter your  name : ')
  298.         Phone=input('Enter your phone number : ')
  299.         File.write(Name+'\t\t'+Phone+'\n')
  300.        
  301.         menuCustomer(Name , Phone)
  302.  
  303.        
  304.     else :
  305.         return
  306.        
  307.        
  308.  
  309.  
  310.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement