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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| package giesen.Interface import giesen.Business.CustomerService import giesen.Model.Customer import scala.io.StdIn import scala.util.control.Breaks.{break, breakable} class CustomerView { var loop = true var key = ' ' var customerService = new CustomerService() def mainMenu(): Unit = { do { println("-----------------Game customer information management software-----------------") println("1 Add a game play guest") println("2 Repair and change tour play guest") println("3 Delete the game user account") println("4 Play guest list") println("5 Back out") println("Please select (1-5):") key = StdIn.readChar() key match { case '1' => this.add() case '2' => this.update() case '3' => this.delete() case '4' => this.list() case '5' => this.quit() case _ => println("Please choose again!") } } while (loop) } def quit(): Unit = { println("Confirm whether to exit (Y/N):") var choice = ' ' breakable { while (true) { choice = StdIn.readChar().toLower if (choice != 'y' || choice != 'n') { println("Confirm whether to exit (Y/N):") } if (choice == 'n') { break() } if (choice == 'y') { this.loop = false break() } } } } def list(): Unit = { println() println("---------------------------Game Client List---------------------------") println("Number\tName\tGender\t\tAge\t\tTelephone\t\tMail") val customers = customerService.list() for (customer <- customers) { println(customer) } println("-------------------------The game client list is complete-------------------------") } def add(): Unit = { println("") println("---------------------Add game customers---------------------") println("Name:") val name = StdIn.readLine() println("Gender:") val gender = StdIn.readChar() println("Age:") val age = StdIn.readShort() println("Telephone:") val tel = StdIn.readLine() println("Mail:") val email = StdIn.readLine() val customer = new Customer(name, gender, age, tel, email) customerService.add(customer) println("---------------------Add to complete---------------------") } def delete(): Unit = { println("") println("---------------------Deleting Game Clients---------------------") println("Select the customer number of the game to be deleted (-1 Exit):") val id = StdIn.readInt() if (id == -1) { println("---------------------Delete failed---------------------") return } println("Confirm whether to delete (Y/N):") var choice = ' ' breakable { do { choice = StdIn.readChar().toLower if (choice == 'y' || choice == 'n') { break() } println("Confirm whether to delete (Y/N):") } while (true) } if (choice == 'y') { if (customerService.delete(id)) { println("---------------------Deleting completed---------------------") return } } println("---------------------Delete failed---------------------") } def update(): Unit ={ println("") println("---------------------Modifying Game Clients---------------------") println("Select the customer ID of the game you want to modify (-1 Exit):") val id = StdIn.readInt() if(id == -1){ println("---------------------Modify the failure---------------------") return } val customerFromArray = customerService.findCustomerById(id) if(customerFromArray.isInstanceOf[Boolean]){ println("---------------------The user does not exist---------------------") update() }else{ val customerFromService = customerFromArray.asInstanceOf[Customer] var name = "" var gender = ' ' var age : Short = -1 var tel = "" var email = "" println(s"Name(${customerFromService.name}):") name = StdIn.readLine() println(s"Gender:(${customerFromService.gender}):") gender = StdIn.readChar() println(s"Age:(${customerFromService.age}):") age = StdIn.readShort() println(s"Telephone:(${customerFromService.tel}):") tel = StdIn.readLine() println(s"Mail:(${customerFromService.email}):") email = StdIn.readLine() val customer = new Customer(name, gender, age, tel, email) val isUpdated = customerService.update(id, customer) if(isUpdated){ println("---------------------Modified to complete---------------------") return } } println("---------------------Modify the failure---------------------") } }
|