-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyApp.py
79 lines (72 loc) · 2.37 KB
/
MyApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#-------------------------------------------------#
# Title: CustomersApp
# Dev: Charles Robison
# Date: 2016.03.23
# Desc: This application manages customer data
# ChangeLog: (Who, When, What)
#
#-------------------------------------------------#
if __name__ == "__main__":
import DataProcessor, Customers
else:
raise Exception("This file was not created to be imported")
#-- Data --#
# declare variables and constants
objE = None #an Customer object
intId = 0 #an CustomerId
gIntLastId = 0 #Records the last CustomerId used in the client
strFirstName = "" #an Customer's first name
strLastName = "" #an Customer's last name
strInput = "" #temporary user input
#-- Processing --#
#perform tasks
def ProcessNewCustomerData(Id, FirstName, LastName):
try:
#Create Customer object
objE = Customers.Customer()
objE.Id = Id
objE.FirstName = FirstName
objE.LastName = LastName
Customers.CustomerList.AddCustomer(objE)
except Exception as e:
print(e)
def SaveDataToFile():
try:
objF = DataProcessor.File()
objF.FileName = "CustomerData.txt"
objF.TextData = Customers.CustomerList.ToString()
print("Reached here")
objF.SaveData()
except Exception as e:
print(e)
#-- Presentation (I/O) --#
#__main__
#get user input
strUserInput = ""
while(True):
strUserInput = input("Would you like to add Customer data? (y/n)")
if(strUserInput == "y"):
#Get Customer Id from the User
intId = int(input("Enter an Customer Id (Last id was " + str(gIntLastId) + "): "))
gIntLastId = intId
#Get Customer FirstName from the User
strFirstName = str(input("Enter an Customer First Name: "))
#Get Customer LastName from the User
strLastName = str(input("Enter an Customer Last Name: ") )
#Process input
ProcessNewCustomerData(intId, strFirstName, strLastName)
else:
break
#send program output
print("The Current Data is: ")
print("------------------------")
print(Customers.CustomerList.ToString())
#get user input
strInput = input("Would you like to save this data to the dat file?(y/n)")
if(strInput == "y"):
SaveDataToFile()
#send program output
print("data saved in file")
else:
print("data was not saved")
print("This application has ended. Thank you!")