-
Notifications
You must be signed in to change notification settings - Fork 0
/
appcontroll.py
136 lines (126 loc) · 4.37 KB
/
appcontroll.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# coding: utf-8
from view import UI
from hardware import Hardware
from software import Software
from product import *
class AppController:
def __init__(self):
self.__ui = UI()
self.__list = prod_list()
def run(self):
choice = -1
while choice != 0:
self.__ui.show_menu()
choice = self.__ui.get_menu_choice()
if choice == 1:
choice2 = self.__ui.product_menu()
if choice2 == 1:
self.new_hardware()
if choice2 == 2:
self.new_software()
elif choice2 == 0:
self.__ui.show_menu()
if choice == 2:
self.show_prod()
elif choice == 3:
self.single_item()
#lagger till product
def new_hardware(self):
while True:
name = raw_input("vilket namn? ")
if name == "":
print("Invalid input.")
else:
break
while True:
manufacture = raw_input("Vilken tillverkare? ")
if manufacture == "":
print("Invalid input.")
else:
break
while True:
try:
productnum = int(raw_input("Vilket produktnummer? "))
break
except ValueError:
print("Invalid input.")
while True:
try:
price = float(raw_input("Vilket pris? "))
break
except ValueError:
print("Invalid input.")
while True:
try:
weight = float(raw_input("Vikt i kg? "))
if weight >= 25:
price = price + 200
except ValueError:
print("Invalid input")
else:
break
hw = Hardware(name, manufacture, productnum, price, weight)
self.__list.set_product_list(hw)
def new_software(self):
while True:
name = raw_input("vilket namn? ")
if name == "":
print("Invalid input.")
else:
break
while True:
manufacture = raw_input("Vilken tillverkare? ")
if manufacture == "":
print("Invalid input.")
else:
break
while True:
try:
productnum = int(raw_input("Vilket produktnummer? "))
break
except ValueError:
print("Invalid input.")
while True:
try:
price = float(raw_input("Vilket pris? "))
break
except ValueError:
print("Invalid input.")
while True:
medium = str(raw_input("DVD/CD? "))
if medium == "DVD":
break
elif medium == "CD":
break
else:
print("Invalid input.")
sw = Software(name, manufacture, productnum, price, medium)
self.__list.set_product_list(sw)
"""printar ut produkter"""
def show_prod(self):
template = "{0:15}|{1:15}|{2:15}"
print template.format("Namn", "Produktnr", "Pris")
for i in self.__list.get_product_list():
print template.format(i.get_name(), i.get_productnum(), i.get_price())
"""skapar produkter som laddas uppe i abc()"""
def abc(self):
h1 = Hardware("Skrivare", "HP", 1, 500.00, 25)
self.__list.set_product_list(h1)
h2 = Hardware("Scanner", "WD", 2, 100.00, 25)
self.__list.set_product_list(h2)
s1 = Software("Office", "Microsoft", 3, 999.00, "DVD")
self.__list.set_product_list(s1)
"""Användaren ska kunna välja en specifik produkt genom någon typ av index"""
def single_item(self):
template = "{0:15}|{1:15}|{2:15}|{3:15}"
num = int(raw_input("Enter productnumber: "))
found = None
for prod in self.__list.get_product_list():
if prod.get_productnum() == num:
found = prod
if found:
print template.format("Namn", "Tillverkare", "Produktnr", "Pris")
print template.format(found.get_name(), found.get_manufacture(), found.get_productnum(), found.get_price())
#found.print_format()
else:
print "Det finns ingen sådan produkt"