纪念一下我的第一个千行代码

告别2017的人和事,期待一下2018。SEE YOU

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <conio.h>
   4 #include <string.h>
   5 #include <windows.h>
   6 
   7 void mygotoxy( int x, int y, char c )           /* 移动光标函数,方便输入时进行修改 */
   8 {
   9     HANDLE    hOut    = GetStdHandle( STD_OUTPUT_HANDLE );
  10     COORD    pos    = { x*2, y };
  11     SetConsoleCursorPosition( hOut, pos );
  12     putchar( c );
  13 }
  14 
  15 
  16 int delay()                      /* 逐字输出welcome! */
  17 {
  18     printf( "\n\n\n" );
  19     printf( "\t\t\t\t     W " );
  20     Sleep( 150 );
  21     printf( "E " );
  22     Sleep( 150 );
  23     printf( "L " );
  24     Sleep( 150 );
  25     printf( "C " );
  26     Sleep( 150 );
  27     printf( "O " );
  28     Sleep( 150 );
  29     printf( "M " );
  30     Sleep( 150 );
  31     printf( "E " );
  32     Sleep( 150 );
  33     printf( "!" );
  34     printf( "\n" );
  35     return(0);
  36 }
  37 
  38 
  39 int twinkle()                     /* 欢迎界面闪烁 */
  40 {
  41     for ( int i = 0; i <= 5; i++ )
  42     {
  43         system( "color 09" );
  44         Sleep( 100 );
  45         system( "color 0F" );
  46         Sleep( 100 );
  47         system( "color 0E" );
  48         Sleep( 100 );
  49         system( "color 02" );
  50         Sleep( 100 );
  51     }
  52     return(0);
  53 }
  54 
  55 
  56 /* 结构体的定义 */
  57 struct PERSON {
  58     char    username[21];
  59     char    userpassword[7];
  60     char    ID_card[20];
  61     char    B_Day[20];
  62 };
  63 struct TICKETS {
  64     char    train_number[20];
  65     char    B_time_day[20];
  66     char    B_time[20];
  67     char    E_time[20];
  68     char    B_station[20];
  69     char    E_station[20];
  70     float    price;
  71     int    tickets_number_out;
  72     int    tickets_number_remain;
  73 };
  74 struct ADMIN {
  75     char    admin_username[20];
  76     char    admin_pwd[20];
  77 };
  78 struct PERSON    person[1000] = {
  79     { "张三", "123456", "330723199904248818", "1999.4.24" },
  80     { "李四", "123456", "330723199905248889", "1999.5.24" }
  81 };
  82 struct TICKETS    tickets[1000] = {
  83     { "G1108", "1.16", "12:02", "1.16  13:31", "长沙", "武汉", 164.5, 87,  13  },
  84     { "T253",  "1.18", "7:40",  "1.18  15:37", "长沙", "广州", 98,    87,  12  },
  85     { "G6481", "1.17", "10:00", "1.17  13:31", "长沙", "深圳", 397,   120, 16  },
  86     { "G1482", "1.23", "8:40",  "1.23  14:59", "长沙", "南京", 502.5, 120, 110 },
  87     { "G2122", "1.21", "5:30",  "1.21  23:10", "长沙", "成都", 215,   87,  13  },
  88 };
  89 struct ADMIN    GM[10] = {
  90     { "admin", "123456" }
  91 };
  92 
  93 
  94 /* 函数定义 */
  95 void mygotoxy( int x, int y, char c );                  /**/
  96 
  97 
  98 int getIndexByTId( char id[] );                         /**/
  99 
 100 
 101 int delay();                                            /**/
 102 
 103 
 104 int twinkle();                                          /**/
 105 
 106 
 107 void f_show();                                          /**/
 108 
 109 
 110 void login_show();                                      /*  */
 111 
 112 
 113 void item_select_1( int sele );                         /* 第一个菜单的选择 */
 114 
 115 
 116 int main_show_1();                                      /* 第一个菜单的展示 ,return 一个int值 */
 117 
 118 
 119 void user_login_show();                                 /* 用户登录函数 */
 120 
 121 
 122 void admin_login_show();                                /* 管理员登录函数 */
 123 
 124 
 125 void user_register();                                   /* 用户注册 */
 126 
 127 
 128 bool isLogin( char name[], char pwd[] );                /* 比对模块 */
 129 
 130 
 131 int main_show_2();                                      /* 用户菜单 的展示,return 一个int */
 132 
 133 
 134 void item_select_2( int sele );                         /* 用户菜单的选择 */
 135 
 136 
 137 void inquire_tickets();                                 /* 用户查询,订票 */
 138 
 139 
 140 void return_show();                                     /*  */
 141 
 142 
 143 void alter_show();                                      /* 查看已购票务 */
 144 
 145 
 146 void alter_pwd();                                       /*  */
 147 
 148 
 149 int getIndexById( char id[] );                          /*  */
 150 
 151 
 152 bool isLogin1( char name[], char pwd[] );               /* 管理员专属密码比对函数 */
 153 
 154 
 155 int main_show_3();                                      /* 管理员 菜单的展示 ,return 一个int值 */
 156 
 157 
 158 void item_select_3( int sele );                         /* 管理员 菜单的选择 */
 159 
 160 
 161 void add_tickets();                                     /* 加车票 */
 162 
 163 
 164 void alter_tickets();                                   /* 改车票 */
 165 
 166 
 167 void delete_tickets();                                  /*删车票 */
 168 
 169 
 170 void add_person();                                      /* 加人 */
 171 
 172 
 173 void alter_person();                                    /* 改人 */
 174 
 175 
 176 void delete_person();                                   /*删人 */
 177 
 178 
 179 int getIndexByTTId( char id0[], char id1[], char id2[] );
 180 
 181 
 182 void printfPersonInfoToFile( char file_path[] );        /* 写入 人的数据 */
 183 
 184 
 185 void scanfPersonInfoToFile( char file_path[] );         /* 读出 人的数据 */
 186 
 187 
 188 void printfTicketsInfoToFile( char file_path[] );       /* 写入 车票数据 */
 189 
 190 
 191 void scanfTicketsInfoToFile( char file_path[] );        /* 读出 车票数据 */
 192 
 193 
 194 /* 全局变量 */
 195 #define USERS_SIZE    2
 196 #define TRAIN_SIZE    5
 197 int flag = -1;                                          /* 用于订票后记录该用户买的票的下标*/
 198 /* 声明全局变量 表示人的实际数量 */
 199 int    person_number    = 2;
 200 int    train_number    = 5;
 201 FILE    *fp;
 202 
 203 
 204 /*
 205  * long N_tickets,N_person;
 206  * 主函数
 207  */
 208 int main()
 209 {
 210     system( "color 02" );
 211     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 212     long length;
 213 
 214 
 215 /*    fp=fopen("Person.dat","a+");
 216  * fseek(fp,0,SEEK_END);
 217  * length=ftell(fp);
 218  * N_person=length/sizeof(person[0]);
 219  * fp=fopen("Tickets.dat","a+");
 220  * fseek(fp,0,SEEK_END);
 221  * length=ftell(fp);
 222  * N_tickets=length/sizeof(tickets[0]);*/
 223     scanfPersonInfoToFile( "Person.dat" );
 224     scanfTicketsInfoToFile( "Tickets.dat" );
 225 
 226 
 227     /*
 228      * printfPersonInfoToFile("Person.dat");
 229      * printfTicketsInfoToFile("Tickets.dat");
 230      */
 231 
 232     f_show();
 233 
 234 
 235     return(0);
 236 }
 237 
 238 
 239 /* 函数声明 */
 240 void f_show()
 241 {
 242     delay();
 243     printf( "\t\t\t******************************************\n" );
 244     printf( "\t\t\t**\t\t\t\t\t**\n" );
 245     printf( "\t\t\t**\t 欢迎来到火车票售票系统!\t**\n" );
 246     printf( "\t\t\t**\t\t\t\t\t**\n" );
 247     printf( "\t\t\t******************************************\n" );
 248     twinkle();
 249     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 250     printf( "\t\t\t\t     按任意键进入系统..." );
 251 
 252     getch();
 253 
 254     item_select_1( main_show_1() ); /* 进入登陆界面 */
 255 }
 256 
 257 
 258 int main_show_1()
 259 {
 260     int sele = 0;
 261     system( "cls" );
 262     printf( "\n\n\n" );
 263     printf( "\t\t\t******************************************\n" );
 264     printf( "\t\t\t\t\t管理菜单\n\n" );
 265     printf( "\t\t\t\t★1、用户登录\n" );
 266     printf( "\t\t\t\t★2、管理员登录\n" );
 267     printf( "\t\t\t\t★3、用户注册\n" );
 268     printf( "\t\t\t\t★0、退出系统\n" );
 269     printf( "\t\t\t******************************************\n" );
 270 
 271     printf( "\t\t\t\t请输入你的选择:\t" );
 272     scanf( "%d", &sele );
 273     return(sele);
 274 }
 275 
 276 
 277 void item_select_1( int sele )
 278 {
 279     switch ( sele )
 280     {
 281     case 1: {
 282         user_login_show();
 283         break;
 284     }
 285     case 2: {
 286         admin_login_show();
 287         break;
 288     }
 289     case 3: {
 290         user_register();
 291         break;
 292     }
 293     case 0: {
 294         exit( 0 );
 295     }
 296     }
 297 }
 298 
 299 
 300 /* 用户注册(增加) */
 301 
 302 void user_register()
 303 {
 304     char password[7];
 305     system( "cls" );
 306     printf( "\n\n\n" );
 307     printf( "\t\t\t******************************************\n" );
 308     printf( "\t\t\t\t\t管理菜单\n\n" );
 309     printf( "\t\t\t用户名:\t" );
 310     scanf( "%s", person[person_number].username );
 311     printf( "\t\t\t密  码:\t" );
 312     for ( int i = 0; i < 6; i++ )           /* 密码统一6位 */
 313     {
 314         if ( (password[i] = getch() ) == 8 )
 315         {
 316             i -= 2;
 317             printf( "\b \b" );
 318             continue;
 319         }
 320         printf( "*" );
 321     }
 322     strcpy( person[person_number].userpassword, password );
 323 
 324     printf( "\n\t\t\t身份证:\t" );
 325     scanf( "%s", person[person_number].ID_card );
 326     printf( "\t\t\t生  日:\t" );
 327     scanf( "%s", person[person_number].B_Day );
 328     person_number++;
 329     printfPersonInfoToFile( "Person.dat" );
 330     printf( "\n\t\t\t***********************************\n" );
 331     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 332     printf( "\t\t\t注册成功,按任意键进入界面菜单.....\t" );
 333     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 334     getch();
 335     item_select_1( main_show_1() );
 336 }
 337 
 338 
 339 /* -----------------------------------华丽的分割线lllll接下来是用户环节----------------------------------------------// */
 340 bool isLogin( char name[], char pwd[] )
 341 {
 342     bool ls = false;
 343     for ( int i = 0; i < 100; i++ )
 344     {
 345         if ( !strcmp( name, person[i].username ) && !strcmp( pwd, person[i].userpassword ) )
 346         {
 347             ls = true;
 348         }
 349     }
 350     return(ls);
 351 }
 352 
 353 
 354 void user_login_show()
 355 {
 356     system( "cls" );
 357     char    username[11];
 358     char    userpassword[7];
 359     fflush( stdin );
 360     printf( "\n\n\n" );
 361     printf( "\t\t\t******************************************\n" );
 362     printf( "\t\t\t\t登陆信息\n" );
 363     printf( "\t\t\t用户名:\t" );
 364     gets( username );
 365     printf( "\t\t\t密  码:\t" );
 366     for ( int i = 0; i < 6; i++ )        /* 密码统一6位 */
 367     {
 368         if ( (userpassword[i] = getch() ) == 8 )
 369         {
 370             i -= 2;
 371             printf( "\b \b" );
 372             continue;
 373         }
 374         printf( "*" );
 375     }
 376     userpassword[6] = '\0';
 377 
 378     if ( isLogin( username, userpassword ) )
 379     {
 380         /* 进入主界面 */
 381         item_select_2( main_show_2() );
 382         /* 进入用户菜单 */
 383     }else{
 384         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 385         printf( "\n\n\t\t\t登陆失败!!!请重新登陆,按任意键继续" );
 386         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 387         getch();
 388         user_login_show();
 389     }
 390 }
 391 
 392 
 393 int main_show_2()
 394 {
 395     int sele = 0;
 396     system( "cls" );
 397     printf( "\n\n\n" );
 398     printf( "\t\t\t******************************************\n" );
 399     printf( "\t\t\t\t\t用户管理菜单\n\n" );
 400     printf( "\t\t\t\t★1、查询票务信息与订票\n" );
 401     printf( "\t\t\t\t★2、退票管理\n" );
 402     printf( "\t\t\t\t★3、查看已购票务\n" );
 403     printf( "\t\t\t\t★4、返回上一级菜单\n" );
 404     printf( "\t\t\t\t★0、退出系统\n" );
 405     printf( "\t\t\t******************************************\n" );
 406 
 407     printf( "\t\t\t\t请输入你的选择:\t" );
 408     scanf( "%d", &sele );
 409     return(sele);
 410 }
 411 
 412 
 413 void item_select_2( int sele )
 414 {
 415     switch ( sele )
 416     {
 417     case 1: {
 418         inquire_tickets();
 419         break;
 420     }
 421     case 2: {
 422         return_show();
 423         break;
 424     }
 425     case 3: {
 426         alter_show();
 427         break;
 428     }
 429 
 430     case 4: {
 431         item_select_1( main_show_1() );
 432     }
 433     case 0: {
 434         exit( 0 );
 435     }
 436     }
 437 }
 438 
 439 
 440 /* 447 288 */
 441 
 442 void inquire_tickets()
 443 {
 444     system( "cls" );
 445     printf( "\n\n\n" );
 446     printf( "\t\t\t******************************************\n" );
 447     printf( "\t\t\t\t\t查询票务信息与订票\n\n" );
 448     char begin_station[10], end_station[10], B_time_day[20];
 449     printf( "\t\t请输入起点站:\t" );
 450     scanf( "%s", begin_station );
 451     printf( "\n\t\t请输入终点站:\t" );
 452     scanf( "%s", end_station );
 453     printf( "\n\t\t请输入发车日期:\t" );
 454     scanf( "%s", B_time_day );
 455     int index = -1;
 456     system( "cls" );
 457     printf( "\n\n\n" );
 458     printf( "\t\t\t***********************************************\n" );
 459     printf( "\t\t\t\t\t订购票务\n\n" );
 460     index = getIndexByTTId( begin_station, end_station, B_time_day );
 461     if ( index == -1 )
 462     {
 463         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 464         printf( "\n\t\t\t没有找到对应的车次列号 按任意键返回上级菜单...\t" );
 465         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 466         getch();
 467         item_select_2( main_show_2() );
 468     }else{
 469         printf( "\t\t\t\t%s--〉%s车次详情\n\n", begin_station, end_station );
 470         printf( "\t\t\t列车次号:\t\t\t%s\n\t\t\t列车出发时间(日):\t\t%s\n\t\t\t列车出发时间(时间):\t\t%s\n\t\t\t列车到达时间:\t\t\t%s\n\t\t\t出发站:\t\t\t\t%s\n\t\t\t终点站:\t\t\t\t%s\n\t\t\t车票价格:\t\t\t%.2f\n\t\t\t已售票数:\t\t\t%d\n\t\t\t未售票数:\t\t\t%d\n",
 471             tickets[index].train_number, tickets[index].B_time_day, tickets[index].B_time, tickets[index].E_time, tickets[index].B_station,
 472             tickets[index].E_station, tickets[index].price, tickets[index].tickets_number_out, tickets[index].tickets_number_remain );
 473         printf( "\t\t\t是否购买?(Y/N)\t" );
 474         char k, l;
 475         fflush( stdin );
 476         scanf( "%c", &k );
 477         if ( k == 'Y' )
 478         {
 479             printf( "\t\t\t请输入需要购买的票数\t" );
 480             int p; /* p为购买的票数 */
 481             scanf( "%d", &p );
 482             printf( "\n\t\t\t您需要一共支付%.2f元\t", p * (tickets[index].price) );
 483             printf( "\n\t\t\t是否确认购买?(Y/N)\t" );
 484             fflush( stdin );
 485             scanf( "%c", &l );
 486             if ( l == 'Y' )
 487             {
 488                 flag = index;
 489                 SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 490                 printf( "\t\t\t购买成功!按任意键返回上级菜单\t" );
 491                 SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 492                 getch();
 493                 item_select_2( main_show_2() );
 494             }else{
 495                 printf( "\t\t\t按任意键返回上级菜单...\t" );
 496                 getch();
 497                 item_select_2( main_show_2() );
 498             }
 499         } else{
 500             printf( "\t\t\t按任意键返回上级菜单...\t" );
 501             getch();
 502             item_select_2( main_show_2() );
 503         }
 504     }
 505 }
 506 
 507 
 508 /* 本函数根据初始站,终点站,时间获取下标[不存在返回-1] */
 509 int getIndexByTTId( char id0[], char id1[], char id2[] )
 510 {
 511     int index = -1;
 512     for ( int i = 0; i < 100; i++ )
 513     {
 514         if ( (!strcmp( tickets[i].B_station, id0 ) ) && (!strcmp( tickets[i].E_station, id1 ) ) && (!strcmp( tickets[i].B_time_day, id2 ) ) )
 515         {
 516             index = i;
 517         }
 518     }
 519     return(index);
 520 }
 521 
 522 
 523 void return_show()
 524 {
 525     char    id[11];
 526     int    index = -1;
 527     system( "cls" );
 528     printf( "\n\n\n" );
 529     printf( "\t\t\t***********************************************\n" );
 530     printf( "\t\t\t\t\t车票退订\n\n" );
 531     fflush( stdin );
 532     printf( "\t\t\t\t请输入退订车次:\t" );
 533     gets( id );
 534     index = getIndexByTId( id );
 535     printf( "\n\n\t\t\t***********************************************\n" );
 536     if ( index == -1 )
 537     {
 538         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 539         printf( "\n\t\t\t没有找到对应的车次编号 按任意键返回上级菜单...\t" );
 540         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 541         getch();
 542         item_select_2( main_show_2() );
 543     }else{
 544         printf( "\t\t\t\t车次详情\n\n" );
 545         printf( "\t\t\t列车次号:\t\t\t%s\n\t\t\t列车出发时间(日):\t\t%s\n\t\t\t列车出发时间(时间):\t\t%s\n\t\t\t列车到达时间:\t\t\t%s\n\t\t\t出发站:\t\t\t\t%s\n\t\t\t终点站:\t\t\t\t%s\n\t\t\t车票价格:\t\t\t%.2f\n\t\t\t已售票数:\t\t\t%d\n\t\t\t未售票数:\t\t\t%d\n",
 546             tickets[index].train_number, tickets[index].B_time_day, tickets[index].B_time, tickets[index].E_time, tickets[index].B_station,
 547             tickets[index].E_station, tickets[index].price, tickets[index].tickets_number_out, tickets[index].tickets_number_remain );
 548         printf( "\n\t\t\t是否退票?(Y/N)\t" );
 549         if ( getch() == 'Y' )
 550         {
 551             for ( int i = index; i < 99; i++ )
 552             {
 553                 tickets[i] = tickets[i + 1];
 554             }
 555             train_number--;
 556             SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 557             printf( "\n\t\t\t退票完成 按任意键返回上级菜单...\t" );
 558             SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 559             getch();
 560             item_select_2( main_show_2() );
 561         }else                                 { printf( "\t\t\t按任意键返回上级菜单...\t" );
 562                             getch();
 563                             item_select_2( main_show_2() ); }
 564     }
 565 }
 566 
 567 
 568 /* 本函数根据用户名获取下标[不存在返回-1] */
 569 int getIndexById( char id[] )
 570 {
 571     int index = -1;
 572     for ( int i = 0; i < person_number; i++ )
 573     {
 574         if ( !strcmp( person[i].username, id ) )
 575         {
 576             index = i;
 577         }
 578     }
 579     return(index);
 580 }
 581 
 582 
 583 void alter_show()
 584 {
 585     printf( "\n\n\t\t\t***********************************************\n" );
 586     printf( "\t\t\t\t\t已购票务\n\n" );
 587     if ( flag == -1 || tickets[flag].tickets_number_out == 0 )
 588     {
 589         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 590         printf( "\t\t\t\t\t您还未订票!\n\n" );
 591         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 592         printf( "\n\t\t\t按任意键返回上级菜单...\t" );
 593 
 594         getch();
 595         item_select_2( main_show_2() );
 596     }else                                 {
 597         printf( "\t\t\t\t车次详情\n\n" );
 598         printf( "\t\t\t列车次号:\t\t\t%s\n\t\t\t列车出发时间(日):\t\t%s\n\t\t\t列车出发时间(时间):\t\t%s\n\t\t\t列车到达时间:\t\t\t%s\n\t\t\t出发站:\t\t\t\t%s\n\t\t\t终点站:\t\t\t\t%s\n\t\t\t车票价格:\t\t\t%.2f\n\t\t\t已售票数:\t\t\t%d\n\t\t\t未售票数:\t\t\t%d\n",
 599             tickets[flag].train_number, tickets[flag].B_time_day, tickets[flag].B_time, tickets[flag].E_time, tickets[flag].B_station,
 600             tickets[flag].E_station, tickets[flag].price, tickets[flag].tickets_number_out, tickets[flag].tickets_number_remain );
 601         printf( "\n\t\t\t按任意键返回上级菜单...\t" );
 602 
 603         getch();
 604         item_select_2( main_show_2() );
 605     }
 606 }
 607 
 608 
 609 /* -----------------------------------华丽的分割线lllll接下来是ADMIN环节----------------------------------------------// */
 610 
 611 void admin_login_show()
 612 {
 613     system( "cls" );
 614     char    username[11];
 615     char    userpassword[7];
 616     fflush( stdin );
 617     printf( "\n\n\n" );
 618     printf( "\t\t\t******************************************\n" );
 619     printf( "\t\t\t\t登陆信息\n" );
 620     printf( "\t\t\t用户名:\t" );
 621     gets( username );
 622     printf( "\t\t\t密  码:\t" );
 623     for ( int i = 0; i < 6; i++ )        /* 密码统一6位 */
 624     {
 625         if ( (userpassword[i] = getch() ) == 8 )
 626         {
 627             i -= 2;
 628             printf( "\b \b" );
 629             continue;
 630         }
 631         printf( "*" );
 632     }
 633     userpassword[6] = '\0';
 634 
 635     if ( isLogin1( username, userpassword ) )
 636     {
 637         /* 进入主界面 */
 638         item_select_3( main_show_3() ); /* 进入管理员菜单 */
 639     }else{
 640         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 641         printf( "\n\n\t\t\t登陆失败!!!请重新登陆,按任意键继续" );
 642         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 643         getch();
 644         admin_login_show();
 645     }
 646 }
 647 
 648 
 649 bool isLogin1( char name[], char pwd[] )
 650 {
 651     bool ls = false;
 652     for ( int i = 0; i < person_number; i++ )
 653     {
 654         if ( !strcmp( name, GM[i].admin_username ) && !strcmp( pwd, GM[i].admin_pwd ) )
 655         {
 656             ls = true;
 657         }
 658     }
 659     return(ls);
 660 }
 661 
 662 
 663 int main_show_3()
 664 {
 665     int sele = 0;
 666     system( "cls" );
 667     printf( "\n\n\n" );
 668     printf( "\t\t\t******************************************\n" );
 669     printf( "\t\t\t\t\t管理员管理菜单\n\n" );
 670     printf( "\t\t\t\t★1、新增车票信息\n" );
 671     printf( "\t\t\t\t★2、编辑与查看车票信息\n" );
 672     printf( "\t\t\t\t★3、删除车票信息\n" );
 673     printf( "\t\t\t\t★4、新增人员信息\n" );
 674     printf( "\t\t\t\t★5、编辑人员信息\n" );
 675     printf( "\t\t\t\t★6、删除人员信息\n" );
 676     printf( "\t\t\t\t★7、返回上一级菜单\n" );
 677     printf( "\t\t\t\t★0、退出系统\n" );
 678     printf( "\t\t\t******************************************\n" );
 679     printf( "\t\t\t\t请输入你的选择:\t" );
 680     scanf( "%d", &sele );
 681     return(sele);
 682 }
 683 
 684 
 685 void item_select_3( int sele )
 686 {
 687     switch ( sele )
 688     {
 689     case 1: {
 690         add_tickets();
 691         break;
 692     }
 693     case 2: {
 694         alter_tickets();
 695         break;
 696     }
 697     case 3: {
 698         delete_tickets();
 699         break;
 700     }
 701     case 4: {
 702         add_person();
 703     }
 704     case 5: {
 705         alter_person();
 706         break;
 707     }
 708     case 6: {
 709         delete_person();
 710         break;
 711     }
 712     case 7: {
 713         item_select_1( main_show_1() );
 714         break;
 715     }
 716     case 0: {
 717         exit( 0 );
 718     }
 719     }
 720 }
 721 
 722 
 723 void add_tickets()
 724 {
 725     system( "cls" );
 726     printf( "\n\n\n" );
 727     printf( "\t\t\t***********************************************\n" );
 728     printf( "\t\t\t\t\t添加车票信息\n\n" );
 729 
 730     printf( "\t\t\t\t车次列号:\t" );
 731     scanf( "%s", tickets[train_number].train_number );
 732     printf( "\n\t\t\t\t出发日期(日):\t" );
 733     scanf( "%s", tickets[train_number].B_time_day );
 734     printf( "\n\t\t\t\t出发日期(时间):\t" );
 735     scanf( "%s", tickets[train_number].B_time );
 736     printf( "\n\t\t\t\t到达时间(日+时间):\t" );
 737     scanf( "%s", tickets[train_number].E_time );
 738     fflush( stdin );
 739     printf( "\n\t\t\t\t出发站:\t" );
 740     scanf( "%s", tickets[train_number].B_station );
 741     printf( "\n\t\t\t\t终点站:\t" );
 742     scanf( "%s", tickets[train_number].E_station );
 743     printf( "\n\t\t\t\t票价:\t" );
 744     scanf( "%f", &tickets[train_number].price );
 745     printf( "\n\t\t\t\t已售票数:\t" );
 746     scanf( "%d", &tickets[train_number].tickets_number_out );
 747     printf( "\n\t\t\t\t未售票数:\t" );
 748     scanf( "%d", &tickets[train_number].tickets_number_remain );
 749     train_number++;
 750     printfTicketsInfoToFile( "Tickets.dat" );
 751     printf( "\n\n\t\t\t***********************************************\n" );
 752     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 753     printf( "\t\t\t\t信息录入完成 按任意键返回上级菜单...\t" );
 754     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 755     getch();
 756     item_select_3( main_show_3() );
 757 }
 758 
 759 
 760 void alter_tickets()
 761 {
 762     char    id[11];
 763     int    index = -1;
 764     system( "cls" );
 765     printf( "\n\n\n" );
 766     printf( "\t\t\t***********************************************\n" );
 767     printf( "\t\t\t\t\t编辑车票信息\n\n" );
 768     fflush( stdin );
 769     printf( "\t\t\t\t车次号:\t" );
 770     gets( id );
 771     index = getIndexByTId( id );
 772     printf( "\n\n\t\t\t***********************************************\n" );
 773     if ( index == -1 )
 774     {
 775         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 776         printf( "\n\t\t\t没有找到对应的车次编号 按任意键返回上级菜单...\t" );
 777         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 778         getch();
 779         item_select_3( main_show_3() );
 780     }else{
 781         printf( "\t\t\t\t找到车次 车次详情\n\n" );
 782         printf( "\t\t\t列车次号:\t\t\t%s\n\t\t\t列车出发时间(日):\t\t%s\n\t\t\t列车出发时间(时间):\t\t%s\n\t\t\t列车到达时间:\t\t\t%s\n\t\t\t出发站:\t\t\t\t%s\n\t\t\t终点站:\t\t\t\t%s\n\t\t\t车票价格:\t\t\t%.2f\n\t\t\t已售票数:\t\t\t%d\n\t\t\t未售票数:\t\t\t%d\n",
 783             tickets[index].train_number, tickets[index].B_time_day, tickets[index].B_time, tickets[index].E_time, tickets[index].B_station,
 784             tickets[index].E_station, tickets[index].price, tickets[index].tickets_number_out, tickets[index].tickets_number_remain );
 785         fflush( stdin );
 786         printf( "\t\t\t如需编辑请按Y\n" );
 787         if ( getch() == 'Y' )
 788         {
 789             printf( "\t\t\t******************编辑信息********************\n" );
 790             printf( "\t\t\t\t列车次号:\t" );
 791             gets( tickets[index].train_number );
 792             printf( "\n\t\t\t\t列车出发时间(日):\t" );
 793             gets( tickets[index].B_time_day );
 794             printf( "\n\t\t\t\t列车出发时间(时间):\t" );
 795             gets( tickets[index].B_time );
 796             printf( "\n\t\t\t\t列车到达时间:\t" );
 797             gets( tickets[index].E_time );
 798             printf( "\n\t\t\t\t出发站:\t" );
 799             gets( tickets[index].B_station );
 800             printf( "\n\t\t\t\t终点站:\t" );
 801             gets( tickets[index].E_station );
 802             printf( "\n\t\t\t\t车票价格:\t" );
 803             scanf( "%f", &tickets[index].price );
 804             printf( "\n\t\t\t\t已售票数:\t" );
 805             scanf( "%d", &tickets[index].tickets_number_out );
 806             printf( "\n\t\t\t\t未售票数:\t" );
 807             scanf( "%d", &tickets[index].tickets_number_remain );
 808             SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 809             printf( "\t\t\t信息编辑完成 按任意键返回上级菜单...\t" );
 810             SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 811             printfTicketsInfoToFile( "Tickets.dat" );
 812             getch();
 813             item_select_3( main_show_3() );
 814         }else{ printf( "\t\t\t按任意键返回上级菜单...\t" );
 815                printfTicketsInfoToFile( "Tickets.dat" );
 816                getch();
 817                item_select_3( main_show_3() ); }
 818     }
 819 }
 820 
 821 
 822 /* 本函数根据车编号获取下标[不存在返回-1] */
 823 int getIndexByTId( char id[] )
 824 {
 825     int index = -1;
 826     for ( int i = 0; i < 100; i++ )
 827     {
 828         if ( !strcmp( tickets[i].train_number, id ) )
 829         {
 830             index = i;
 831         }
 832     }
 833     return(index);
 834 }
 835 
 836 
 837 void delete_tickets()
 838 {
 839     char    id[11];
 840     int    index = -1;
 841     system( "cls" );
 842     printf( "\n\n\n" );
 843     printf( "\t\t\t***********************************************\n" );
 844     printf( "\t\t\t\t\t删除车票信息\n\n" );
 845     fflush( stdin );
 846     printf( "\t\t\t\t车次编号:\t" );
 847     gets( id );
 848     index = getIndexByTId( id );
 849     printf( "\n\n\t\t\t***********************************************\n" );
 850     if ( index == -1 )
 851     {
 852         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 853         printf( "\n\t\t\t没有找到对应的车次编号 按任意键返回上级菜单...\t" );
 854         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 855         getch();
 856         item_select_3( main_show_3() );
 857     }else{
 858         printf( "\t\t\t列车次号:\t\t\t%s\n\t\t\t列车出发时间(日):\t\t%s\n\t\t\t列车出发时间(时间):\t\t%s\n\t\t\t列车到达时间:\t\t\t%s\n\t\t\t出发站:\t\t\t\t%s\n\t\t\t终点站:\t\t\t\t%s\n\t\t\t车票价格:\t\t\t%.2f\n\t\t\t已售票数:\t\t\t%d\n\t\t\t未售票数:\t\t\t%d\n",
 859             tickets[index].train_number, tickets[index].B_time_day, tickets[index].B_time, tickets[index].E_time, tickets[index].B_station,
 860             tickets[index].E_station, tickets[index].price, tickets[index].tickets_number_out, tickets[index].tickets_number_remain );
 861         fflush( stdin );
 862         printf( "\t\t\t如需编辑请按Y\n" );
 863         if ( getch() == 'Y' )
 864         {
 865             for ( int i = index; i < 99; i++ )
 866             {
 867                 tickets[i] = tickets[i + 1];
 868             }
 869             train_number--; printfTicketsInfoToFile( "Tickets.dat" );
 870             SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 871             printf( "\n\t\t\t车票删除完成 按任意键返回上级菜单...\t" );
 872             SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 873             getch();
 874             item_select_3( main_show_3() );
 875         }else{
 876             printf( "\t\t\t按任意键返回上级菜单...\t" );
 877             getch();
 878             item_select_3( main_show_3() );
 879         }
 880     }
 881 }
 882 
 883 
 884 void add_person()
 885 {
 886     system( "cls" );
 887     printf( "\n\n\n" );
 888     printf( "\t\t\t******************************************\n" );
 889     printf( "\t\t\t\t\t增加人员信息\n\n" );
 890     printf( "\t\t\t用户名:\t" );
 891     scanf( "%s", person[person_number].username );
 892     printf( "\t\t\t密  码:\t" );
 893     scanf( "%s", person[person_number].userpassword );
 894     printf( "\t\t\t身份证:\t" );
 895     scanf( "%s", person[person_number].ID_card );
 896     printf( "\t\t\t生  日:\t" );
 897     scanf( "%s", person[person_number].B_Day );
 898     person_number++; printfPersonInfoToFile( "Person.dat" );
 899     printf( "\n\t\t\t***********************************\n" );
 900     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 901     printf( "\t\t\t增加成功,按任意键进入界面上一层菜单.....\t" );
 902     SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 903     getch();
 904     item_select_3( main_show_3() );
 905 }
 906 
 907 
 908 void alter_person()                                                                         /*有改动,排版问题修复*/
 909 {
 910     char    id[11];
 911     int    index = -1;
 912     system( "cls" );
 913     printf( "\n\n\n" );
 914     printf( "\t\t\t***********************************************\n" );
 915     printf( "\t\t\t\t\t编辑用户信息\n\n" );
 916     fflush( stdin );
 917     printf( "\t\t\t\t请输入用户名:\t" );
 918     gets( id );
 919     index = getIndexById( id );
 920     printf( "\n\n\t\t\t***********************************************\n" );
 921     if ( index == -1 )
 922     {
 923         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 924         printf( "\n\t\t\t没有找到对应用户名 按任意键返回上级菜单...\t" );
 925         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 926     }else{
 927         printf( "\t\t\t\t\t信息详情\n\n" );
 928         printf( "\t\t\t用户名\t身份证\t\t\t生日\n" );
 929         printf( "\t\t\t%s\t%s\t%s", person[index].username, person[index].ID_card, person[index].B_Day );
 930         fflush( stdin );
 931         printf( "\n\t\t\t***************编辑用户信息********************" );
 932         printf( "\n\t\t\t修改用户名:\t" );
 933         gets( person[index].username );
 934         printf( "\n\t\t\t修改密码:\t" );
 935         gets( person[index].userpassword );
 936         printf( "\n\t\t\t修改绑定身份证号:\t" );
 937         gets( person[index].ID_card );
 938         printf( "\n\t\t\t修改生日:\t" );
 939         gets( person[index].B_Day );
 940         printfPersonInfoToFile( "Person.dat" );
 941         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 942         printf( "\t\t\t用户信息编辑完成 按任意键返回上级菜单...\t" );
 943         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 944     }
 945     getch();
 946     item_select_3( main_show_3() );
 947 }
 948 
 949 
 950 void delete_person()
 951 {
 952     char    id[11];
 953     int    index = -1;
 954     system( "cls" );
 955     printf( "\n\n\n" );
 956     printf( "\t\t\t***********************************************\n" );
 957     printf( "\t\t\t\t\t删除人员信息\n\n" );
 958     fflush( stdin );
 959     printf( "\t\t\t\t请输入需删除用户名:\t" );
 960     gets( id );
 961     index = getIndexById( id );
 962     printf( "\n\n\t\t\t***********************************************\n" );
 963     if ( index == -1 )
 964     {
 965         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_RED );
 966         printf( "\n\t\t\t不存在该用户 按任意键返回上级菜单...\t" );
 967         SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 968         getch();
 969         item_select_3( main_show_3() );
 970     }else{ printf( "\t\t\t\t\t信息详情\n\n" );
 971            printf( "\t\t\t用户名\t身份证\t\t\t生日\n" );
 972            printf( "\t\t\t%s\t%s\t%s", person[index].username, person[index].ID_card, person[index].B_Day );
 973            printf( "\n\n\t\t\t***********************************************\n" );
 974            printf( "\t\t\t是否删除该用户?(Y/N):\t" );
 975            fflush( stdin );
 976            if ( getch() == 'Y' )
 977            {
 978                for ( int i = index; i < 99; i++ )
 979                {
 980                    person[i] = person[i + 1];
 981                }
 982                person_number--; printfPersonInfoToFile( "Person.dat" );
 983                SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_BLUE );
 984                printf( "\t\t\t用户信息删除完成 按任意键返回上级菜单...\t" );
 985                SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY | FOREGROUND_GREEN );
 986                getch();
 987                item_select_3( main_show_3() );
 988            }else{
 989                printf( "\t\t\t按任意键返回上级菜单...\t" );
 990                getch();
 991                item_select_3( main_show_3() );
 992            } }
 993 }
 994 
 995 
 996 void printfPersonInfoToFile( char file_path[] )
 997 {
 998     fp = fopen( file_path, "w+" );
 999     for ( int i = 0; i < 100; i++ )
1000     {
1001         fprintf( fp, "%s %s %s %s ", person[i].username, person[i].userpassword, person[i].ID_card, person[i].B_Day );
1002     }
1003     fclose( fp );
1004 }
1005 
1006 
1007 void scanfPersonInfoToFile( char file_path[] )
1008 {
1009     fp = fopen( file_path, "r+" );
1010     for ( int i = 0; i < 100; i++ )
1011     {
1012         fscanf( fp, "%s %s %s %s ", person[i].username, person[i].userpassword, person[i].ID_card, person[i].B_Day );
1013     }
1014     fclose( fp );
1015 }
1016 
1017 
1018 void printfTicketsInfoToFile( char file_path[] )
1019 {
1020     fp = fopen( file_path, "w+" );
1021     for ( int i = 0; i < 100; i++ )
1022     {
1023         fprintf( fp, "%s %s %s %s %s %.2f %d %d ", tickets[i].train_number, tickets[i].B_time_day, tickets[i].B_time, tickets[i].E_time, tickets[i].B_station, tickets[i].E_station, tickets[i].price, tickets[i].tickets_number_out, tickets[i].tickets_number_remain );
1024     }
1025     fclose( fp );
1026 }
1027 
1028 
1029 void scanfTicketsInfoToFile( char file_path[] )
1030 {
1031     fp = fopen( file_path, "r+" );
1032     for ( int i = 0; i < 100; i++ )
1033     {
1034         fscanf( fp, "%s %s %s %s %s %.2f %d %d ", tickets[i].train_number, tickets[i].B_time_day, tickets[i].B_time, tickets[i].E_time, tickets[i].B_station, tickets[i].E_station, &tickets[i].price, &tickets[i].tickets_number_out, &tickets[i].tickets_number_remain );
1035     }
1036     fclose( fp );
1037 }

 

 

Damn, who knew all the planes we flew
Good things we've been through
That I'll be standing right here
Talking to you about another path
I know we loved to hit the road and laugh
But something told me that it wouldn't last
Had to switch up look at things different see the bigger picture
Those were the days hard work forever pays
Now I see you win the better place
How could we not talk about family when family's all that we got?
Everything I went through you were standing there by my side
And now you gonna be with me for the last ride
posted @ 2018-01-17 18:38  Rohlf  阅读(378)  评论(0编辑  收藏  举报