-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.cpp
1509 lines (1276 loc) · 36.9 KB
/
User.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
#include"User.h"
User::User() { userState = 1; balance = 0.0; };
User::User(string userID, string username, string password, string phoneNumber, string address, double balance, int userState) {
this->userID = userID;
this->username = username;
this->password = password;
this->phoneNumber = phoneNumber;
this->address = address;
this->balance = balance;
this->userState = userState;
};
User::User(vector<string> vcstr) {
//用户ID,用户名,密码,联系方式,地址,钱包余额,用户状态
//U001, 南大, 123456, 12345678, 仙林大道163号, 1024.0, 正常
// double int
balance = 0.0;
userState = 1;
int i = 0;
for (i; i < 7; ++i) {
switch (i)
{
case 0:
userID = vcstr.at(i);
break;
case 1:
username = vcstr.at(i);
break;
case 2:
password = vcstr.at(i);
break;
case 3:
phoneNumber = vcstr.at(i);
break;
case 4:
address = vcstr.at(i);
break;
case 5:
{
balance = 0.0;
//balance
string blcstr = vcstr.at(i);
balance = stod(blcstr);
//balance = vcstr.at(i);
}
break;
case 6:
{
userState = 1;
//state
string usstr = vcstr.at(i); // 传入的是 正常/封禁
if (usstr == "正常") {
userState = 1;
}
if (usstr == "封禁") {
userState = 0;
}
//userState = vcstr.at(i);
}
break;
default:
break;
}
}
};
//User::User(const User& cpyuser) {};
//----------------------用户函数
void User::showUSERMenu() {
cout << "——————现在处于用户模式——————" << endl;
cout << "============================================================" << endl;
cout << "1.我是买家 2.我是卖家 3.个人信息管理 4.聊天室 5.退出登录" << endl;
cout << "============================================================" << endl;
};
void User::Module_BUYER(int& numbgoods, int& numborder, vector <User*>& userVec, vector<Goods*>& gdvec, vector<Order*>& orvec) {
Buyer n_buyer;
n_buyer.userID = this->userID;
//先进行清屏,然后用户菜单展示
system("cls");
//用来储存用户选项
string choicebb;
bool judge = true;
while (judge) {
n_buyer.showBUYERMenu();
cout << "输入选项:";
cin.sync();
getline(cin, choicebb);
if (size(choicebb) > 1) {
cout << "输入有误!请重新输入!!" << endl;
WarmSound();
system("pause");
system("cls");
continue;
}
switch (choicebb[0])
{
case '1': //查看商品列表(只能看到在售)
n_buyer.viewBGOODS(gdvec);
break;
case '2': //购买商品
n_buyer.buyGOODS(numbgoods, numborder, userVec, gdvec, orvec);
break;
case '3': //搜索商品
n_buyer.searchGOODS(gdvec);
break;
case '4': //查看历史订单
n_buyer.viewBORDER(orvec);
break;
case '5': //查看商品详细信息
n_buyer.detailGOODS(gdvec);
break;
case '6': //返回用户主界面
n_buyer.exitBUYER();
judge = false;
break;
default:
WarmSound();
cout << "输入有误!请重新输入!!" << endl;
system("pause");
system("cls"); //清屏
break;
}
}
};
void User::Module_SELLER(int& numbgoods, vector<Goods*>& gdvec, vector<Order*>& orvec) {
Seller n_seller;
n_seller.userID = this->userID;
//先进行清屏,然后用户菜单展示
system("cls");
//用来储存用户选项
string choicess;
bool judge = true;
while (judge) {
n_seller.showSELLERMenu();
cout << "输入选项:";
cin.sync();
getline(cin, choicess);
if (size(choicess) > 1) {
WarmSound();
cout << "输入有误!请重新输入!!" << endl;
system("pause");
system("cls");
continue;
}
switch (choicess[0])
{
case '1': //发布商品
n_seller.publishGOODS(numbgoods, gdvec);
break;
case '2': //查看发布商品
n_seller.viewSGOODS(userID, gdvec);
break;
case '3': //修改商品信息
n_seller.modifyGOODS(gdvec);
break;
case '4': //下架商品
n_seller.removeGOODS(gdvec);
break;
case '5': //查看历史订单
n_seller.viewSORDER(userID, orvec);
break;
case '6': //返回用户主界面
n_seller.exitSELLER();
judge = false;
break;
default:
WarmSound();
cout << "输入有误!请重新输入!!" << endl;
system("pause");
system("cls"); //清屏
break;
}
}
};
//外面PL的switch语句中已经有保存函数
void User::infoManageUSER(vector<User*> vec, vector<Order*>& orvec) {
//先进行清屏,然后用户菜单展示
system("cls");
//用来储存用户选项
string choiceii;
bool judge = true;
while (judge) {
this->showINFOMenu();
cout << "输入选项:";
cin.sync();
getline(cin, choiceii);
if (size(choiceii) > 1) {
WarmSound();
cout << "输入有误!请重新输入!!" << endl;
system("pause");
system("cls");
continue;
}
switch (choiceii[0])
{
case '1': //查看信息
this->GetUserinfo(orvec);
break;
case '2': //修改信息
this->ModifyUserinfo(vec);
break;
case '3': //充值
this->Topup_Userbalance();
break;
case '4': //返回用户主界面
this->exitINFO();
judge = false;
break;
default:
WarmSound();
cout << "输入有误!请重新输入!!" << endl;
system("pause");
system("cls"); //清屏
break;
}
}
};
void User::exitUSER() {
ExitSound();
cout << "欢迎下次使用!!" << endl;
system("pause");
system("cls");
return;
};
//---------------------买家菜单
//买家菜单展示
void Buyer::showBUYERMenu() {
cout << "—————————— 现在处于用户买家模式 ——————————" << endl;
cout << "============================================================================================" << endl;
cout << "1.查看商品列表 2.购买商品 3.搜索商品 4.查看历史订单 5.查看商品详细信息 6.返回用户主界面" << endl;
cout << "============================================================================================" << endl;
};
//查看商品列表(只能看到在售)
void Buyer::viewBGOODS(vector<Goods*>& gdvec) {
SearchSound();
//SSSQQQLLL
string sqlstr = SQLshow_goods(BUYER, this->userID);
//analySQL(sqlstr1);
cout << endl;
cout << "************************************************************************************************************" << endl;
cout << left << setw(20) << "商品ID" << setw(20) << "名称" << setw(20) << "价格" << setw(20)
<< "上架时间" << setw(20) << "卖家ID" << endl;
for (vector<Goods*>::iterator it = gdvec.begin(); it != gdvec.end(); it++) {
if ((*it)->state == "销售中") {
cout << left << setw(20) << (*it)->commodityID << setw(20)
<< (*it)->commodityName << setw(20)
<< (*it)->price << setw(20)
<< (*it)->addedDate << setw(20)
<< (*it)->sellerID << endl;
}
}
cout << "************************************************************************************************************" << endl;
cout << endl;
system("pause");
system("cls");
};
//购买商品
void Buyer::buyGOODS(int& numbgoods, int& numborder, vector <User*>& usvec, vector<Goods*>& gdvec, vector<Order*>& orvec) {
//利用iterator找到商品对应的买家
vector<User*>::iterator bt = usvec.begin();
for (bt; bt != usvec.end(); bt++) {
if (this->userID == (*bt)->userID) break;
}
cout << "请输入商品ID: ";
string gID;
cin.sync();
getline(cin, gID);
SearchSound();
//利用iterator找到商品所在位置
vector<Goods*>::iterator it = gdvec.begin();
for (it; it != gdvec.end(); it++) {
if ((*it)->commodityID == gID && (*it)->state == "销售中") break;
}
if (it == gdvec.end()) {
cout << "无此商品!!" << endl;
system("pause");
system("cls");
return;
}
//找到后
cout << "请输入数量: ";
string gnumb;
cin.sync();
getline(cin, gnumb);
//判断输入是否为数字
if (!isNumber(gnumb)) {
WarmSound();
cout << "输入有误!!购买失败!!" << endl;
system("pause");
system("cls");
return;
}
//判断是否为整数
int k = 0;
for (k; k < gnumb.length(); k++) {
if (gnumb[k] == '.') break;
}
if (gnumb.length() != k) {
WarmSound();
cout << "输入数量不是整数!!购买失败!!" << endl;
system("pause");
system("cls");
return;
}
//判断商品数量够不够
if (stoi(gnumb) > stoi((*it)->number)) { //库存不足的情况
WarmSound();
cout << "没有足够库存!!" << endl;
system("pause");
system("cls");
return;
}
//交易额
double prcsum = stoi(gnumb) * stod((*it)->price);
//判断交易额与买家余额关系
if (prcsum > (*bt)->balance) {
WarmSound();
cout << "没有足够余额!!" << endl;
system("pause");
system("cls");
return;
}
/////////////////////获取时间
struct tm* tm_ptr;
time_t the_time;
(void)time(&the_time);
tm_ptr = gmtime(&the_time);
int year = tm_ptr->tm_year + 1900;
int month = tm_ptr->tm_mon + 1;
int day = tm_ptr->tm_mday;
string theTime = to_string(year) + "-" + to_string(month) + "-" + to_string(day);
/////////////////////////////////
//SSSQQQLLL
string sqlstr1 = SQLbuy_goodsOrder(ORDERIDback(numborder + 1), (*it)->commodityID, (*it)->price, gnumb, theTime, (*it)->sellerID, this->userID);
string sqlstr2 = SQLbuy_goodsGoods((*it)->commodityID, gnumb);
//analySQL(sqlstr1);
//analySQL(sqlstr2);
//商品够并且买家余额足够,生成订单
Order* order = new Order(ORDERIDback(numborder + 1), (*it)->commodityID, (*it)->price, gnumb, theTime, (*it)->sellerID, this->userID);
orvec.push_back(order);
//进行商品修改
int remainNumb = stoi((*it)->number) - stoi(gnumb);//剩余商品数量
(*it)->number = to_string(remainNumb);
//进一步修改商品状态及商品种类数
if (remainNumb == 0) {
(*it)->state = "已下架";
//SSSQQQLLL
string sqlstr3 = SQLnone_goods((*it)->commodityID);
//analySQL(sqlstr3);
}
//利用iterator找到商品对应的卖家
vector<User*>::iterator sut = usvec.begin();
for (sut; sut != usvec.end(); sut++) {
if ((*it)->sellerID == (*sut)->userID) break;
}
//进行买卖家余额变动
(*sut)->balance += prcsum;
(*bt)->balance -= prcsum;
SuccessSound();
cout << "**************************************" << endl;
cout << "**交易提醒*************************" << endl;
cout << "交易时间:" << theTime << endl;
cout << "交易单价:" << (*it)->price << endl;
cout << "交易数量:" << gnumb << endl;
cout << "交易状态:交易成功" << endl;
cout << "您的余额:" << (*bt)->balance << endl;
cout << "**************************************" << endl;
cout << endl;
saveGOOD(gdvec);
saveORDER(orvec);
system("pause");
system("cls");
};
//搜索商品(只能看到在售)
void Buyer::searchGOODS(vector<Goods*>& gdvec) {
//SSSQQQLLL
string sqlstr = SQLsearch_goods(BUYER, this->userID);
//analySQL(sqlstr1);
string gname;
cout << "请输入您要查找的商品名:";
cin.sync();
getline(cin, gname);
SearchSound();
cout << endl;
cout << "************************************************************************************************************" << endl;
cout << left << setw(20) << "商品ID" << setw(20) << "名称" << setw(20) << "价格" << setw(20)
<< "上架时间" << setw(20) << "卖家ID" << endl;
//寻找商品再vec中的位置
bool flag = false;
int i = 0;
vector<Goods*>::iterator it = gdvec.begin();
for (it; it != gdvec.end(); it++) {
//寻找字符
int fdstr = (*it)->commodityName.find(gname, 0);
//若找到,则记录当前vec下标位置,进行输出
if (fdstr < (*it)->commodityName.length() && (*it)->state == "销售中") {
cout << left << setw(20) << (*it)->commodityID << setw(20)
<< (*it)->commodityName << setw(20)
<< (*it)->price << setw(20)
<< (*it)->addedDate << setw(20)
<< (*it)->sellerID << endl;
flag = true;
}
i++;
}
//没有商品存在
if (!flag) {
cout << " 没有该商品!! " << endl;
cout << "************************************************************************************************************" << endl;
cout << endl;
system("pause");
system("cls");
return;
}
cout << "************************************************************************************************************" << endl;
cout << endl;
system("pause");
system("cls");
};
//查看历史订单
void Buyer::viewBORDER(vector<Order*>& orvec) {
SearchSound();
//SSSQQQLLL
string sqlstr = SQLshow_order(BUYER, this->userID);
//analySQL(sqlstr1);
cout << endl;
cout << "************************************************************************************************************" << endl;
cout << left << setw(20) << "订单ID" << setw(20) << "商品ID" << setw(20) << "交易单价" << setw(20)
<< "数量" << setw(20) << "交易时间" << setw(20) << "卖家ID" << setw(20) << endl;
for (vector<Order*>::iterator it = orvec.begin(); it != orvec.end(); it++) {
if ((*it)->buyerID == this->userID) {
cout << left << setw(20) << (*it)->orderID << setw(20)
<< (*it)->commodityID << setw(20)
<< (*it)->unitPrice << setw(20)
<< (*it)->number << setw(20)
<< (*it)->date << setw(20)
<< (*it)->sellerID << setw(20) << endl;
}
}
cout << "************************************************************************************************************" << endl;
cout << endl;
system("pause");
system("cls");
};
//查看商品详细信息
void Buyer::detailGOODS(vector<Goods*>& gdvec) {
cout << endl;
string gID;
cout << "请输入想要查看的商品ID:";
cin.sync();
getline(cin, gID);
SearchSound();
//SSSQQQLLL
string sqlstr = SQLdetail_goods(gID);
//analySQL(sqlstr1);
//利用iterator找到商品所在位置
vector<Goods*>::iterator it = gdvec.begin();
for (it; it != gdvec.end(); it++) {
if ((*it)->commodityID == gID && (*it)->state == "销售中") break;
}
if (it == gdvec.end()) {
cout << "无此商品!!" << endl;
system("pause");
system("cls");
return;
}
//找到商品
cout << endl;
cout << "************************************************" << endl;
cout << "商品ID:" << (*it)->commodityID << endl;
cout << "商品名称:" << (*it)->commodityName << endl;
cout << "商品价格:" << (*it)->price << endl;
cout << "上架时间:" << (*it)->addedDate << endl;
cout << "商品描述:" << (*it)->description << endl;
cout << "商品卖家: " << (*it)->sellerID << endl;
cout << "************************************************" << endl;
system("pause");
system("cls");
};
//返回用户主界面
void Buyer::exitBUYER() {
ExitSound();
system("pause");
system("cls");
};
//---------------------卖家菜单
//卖家菜单展示
void Seller::showSELLERMenu() {
cout << "———————————— 现在处于用户卖家模式 ———————————" << endl;
cout << "========================================================================================" << endl;
cout << "1.发布商品 2.查看发布商品 3.修改商品信息 4.下架商品 5.查看历史订单 6.返回用户主界面" << endl;
cout << "========================================================================================" << endl;
};
//发布商品
void Seller::publishGOODS(int& numbgoods, vector<Goods*>& gdvec) {
cout << endl << endl;
string gname;
string gprice;
string gnumb;
string gdescrib;
cout << "请输入商品名称:";
cin.sync();
getline(cin, gname);
cout << "请输入商品价值:(需要一位小数) ";
cin.sync();
getline(cin, gprice);
//判断是否为一位小数
//判断输入是否为数字
if (!isNumber(gprice)) {
WarmSound();
cout << "输入有误!!发布失败!!" << endl;
system("pause");
system("cls");
return;
}
//判断是否为保留一位小数,先找到小数点,再进行长度相减
int i = 0;
for (i; i < gprice.length(); i++) {
if (gprice[i] == '.') break;
}
if (gprice.length() - i - 1 > 1) {
//超出小数位长度
WarmSound();
cout << "输入超出小数位长度!!发布失败!!" << endl;
system("pause");
system("cls");
return;
}
cout << "请输入商品数量:";
cin.sync();
getline(cin, gnumb);
//判断输入是否为数字
if (!isNumber(gnumb)) {
WarmSound();
cout << "输入有误!!发布失败!!" << endl;
system("pause");
system("cls");
return;
}
//判断是否为整数
int k = 0;
for (k; k < gnumb.length(); k++) {
if (gnumb[k] == '.') break;
}
if (gnumb.length() != k) {
WarmSound();
cout << "输入数量不是整数!!发布失败!!" << endl;
system("pause");
system("cls");
return;
}
cout << "请输入商品描述:";
cin.sync();
getline(cin, gdescrib);
cout << endl;
cout << "请再次确定商品信息:" << endl;
cout << "*********************************************" << endl;
cout << "商品名称:" << gname << endl;
cout << "商品价格:" << gprice << endl;
cout << "商品数量:" << gnumb << endl;
cout << "商品描述:" << gdescrib << endl;
cout << "*********************************************" << endl;
cout << endl;
cout << "确定发布?(y/n)";
string judge;
cin.sync();
getline(cin, judge);
//---发布并进行文件写入
if (judge != "y") {
WarmSound();
cout << "已取消发布。" << endl;
system("pause");
system("cls");
return;
}
else {
string st = "销售中";
/////////////////////获取时间
struct tm* tm_ptr;
time_t the_time;
(void)time(&the_time);
tm_ptr = gmtime(&the_time);
int year = tm_ptr->tm_year + 1900;
int month = tm_ptr->tm_mon + 1;
int day = tm_ptr->tm_mday;
string theTime = to_string(year) + "-" + to_string(month) + "-" + to_string(day);
/////////////////////////////////
//SSSQQQLLL
string sqlstr = SQLpublish_goods(gname, gprice, gnumb, gdescrib);
//analySQL(sqlstr1);
Goods* good = new Goods(GOODSIDback(numbgoods + 1), gname, gprice, gnumb, gdescrib, this->userID, theTime, st);
gdvec.push_back(good);
numbgoods++;
//-------保存该vec,进行文件写入
saveGOOD(gdvec);
SuccessSound();
cout << "发布成功!!" << endl;
}
system("pause");
system("cls");
};
//查看发布商品
void Seller::viewSGOODS(string ID, vector<Goods*>& gdvec) {
SearchSound();
//SSSQQQLLL
string sqlstr = SQLshow_goods(SELLER, this->userID);
//analySQL(sqlstr1);
cout << endl;
cout << "************************************************************************************************************************" << endl;
cout << left << setw(20) << "商品ID" << setw(20) << "名称" << setw(20) << "价格" << setw(20)
<< "数量" << setw(20) << "上架时间" << setw(20) << "商品状态" << setw(20) << endl;
for (vector<Goods*>::iterator it = gdvec.begin(); it != gdvec.end(); it++) {
if ((*it)->sellerID == ID) {
cout << left << setw(20) << (*it)->commodityID << setw(20)
<< (*it)->commodityName << setw(20)
<< (*it)->price << setw(20)
<< (*it)->number << setw(20)
<< (*it)->addedDate << setw(20)
<< (*it)->state << setw(20) << endl;
}
}
cout << "************************************************************************************************************************" << endl;
cout << endl;
system("pause");
system("cls");
};
//修改商品信息
void Seller::modifyGOODS(vector<Goods*>& gdvec) {
cout << endl;
string gID;
string gchoose;
cout << "请输入需要修改的商品ID:";
cin.sync();
getline(cin, gID);
SearchSound();
//利用iterator找到商品所在位置
vector<Goods*>::iterator it = gdvec.begin();
for (it; it != gdvec.end(); it++) {
if ((*it)->commodityID == gID && (*it)->sellerID == this->userID) break;
}
if (it == gdvec.end()) {
cout << "无此商品!!" << endl;
system("pause");
system("cls");
return;
}
cout << "请输入需要修改的商品属性:(1.价格 2.描述) ";
cin.sync();
while (getline(cin, gchoose)) {
if (gchoose.length() > 1) {
WarmSound();
cout << "输入有误!!请重新输入!!" << endl;
cout << "请输入需要修改的商品属性:(1.价格 2.描述) ";
cin.sync();
continue;
}
if (gchoose != "1" && gchoose != "2") {
WarmSound();
cout << "输入有误!!请重新输入!!" << endl;
cout << "请输入需要修改的商品属性:(1.价格 2.描述) ";
cin.sync();
continue;
}
//修改描述
if (gchoose == "2") {
cout << "请输入修改商品的描述: ";
string desci;
cin.sync();
getline(cin, desci);
cout << "请确定商品信息无误!!" << endl;
cout << "**********************************************" << endl;
cout << "商品名称:" << gID << endl;
cout << "商品价格:" << (*it)->commodityName << endl;
cout << "商品数量:" << (*it)->price << endl;
cout << "商品描述:" << desci << endl;
cout << "**********************************************" << endl;
cout << "确定修改?(y/n) ";
string judge;
cin.sync();
getline(cin, judge);
//---修改并进行文件写入
if (judge != "y") {
WarmSound();
cout << "已取消修改。" << endl;
system("pause");
system("cls");
return;
}
else {
//SSSQQQLLL
string sqlstr = SQLmodify_goodsDescr(desci, (*it)->commodityID);
//analySQL(sqlstr1);
//进行修改
(*it)->description = desci;
saveGOOD(gdvec);
SuccessSound();
cout << "修改成功!!" << endl;
system("pause");
system("cls");
return;
}
}
//修改价格
if (gchoose == "1") {
cout << "请输入修改商品的价格:(需要一位小数) ";
string prc;
cin.sync();
getline(cin, prc);
//判断输入是否为数字
if (!isNumber(prc)) {
WarmSound();
cout << "输入有误!!修改失败!!" << endl;
system("pause");
system("cls");
return;
}
//判断是否为保留一位小数,先找到小数点,再进行长度相减
int i = 0;
for (i; i < prc.length(); i++) {
if (prc[i] == '.') break;
}
if (prc.length() - i - 1 > 1) {
//超出小数位长度
WarmSound();
cout << "输入超出小数位长度!!修改失败!!" << endl;
system("pause");
system("cls");
return;
}
cout << "请确定商品信息无误!!" << endl;
cout << "*****************************************" << endl;
cout << "商品名称:" << gID << endl;
cout << "商品价格:" << (*it)->commodityName << endl;
cout << "商品数量:" << prc << endl;
cout << "商品描述:" << (*it)->description << endl;
cout << "*****************************************" << endl;
cout << "确定修改?(y/n) ";
string judge;
cin.sync();
getline(cin, judge);
//---修改并进行文件写入
if (judge != "y") {
WarmSound();
cout << "已取消修改。" << endl;
system("pause");
system("cls");
return;
}
else {
//SSSQQQLLL
string sqlstr = SQLmodify_goodsPrice(prc, (*it)->commodityID);
//analySQL(sqlstr1);
//进行修改
(*it)->price = prc;
saveGOOD(gdvec);
SuccessSound();
cout << "修改成功!!" << endl;
system("pause");
system("cls");
return;
}
}
}
}
//下架商品
void Seller::removeGOODS(vector<Goods*>& gdvec) {
cout << endl;
string gID;
cout << "请输入需要修改的商品ID:";
cin.sync();
getline(cin, gID);
SearchSound();
//利用iterator找到商品所在位置
vector<Goods*>::iterator it = gdvec.begin();
for (it; it != gdvec.end(); it++) {
if ((*it)->commodityID == gID && (*it)->sellerID == this->userID) break;
}
if (it == gdvec.end()) {
WarmSound();
cout << "无此商品!!" << endl;
system("pause");
system("cls");
return;
}
cout << "确定下架该商品?" << endl;
cout << endl;
cout << "************************************************************************************************************************" << endl;
cout << left << setw(20) << "商品ID" << setw(20) << "名称" << setw(20) << "价格" << setw(20)
<< "上架时间" << setw(20) << "商品状态" << setw(20) << endl;
cout << left << setw(20) << (*it)->commodityID << setw(20)
<< (*it)->commodityName << setw(20)
<< (*it)->price << setw(20)
<< (*it)->addedDate << setw(20)
<< (*it)->state << setw(20) << endl;
cout << "************************************************************************************************************************" << endl;
cout << endl;
cout << "请选择:(y/n) ";
string judge;
cin.sync();
getline(cin, judge);
//---修改并进行文件写入
if (judge != "y") {
WarmSound();
cout << "已取消修改。" << endl;
system("pause");
system("cls");
return;
}
else {
//SSSQQQLLL
string sqlstr = SQLremove_goods(SELLER, (*it)->commodityID);
//analySQL(sqlstr1);
//进行修改
(*it)->state = "已下架";
saveGOOD(gdvec);
SuccessSound();
cout << "下架成功!!" << endl;
system("pause");
system("cls");
return;
}
};
//查看历史订单
void Seller::viewSORDER(string ID, vector<Order*>& orvec) {
SearchSound();
//SSSQQQLLL
string sqlstr = SQLshow_order(SELLER, this->userID);
//analySQL(sqlstr1);
cout << endl;
cout << "************************************************************************************************************************" << endl;
cout << left << setw(20) << "订单ID" << setw(20) << "商品ID" << setw(20) << "交易单价" << setw(20)
<< "数量" << setw(20) << "交易时间" << setw(20) << "买家ID" << setw(20) << endl;
for (vector<Order*>::iterator it = orvec.begin(); it != orvec.end(); it++) {
if ((*it)->sellerID == ID) {
cout << left << setw(20) << (*it)->orderID << setw(20)
<< (*it)->commodityID << setw(20)
<< (*it)->unitPrice << setw(20)
<< (*it)->number << setw(20)
<< (*it)->date << setw(20)
<< (*it)->buyerID << setw(20) << endl;
}
}
cout << "************************************************************************************************************************" << endl;
cout << endl;