Advertisement
Zeinab_Hamdy

fff

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