-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChaoShi.cpp
3239 lines (3202 loc) · 104 KB
/
ChaoShi.cpp
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
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include"ChaoShi.h"
#include <graphics.h> // 引用图形库头文件
#include <conio.h>
#include<cwchar>
void UI_denglu() {
initgraph(640,480, EW_DBLCLKS | EW_SHOWCONSOLE);
setbkcolor(WHITE);
cleardevice();
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
settextcolor(RGB(21, 64, 234));
setlinecolor(BLACK);
fillrectangle(0,219,101,261);
RECT r1 = { 1,220, 100,260 };
drawtext(_T("初次初始账户"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
fillrectangle(538, 130, 640, 171);
RECT r2 = { 539,131, 639,170 };
drawtext(_T("登录已有账户"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
fillrectangle(538, 310, 640, 351);
RECT r3 = { 539,311, 639, 350 };
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
int click_denglu() {
ExMessage m;
getmessage(&m,EM_MOUSE);
switch (m.message) {
case WM_LBUTTONDOWN:
if (220 < m.y && m.y < 260 && 1 < m.x && m.x < 100) {
return 1;
}
else if (131 < m.y && m.y < 170 && 539 < m.x && m.x < 640) {
return 2;
}
else if (311 < m.y && m.y < 350 && 539 < m.x && m.x < 640) {
return 3;
}
else { return 4; }
break;
default:
return 0;
}
return 8;
}
void interface1(void)//定义进入界面时第一个函数
{
float y, x, z, f;
for (y = 1.5f; y > -1.5f; y-=0.1f)
{
for (x = -1.5f; x < 1.5f; x += 0.05f)
{
z = x*x + y*y -1;
f = z*z*z - x*x*y*y*y;
putchar(f <= 0.0f ? "*********"[(int)(f*-8.0f)]:' ');
}
putchar('\n');
}
printf("欢迎使用小型超市商品管理系统(请按Enter键进入.......)");
getchar();
system("cls");
}
void interface2(void)//定义进入界面时第二个函数
{
int i;
char ch='*';
for(i=1;i<20;i++)
{
putchar(ch);
}
printf("小型超市商品管理系统");
for(i=1;i<20;i++)
{
putchar(ch);
}
}
void set_account(void)//初始化账号密码
{
int a;
struct Account account_neu;
struct Account nnnn;
//scanf("%ld",&nnnn.ID_g);
//struct Account account_cse;
FILE *fp;
if((fp=fopen("account.dat","wb+"))==NULL)//打开磁盘文件
{
//printf("系统出错!!!!!!!!!\n");
RECT r = { 140,160,400,320 };
drawtext(_T("系统出错!!!!!!!!!"),&r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
exit(0);//结束函数
}
//printf("请输入初始化的账号密码\n");
fillrectangle(200, 139, 441, 341);
RECT r1 = { 201,140,440,340 };
drawtext(_T("请输入初始化账号密码"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
//printf("初始化收银员账号:");
wchar_t s[10];
InputBox(s, 10, L"初始化收银员账号");
//scanf("%ld",&account_neu.ID_s);
account_neu.ID_s = _wtoi(s);
//printf("初始化收银员密码:");
InputBox(s, 10, L"初始化收银员密码");
//scanf("%ld",&account_neu.password_s);
account_neu.password_s = _wtoi(s);
InputBox(s, 10, L"初始化管理员账号");
account_neu.ID_g = _wtoi(s);
InputBox(s, 10, L"初始化管理员密码");
account_neu.password_g = _wtoi(s);
//printf("初始化管理员账号:");
//scanf("%ld",&account_neu.ID_g);
//printf("初始化管理员密码:");
//scanf("%ld",&account_neu.password_g);
//printf("%ld %ld %ld %ld\n",account_neu.ID_s,account_neu.password_s,account_neu.ID_g,account_neu.password_g);
fwrite(&account_neu,sizeof(account_neu),1,fp);//将账号密码读入文件
rewind(fp);
//fread(&account_cse,sizeof(account_cse),1,fp);
//printf("%ld %ld %ld %ld\n",account_cse.ID_s,account_cse.password_s,account_cse.ID_g,account_cse.password_g);
//printf("账号密码设置完成");
//printf("再次输入账号密码登录\n");
clearrectangle(101,61,538,419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
fillrectangle(200, 79, 441, 221);
fillrectangle(200, 259, 441, 401);
r1 = { 201,80,440,220};
RECT r2 = { 201,260,440,400};
drawtext(_T("账号密码设置完成"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("再次输入账号密码登录"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
//printf("如果是管理者请输入1,如果是收银员请输入2:\n");
InputBox(s, 10, L"如果是管理者请输入1,如果是收银员请输入2");
a = _wtoi(s);
clearrectangle(101, 61, 538, 419);
log_in_s(a);//收银员的登录界面
log_in_g(a);//管理者的登录界面
}
void log_in_s(int x)//收银员登陆界面
{
if(x==2)
{
struct Account* account1;
account1=read_account();
struct Account account_t;
account_t.ID_s=account1->ID_s;
account_t.password_s=account1->password_s;
account_t.ID_g=account1->ID_g;
account_t.password_g=account1->password_g;
//printf("%ld %ld %ld %ld\n",account_t.ID_s,account_t.password_s,account_t.ID_g,account_t.password_g);
long int ID,password;
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
//printf("你好收银员,请输入你的账号,密码\n");
fillrectangle(200, 80, 441, 182);
RECT r1 = { 201,81,440,181 };
drawtext(_T("你好收银员,请输入你的账号,密码"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
//printf("账号:");
wchar_t s[10];
InputBox(s, 10, L"账号");
ID = _wtoi(s);
//scanf("%ld",&ID);
//printf("密码:");
//scanf("%ld",&password);
InputBox(s, 10, L"密码");
password = _wtoi(s);
printf("\n");
if((ID==account_t.ID_s)&&(password==account_t.password_s))
{
system("cls");
//printf("登录成功\n欢迎进入美好的收银时间\n");
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
//printf("你好收银员,请输入你的账号,密码\n");
drawtext(_T("登录成功,欢迎进入美好的收银时间"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
selled();
}
else
{
//printf("账号密码错误,系统自动退出\n");
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
drawtext(_T("账号密码错误,系统自动退出"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
exit(0);
}
}
}
struct Account* read_account(void)//读出账号密码
{
FILE *fp;
struct Account account_cse;
struct Account *pp;
pp=&account_cse;
if((fp=fopen("account.dat","ab+"))==NULL)//打开磁盘文件
{
printf("系统出错!!!!!!!!!\n");
return 0;//结束函数
}
fread(pp,sizeof(account_cse),1,fp);
//printf("%ld %ld %ld %ld\n",account_cse.ID_s,account_cse.password_s,account_cse.ID_g,account_cse.password_g);
return pp;
}
void log_in_g(int x)//管理员登陆界面
{
if(x==1)
{
struct Account* account1;
account1=read_account();
struct Account account_t;
account_t.ID_s=account1->ID_s;
account_t.password_s=account1->password_s;
account_t.ID_g=account1->ID_g;
account_t.password_g=account1->password_g;
// printf("%ld %ld %ld %ld\n",account_t.ID_s,account_t.password_s,account_t.ID_g,account_t.password_g);
long int ID,password;
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
//printf("你好收银员,请输入你的账号,密码\n");
fillrectangle(200, 80, 441, 180);
RECT r1 = { 201,81,440,181 };
drawtext(_T("你好管理员,请输入你的账号,密码"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
//printf("账号:");
wchar_t s[10];
InputBox(s, 10, L"账号");
ID = _wtoi(s);
//scanf("%ld",&ID);
printf("\n");
//printf("密码:");
//scanf("%ld",&password);
InputBox(s, 10, L"密码");
password = _wtoi(s);
printf("\n");
//printf("%ld %ld %ld %ld\n",account1->ID_s,account1->password_s,account1->ID_g,account1->password_g);
if((ID==account_t.ID_g)&&(password==account_t.password_g))
{
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
drawtext(_T("登陆成功"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
user();
}
else {
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
drawtext(_T("账号密码错误,系统自动退出"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
exit(0);
//user();
}
system("cls");
}
void user(void)
{
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
int choice;
/*printf(" \n\n \n\n");
printf(" ******************************************************\n\n");
printf(" * 管理系统 *\n \n");
printf(" ******************************************************\n\n");
printf("*********************系统功能菜单*********************** \n");
printf(" ----------------------- --------------------- \n");
printf(" ********************************************** \n");
printf(" * 0.退出该系统 * * 1.修改登录账号密码 * \n");
printf(" ********************************************** \n");
printf(" * 2.顾客管理系统 * * 3.商品管理系统 * \n");
printf(" ********************************************** \n");
printf(" * 4.查询畅销商品 * \n");
printf(" ********************************************** \n");
//printf(" * 6. * * 7. * \n");
//printf(" ********************************************** \n");
printf(" ----------------------- --------------------- \n");
printf("******************************************************** \n");
//printf("请选择菜单编号:");
//scanf("%d",&choice);
*/
fillrectangle(0, 130, 101, 171);
fillrectangle(0, 310, 101, 351);
fillrectangle(538, 126, 640, 168);
fillrectangle(538, 233, 640, 274);
fillrectangle(538, 340, 640, 382);
RECT r1 = { 1,131, 100,170 };
drawtext(_T("退出系统"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 1,311, 100,350 };
drawtext(_T("修改账户"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 539,127, 639,167 };
drawtext(_T("顾客管理"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 539,234, 639,274 };
drawtext(_T("商品管理"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 539,341, 639,381 };
drawtext(_T("畅销商品管理"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
while(1)
{
choice = click_user();
if(choice==0||choice==1||choice==2||choice==3||choice==4)break;
}
switch(choice)
{
case 1:
change_account();
break;
case 2:
showorchange_customer();
break;
case 3:
goods_message();
//system("cls");
break;
case 4:
search_selled();
break;
case 0:
return ;
break;
default:
printf("输入有误,没有该功能\n");
break;
}
//system("cls");
}
int click_user() {
ExMessage m;
getmessage(&m, EM_MOUSE);
switch (m.message) {
case WM_LBUTTONDOWN:
if (131 < m.y && m.y < 171 && 1 < m.x && m.x < 100) {
return 0;
}
else if (311 < m.y && m.y < 350 && 1 < m.x && m.x < 100) {
return 1;
}
else if (127 < m.y && m.y < 167 && 539 < m.x && m.x < 640) {
return 2;
}
else if (234 < m.y && m.y < 274 && 539 < m.x && m.x < 640) {
return 3;
}
else if (341 < m.y && m.y < 380 && 539 < m.x && m.x < 640) {
return 4;
}
else { return 5; }
break;
default:
return 5;
}
return 8;
}
int click_change_account() {
ExMessage m;
getmessage(&m, EM_MOUSE);
switch (m.message) {
case WM_LBUTTONDOWN:
if (221 < m.y && m.y < 260 && 1 < m.x && m.x < 100) {
return 1;
}
else if (221 < m.y && m.y < 260 && 539 < m.x && m.x < 640) {
return 2;
}
else { return 5; }
break;
default:
return 5;
}
return 8;
}
void change_account(void)
{
FILE *fp;
struct Account account_neucse;
RECT r1 = { 201,81,440,181 };
if((fp=fopen("account.dat","ab"))==NULL)//打开磁盘文件
{
clearrectangle(0, 61, 640, 419);
drawtext(_T("系统出错"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
exit(0);
}
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
fillrectangle(200, 80, 441, 182);
drawtext(_T("请输入修改后的账号密码"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
wchar_t s[10];
InputBox(s, 10, L"收银员账号");
//scanf("%ld",&account_neucse.ID_s);
account_neucse.ID_s = _wtoi(s);
//printf("修改后收银员密码:");
InputBox(s, 10, L"收银员密码");
account_neucse.password_s = _wtoi(s);
//scanf("%ld",&account_neucse.password_s);
InputBox(s, 10, L"管理员账号");
account_neucse.ID_g = _wtoi(s);
InputBox(s, 10, L"管理员密码");
account_neucse.password_g = _wtoi(s);
fwrite(&account_neucse,sizeof(account_neucse),1,fp);//将账号密码读入文件
clearrectangle(0, 61, 640, 419);
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
fillrectangle(200, 80, 441, 182);
drawtext(_T("修改完成"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
int a;
RECT r2 = {1,221,100,260};
fillrectangle(0, 220, 101, 261);
drawtext(_T("返回管理员系统"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 539,221,639,260 };
fillrectangle(538, 220, 640, 261);
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
while (1) {
a = click_change_account();
if (a == 1 || a == 2) {
break;
}
}
if(a==1)user();
else if(a==2) exit(0);
}
int click_showorchange_customer() {
ExMessage m;
getmessage(&m, EM_MOUSE);
switch (m.message) {
case WM_LBUTTONDOWN:
if (85 < m.y && m.y < 125 && 539 < m.x && m.x < 639) {
return 0;
}
else if (92 < m.y && m.y < 132 && 1 < m.x && m.x < 640) {
return 1;
}
else if (165 < m.y && m.y < 205 && 1 < m.x && m.x < 100) {
return 2;
}
else if (238 < m.y && m.y < 278 && 1 < m.x && m.x < 100) {
return 3;
}
else if (311 < m.y && m.y < 351 && 1 < m.x && m.x < 100) {
return 4;
}
else if (150 < m.y && m.y < 190 && 539 < m.x && m.x < 640) {
return 5;
}
else if (215 < m.y && m.y < 255 && 539 < m.x && m.x < 640) {
return 6;
}
else if (280 < m.y && m.y < 320 && 539 < m.x && m.x < 640) {
return 7;
}
else if (345 < m.y && m.y < 385 && 539 < m.x && m.x < 640) {
return 8;
}
else { return 9; }
break;
default:
return 9;
}
return 9;
}
void showorchange_customer(void)
{
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
int a;
fillrectangle(0,91,101,133);
RECT r1 = { 1,92,100,132 };
fillrectangle(0,164, 101,206);
RECT r2 = { 1,165,100,205 };
fillrectangle(0,237, 101,279);
RECT r3 = { 1,238,100,278 };
fillrectangle(0,310, 101, 352);
RECT r4 = { 1,311,100,351 };
fillrectangle(538, 84, 640, 126);
RECT r0 = { 539,85,639,125 };
fillrectangle(538,149, 640, 191);
RECT r5 = { 539,150,639,190 };
fillrectangle(538, 214, 640, 256);
RECT r6 = { 539,215,639,255 };
fillrectangle(538, 279, 640, 321);
RECT r7 = { 539,280,639,320 };
fillrectangle(538, 344, 640, 386);
RECT r8 = { 539,345,639,385 };
drawtext(_T("返回上级"), &r0, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("帮助文档"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("录入顾客"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("添加顾客"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("修改顾客"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("删除顾客"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("显示顾客"), &r6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("查询顾客"), &r7, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("模糊查询"), &r8, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
//查询顾客信息,帮助
while (1) {
a = click_showorchange_customer();
if (a == 0 || a == 1 || a == 2 || a == 3 || a == 4 || a == 5 || a == 6 || a == 7 || a == 8) {
break;
}
}
switch(a)
{
case 1:
{
int ss;
clearrectangle(0, 61, 640, 419);
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r1 = { 201,101,440,161 };
drawtext(_T("1.请按照提示使用该功能"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 201,181,440,241 };
drawtext(_T("2.如有疑问请拨打咨询热线15294748920"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 201,261,440,321 };
drawtext(_T("3.谢谢您对该系统的支持"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 201,341,440,401 };
drawtext(_T("如果返回上一级请输入1,如果直接退出系统请输入2"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
wchar_t s[10];
InputBox(s, 10);
ss = _wtoi(s);
if (ss == 1) {
clearrectangle(0, 61, 640, 419);
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
showorchange_customer();
}
else if (ss == 2) {
clearrectangle(0, 61, 640, 419);
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
exit(0);
}
}
break;
case 2:
save_Customer();
break;
case 3:
add_customer();
break;
case 4:
revise1();
break;
case 5:
del1();
break;
case 6:
show_customer();
break;
case 7:
search_customer_message();
break;
case 0:
user();
break;
case 8:
search_customer_mohu();
break;
default:
printf("输入有误,没有该功能\n");
int ss;
wchar_t sss[15];
InputBox(sss,10,L"如果想继续使用本系统请输入1");
ss = _wtoi(sss);
if(ss==1)showorchange_customer();
//user();
break;
}
//system("cls");
}
void search_customer_message(void)
{
struct Customer_list *head_cust,*p;
int i,temp,num_cust,a,grade,ss,nn=0;//temp为要搜索顾客数目,num_cust为要搜索的顾客标号
wchar_t name_cust[15];//要搜索顾客姓名
head_cust=look_customer();
p=NULL;
//printf("请选择搜索方式(按姓名搜索或按顾客编号搜索");
//printf("按姓名搜索请输入1,按顾客编号搜索请输入2):");
wchar_t s[15];
wchar_t num[15];
wchar_t grades[15];
wchar_t salemount[15];
int axisy=80;
int axisx = 140;
InputBox(s, 10, L"按姓名搜索请输入1,按顾客编号搜索请输入2");
a = _wtoi(s);
//scanf("%d",&a);
//printf("请输入要搜索次数:");
InputBox(s, 10, L"请输入要搜索次数");
temp = _wtoi(s);
if(a==1)
{
for(i=0;i<temp;i++)
{
InputBox(name_cust, 10, L"请输入搜索顾客名称");
if(head_cust!=NULL)
{
p=head_cust;
clearrectangle(0, 61, 640, 419);
do
{
if(wcscmp(name_cust,p->god.name)== 0)
{
nn++;
outtextxy(axisx,axisy,_T("|顾客序号|顾客名称|顾客等级|交易额"));
axisy += 25;
if(p->god.sale_amount<100)
{
grade=0;
}
else if((p->god.sale_amount>=100)&&(p->god.sale_amount<1000))
{
grade=1;
}
else if((p->god.sale_amount>=1000)&&(p->god.sale_amount<2000))
{
grade=2;
}
else grade=3;
wsprintf(num,_T("%d"),p->god.number);
wsprintf(grades, _T("%d"), grade);
wsprintf(salemount, _T("%d"), p->god.sale_amount);
outtextxy(axisx, axisy, num);
axisx += 30;
outtextxy(axisx, axisy, p->god.name);
axisx += 100;
outtextxy(axisx, axisy, grades);
axisx += 30;
outtextxy(axisx, axisy, salemount);
axisx += 50;
axisy += 25;
axisx = 140;
}
p=p->next;
}
while(p!=NULL);
}
}
}
else if(a==2)
{
for(i=0;i<temp;i++)
{
InputBox(name_cust, 10, L"请输入搜索顾客名称");
num_cust = _wtoi(name_cust);
if(head_cust!=NULL)
{
p=head_cust;
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
do
{
if(p->god.number==num_cust)
{
nn++;
outtextxy(axisx, axisy, _T("|顾客序号|顾客名称|顾客等级|交易额"));
axisy += 25;
if(p->god.sale_amount<100)
{
grade=0;
}
else if((p->god.sale_amount>=100)&&(p->god.sale_amount<1000))
{
grade=1;
}
else if((p->god.sale_amount>=1000)&&(p->god.sale_amount<2000))
{
grade=2;
}
else grade=3;
wsprintf(num, _T("%d"), p->god.number);
wsprintf(grades, _T("%d"), grade);
wsprintf(salemount, _T("%d"), p->god.sale_amount);
outtextxy(axisx, axisy, num);
axisx += 15;
outtextxy(axisx, axisy, p->god.name);
axisx += 15;
outtextxy(axisx, axisy, grades);
axisx += 15;
outtextxy(axisx, axisy, salemount);
axisx += 15;
axisy += 25;
}
p=p->next;
}
while(p!=NULL);
}
}
}
if (nn == 0) {
clearrectangle(0, 61, 640, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r1 = { 140,160,400,320 };
drawtext(_T("未查询到用户!!!"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
InputBox(s, 10,L"如果返回上一级请输入1,如果直接退出系统请输入2");
ss = _wtoi(s);
if(ss==1)showorchange_customer();
else if(ss==2)exit(0);
}
void search_customer_mohu() {
struct Customer_list* head_cust, * p;
int i, temp, a, grade,tmp, ss, nn = 0;//temp为要搜索顾客数目,num_cust为要搜索的顾客标号
wchar_t name_cust[20];//要搜索顾客姓名
wchar_t shortname[20];
wchar_t s[15];
wchar_t num[15];
wchar_t grades[15];
wchar_t salemount[15];
int axisy = 80;
int axisx = 140;
head_cust = look_customer();
InputBox(s, 10, L"请输入要搜索的人数");
temp = _wtoi(s);
for (i = 0; i < temp; i++)
{
InputBox(name_cust, 10, L"请输入要搜索的部分名称");
int n = wcslen(name_cust);
if (head_cust != NULL)
{
p = head_cust;
int m = wcslen(p->god.name);
for (int item = 0; item <= m - n;item+=2) {
tmp = 0;
for (int t = item; t < item + n; t++) {
shortname[tmp] = p->god.name[t];
tmp += 1;
}
shortname[tmp] = '\0';
if (wcscmp(name_cust, shortname) == 0)
{
outtextxy(axisx, axisy, _T("|顾客序号|顾客名称|顾客等级|交易额"));
axisy += 40;
if (p->god.sale_amount < 100)
{
grade = 0;
}
else if ((p->god.sale_amount >= 100) && (p->god.sale_amount < 1000))
{
grade = 1;
}
else if ((p->god.sale_amount >= 1000) && (p->god.sale_amount < 2000))
{
grade = 2;
}
else grade = 3;
wsprintf(num, _T("%d"), p->god.number);
wsprintf(grades, _T("%d"), grade);
wsprintf(salemount, _T("%d"), p->god.sale_amount);
outtextxy(axisx, axisy, num);
axisx += 30;
outtextxy(axisx, axisy, p->god.name);
axisx += 100;
outtextxy(axisx, axisy, grades);
axisx += 30;
outtextxy(axisx, axisy, salemount);
axisx += 50;
axisy += 40;
axisx = 140;
break;
}
}
p = p->next;
}
}
InputBox(s, 10, L"如果返回上一级请输入1,如果直接退出系统请输入2");
ss = _wtoi(s);
if (ss == 1)showorchange_customer();
else if (ss == 2) exit(0);
}
void save_Customer(void)//用户第一次进行数据录入
{
//该程序为第一次录入顾客信息时所使用的函数
FILE *fp;//建立文件指针
struct Customer cust[100];//建立顾客信息结构体数组,将信息读入文件之后在读出到数组进行排序
//Customer cust1[5];
int i,num_cust,ss;//后者为顾客数目
wchar_t name_cust[20];
wchar_t s[15];
wchar_t num[15];
wchar_t salemount[15];
InputBox(s, 10, L"请输入要录入的人数");
num_cust = _wtoi(s);
for(i=0;i<num_cust;i++)//建立循环
{
InputBox(cust[i].name, 10, L"请输入顾客姓名");
InputBox(num, 10, L"请输入顾客的编号");
InputBox(salemount, 10, L"请输入顾客的交易额");
cust[i].number = _wtoi(num);
cust[i].sale_amount = _wtoi(salemount);
}
//将信息导入文件
if((fp=fopen("customer_information.dat","ab"))==NULL)//打开磁盘文件
{
clearrectangle(101, 61, 538, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r = { 140,160,400,320 };
drawtext(_T("系统出错!!!!!!!!!"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
exit(0);
}
for(i=0;i<num_cust;i++)
{
fwrite(&cust[i],sizeof(cust[i]),1,fp);//向文件中读入数据
}
memset(cust,0,sizeof(cust));//将cust数组中的数据清空,再次利用
fclose(fp);
clearrectangle(101, 61, 538, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r = { 140,160,400,320 };
drawtext(_T("录入成功"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
InputBox(s, 10, L"如果返回上一级请输入1,如果直接退出系统请输入2");
ss = _wtoi(s);
if(ss==1)showorchange_customer();
else if(ss==2) exit(0);
}
void add_customer()//在文件中添加数据
{
FILE *fp;
struct Customer cust[50];
int i,num_cust,ss;
wchar_t name_cust[20];
wchar_t s[15];
wchar_t num[15];
wchar_t salemount[15];
InputBox(s, 10, L"请输入要录入的人数");
num_cust = _wtoi(s);
for(i=0;i<num_cust;i++)//建立循环
{
InputBox(cust[i].name, 10, L"请输入顾客姓名");
InputBox(num, 10, L"请输入顾客的编号");
InputBox(salemount, 10, L"请输入顾客的交易额");
cust[i].number = _wtoi(num);
cust[i].sale_amount = _wtoi(salemount);
}
if((fp=fopen("customer_information.dat","ab"))==NULL)//打开磁盘文件
{
clearrectangle(101, 61, 538, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r = { 140,160,400,320 };
drawtext(_T("系统出错!!!!!!!!!"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
exit(0);
}
for(i=0;i<num_cust;i++)
{
fwrite(&cust[i],sizeof(cust[i]),1,fp);//向文件中读入数据
}
memset(cust,0,sizeof(cust));//将cust数组中的数据清空,再次利用
fclose(fp);
clearrectangle(101, 61, 538, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r = { 140,160,400,320 };
drawtext(_T("录入成功"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
InputBox(s, 10, L"如果返回上一级请输入1,如果直接退出系统请输入2");
ss = _wtoi(s);
if(ss==1)showorchange_customer();
else if(ss==2) exit(0);
}
void revise1()//修改用户信息
{
FILE* fp;
int ss;
//char name[20];
int num_cha;
struct Customer cust_t;
fp = fopen("customer_information.dat","rb+");
wchar_t name_cust[20];
wchar_t s[15];
wchar_t num[15];
wchar_t salemount[15];
InputBox(s, 10, L"请输入要修改顾客的编号");
num_cha = _wtoi(s);
//printf("11111");
while(fread(&cust_t,sizeof(cust_t),1,fp) != 0)
{
//printf("11111");
if(cust_t.number==num_cha){
fseek(fp,0-sizeof(cust_t),SEEK_CUR);
InputBox(cust_t.name, 10, L"请输入顾客姓名");
InputBox(num, 10, L"请输入顾客的编号");
InputBox(salemount, 10, L"请输入顾客的交易额");
cust_t.number = _wtoi(num);
cust_t.sale_amount = _wtoi(salemount);
fwrite(&cust_t,sizeof(cust_t),1,fp);
break;
}
}
fclose(fp);
clearrectangle(101, 61, 538, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
RECT r = { 140,160,400,320 };
drawtext(_T("录入成功"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
InputBox(s, 10, L"如果返回上一级请输入1,如果直接退出系统请输入2");
ss = _wtoi(s);
if(ss==1)showorchange_customer();
else if(ss==2) exit(0);
}
void del1(void)//删除用户数据
{
FILE *fp,*fq;
int ss;
fp = fopen("customer_information.dat","rb");
fq = fopen("data.dat", "wb");
wchar_t name[20];
wchar_t s[15];
struct Customer cust_t;
InputBox(name, 10, L"请输入要删除的顾客姓名");
while(fread(&cust_t,sizeof(cust_t),1,fp) != 0)
{
if(wcscmp(cust_t.name,name) != 0){
fwrite(&cust_t, sizeof(cust_t), 1, fq);
}
}
fclose(fp);
fclose(fq);
remove("customer_information.dat");
rename("data.dat", "customer_information.dat");
clearrectangle(101, 61, 538, 419);
RECT r = { 140,160,400,320 };
drawtext(_T("录入成功"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
InputBox(s, 10, L"如果返回上一级请输入1,如果直接退出系统请输入2");
ss = _wtoi(s);
if(ss==1)showorchange_customer();
else if(ss==2) exit(0);
}
void show_customer(void)
{
struct Customer_list *look,*p;
int ss;
look=NULL;
look=look_customer();
int grade=0;
wchar_t num[15];
wchar_t s[15];
wchar_t grades[15];
wchar_t salemount[15];
int axisy = 80;
int axisx = 140;
p=NULL;
clearrectangle(101, 61, 538, 419);
IMAGE background;
loadimage(&background, _T("E:\\计算机练习\\小型超市\\背景.jpg"));
putimage(0, 0, &background);
setbkmode(TRANSPARENT);
if(look!=NULL)
{