예제 #1
0
    def main_view(self):
        menu = "..::STUDENT MANAGER::..\n1. Enter infor student form keyboard\n2. View list Student\n3. Edit a Student\n4. Delete a Student\n5. Search\n6. Statistics\n0. Exit"
        list_std = Model().read('input2.json')

        while True:
            choice = input(menu + "\nMain - Choose 0 -> 6: ")
            if choice == 0:
                print('Exiting...')
                sys.exit(1)
            elif choice == 1:
                self._tmp = self.add_student()
                for std in self._tmp:
                    print Model().student_print(std)
                print Controller().con_add(self._tmp)
            elif choice == 2:
                print('List Student:')
                lists = Controller().con_main()
                self.view_student(lists)
            elif choice == 3:
                self.edit_option(list_std)
            elif choice == 4:
                id_del = int(raw_input('Nhap id Student can xoa: '))
                for j in range(0, list_std.__len__()):
                    if id_del == int(list_std[j]["id"]):
                        print(str(json.dumps(list_std[j])))
                Controller().con_delete(list_std, id_del)
                print('Deleted!')
            elif choice == 5:
                self.search_option(Model().sorted(list_std))
            elif choice == 6:
                self.statistic_option(list_std)

            else:
                print("Choose not exists")
예제 #2
0
파일: view.py 프로젝트: thaild/1LinkIntern
    def main_view(self):
        menu = "..::STUDENT MANAGER::..\n1. Enter infor student form keyboard\n2. View list Student\n3. Edit a Student\n4. Delete a Student\n5. Search\n6. Statistics\n0. Exit"
        list_std = Model().read('input.txt', 'r')

        while True:
            choice = input(menu + "\nMain - Choose 0 -> 6: ")
            if choice == 0:
                print('Exiting...')
                sys.exit(1)
            elif choice == 2:
                print('List Student:')
                self._list = (Controller().con_main())
                for i in range(self._list.__len__()):
                    print(self._list[i])
            elif choice == 1:
                self._add_student()
                Controller().con_add('input.txt', 'a', self._tmp)
            elif choice == 3:
                self._edit_option(list_std)
            elif choice == 4:
                id_del = int(raw_input('Nhap id Student can xoa: '))
                for j in range(0, list_std.__len__()):
                    if id_del == int(list_std[j].get_id()):
                        print(list_std[j])
                self._tmp = Controller().con_delete(list_std, id_del)
                print('Deleted!')
            elif choice == 5:
                self._search_option(Model().sorted(list_std))
            elif choice == 6:
                self._statistic_option(list_std)

            else:
                print("Choose not exists")
예제 #3
0
 def con_add(self, student):
     list_std = Model().read('input2.json')
     for i in range(student.__len__()):
         _id = list_std.__len__() + 1
         name = student[i]._name
         add = student[i]._add
         gender = student[i]._sex
         math = student[i]._math
         phy = student[i]._physics
         chem = student[i]._chemistry
         if math > 10 or chem > 10 or phy > 10:
             return ("Scores Error!!")
         else:
             std_dict = {
                 "gender": gender,
                 "add": add,
                 "chemistry": chem,
                 "physics": phy,
                 "math": math,
                 "id": _id,
                 "name": name
             }
             self._tmp.append(json.dumps(std_dict))
     Model().write_add("input2.json", "w", self._tmp)
     return ("Add ok!")
예제 #4
0
파일: test.py 프로젝트: thaild/1LinkIntern

import json
from model.model import Model

students = Model()
std = {}
fi = open("input.json")
fo = open("output.json", "w+")
data = fi.read()
students = json.loads(data)
fo.write('[\n')
for i in range(students.__len__()-1):
	fo.write(str(json.dumps(students[i]))+',\n')
fo.write(str(json.dumps(students[students.__len__()-1])))
fo.write(']')
#out = json.dumps(std)
#print demjson.decode(std)

#fo.write(out)
# fi = (json.dumps({'id': 11, 'name': "le dinh thai", "add":"Hanoi","gender":"nam","score":{"math":8,"physics":9, "chemistry":10}}))



fo.close()
fi.close()