diff --git a/code/commodity1.txt b/code/commodity1.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c3e0c272d4af3a56a2ddb3e1f682b6932186ceb --- /dev/null +++ b/code/commodity1.txt @@ -0,0 +1,12 @@ +001 apple 2020 7 14 wangyi qiang 100 5 6 2020 6 20 365 westroom +002 orange 2020 6 14 tengxun qiang 80 4 5 2020 6 10 35 westroom +003 banana 2020 7 5 sanxing qiang 100 9 10 2020 7 2 15 westroom +004 pear 2020 6 30 xiaomi qiang 90 5 6 2020 6 20 90 westroom +005 watermelon 2020 7 14 tengxun qiang 100 6 7 2020 6 15 90 eastroom +006 peach 2020 7 12 huawei qiang 100 3 5 2020 7 10 5 eastroom +007 pen 2020 7 14 zhongxing qiang 45 1 2 2020 5 11 365 eastroom +008 camera 2020 7 14 sanxing gift 10 500 650 2020 7 10 365 west-1A +009 computer 2020 6 10 huawei gift 30 3000 4000 2020 6 1 1000 west-1B +010 audio 2020 7 14 xiaomi buy 80 100 150 2020 7 5 180 east-1A +011 phone 2020 6 2 huawei buy 5 5000 6000 2020 6 1 700 east-1B +012 MP3 2020 7 14 zhongxing buy 100 50 70 2020 6 20 365 east-1C \ No newline at end of file diff --git a/code/purchase.cpp b/code/purchase.cpp new file mode 100644 index 0000000000000000000000000000000000000000..efa919de362c3accab9f125adeaf7b196956fc56 --- /dev/null +++ b/code/purchase.cpp @@ -0,0 +1,780 @@ +#include +#include +#include +#include "purchase.h" + +suppliers suppliers_head; +suppliers suppliers_tail; +commodity commodity_head; +commodity commodity_tail; + +// 构造一个空的带头结点的进货双向链表 +Status InitList_purchase(purchase &head, purchase &tail) +{ + head = (purchase)malloc(sizeof(purchase_information)); + if(!head) + exit(OVERFLOW); + head->next = NULL; + tail = head; + return OK; +} + +// 在进货链表尾部添加一个进货结点 +Status ListAdd_purchase(purchase &tail, char number[], char name[], char source[], char channel[], int quantity, double price, date time) +{ + purchase p; + p = (purchase)malloc(sizeof(purchase_information)); + if(!p) + exit(OVERFLOW); + strcpy(p->number, number); + strcpy(p->name, name); + strcpy(p->source, source); + strcpy(p->channel, channel); + p->quantity = quantity; + p->price = price; + p->time.year = time.year; + p->time.month = time.month; + p->time.day = time.day; + p->pre = tail; + p->next = NULL; + tail->next = p; + tail = p; + return OK; +} + +// 在窗口中录出进货信息 +Status Printf_purchas(purchase &p) +{ + printf("%s %s %s %s %d %.2lf %d %d %d\n", + p->number, p->name, p->source, p->channel, p->quantity, p->price, p->time.year, p->time.month, p->time.day); + return OK; +} + +// 在文件中导出进货信息 +Status Fprintf_purchas(purchase &p) +{ + FILE *fp; + fp = fopen("suppliers2.txt", "a"); + if(fp == NULL) + { + printf("Can not open the file!"); + exit(INFEASIBLE); + } + fprintf(fp, "%s %s %s %s %d %lf %d %d %d\n", + p->number, p->name, p->source, p->channel, p->quantity, p->price, p->time.year, p->time.month, p->time.day); + fclose(fp); + return OK; +} + +// 遍历进货链表,依次对每个节点调用函数visit(),一旦visit()失败,则操作失败 +Status TraverseList_purchas(purchase &head, Status(*visit)(purchase &p)) +{ + purchase p; + p = head->next; + if(!p) + { + printf("暂无进货信息!\n"); + return OK; + } + while(p) + { + if(!visit(p)) + { + printf("进货信息遍历失败!\n"); + return ERROR; + } + p = p->next; + } + return OK; +} + +// 在窗口中录出进货链表 +Status DisplayList_purchas(purchase &head) +{ + TraverseList_purchas(head, Printf_purchas); + return OK; +} + +// 在文件中导出进货链表 +Status FdisplayList_purchas(purchase &head) +{ + TraverseList_purchas(head, Fprintf_purchas); + return OK; +} + +// 构造一个空的带头结点的供应商双向链表 +Status InitList_suppliers(suppliers &head, suppliers &tail) +{ + head = (suppliers)malloc(sizeof(suppliers_information)); + if(!head) + exit(OVERFLOW); + head->next = NULL; + tail = head; + InitList_purchase(head->purchase_head, head->purchase_tail); + return OK; +} + +// 查找供应商公司名称与关键字匹配的供应商结点 +Status ListHandle_suppliers(suppliers &head, suppliers &p, char corporate_name[]) +{ + p = head->next; + while(p) + { + if(strcmp(p->corporate_name, corporate_name) == 0) + { + break; + } + p = p->next; + } + return OK; +} + +// 在供应商链表尾部添加一个供应商结点 +Status ListAdd_suppliers(suppliers &tail, char corporate_name[], char main_business[], char main_products[], char brand[], char contact_person[], char telephone[]) +{ + suppliers p; + p = (suppliers)malloc(sizeof(suppliers_information)); + if(!p) + exit(OVERFLOW); + strcpy(p->corporate_name, corporate_name); + strcpy(p->main_business, main_business); + strcpy(p->main_products, main_products); + strcpy(p->brand, brand); + strcpy(p->contact_person, contact_person); + strcpy(p->telephone, telephone); + InitList_purchase(p->purchase_head, p->purchase_tail); + p->pre = tail; + p->next = NULL; + tail->next = p; + tail = p; + return OK; +} + +// 从窗口中录入供应商信息 +Status Add_suppliers(suppliers &head, suppliers &tail) +{ + suppliers p; + char corporate_name[MAX_SIZE]; + char main_business[MAX_SIZE]; + char main_products[MAX_SIZE]; + char brand[MAX_SIZE]; + char contact_person[MAX_SIZE]; + char telephone[MAX_SIZE]; + printf("请依次输入“公司名称、主营业务、主营产品、品牌、联络人、电话”,以空格作为结尾。\n"); + while(1) + { + scanf("%s %s %s %s %s %s", corporate_name, main_business, main_products, brand, contact_person, telephone); + ListHandle_suppliers(head, p, corporate_name); + if(p) + { + printf("公司名称为 %s 的供应商已存在,无需添加。\n", p->corporate_name); + if(getchar() == ' ') + { + break; + } + else + continue; + } + ListAdd_suppliers(tail, corporate_name, main_business, main_products, brand, contact_person, telephone); + if(getchar() == ' ') + { + break; + } + } + printf("供应商信息录入成功!\n"); + return OK; +} + +// 从文件中导入供应商信息 +Status Fadd_suppliers(suppliers &head, suppliers &tail) +{ + FILE *fp; + suppliers p; + char corporate_name[MAX_SIZE]; + char main_business[MAX_SIZE]; + char main_products[MAX_SIZE]; + char brand[MAX_SIZE]; + char contact_person[MAX_SIZE]; + char telephone[MAX_SIZE]; + fp = fopen("suppliers1.txt", "r"); + if(fp == NULL) + { + printf("Can not open the file!"); + exit(INFEASIBLE); + } + while(1) + { + fscanf(fp, "%s %s %s %s %s %s", corporate_name, main_business, main_products, brand, contact_person, telephone); + ListHandle_suppliers(head, p, corporate_name); + if(p) + { + printf("公司名称为 %s 的供应商已存在,无需添加!\n", p->corporate_name); + if(fgetc(fp) == ' ') + { + break; + } + else + continue; + } + ListAdd_suppliers(tail, corporate_name, main_business, main_products, brand, contact_person, telephone); + if(fgetc(fp) == ' ') + { + break; + } + } + fclose(fp); + printf("供应商信息导入成功!\n"); + return OK; +} + +// 删除供应商公司名称与关键字匹配的供应商结点 +Status ListDelete_suppliers(suppliers &head) +{ + suppliers p; + char corporate_name[MAX_SIZE]; + printf("请输入要删除供应商的公司名称:\n"); + scanf("%s", corporate_name); + ListHandle_suppliers(head, p, corporate_name); + if(!p) + { + printf("未找到公司名称为 %s 的供应商,无需删除!\n"); + return ERROR; + } + if(p->next) + { + p->next->pre = p->pre; + } + p->pre->next = p->next; + free(p); + printf("供应商信息删除成功!\n"); + return OK; +} + +// 修改供应商公司名称与关键字匹配的供应商结点 +Status ListAlter_suppliers(suppliers &head, suppliers &tail) +{ + suppliers p; + char corporate_name[MAX_SIZE]; + char main_business[MAX_SIZE]; + char main_products[MAX_SIZE]; + char brand[MAX_SIZE]; + char contact_person[MAX_SIZE]; + char telephone[MAX_SIZE]; + char option; + bool flag = false; + printf("请输入要修改供应商的公司名称:\n"); + scanf("%s", corporate_name); + getchar(); + ListHandle_suppliers(head, p, corporate_name); + if(!p) + { + printf("未找到公司名称为 %s 的供应商,是否添加?(y/n)\n", corporate_name); + while(!flag) + { + scanf("%c", &option); + switch(option) + { + case 'y': + printf("请依次输入“主营业务、主营产品、品牌、联络人、电话”\n"); + scanf("%s %s %s %s %s", main_business, main_products, brand, contact_person, telephone); + ListAdd_suppliers(tail, corporate_name, main_business, main_products, brand, contact_person, telephone); + printf("供应商信息添加成功!\n"); + return OK; + case 'n': + flag = true; + break; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return ERROR; + } + printf("请依次输入“公司名称、主营业务、主营产品、品牌、联络人、电话”\n"); + scanf("%s %s %s %s %s %s", corporate_name, main_business, main_products, brand, contact_person, telephone); + strcpy(p->corporate_name, corporate_name); + strcpy(p->main_business, main_business); + strcpy(p->main_products, main_products); + strcpy(p->brand, brand); + strcpy(p->contact_person, contact_person); + strcpy(p->telephone, telephone); + printf("供应商信息修改成功!\n"); + return OK; +} + +// 查询供应商公司名称与关键字匹配的供应商结点供应商信息 +Status ListSearch_suppliers(suppliers &head, suppliers &tail) +{ + suppliers p; + char corporate_name[MAX_SIZE]; + char main_business[MAX_SIZE]; + char main_products[MAX_SIZE]; + char brand[MAX_SIZE]; + char contact_person[MAX_SIZE]; + char telephone[MAX_SIZE]; + char option; + bool flag = false; + printf("请输入要查询供应商的公司名称:\n"); + scanf("%s", corporate_name); + getchar(); + ListHandle_suppliers(head, p, corporate_name); + if(!p) + { + printf("未找到公司名称为 %s 的供应商,是否添加?(y/n)\n", corporate_name); + while(!flag) + { + scanf("%c", &option); + switch(option) + { + case 'y': + printf("请依次输入“主营业务、主营产品、品牌、联络人、电话”\n"); + scanf("%s %s %s %s %s", main_business, main_products, brand, contact_person, telephone); + ListAdd_suppliers(tail, corporate_name, main_business, main_products, brand, contact_person, telephone); + printf("供应商信息添加成功!\n"); + return OK; + case 'n': + flag = true; + break; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return ERROR; + } + Printf_suppliers(p); + return OK; +} + +// 在窗口中录出供应商信息 +Status Printf_suppliers(suppliers &p) +{ + printf("%s %s %s %s %s %s\n", p->corporate_name, p->main_business, p->main_products, p->brand, p->contact_person, p->telephone); + DisplayList_purchas(p->purchase_head); + return OK; +} + +// 在文件中导出供应商信息 +Status Fprintf_suppliers(suppliers &p) +{ + FILE *fp; + fp = fopen("suppliers2.txt", "a"); + if(fp == NULL) + { + printf("Can not open the file!"); + exit(INFEASIBLE); + } + fprintf(fp, "%s %s %s %s %s %s\n", p->corporate_name, p->main_business, p->main_products, p->brand, p->contact_person, p->telephone); + fclose(fp); + FdisplayList_purchas(p->purchase_head); + return OK; +} + +// 遍历供应商链表,依次对每个节点调用函数visit(),一旦visit()失败,则操作失败 +Status TraverseList_suppliers(suppliers &head, Status(*visit)(suppliers &p)) +{ + suppliers p; + p = head->next; + if(!p) + { + printf("暂无供应商信息!\n"); + return OK; + } + while(p) + { + if(!visit(p)) + { + printf("供应商信息遍历失败!\n"); + return ERROR; + } + p = p->next; + } + return OK; +} + +// 在窗口中录出供应商链表 +Status DisplayList_suppliers(suppliers &head) +{ + TraverseList_suppliers(head, Printf_suppliers); + printf("供应商信息录出成功!\n"); + return OK; +} + +// 在文件中导出供应商链表 +Status FdisplayList_suppliers(suppliers &head) +{ + TraverseList_suppliers(head, Fprintf_suppliers); + printf("供应商信息导出成功!\n"); + return OK; +} + +// 构造一个空的带头结点的商品向链表 +Status InitList_commodity(commodity &head, commodity &tail) +{ + head = (commodity)malloc(sizeof(goods)); + if(!head) + exit(OVERFLOW); + head->next = NULL; + tail = head; + return OK; +} + +// 在商品链表尾部添加一个商品结点 +Status ListAdd_commodity(commodity &tail, char id_Number[], char goods_Name[], char place[], + double buy_Price, double sell_Price, int remain_Number, int quality_Date, date purchase_Date, date produce_Date) +{ + commodity p; + p = (commodity)malloc(sizeof(goods)); + if(!p) + exit(OVERFLOW); + strcpy(p->id_Number, id_Number); + strcpy(p->goods_Name, goods_Name); + strcpy(p->place, place); + p->buy_Price = buy_Price; + p->sell_Price = sell_Price; + p->remain_Number = remain_Number; + p->quality_Date = quality_Date; + p->purchase_Date.year = purchase_Date.year; + p->purchase_Date.month = purchase_Date.month; + p->purchase_Date.day = purchase_Date.day; + p->produce_Date.year = produce_Date.year; + p->produce_Date.month = produce_Date.month; + p->produce_Date.day = produce_Date.day; + p->pre = tail; + p->next = NULL; + tail->next = p; + tail = p; + return OK; +} + +// 查找商品编号与关键字匹配的供应商结点 +Status ListHandle_commodity(commodity &head, commodity &p, char id_Number[]) +{ + p = head->next; + while(p) + { + if(strcmp(p->id_Number, id_Number) == 0) + { + break; + } + p = p->next; + } + return OK; +} + +// 从窗口中录入商品信息 +Status Add_commodity(commodity &head, commodity &tail, suppliers &suppliers_head, suppliers &suppliers_tail) +{ + commodity p; + suppliers suppliers_p; + char id_Number[20]; + char goods_Name[20]; + char place[20]; + char source[MAX_SIZE]; + char channel[MAX_SIZE]; + char main_business[MAX_SIZE]; + char main_products[MAX_SIZE]; + char brand[MAX_SIZE]; + char contact_person[MAX_SIZE]; + char telephone[MAX_SIZE]; + double buy_Price; + double sell_Price; + int quantity; + int quality_Date; + date purchase_Date; + date produce_Date; + bool flag = false; + printf("请依次输入“商品编号、商品名称、进货日期、进货来源(供应商)、进货渠道、进货数量、商品进价、商品售价、生产日期、保质期、库存位置”,以空格作为结尾。\n"); + while(1) + { + scanf("%s %s %d %d %d %s %s %d %lf %lf %d %d %d %d %s", + id_Number, goods_Name, &purchase_Date.year, &purchase_Date.month, &purchase_Date.day, source, channel, &quantity, + &buy_Price, &sell_Price, &produce_Date.year, &produce_Date.month, &produce_Date.day, &quality_Date, place); + if(getchar() == ' ') + { + flag = true; + } + ListHandle_commodity(head, p, id_Number); + if(p) + { + if(strcmp(p->goods_Name, goods_Name) != 0 || strcmp(p->place, place) != 0 + || p->buy_Price != buy_Price || p->sell_Price != sell_Price || p->quality_Date != quality_Date + || p->purchase_Date.year != purchase_Date.year || p->purchase_Date.month != purchase_Date.month || p->purchase_Date.day != purchase_Date.day + || p->produce_Date.year != produce_Date.year || p->produce_Date.month != produce_Date.month || p->produce_Date.day != produce_Date.day) + { + printf("编号 %s 已存在商品信息\n", id_Number); + return ERROR; + } + p->remain_Number += quantity; + } + else + ListAdd_commodity(tail, id_Number, goods_Name, place, buy_Price, sell_Price, quantity, quality_Date, purchase_Date, produce_Date); + ListHandle_suppliers(suppliers_head, suppliers_p, source); + if(!suppliers_p) + { + printf("未找到公司名称为 %s 的供应商,请先添加!\n", source); + printf("请依次输入“主营业务、主营产品、品牌、联络人、电话”\n"); + scanf("%s %s %s %s %s", main_business, main_products, brand, contact_person, telephone); + ListAdd_suppliers(suppliers_tail, source, main_business, main_products, brand, contact_person, telephone); + printf("供应商信息添加成功!\n"); + ListHandle_suppliers(suppliers_head, suppliers_p, source); + } + ListAdd_purchase(suppliers_p->purchase_tail, id_Number, goods_Name, source, channel, quantity, buy_Price, purchase_Date); + if(flag == true) + { + break; + } + } + printf("商品信息录入成功!\n"); + printf("进货信息录入成功!\n"); + return OK; +} + +// 从文件中导入商品信息 +Status Fadd_commodity(commodity &head, commodity &tail, suppliers &suppliers_head, suppliers &suppliers_tail) +{ + FILE *fp; + commodity p; + suppliers suppliers_p; + char id_Number[20]; + char goods_Name[20]; + char place[20]; + char source[MAX_SIZE]; + char channel[MAX_SIZE]; + char main_business[MAX_SIZE]; + char main_products[MAX_SIZE]; + char brand[MAX_SIZE]; + char contact_person[MAX_SIZE]; + char telephone[MAX_SIZE]; + double buy_Price; + double sell_Price; + int quantity; + int quality_Date; + date purchase_Date; + date produce_Date; + bool flag = false; + fp = fopen("commodity1.txt", "r"); + if(fp == NULL) + { + printf("Can not open the file!"); + exit(INFEASIBLE); + } + while(1) + { + fscanf(fp, "%s %s %d %d %d %s %s %d %lf %lf %d %d %d %d %s", + id_Number, goods_Name, &purchase_Date.year, &purchase_Date.month, &purchase_Date.day, source, channel, &quantity, + &buy_Price, &sell_Price, &produce_Date.year, &produce_Date.month, &produce_Date.day, &quality_Date, place); + if(fgetc(fp) == ' ') + { + flag = true; + } + ListHandle_commodity(head, p, id_Number); + if(p) + { + if(strcmp(p->goods_Name, goods_Name) != 0 || strcmp(p->place, place) != 0 + || p->buy_Price != buy_Price || p->sell_Price != sell_Price || p->quality_Date != quality_Date + || p->purchase_Date.year != purchase_Date.year || p->purchase_Date.month != purchase_Date.month || p->purchase_Date.day != purchase_Date.day + || p->produce_Date.year != produce_Date.year || p->produce_Date.month != produce_Date.month || p->produce_Date.day != produce_Date.day) + { + printf("编号 %s 已存在商品信息\n", id_Number); + return ERROR; + } + p->remain_Number += quantity; + } + else + ListAdd_commodity(tail, id_Number, goods_Name, place, buy_Price, sell_Price, quantity, quality_Date, purchase_Date, produce_Date); + ListHandle_suppliers(suppliers_head, suppliers_p, source); + if(!suppliers_p) + { + printf("未找到公司名称为 %s 的供应商,请先添加!\n", source); + printf("请依次输入“主营业务、主营产品、品牌、联络人、电话”\n"); + scanf("%s %s %s %s %s", main_business, main_products, brand, contact_person, telephone); + ListAdd_suppliers(suppliers_tail, source, main_business, main_products, brand, contact_person, telephone); + printf("供应商信息添加成功!\n"); + ListHandle_suppliers(suppliers_head, suppliers_p, source); + } + ListAdd_purchase(suppliers_p->purchase_tail, id_Number, goods_Name, source, channel, quantity, buy_Price, purchase_Date); + if(flag == true) + { + break; + } + } + fclose(fp); + printf("商品信息导入成功!\n"); + printf("进货信息导入成功!\n"); + return OK; +} + +// 添加供应商信息界面 +Status Interface_add_suppliers(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail) +{ + int option; + bool flag = false; + system("cls"); + printf("添加供应商信息界面\n1.从窗口中录入供应商信息\n2.从文件中导入供应商信息\n3.返回上一级界面\n4.返回主界面\n"); + while(!flag) + { + scanf("%d", &option); + switch(option) + { + case 1: + Add_suppliers(suppliers_head, suppliers_tail); + break; + case 2: + Fadd_suppliers(suppliers_head, suppliers_tail); + break; + case 3: + Interface_suppliers_management(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + case 4: + Main_interface(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return OK; +} + +// 打印供应商信息界面 +Status Interface_print_suppliers(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail) +{ + int option; + bool flag = false; + system("cls"); + printf("打印供应商信息界面\n1.从窗口中录出供应商信息\n2.从文件中导出供应商信息\n3.返回上一级界面\n4.返回主界面\n"); + while(!flag) + { + scanf("%d", &option); + switch(option) + { + case 1: + DisplayList_suppliers(suppliers_head); + break; + case 2: + FdisplayList_suppliers(suppliers_head); + break; + case 3: + Interface_suppliers_management(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + case 4: + Main_interface(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return OK; +} + +// 供应商信息管理界面 +Status Interface_suppliers_management(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail) +{ + int option; + bool flag = false; + system("cls"); + printf("供应商信息管理界面\n1.添加供应商信息\n2.删除供应商信息\n3.修改供应商信息\n4.查询供应商信息\n5.打印供应商信息\n6.返回主界面\n"); + while(!flag) + { + scanf("%d", &option); + switch(option) + { + case 1: + Interface_add_suppliers(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + case 2: + ListDelete_suppliers(suppliers_head); + break; + case 3: + ListAlter_suppliers(suppliers_head, suppliers_tail); + break; + case 4: + ListSearch_suppliers(suppliers_head, suppliers_tail); + break; + case 5: + Interface_print_suppliers(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + case 6: + Main_interface(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return OK; +} + +// 进货管理界面 +Status Interface_purchase_management(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail) +{ + int option; + bool flag = false; + system("cls"); + printf("进货管理界面\n1.从窗口中录入商品信息和进货信息\n2.从文件中导入商品信息和进货信息\n3.返回主界面\n"); + while(!flag) + { + scanf("%d", &option); + switch(option) + { + case 1: + Add_commodity(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + break; + case 2: + Fadd_commodity(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + break; + case 3: + Main_interface(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return OK; +} + +// 主界面 +Status Main_interface(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail) +{ + int option; + bool flag = false; + system("cls"); + printf("主界面\n1.供应商信息管理\n2.进货管理\n3.退出主界面\n"); + while(!flag) + { + scanf("%d", &option); + switch(option) + { + case 1: + Interface_suppliers_management(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + case 2: + Interface_purchase_management(commodity_head, commodity_tail, suppliers_head, suppliers_tail); + flag = true; + break; + case 3: + return OK; + default: + printf("输入有误,请重新输入!\n"); + break; + } + } + return OK; +} diff --git a/code/purchase.h b/code/purchase.h new file mode 100644 index 0000000000000000000000000000000000000000..9dd0e32a1e71ee6f0924d9f762924223758659b3 --- /dev/null +++ b/code/purchase.h @@ -0,0 +1,159 @@ +#ifndef __PURCHASE_H__ +#define __PURCHASE_H__ + +// 标准头文件结构。 + +// 数组最大容量 +#define MAX_SIZE 30 + +// 函数结果状态代码 +#define TRUE 1 // 真 +#define FALSE 0 // 假 +#define OK 1 // 正常 +#define ERROR 0 // 错误 +#define INFEASIBLE -1 //不可行 +#define OVERFLOW -2 //溢出 + +// Status 是函数的类型,其值是函数结果状态代码 +typedef int Status; + +// 时间结构体,存储年、月、日信息 +#include "date.h" + +// 商品(库存)结构体 +#include "sell.h" + +/* 双向链表的单个节点,添加相应的结构体成员,同时修改构造函数(在purchase.cpp中) */ + +// 进货信息管理,对超市的采购活动进行管理,存储进了哪些货、进货数量、进货时间、进货的来源/渠道、进货价格等信息 +typedef struct purchase_information +{ + char number[MAX_SIZE]; // 商品编号 + char name[MAX_SIZE]; // 商品名称 + char source[MAX_SIZE]; // 进货来源 + char channel[MAX_SIZE]; // 进货渠道 + int quantity; // 进货数量 + double price; // 进货价格 + date time; // 进货时间 + purchase_information *pre; // 上一个进货指针 + purchase_information *next; // 下一个进货指针 +}*purchase; + +// 供应商信息管理,存储公司名称、主营业务/产品、品牌、联络人、电话等信息 +struct suppliers_information +{ + char corporate_name[MAX_SIZE]; // 公司名称 + char main_business[MAX_SIZE]; // 主营业务 + char main_products[MAX_SIZE]; // 主营产品 + char brand[MAX_SIZE]; // 品牌 + char contact_person[MAX_SIZE]; //联络人 + char telephone[MAX_SIZE]; // 电话 + purchase purchase_head; // 进货信息头节点 + purchase purchase_tail; // 进货信息尾结点 + suppliers_information *pre; // 上一个供应商指针 + suppliers_information *next; // 下一个供应商指针 +}; +typedef struct suppliers_information *suppliers; + +extern suppliers suppliers_head; +extern suppliers suppliers_tail; +extern commodity commodity_head; +extern commodity commodity_tail; + +// 构造一个空的带头结点的进货双向链表 +Status InitList_purchase(purchase &head, purchase &tail); + +// 在进货链表尾部添加一个进货结点 +Status ListAdd_purchase(purchase &tail, char number[], char name[], char source[], char channel[], int quantity, double price, date time); + +// 在窗口中录出进货信息 +Status Printf_purchas(purchase &p); + +// 在文件中导出进货信息 +Status Fprintf_purchas(purchase &p); + +// 遍历进货链表,依次对每个节点调用函数visit(),一旦visit()失败,则操作失败 +Status TraverseList_purchas(purchase &head, Status(*visit)(purchase &p)); + +// 在窗口中录出进货链表 +Status DisplayList_purchas(purchase &head); + +// 在文件中导出进货链表 +Status FdisplayList_purchas(purchase &head); + +// 构造一个空的带头结点的供应商双向链表 +Status InitList_suppliers(suppliers &head, suppliers &tail); + +// 查找供应商公司名称与关键字匹配的供应商结点 +Status ListHandle_suppliers(suppliers &head, suppliers &p, char corporate_name[]); + +// 在供应商链表尾部添加一个供应商结点 +Status ListAdd_suppliers(suppliers &tail, char corporate_name[], char main_business[], char main_products[], char brand[], char contact_person[], char telephone[]); + +// 从窗口中录入供应商信息 +Status Add_suppliers(suppliers &head, suppliers &tail); + +// 从文件中导入供应商信息 +Status Fadd_suppliers(suppliers &head, suppliers &tail); + +// 删除供应商公司名称与关键字匹配的供应商结点 +Status ListDelete_suppliers(suppliers &head); + +// 修改供应商公司名称与关键字匹配的供应商结点 +Status ListAlter_suppliers(suppliers &head, suppliers &tail); + +// 查询供应商公司名称与关键字匹配的供应商结点供应商信息 +Status ListSearch_suppliers(suppliers &head, suppliers &tail); + +// 在窗口中输出供应商信息 +Status Printf_suppliers(suppliers &p); + +// 在文件中导出供应商信息 +Status Fprintf_suppliers(suppliers &p); + +// 遍历供应商链表,依次对每个节点调用函数visit(),一旦visit()失败,则操作失败 +Status TraverseList_suppliers(suppliers &head, Status(*visit)(suppliers &p)); + +// 在窗口中录出供应商链表 +Status DisplayList_suppliers(suppliers &head); + +// 在文件中导出供应商链表 +Status FdisplayList_suppliers(suppliers &head); + +// 构造一个空的带头结点的商品向链表 +Status InitList_commodity(commodity &head, commodity &tail); + +// 在商品链表尾部添加一个商品结点 +Status ListAdd_commodity(commodity &tail, char id_Number[], char goods_Name[], char place[], + double buy_Prise, double sell_Prise, int remain_Number, int quality_Date, date purchase_Date, date produce_Date); + +// 查找商品编号与关键字匹配的供应商结点 +Status ListHandle_commodity(commodity &head, commodity &p, char id_Number[]); + +// 从窗口中录入商品信息 +Status Add_commodity(commodity &head, commodity &tail, suppliers &suppliers_head, suppliers &suppliers_tail); + +// 从文件中导入商品信息 +Status Fadd_commodity(commodity &head, commodity &tail, suppliers &suppliers_head, suppliers &suppliers_tail); + +// 添加供应商信息界面 +Status Interface_add_suppliers(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail); + +// 打印供应商信息界面 +Status Interface_print_suppliers(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail); + +// 供应商信息管理界面 +Status Interface_suppliers_management(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail); + +// 进货管理界面 +Status Interface_purchase_management(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail); + +// 主界面 +Status Main_interface(commodity &commodity_head, commodity &commodity_tail, + suppliers &suppliers_head, suppliers &suppliers_tail); + +#endif \ No newline at end of file diff --git a/code/suppliers1.txt b/code/suppliers1.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e80b655a138a99701d279058a2c0f374392dc49 --- /dev/null +++ b/code/suppliers1.txt @@ -0,0 +1,6 @@ +tengxun tengxun1 tengxun2 tengxun3 tengxun4 1111 +wangyi wangyi1 wangyi2 wangyi3 wangyi4 2222 +xiaomi xiaomi1 xiaomi2 xiaomi3 xiaomi4 3333 +huawei huawei1 huawei2 huawei3 huawei4 4444 +zhongxing zhongxing1 zhongxing2 zhongxing3 zhongxing4 5555 +sanxing sanxing1 sanxing2 sanxing3 sanxing4 6666 \ No newline at end of file