// 전화번호 형식으로 입력받아 문자열을 반환하는 함수 public string PhoneNumberFormatInput(CursorPoint cursor) { ConsoleKeyInfo inputKey; string inputString = "01"; // 전화번호 형식 지정 Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write("01_-____-____"); Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(cursor.CursorLeft + 2, cursor.CursorTop); while (inputString.Length < 13) { inputKey = Console.ReadKey(true); // ESC가 입력되면 탈출함 if (inputKey.Key == ConsoleKey.Escape) { return(null); } // 숫자면 문자열에 추가한다 if (inputKey.KeyChar >= '0' && inputKey.KeyChar <= '9') { inputString += inputKey.KeyChar; Console.Write(inputKey.KeyChar + ""); if (inputString.Length == 3 || inputString.Length == 8) { Console.Write("-"); inputString += '-'; } } else { // 백스페이스에 대한 예외처리 if (inputKey.Key == ConsoleKey.Backspace) { Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); Console.Write(" "); Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); // 삭제한 문자 제거 if (inputString.Length > 0) { inputString = inputString.Remove(inputString.Length - 1); } if (cursor.CursorLeft > Console.CursorLeft) { Console.SetCursorPosition(cursor.CursorLeft, Console.CursorTop); } } } } return(inputString); }
public string AddressFormatInput(CursorPoint cursor) { int choice = 0; string[] city = { "서울특별시", "인천광역시", "대전광역시", "대구광역시", "울산광역시", "부산광역시", "광주광역시", "경기도", "강원도" }; string[] seoul = { "강서구", "양천구", "구로구", "마포구", "영등포구", "은평구", "서대문구", "종로구", "중구", "용산구", "동작구", "관악구", "도봉구", "강북구", "성북구", "동대문구", "성동구", "서초구", "노원구", "중랑구", "광진구", "강남구", "송파구", "강동구" }; string[] incheon = { "중구", "동구", "남구", "연수구", "남동구", "부평구", "계양구", "서구", "강화군", "옹진군" }; string[] daegeon = { "유성구", "서구", "중구", "대덕구", "동구" }; string[] daegoo = { "남구", "달서구", "동구", "북구", "서구", "수성구", "중구" }; string[] ulsan = { "남구", "동구", "북구", "중구" }; string[] busan = { "중구", "서구", "동구", "영도구", "부산진구", "동래구", "남구", "북구", "해운대구", "사하구", "금정구", "강서구", "연제구", "수영구", "사상구", "기장군" }; string[] gwangju = { "광산구", "남구", "동구", "북구", "서구" }; string[] gyunggi = { "수원시", "고양시", "성남시", "부천시", "안양시", "광명시", "평택시", "안산시", "과천시", "오산시", "시흥시", "군포시", "의왕시", "하남시", "용인시", "이천시", "안성시", "김포시", "화성시", "광주시", "의정부시", "동두천시", "구리시", "남양주시", "파주시", "양주시", "포천시", "여주시", "연천군", "가평군", "양평군" }; string[] gangwon = { "원주시", "춘천시", "강릉시", "동해시", "속초시", "삼척시", "태백시" }; string[][] districtSets = { seoul, incheon, daegeon, daegoo, ulsan, busan, gwangju, gyunggi, gangwon }; Hashtable districts = new Hashtable(); // 지역 해시테이블 초기화 for (int i = 0; i < city.Length; i++) { districts[city[i]] = districtSets[i]; } string inputString = ""; // 시 선택 choice = ComboBox(new List <string>(city), cursor, " "); if (choice == ConstNumber.ESC) { return(null); } // 시 선택 저장 inputString += city[choice]; string[] chosenCity = (string[])districts[inputString]; inputString += " "; // 도 선택 choice = ComboBox(new List <string>(chosenCity), new CursorPoint(cursor.CursorLeft + inputString.Length * 2 - 1, cursor.CursorTop), " "); if (choice == ConstNumber.ESC) { return(null); } // 도 선택 저장 inputString += chosenCity[choice]; return(inputString); }
public int ComboBox(List <string> items, CursorPoint cursor, string blankString) { int choice = 0, inputKey; while (true) { // 현재 선택 중인 문자열을 출력 Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop); Console.Write(blankString); Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop); Console.Write(items[choice]); inputKey = inputProcessor.PressDirectionKey(); switch (inputKey) { case ConstNumber.LEFT: case ConstNumber.UP: choice--; break; case ConstNumber.RIGHT: case ConstNumber.DOWN: choice++; break; case ConstNumber.ESC: return(ConstNumber.ESC); // Enter가 입력되면 선택 인덱스를 출력 default: return(choice); } // 선택 범위 제한 if (choice < 0) { choice = 0; } if (choice >= items.Count) { choice = items.Count - 1; } } }
public Data.Student MemberRegistrationScreen() { Data.Student newStudent = new Data.Student(); // 각각 항목들에 대해 문자열을 입력받는다. // 이름 입력 위치로 이동 Console.SetCursorPosition(14, 11); // 이름 입력 형식 지정 Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write("성이름"); Console.SetCursorPosition(14, 11); Console.ForegroundColor = ConsoleColor.White; newStudent.name = inputProcessor.NameFormatInput(14); if (newStudent.name == null) { return(null); } // 학번 입력 위치로 이동 Console.SetCursorPosition(14, 13); // 학번 형식 지정 Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write("________"); Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(14, 13); newStudent.StudentNo = inputProcessor.InputStudentNoFormat(14); if (newStudent.StudentNo == null) { return(null); } CursorPoint cursor = new CursorPoint(14, 15); // 주소 입력 위치로 이동 Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop); Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write("주소 선택"); Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop); // 키보드로 주소 선택 newStudent.address = inputProcessor.AddressFormatInput(cursor); if (newStudent.address == null) { return(null); } cursor = new CursorPoint(14, 17); // 전화번호 입력 위치로 이동 Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop); newStudent.phoneNumber = inputProcessor.PhoneNumberFormatInput(cursor); if (newStudent.phoneNumber == null) { return(null); } Console.SetCursorPosition(14, 19); newStudent.Password = inputProcessor.InputPassword(10, 30, 14, 19); if (newStudent.Password == null) { return(null); } Console.Clear(); return(newStudent); }