Guest User

Untitled

a guest
Aug 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. /* BRM.h */
  2. #ifndef BRM_H
  3. #define BRM_H
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <conio.h>
  8. #include <string.h>
  9. #include <io.h>
  10. #include <windows.h>
  11. #pragma warning( disable : 4996 )
  12.  
  13. /* 글꼴 색상 */
  14. enum
  15. {
  16. BLACK,/* 0 : 검정 */
  17. DARK_BLUE,/* 1 : 어두운 파랑 */
  18. DARK_GREEN,/* 2 : 어두운 초록 */
  19. DARK_SKY_BLUE, /* 3 : 어두운 하늘 */
  20. DARK_RED, /* 4 : 어두운 빨강 */
  21. DARK_VIOLET, /* 5 : 어두운 보라 */
  22. DARK_YELLOW, /* 6 : 어두운 노랑 */
  23. GRAY, /* 7 : 회색 */
  24. DARK_GRAY, /* 8 : 어두운 회색 */
  25. BLUE, /* 9 : 파랑 */
  26. GREEN, /* 10 : 초록 */
  27. SKY_BLUE, /* 11 : 하늘 */
  28. RED, /* 12 : 빨강 */
  29. VIOLET, /* 13 : 보라 */
  30. YELLOW, /* 14 : 노랑 */
  31. WHITE, /* 15 : 하양 */
  32. };
  33.  
  34. void Setcolor(int color) // 글자색
  35. {
  36. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (short)color);
  37. }
  38. /* BOOL Type 정의 */
  39. typedef int BOOL;
  40.  
  41. #define FALSE 0
  42. #define TRUE 1
  43.  
  44. /* 구조체 선언 */
  45. typedef struct tagBook // 도서 구조체
  46. {
  47. char ID[10]; // 도서번호
  48. char Name[20]; // 도서명
  49. char Author[10]; // 저자
  50. char publisher[20];// 출판사
  51. BOOL IsRetal; // 대여 여부
  52. } Book;
  53.  
  54. typedef struct tagCustomer // 고객 구조체
  55. {
  56. char Name[20]; // 고객명( ID )
  57. char HPnumber[20]; // 고객 연락처
  58. char PW[10]; // 비밀번호
  59. Book RentalList[10]; // 대여 도서 목록
  60. } Customer;
  61.  
  62. /* 함수 원형 선언 */
  63.  
  64. /* 건드리지 말 것 */
  65. int ReadBL ( Book **BookList );
  66. int ReadCL ( Customer **CustomerList );
  67. int ReadAI ( char *AdminPW);
  68. int LogIn ( Book *BookList, Customer *CustomerList, int CLRecordCount, int BLRecordCount );
  69. int ShowMainMenu ( ); // 미구현
  70. int SignIn ( Customer **CustomerList, int CLRecordCount ); // 미구현
  71.  
  72.  
  73. /* 정용만 건드릴 것 */
  74. int ShowUserMenu ( );
  75. int UserMenu ( Customer *User );
  76. /* 민식만 건드릴 것 */
  77. int ShowAdminMenu( );
  78. int AdminMenu ( Book *BookList, Customer *CustomerList, int CLRecordCount, int BLRecordCount );
  79. /* 창완만 건드릴 것 */
  80. int Exit ( );
  81.  
  82.  
  83. #endif
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. /* BRM.c */
  93. #include "BRM.h"
  94.  
  95. int ReadBL( Book **BookList )
  96. {
  97. FILE* BLfp;
  98. int i, BLRecordCount;
  99. char buf[200];
  100.  
  101. /* BookList.txt 파일 개방 */
  102. BLfp = fopen("BookList.txt","r");
  103. if(BLfp == NULL)
  104. {
  105. puts("지정된 경로에서 'BookList.txt' 를 찾을 수 없습니다");
  106. exit(-1);
  107. }
  108.  
  109. /* 레코드 개수 계산 */
  110. for( i=0 ;; i++ )
  111. {
  112. if ( NULL == fgets( buf, sizeof(buf), BLfp ) )
  113. break;
  114. }
  115. BLRecordCount = i; // 루프의 총 반복 횟수를 BLRecordCount 에 저장
  116.  
  117. /* 읽은 크기만큼 동적 할당하여 레코드 저장 */
  118. *BookList = (Book *)malloc( sizeof(BookList) * BLRecordCount );
  119.  
  120. /* 레코드를 메모리로 읽어온다 */
  121. for( i = 0; i < BLRecordCount; i++ )
  122. {
  123. fscanf( BLfp, "%s%s%s%s", &(*BookList)[i].ID, &(*BookList)[i].Name, &(*BookList)[i].Author, &(*BookList)[i].publisher );
  124. }
  125.  
  126.  
  127. fclose( BLfp );
  128.  
  129. return BLRecordCount;
  130. }
  131.  
  132. int ReadCL( Customer **CustomerList )
  133. {
  134. FILE *CLfp, *Psnlfp;
  135. int i, CLRecordCount;
  136. char buf[200];
  137.  
  138. /* CustomerList.txt 파일 개방 */
  139.  
  140. CLfp = fopen("CustomerList.txt","r");
  141. if(CLfp == NULL)
  142. {
  143. puts("지정된 경로에서 'CustomerList.txt' 를 찾을 수 없습니다");
  144. exit(-1);
  145. }
  146. /* 레코드 개수 계산 */
  147.  
  148. for( i=0 ;; i++ )
  149. {
  150. if ( NULL == fgets( buf, sizeof(buf), CLfp ) )
  151. break;
  152. }
  153. CLRecordCount = i; // 루프의 총 반복 횟수를 CLRecordCount 에 저장
  154. /* 읽은 크기만큼 동적 할당하여 레코드 저장 */
  155.  
  156. *CustomerList = (Customer *)malloc( sizeof( Customer ) * CLRecordCount );
  157.  
  158.  
  159. /* 레코드를 메모리로 읽어온다 */
  160.  
  161. rewind( CLfp ); // 파일 위치 지시자를 시작점으로
  162. for( i = 0; i < CLRecordCount; i++ )
  163. {
  164. int j;
  165. char buf2[200]={0};
  166. char title[] = "PersonalRentalList\\";
  167. char txt[] = ".txt";
  168. fscanf( CLfp, "%s%s%s", (*CustomerList)[i].Name, (*CustomerList)[i].PW, (*CustomerList)[i].HPnumber );
  169. strcpy( buf2, title );
  170. strcat( buf2, (*CustomerList)[i].Name);
  171. strcat(buf2, ".txt");
  172. /* 고객명으로 된 파일제목을 가진 파일이 존재하는지 확인 */
  173.  
  174. if ( 0 == access(buf2, 0 ) )
  175. {
  176. Psnlfp = fopen(buf2,"r");
  177. for( j = 0; j < 10 ; j++ )
  178. {
  179. if ( EOF == fscanf( Psnlfp, "%s%s%s%s",(*CustomerList)[i].RentalList[j].ID, (*CustomerList)[i].RentalList[j].Name,(*CustomerList)[i].RentalList[j].Author,(*CustomerList)[i].RentalList[j].publisher ) )
  180. break;
Add Comment
Please, Sign In to add comment