/
UserManagement_subin.c
1392 lines (1166 loc) · 32 KB
/
UserManagement_subin.c
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
작성자: 141033 박수빈
최종 작성일: 2014.06.13
설명: 사용자 입장에서 최대한 간편하게 느낄 수 있도록 하는 것을 목표로 했습니다.
그리고 어떤 상황에서도 에러가 생기지 않는 안전성을 추구했습니다.
1. 조작키를 방향키, ENTER키, ESC키로 통일 했습니다.
2. 회원 등록시 리스트에 제대로 출력될 수 있는 값 범위 안으로 입력을 제한하였습니다.
(즉, 너무 길거나 짧은 입력, Tap입력 등은 사전에 방지)
3. 어떤 입력 도중 취소하고 나가고 싶을 경우 바로 나갈 수 있도록 구성했습니다.
4. 리스트 화면에서 페이지를 빠르게 탐색할 수 있도록 ENTER키를 입력하면
페이지를 검색할 수 있도록 하였습니다.
5. 검색 결과가 중복될 경우, 그 목록 창이 출력되도록 하였습니다.
=== 변경 사항 (2014.06.13) ===
* 강조색 구현방법 수정
* 종료시 선택지에도 적용
* 회원 등록시에 컬러 추가
* 연락처에 지번이 두 개인 경우도 등록 가능하게 수정
* 프로그램 시작 화면, 종료 화면 구성
* 시작, 종료 사운드 변경
=== 변경 사항 (2014.06.12) ===
* 메인 화면 구성 방법 변경
* 강조색 사용
* 메뉴 선택 숫자키로도 가능하도록 수정
* 페이지 검색 기능 추가
* 경고 메시지 함수로 분리
* define 이름 몇몇 가지 통합사용
=== 변경 사항 (2014.06.10) ===
* bottomMessageC 추가
* deleteMessage -> centerMessage로 함수 이름 변경
=== 변경 사항 (2014.06.08) ===
* 초기 화면 구성 방법 수정
=== 변경 사항 (2014.06.07) ===
* dataInput 함수 3가지 함수로 분리(dataInputA, dataInputB, dataInputWarning)
* 중복되는 UI 분리 (topMessage, bottomMessageA, bottomMessageB)
* 주석 추가
* 사운드 추가
* UI 색상 조금 변경
* 사운드 조정
* UI 개선 (메세지 박스 생성)
* 종료 노래 조정
=== 변경 사항 (2014.06.06) ===
* 회원 등록 중 주소 입력 시 발생할 수 있는 오류 수정
* 회원 수정 중 탭 입력 시 발생할 수 있는 오류 수정
* 데이터 파일 로드 중 띄어쓰기 있는 경우 발생하는 오류 수정
* maxsize, count 전역변수로 변경하고, 전반적인 함수 간소화
* 함수 위치 기능별 순서에 맞게 재배치
* 대대적인 UI 개선 (컬러 도입)
* 파일에 내용이 없을 경우 생기는 오류 수정
* 추가적인 UI 개선
=== 변경 사항 (2014.06.05) ===
* 회원 등록시 매번 maxid를 계산하는 것을 처음 한번만 하도록 수정
* 등록, 삭제, 수정 시에 중첩되는 입력 코드를 함수로 분리해서 단일화
* 마찬가지로 중복되는 검색 코드를 함수로 분리
* 여러 정수값 define 설정
* 검색, 종료 기능 완성
* 전반적으로 디버깅 하여 발견된 버그 모두 수정
=== 변경 사항 (2014.06.03) ===
* 입력키 값 define으로 정의 (ENTER, ESC 등)
* 코드 정돈 (줄 간격, 들여쓰기 등)
* 회원 등록 중도 취소 기능 변경 ('esc' 타이핑 -> ESC키 누르는 것으로)
* 중복되는 메시지 출력 코드 함수로 만들어 압축
* 검색 시 중복되는 값 필터링 기능 추가
* 회원 명단 출력 UI 개선
=== 변경 사항 (2014.06.03)(새벽) ===
* 회원 명단 출력 UI 개선
* 회원 등록시 이름 3글자 제한에서 4글자 제한으로 확대
* 회원 등록시 주소 10 ~ 15글자 에서 5 ~ 15글자로 범위 확대
* 삭제 기능 완성
* 버퍼 오버플로우 방지를 위해 함수 교체 (gets -> fgets)
* fgets는 '\n'을 저장해버리므로 이를 제거하는 과정 추가
=== 변경 사항 (2014.06.02) ===
* 메인 화면 인터페이스 변경 ( 숫자 입력에서 화살표 입력으로 )
* 연락처 입력시 형식에 정확히 맞아야 입력 되도록 입력 제한 기능 강화
* 검색 기능, 삭제 기능(아직 미완) 추가
* 몇몇 주석 수정
*/
#include "UserManagement.h"
static int maxid; //가장 큰 ID 값
static int maxsize; //메모리 할당 사이즈
static int count = -1; //전체 회원 수
int main(void)
{
system("mode con lines=25 cols=80"); //콘솔 창 크기 초기화
UserInfo *userInfo = NULL;
FILE *readFile = NULL;
FILE *writeFile = NULL;
int input = 1, menu = 1, choice;
int *ptr = &menu;
char *menu_num[MENU_NUM];
puts("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t = 시작하는 중 = \n\n\n\n\n\n\n\n\n\n\n");
userInfo = setUserInfo(userInfo, readFile); //구조체 배열에 파일 데이터 저장
if (userInfo == (UserInfo*)-1) return 0; //오류 났을 경우 바로 종료
startSound(); //로딩 완료 효과음
printMainSub(menu, menu_num); //메인 메뉴 구성
while(1) {
printMain(menu, menu_num); //메인 화면 출력
input = getch(); //입력
if (input == ARROW_BUFFER) //방향키는 입력 시 아스키확장 값이 먼저 들어온 후 값이 들어옴
input = getch(); //그래서 이 경우 버퍼를 한번 비우도록 하였음
switch (input)
{
case UP_ARROW_KEY: //상 방향키
if (menu > 1) menu--;
moveSound();
break;
case DOWN_ARROW_KEY: //하 방향키
if (menu < 6) menu++;
moveSound();
break;
case ENTER_KEY: //enter키
inSound();
switch (menu)
{
case 1: //출력
printList(userInfo);
break;
case 2: //등록
addUser(userInfo);
break;
case 3: //삭제
searchMain(userInfo, _DELETE, "삭제", "Delete");
break;
case 4: //수정
searchMain(userInfo, MODIFY, "수정", "Modify");
break;
case 5: //검색
searchMain(userInfo, SEARCH, "검색", "Search");
break;
case 6: //저장
saveInfo(userInfo, writeFile);
break;
} //switch(menu) out
break;
case ESC_KEY: //esc키
inSound();
choice = closeProgram();
if (choice == SAVE)
choice = saveInfo(userInfo, writeFile);
if (choice == SAVE || choice == EXIT){
printClose();
free(userInfo);
closeSound();
printClose_sub();
return 0;
}
else break;
default:
warningMessage(input - '0', 6, ptr);
break;
} //switch(input) out
}
free(userInfo);
return 0;
}
UserInfo* setUserInfo(UserInfo userInfo[], FILE *readFile)
{
readFile = fopen("data.txt", "rt"); //readFile open
if (readFile == NULL){
puts("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t 데이터가 존재하지 않습니다! \n\n\n\n\n\n\n\n\n\n\n");
return (UserInfo*)-1;
}
while (!feof(readFile)) { //초기 회원수 count에 저장
if (fgetc(readFile) == '\n') count++;
}
if (count < 1){
puts("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t 데이터가 존재하지 않습니다! \n\n\n\n\n\n\n\n\n\n\n");
return (UserInfo*)-1;
}
maxsize = 2 * count; //초기 회원수의 2배 만큼 메모리 할당
userInfo = (UserInfo*)malloc(sizeof(UserInfo)*maxsize);
fseek(readFile, 0, SEEK_SET); //파일 포인터 처음 위치로 귀환
fscanf(readFile, "%[^\n]", userInfo[0].userAddress); //첫 문장은 따로 저장
for (int i = 1; !feof(readFile); i++)
fscanf(readFile, "%d\t%[^\t]\t%[^\t]\t%[^\n]\n",
&userInfo[i].userId, userInfo[i].userName, userInfo[i].userAddress, userInfo[i].handphone);
fclose(readFile); //readFile close
maxid = userInfo[1].userId; //초기값 설정
for (int i = 2; i <= count; i++) //가장 큰 id값 계산
maxid = maxid > userInfo[i].userId ? maxid : userInfo[i].userId;
return userInfo;
}
void printMain(int menu, char *menu_num[MENU_NUM])
{
system("cls");
TOP_COLOR;
printf("Main \t\t\t\t\t\t\t\t\t "); printf("\t\t\t\t\t\t\t\t\t ");
BOT_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
printf("\t\t\t 회원 관리 프로그램\t\t\t ");
printf("\t\t\t\t\t\t\t\t\t ");
DEF_COLOR;
menuSelectA(menu, 6, menu_num);
bottomMessageC();
}
void printMainSub(int menu, char *menu_num[MENU_NUM])
{
menu_num[0] = "1. 전체 명단 보기";
menu_num[1] = "2. 신규 회원 등록";
menu_num[2] = "3. 기존 회원 삭제";
menu_num[3] = "4. 회원 정보 수정";
menu_num[4] = "5. 회원 정보 검색";
menu_num[5] = "6. 변경 사항 저장";
printMain(menu, menu_num); //초기 화면 기반
printMain(menu, menu_num); //초기 화면 정돈
}
void printList(UserInfo userInfo[])
{
int input, page, k = 1, temp;
int *ptr = &k;
char search[OVERLAP_BUFFER];
page = 1 + (count - 1) / 18; //전체 페이지 계산
while(1) {
printListSub(userInfo, page, ptr, ON);
input = getch();
if (input == ARROW_BUFFER)
input = getch();
switch (input)
{
case LEFT_ARROW_KEY: //좌측 방향키
moveSound();
if (k != 1) k--;
break;
case RIGHT_ARROW_KEY: //우측 방향키
moveSound();
if (k != page) k++;
break;
case ENTER_KEY: //enter키
inSound();
printListSub(userInfo, page, ptr, OFF);
printf("페이지 검색: "); fgets(search, OVERLAP_BUFFER, stdin);
temp = atoi(search);
if (temp > 0 && temp <= page) k = temp;
else warningMessage(0, 0, 0);
break;
case ESC_KEY: //esc키
outSound();
return;
default:
warningMessage(input - '0', page, ptr);
break;
}
}
}
void printListSub(UserInfo userInfo[], int page, int *ptr, int swit)
{
int i;
system("cls");
TOP_COLOR;
printf("List \t\t\t\t\t\t\t\t page %d/%d ", *ptr, page); printf("\t\t\t\t\t\t\t\t\t ");
BOT_COLOR;
printf("\t회원ID \t 이름 \t연락처 \t주소 \t\t\t\t");
DEF_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
for (i = 1 + (*ptr - 1) * 18; i <= *ptr * 18 && i <= count; i++){ //리스트 출력
if (i % 6 == 1) BEAUTI2_COLOR;
else DEF_COLOR;
printf("\t%d \t %s \t%s \t%s\n",
userInfo[i].userId, userInfo[i].userName, userInfo[i].handphone, userInfo[i].userAddress);
}
if (page == *ptr){ //공백 채우기
for (i = count - (1 + (*ptr - 1) * 18); 17 - i > 0; i++)
puts(" ");
}
if (swit) puts(" ");
BOT_COLOR;
printf("\t 페이지 이동 : ← → or 숫자키\t\t 나가기 : ESC \t\t");
DEF_COLOR;
}
void printClose(void)
{
DEF_COLOR;
puts("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t = 종료하는 중 = \n\n\n\n\n\n\n\n\n\n\n");
}
void printClose_sub(void)
{
ORIGIN_COLOR;
system("cls");
puts("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t = 종료 완료 = \n");
printf("\t\t\t");
}
void menuSelectA(int menu, int max, char *menu_num[MENU_NUM])
{
puts("\n");
for (int i = 0; i < max; i++){
if (menu == i + 1){
BEAUTI1_COLOR; printf("\n\t\t\t [ ");
BEAUTI2_COLOR; printf("%s", menu_num[i]);
BEAUTI1_COLOR; printf(" ] \n"); DEF_COLOR;
}
else printf("\n\t\t\t %s \n", menu_num[i]);
}
puts("\n");
}
void menuSelectB(int menu, int max, char *menu_num[MENU_NUM])
{
puts(" ");
for (int i = 0; i < max; i++){
if (menu == i + 1){
BEAUTI1_COLOR; printf("\n\t\t\t [ ");
BEAUTI2_COLOR; printf("%s", menu_num[i]);
BEAUTI1_COLOR; printf(" ] \n"); DEF_COLOR;
}
else printf("\n\t\t\t %s \n", menu_num[i]);
}
puts("\n\n");
}
void menuSelectC(int menu, int max, char *menu_num[MENU_NUM])
{
puts(" ");
for (int i = 0; i < max; i++){
if (menu == i + 1){
BEAUTI1_COLOR; printf("\n\t\t\t [ ");
BEAUTI2_COLOR; printf("%s", menu_num[i]);
BEAUTI1_COLOR; printf(" ] \n"); DEF_COLOR;
}
else printf("\n\t\t\t %s \n", menu_num[i]);
}
puts("\n\n");
}
void topMessage(char mess[], char top[])
{
system("cls");
TOP_COLOR;
printf("%s \t\t\t\t\t\t\t\t\t\t ", top); printf("\t\t\t\t\t\t\t\t\t ");
BOT_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
printf("\t\t\t 회원 정보 %s\t\t\t\t\t ", mess);
printf("\t\t\t\t\t\t\t\t\t ");
DEF_COLOR;
}
void bottomMessageA(void)
{
warningSound();
BOT_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
printf("\t\t다시 입력 : ENTER \t\t나가기 : ESC \t\t\t ");
printf("\t\t\t\t\t\t\t\t\t ");
DEF_COLOR;
}
void bottomMessageB(char mess[])
{
warningSound();
BOT_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
printf("\t\t %s : ENTER \t\t 취소 : ESC \t\t\t ", mess);
printf("\t\t\t\t\t\t\t\t\t ");
DEF_COLOR;
}
void bottomMessageC(void)
{
BOT_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
printf(" 메뉴 선택 : ENTER 메뉴 이동 : ↑↓ or 숫자키 나가기 : ESC \t ");
printf("\t\t\t\t\t\t\t\t\t ");
DEF_COLOR;
}
void centerMessage(char mess[], char top[])
{
topMessage(mess, top);
printf("\n\n\n\n\n\n\t\t\t "); BOX_COLOR;
printf("┌──────────┐"); DEF_COLOR;
printf("\n\t\t\t "); BOX_COLOR;
printf("│\t\t\t │"); DEF_COLOR;
printf("\n\t\t\t "); BOX_COLOR;
printf("│ %s 완료 │", mess); DEF_COLOR;
printf("\n\t\t\t "); BOX_COLOR;
printf("│\t\t\t │"); DEF_COLOR;
printf("\n\t\t\t "); BOX_COLOR;
printf("└──────────┘\n\n\n\n\n\n"); DEF_COLOR;
resultSound();
BOT_COLOR;
printf("\t\t\t\t\t\t\t\t\t ");
printf("\t\t\t 계속하려면 아무 키나 누르세요 \t\t\t\t ");
printf("\t\t\t\t\t\t\t\t\t ");
DEF_COLOR;
getch(); //메시지 출력을 위해 정지
}
void messageBoxA(char mess[])
{
printf("\n\n\n\t\t\t "); BOX_COLOR;
printf("┌────────┐"); DEF_COLOR;
printf("\n\t\t\t "); BOX_COLOR;
printf("│ %s │\n", mess); DEF_COLOR;
printf("\t\t\t "); BOX_COLOR;
printf("└────────┘\n"); DEF_COLOR;
}
void messageBoxB(char str[], char mess[])
{
printf("\n\n\n\t\t\t "); BOX_COLOR;
printf("┌───────┐"); DEF_COLOR;
printf("\n\t\t\t "); BOX_COLOR;
printf("│ %s%s │\n", str, mess); DEF_COLOR;
printf("\t\t\t "); BOX_COLOR;
printf("└───────┘\n"); DEF_COLOR;
}
void warningMessage(int input, int max, int *ptr)
{
if (input > 0 && input <= max) *ptr = input;
else{
WAR_COLOR; printf("잘못된 입력입니다.\t\t\t\t\t\t\t "); DEF_COLOR;
warningSound();
}
}
void addUser(UserInfo userInfo[])
{
userInfo[++count].userId = ++maxid; //count값 1증가 시키고 새로운 id 부여
if (count > maxsize - 5){ //메모리 할당량 한계치에 가까워지면 추가할당
maxsize *= 2;
userInfo = (UserInfo*)realloc(userInfo, sizeof(UserInfo)*maxsize);
}
dataInputA(userInfo);
}
void deleteUser(UserInfo userInfo[], int del)
{
int input, menu = 1;
while (del){
topMessage("삭제", "Delete");
printf("\n\n\n\n\t\t\t회원ID\t: %d \n\n", userInfo[del].userId);
printf("\t\t\t이름\t: %s \n", userInfo[del].userName);
printf("\t\t\t연락처\t: %s \n", userInfo[del].handphone);
printf("\t\t\t주소\t: %s \n", userInfo[del].userAddress);
puts("\n\n\n\t\t\t 정말로 삭제하시겠습니까? \n\n\n");
bottomMessageB("삭제");
input = getch();
if (input == ENTER_KEY){
inSound();
/* 빈 메모리 공간이 많아지면 메모리 할당량 축소 */
if (count < maxsize / 3){
maxsize /= 2;
userInfo = (UserInfo*)realloc(userInfo, sizeof(UserInfo)*maxsize);
}
/* 삭제 대상이 맨 마지막에 있다면, count를 하나 줄이는 것으로 끝 */
if (del == count){
centerMessage("삭제", "Delete");
count--;
return;
}
/* 나머지 경우는 한 칸씩 앞으로 덮어씌움 */
else{
for (int i = del + 1; i <= count; i++){
userInfo[i - 1].userId = userInfo[i].userId;
strcpy(userInfo[i - 1].userName, userInfo[i].userName);
strcpy(userInfo[i - 1].userAddress, userInfo[i].userAddress);
strcpy(userInfo[i - 1].handphone, userInfo[i].handphone);
}
centerMessage("삭제", "Delete");
count--;
return;
}
}
else if (input == ESC_KEY){
outSound();
return;
}
else warningMessage(input - '0', 0, 0);
}
return;
}
void modifyUser(UserInfo userInfo[], int fix)
{
int input, menu = 1, action, action2;
char temp[ADDRESS_BUFFER];
char *ptr;
int *ptr2;
ptr = temp;
ptr2 = &menu;
action = 1;
char *menu_num3[MENU_NUM] = {
{ "1. 이름" },
{ "2. 주소" },
{ "3. 연락처" },
};
inSound();
while (action){
topMessage("수정", "Modify");
messageBoxA(" 수정할 정보 ");
menuSelectC(menu, 3, menu_num3);
bottomMessageC();
input = getch();
if (input == ARROW_BUFFER)
input = getch();
switch (input)
{
case UP_ARROW_KEY:
moveSound();
if (menu > 1) menu--;
break;
case DOWN_ARROW_KEY:
moveSound();
if (menu < 3) menu++;
break;
case ENTER_KEY:
inSound();
switch (menu){
case NAME:
action2 = dataInputB(userInfo, NAME, ptr, fix, "이름 ", 4, 8);
if (action2){
strcpy(userInfo[fix].userName, temp);
centerMessage("수정", "Modify");
}
break;
case ADDRESS:
action2 = dataInputB(userInfo, ADDRESS, ptr, fix, "주소 ", 10, 30);
if (action2){
strcpy(userInfo[fix].userAddress, temp);
centerMessage("수정", "Modify");
}
break;
case PHONE:
action2 = dataInputB(userInfo, PHONE, ptr, fix, "연락처", 12, 13);
if (action2){
strcpy(userInfo[fix].handphone, temp);
centerMessage("수정", "Modify");
}
break;
}
break;
case ESC_KEY:
action = 0;
outSound();
break;
default:
warningMessage(input - '0', 3, ptr2);
break;
}
}
}
void dataInputA(UserInfo userInfo[])
{
int input, warning = 0, action = 1, switC = 1, switD = 1;
int *ptrC = &switC;
while (1) {
topMessage("입력", "Regist");
printf("\n\n\n\n\t\t\t 회원ID\t: "); BEAUTI3_COLOR;
printf("%d \n\n", userInfo[count].userId); DEF_COLOR;
if (switD == 1){
for (int i = 0; i < NAME_PHONE_BUFFER; i++)
userInfo[count].userName[i] = 0;
}
else if (switD == 2){
for (int i = 0; i < NAME_PHONE_BUFFER; i++)
userInfo[count].handphone[i] = 0;
}
else if (switD == 3){
for (int i = 0; i < ADDRESS_BUFFER; i++)
userInfo[count].userAddress[i] = 0;
}
if (switD == 1 && action){
BEAUTI2_COLOR; printf("\t\t\t 이름\t: "); BEAUTI1_COLOR;
switC = NAME;
warning = dataInputAction(warning, NAME, ptrC, userInfo[count].userName, 4, 8);
if (!warning){
switD = 2; continue;
}
}
else if (switD >= 1){
printf("\t\t\t 이름\t: "); BEAUTI3_COLOR;
printf("%s \n", userInfo[count].userName); DEF_COLOR;
}
if (switD == 2 && action){;
BEAUTI2_COLOR; printf("\t\t\t 연락처\t: "); BEAUTI1_COLOR;
switC = PHONE;
warning = dataInputAction(warning, PHONE, ptrC, userInfo[count].handphone, 11, 13);
if (!warning){
switD = 3; continue;
}
}
else if (switD >= 2){
printf("\t\t\t 연락처\t: "); BEAUTI3_COLOR;
printf("%s \n", userInfo[count].handphone); DEF_COLOR;
}
if (switD == 3 && action){
BEAUTI2_COLOR; printf("\t\t\t 주소\t: "); BEAUTI1_COLOR;
switC = ADDRESS;
warning = dataInputAction(warning, ADDRESS, ptrC, userInfo[count].userAddress, 10, 30);
if (!warning){
switD = 4; continue;
}
}
else if (switD >= 3){
printf("\t\t\t 주소\t: "); BEAUTI3_COLOR;
printf("%s \n", userInfo[count].userAddress); DEF_COLOR;
}
if (warning){
dataInputWarning((char*)0, INSERT, 0, switC);
input = getch();
if (input == ESC_KEY){
maxid--; count--; //등록하지 않으면 count 원래대로 되돌려 놓고 종료
outSound();
return;
}
else if (input == ENTER_KEY){
action = 1;
inSound();
}
else{
action = 0;
warningMessage(input - '0', 0, 0);
}
}
else{
puts("\n\n\n\t\t\t 정말로 등록하시겠습니까? \n\n\n");
bottomMessageB("등록");
input = getch();
if (input == ESC_KEY){
maxid--; count--;
outSound();
return;
}
else if (input == ENTER_KEY){
actionSound();
Beep(_DO, DURATION);
return; //등록하면 count 증가한 채로 종료
}
else{
action = 0;
warningMessage(input - '0', 0, 0);
}
}
}
}
int dataInputB(UserInfo userInfo[], int switB, char *temp, int fix, char str[], int min, int max)
{
int input, warning = 0, action = 1, switC = 1, switD = 1;
int *ptrC;
ptrC = &switC;
while (1) {
topMessage("수정", "Modify");
messageBoxB(str, "수정");
switch (switB){
case NAME:
printf("\n\t\t 기존 %s : %s \n", str, userInfo[fix].userName);
break;
case ADDRESS:
printf("\n\t\t 기존 %s : %s \n", str, userInfo[fix].userAddress);
break;
case PHONE:
printf("\n\t\t 기존 %s : %s \n", str, userInfo[fix].handphone);
break;
}
printf("\t\t 새로운 %s : ", str);
if (action){
switC = switB;
warning = dataInputAction(warning, switB, ptrC, temp, min, max);
}
else printf("%s \n", temp);
if(warning){
dataInputWarning(temp, MODIFY, switB, switC);
input = getch();
if (input == ESC_KEY){
outSound();
return 0; //취소시 0을 리턴
}
else if (input == ENTER_KEY){
inSound();
action = 1;
}
else{
action = 0;
warningMessage(input - '0', 0, 0);
}
}
else{
puts("\n\n\n\t\t\t 정말로 수정하시겠습니까? \n\n\n");
bottomMessageB("수정");
input = getch();
if (input == ENTER_KEY){
inSound();
return 1; //수정하면 1반환
}
else if (input == ESC_KEY){
outSound();
return 0;
}
else{
action = 0;
warningMessage(input - '0', 0, 0);
}
}
}
}
int dataInputAction(int warning, int switB, int *ptrC, char *temp, int min, int max)
{
int sizeTemp;
if (switB == ADDRESS) fgets(temp, ADDRESS_BUFFER, stdin);
else fgets(temp, NAME_PHONE_BUFFER, stdin);
if (*(temp + strlen(temp) - 1) == '\n') //fgets는 '\n'도 변수에 저장하기 때문에 이를 제거
*(temp + strlen(temp) - 1) = '\0';
else while (getchar() != '\n');
sizeTemp = strlen(temp); //strlen은 unsigned int 형으로 반환하기 때문
if (sizeTemp < min || sizeTemp > max)
warning = 1;
else
warning = 0;
if (!warning){ // !warning의 의미는 이전 검사를 통과했다는 의미
for (int i = 0; temp[i] != '\0'; i++){
/* 탭 입력 발견시 다시 입력 */
if (temp[i] == '\t'){
*ptrC = TAB;
warning = 1;
break;
}
/* '-'이외에는 숫자를 입력했는지 검사 */
if (switB == PHONE){
if ((temp[i] < '0' || temp[i] > '9') &&
(temp[i] != '-' || (i != 2 && i != 3 && i != 6 && i != 7 && i != 8))){
warning = 1;
break;
}
}
warning = 0;
}
}
if (!warning){
/* '-'의 위치가 적절한지 검사 */
if (switB == PHONE){
if (temp[2] == '-'){
if (temp[3] == '-' || temp[6] != '-' && temp[7] != '-' || temp[6] == '-' && temp[7] == '-')
warning = 1;
}
else if (temp[3] == '-'){
if (temp[7] != '-' && temp[8] != '-' || temp[7] == '-' && temp[8] == '-')
warning = 1;
}
else warning = 1;
}
else warning = 0;
}
return warning;
}
void dataInputWarning(char *temp, int switA, int switB, int switC)
{
switch (switC){
case NAME:
if (switA == MODIFY){
for (int i = 0; i < NAME_PHONE_BUFFER; i++)
temp[i] = 0;
}
else puts("\n");
BEAUTI1_COLOR; printf("\n\t\t ┌────────────────┐\n\t\t │");
BEAUTI4_COLOR; printf(" 이름이 너무 길거나 짧습니다. ");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI4_COLOR; printf(" 이름은 2 ~ 4 글자만 가능합니다.");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI5_COLOR; printf(" [ 영문 : 4 ~ 8 글자 ] ");
BEAUTI1_COLOR; printf("│ \n\t\t └────────────────┘\n\n");
break;
case ADDRESS:
if (switA == MODIFY){
for (int i = 0; i < ADDRESS_BUFFER; i++)
temp[i] = 0;
}
BEAUTI1_COLOR; printf("\n\t\t ┌────────────────┐\n\t\t │");
BEAUTI4_COLOR; printf(" 주소가 너무 길거나 짧습니다. ");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI4_COLOR; printf(" 5 ~ 15글자 이내로 입력해주세요.");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI5_COLOR; printf(" [ 영문: 10~30글자 (공백 포함) ]");
BEAUTI1_COLOR; printf("│ \n\t\t └────────────────┘\n\n");
break;
case PHONE:
if (switA == MODIFY){
for (int i = 0; i < NAME_PHONE_BUFFER; i++)
temp[i] = 0;
}
else puts(" ");
BEAUTI1_COLOR; printf("\n\t\t ┌────────────────────┐\n\t\t │");
BEAUTI4_COLOR; printf(" 연락처 형식에 맞지 않습니다. ");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI4_COLOR; printf(" 형식에 맞게 입력해주세요. ");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI5_COLOR; printf(" [ 예) 010-1234-5678 or 031-123-4567 ]");
BEAUTI1_COLOR; printf("│ \n\t\t └────────────────────┘\n\n");
break;
case TAB:
if (switA == MODIFY){
if (switB == ADDRESS){
for (int i = 0; i < ADDRESS_BUFFER; i++)
temp[i] = 0;
}
else{
for (int i = 0; i < NAME_PHONE_BUFFER; i++)
temp[i] = 0;
}
}
BEAUTI1_COLOR; printf("\n\t\t ┌────────────────┐\n\t\t │");
BEAUTI4_COLOR; printf(" \t\t\t\t ");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI4_COLOR; printf(" 탭(Tab)은 입력할 수 없습니다! ");
BEAUTI1_COLOR; printf("│ \n\t\t │");
BEAUTI4_COLOR; printf(" \t\t\t\t ");
BEAUTI1_COLOR; printf("│ \n\t\t └────────────────┘\n\n");
break;
}
bottomMessageA();
}
void searchMain(UserInfo userInfo[], int todo, char mess[], char top[])
{
int input, menu = 1, num;
int *ptr = &menu;
char *menu_num2[MENU_NUM] = {
{ "1. 회원ID로 검색" },
{ "2. 이름으로 검색" },
{ "3. 연락처로 검색" }
};
while (1) {
topMessage(mess, top);
messageBoxB("검색 ", "방법");
menuSelectB(menu, 3, menu_num2);
bottomMessageC();
input = getch();
if (input == ARROW_BUFFER)
input = getch();
switch (input)
{
case UP_ARROW_KEY:
moveSound();
if (menu > 1) menu--;
break;
case DOWN_ARROW_KEY:
moveSound();
if (menu < 3) menu++;
break;
case ENTER_KEY:
inSound();
num = searchUser(userInfo, menu);
if (num){
if (todo == _DELETE)
deleteUser(userInfo, num);
else if (todo == MODIFY)
modifyUser(userInfo, num);
else
searchResult(userInfo, num);
}
break;
case ESC_KEY:
outSound();
return;
default:
warningMessage(input - '0', 3, ptr);