diff --git a/code/sell.cpp b/code/sell.cpp index ce6c83d7359d482e9c1f1bfc3605357544e195b1..7778b85fb2eaeaabf13cb7f0ec7dcbce42c5587f 100644 --- a/code/sell.cpp +++ b/code/sell.cpp @@ -5,11 +5,12 @@ #include "sellFun.h" extern commodity commodity_head;//商品(库存)头指针 - __declspec(selectany) records *all;//总销售记录头指针 records *single;//实时销售记录头指针 bool isAllInited = false;//总销售记录头指针是否已被初始化 +FILE* fsingleRecords; + /**************************************************** * createRecordList -- 创建记录链表 * 参数:无 @@ -172,6 +173,10 @@ void printAllRecord(records *head) ****************************************************/ double sell(goods *goodsHead, records *singleRecord, int &a) { + time_t t; + struct tm* lt; + time(&t); + lt = localtime(&t); //获取当前时间 soldGoods soldGoods; double money; char salespersonName[15]; @@ -191,10 +196,6 @@ double sell(goods *goodsHead, records *singleRecord, int &a) { printf("%s(%s)正好卖没货了。\n", n->goods_Name, n->id_Number); //可以删除但还是要进货的 } - time_t t; - struct tm *lt; - time(&t); - lt = localtime(&t); //获取当前时间 addRecords(singleRecord, soldGoods, n, salespersonName, lt); //更新实时销售记录 addRecords(all, soldGoods, n, salespersonName, lt); // 更新总销售记录 return soldGoods.count * n->sell_Price; @@ -206,6 +207,30 @@ double sell(goods *goodsHead, records *singleRecord, int &a) return 0; } } +/**************************************************** + * read_In -- 将singleRecords文件中的内容读入 + * 参数:无 + * 返回值:新的总销售指针 + ****************************************************/ +records* read_In() +{ + records* q; + records* head; + records* rear; + head = (records*)malloc(sizeof(records)); + head->next = NULL; + rear = head; + q = (records*)malloc(sizeof(records)); + fsingleRecords = fopen("singleRecords.txt", "r"); + while(fscanf(fsingleRecords, "%s %lf %d年%d月%d日 %d:%d:%d\n", q->goodsName, &q->price, &q->year, &q->mon, &q->day, &q->hour, &q->min, &q->sec) != EOF) + { + q->next = NULL; + rear->next = q; + rear = q; + q = (records*)malloc(sizeof(records)); + } + return head; +} /**************************************************** * sellmain -- 销售管理主界面 @@ -216,6 +241,8 @@ int sellmain() { goods *goods = commodity_head;//货物头指针 double money1 = 0, money2 = 0, money3 = 0; + records* p1; + records* p2; int n; int a; single = createRecordList(); @@ -241,8 +268,17 @@ int sellmain() while(n > 0) { money2 = money2 + sell(goods, single, n); + n--; } + p1 = all->next; + fsingleRecords = fopen("singleRecords.txt", "a+"); + while (p1) + { + fprintf(fsingleRecords, "%s %.2lf %d年%d月%d日 %d:%d:%d\n", p1->goodsName, p1->price, p1->year, p1->mon, p1->day, p1->hour, p1->min, p1->sec); + p1 = p1->next; + } + fclose(fsingleRecords); printf("金额合计:%.2lf元。\n", money2); printf("输入顾客所付钱数:"); scanf("%lf", &money1); @@ -262,7 +298,8 @@ int sellmain() } else if(a == 3) { - printAllRecord(all); + p2 = read_In(); + printAllRecord(p2); } else if(a == 0) { @@ -270,6 +307,5 @@ int sellmain() } system("pause"); } - return 0; } \ No newline at end of file