C语言商品订购系统

该系统主页面

以下是部分代码。需要源码的私信

#define _CRT_SECURE_NO_WARNINGS 1//vs的取消报警
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
typedef struct//创建商品的结构体
{
	char name[100];//名字
	char number[100];//编号
	char classify[100];//分类
	int price;//价格
	int amount;//总库存
	int extant;//现在还剩多少
	char user_information[100];//订购员的地址
}data;
data order[100];//创建全局变量存储数据
data manage[100];//用于订单管理
int count_order = 0;//创建全局变量
//将商品信息提取

int choose_()//创建一个选择函数--方便后期调用进行页面的选择
{
	while (1)
	{
		printf("请输入你的选择:");
			int choose;
			scanf("%d", &choose);
			if (choose == 1)
			{
				return 1;
			}
			else if (choose == 2)
			{
				return 2;
			}
			else if (choose == 3)
			{
				return 3;
			}
			else if (choose == 4)
			{
				return 4;
			}
			else if (choose == 0)
			{
				return 0;
			}
			else if (choose == 5)
			{
				return 5;
			}
			else if (choose == 6)
			{
				return 6;
			}
			else if (choose == 7)
			{
				return 7;
			}
			else
			{
				printf("输入错误重新输入\n");
			}
	}
	return 0;
		
}

int updata_file_information()//用于实时更新数据--将添加的商品信息实时更新到文本文件中
{
	FILE* fp = fopen("./information.txt", "w+");//打开当前文件夹--重写模式
	if (!fp)
	{
		printf("更新失败\n");
		return 0;
	}
	int i = 0;

	while (i < count_order)//count_order=全局变量中的商品数量
	{
		fprintf(fp, "%s %s %s %d %d %d %s\n", order[i].name, order[i].number, order[i].classify, order[i].price, order[i].amount, order[i].extant, order[i].user_information);
		i++;//打印放在文本文件中
	}

	fclose(fp);//关闭文件
	return 0;
}
int file_information_scanf()//文件读取//从文件中将商品信息放入全局变量中
{
	FILE* fp = fopen("./information.txt", "r");//打开当前文件--只读模式
	if (!fp)
	{
		printf("读取文件失败\n");
		return 0;
	}
	int i = 0;
	while (fscanf(fp, "%s%s%s%d%d%d%s", order[i].name, order[i].number, order[i].classify, &order[i].price, &order[i].amount, &order[i].extant, order[i].user_information) != EOF)
	{
		i++;从文件中将商品信息放入全局变量中
	}
	fclose(fp);//关闭文件
	count_order = i;//设置全局变量为商品信息
	return 0;
}

int modifiction_goods()
{
	printf("请输入你想修改的商品名字或者编号:");
	char name[50];
	scanf("%s", name);
	int i = 0;
	while (i < count_order)
	{
		if ((strcmp(name, order[i].name) == 0) || (strcmp(name, order[i].number) == 0))//找到该商品
		{
			printf("*****************找到该商品**********************\n");
			printf("商品的名字:%s    ", order[i].name);
			printf("商品的编号:%s    ", order[i].number);
			printf("商品的分类:%s     ", order[i].classify);
			printf("商品的价格:%d      ", order[i].price);
			printf("商品的总库存:%d      ", order[i].amount);
			printf("商品的现在库存:%d      ", order[i].extant);//打印商品信息
			printf("\n是否修改该商品  1:修改   0:退出\n");
			int chose = choose_();
			if (chose == 0)
			{
				printf("退出修改\n");
				return 0;
			}
			else if (chose == 1)
			{
				printf("请输入商品名字:");
				scanf("%s", order[count_order].name);

				printf("请输入商品编号:");
				scanf("%s", order[count_order].number);

				printf("请输入商品类别:");
				scanf("%s", order[count_order].classify);

				printf("请输入价格:");
				scanf("%d", &order[count_order].price);

				printf("请输入库存总数:");
				scanf("%d", &order[count_order].amount);
				order[count_order].extant = order[count_order].amount;//总库存就是现库存
				printf("修改成功\n");
				updata_file_information();
				return 0;
			}
		}
		i++;
	}


	return 0;
	
}


int Delete_goods()
{
	printf("请输入你想删除的商品名字或者编号:");
	char name[50];
	scanf("%s", name);
	int i = 0;
	while (i < count_order)
	{
		if ((strcmp(name, order[i].name) == 0) || (strcmp(name, order[i].number) == 0))//找到该商品
		{
			printf("*****************找到该商品**********************\n");
			printf("商品的名字:%s    ", order[i].name);
			printf("商品的编号:%s    ", order[i].number);
			printf("商品的分类:%s     ", order[i].classify);
			printf("商品的价格:%d      ", order[i].price);
			printf("商品的总库存:%d      ", order[i].amount);
			printf("商品的现在库存:%d      ", order[i].extant);//打印商品信息
			printf("\n是否删除该商品  1:删除   0:退出\n");
			int chose = choose_();
			if (chose == 0)
			{
				printf("退出该界面\n");
				return 0;
			}
			else if (chose == 1)
			{
				if ((i + 1) == count_order)//删除位置在最后一个
				{
					count_order--;
					printf("删除成功\n");
					updata_file_information();
					return 0;
				}
				while (i < count_order-1)
				{

					strcpy(order[i].name, order[i + 1].name);
					strcpy(order[i].classify, order[i + 1].classify);
					strcpy(order[i].user_information, order[i + 1].user_information);
					strcpy(order[i].number, order[i + 1].number);
					order[i].amount = order[i+1].amount;
					order[i].extant = order[i + 1].extant;
					order[i].price = order[i + 1].price;
					i++;
				}
				count_order--;
				printf("删除成功\n");
				updata_file_information();
				return 0;
			}
		}
		i++;
	}


	return 0;

}


int file_order_print()//文件输出--进行保存
{
	FILE* fp = fopen("./information.txt", "a+");//将添加的商品信息添加到文件中
	if (!fp)
	{
		printf("打开information失败\n");
		return 0;
	}

	printf("************************\n");
	printf("********入库界面********\n");
	printf("请输入商品名字:");
	scanf("%s", order[count_order].name );

	printf("请输入商品编号:");
	scanf("%s", order[count_order].number );

	printf("请输入商品类别:");
	scanf("%s", order[count_order].classify );

	printf("请输入价格:");
	scanf("%d", &order[count_order].price );

	printf("请输入库存总数:");
	scanf("%d", &order[count_order].amount );
	order[count_order].extant = order[count_order].amount;//总库存就是现库存

	//将信息添加到文本中
	fprintf(fp, "%s %s %s %d %d %d %s\n", order[count_order].name, order[count_order].number, order[count_order].classify, order[count_order].price, order[count_order].amount, order[count_order].extant,order[count_order].user_information);
	count_order++;//商品数量+1
	fclose(fp);
	updata_file_information();//实时更新文件
	return 0;
}
void User_menu()//打印主页面
{
	printf("**************欢迎进入订购页面****************\n");
	printf("********************************************\n");
	printf("*************1:商品名称查找-订购**************\n");
	printf("*************2:商品类型查找-订购**************\n");
	printf("*************3:商品编号查找-订购**************\n");
	printf("*************4:查看所用商品信息**************\n");
	printf("****************5:清屏***********************\n");
	printf("****************0:退出***********************\n");
	printf("*********************************************\n");
}
//两个文件分别是information用来存储订购信息和order文件用来存储商品信息


int order_manage()
{
	FILE* fp = fopen("./manage.txt", "a+");
	if (!fp)
	{
		printf("打开manage失败\n");
		return -1;
	}
	FILE* fph = fopen("./history.txt", "r");//用来读取history中的文件
	if (!fph)
	{
		printf("打开manage失败\n");
		return -1;
	}
	int i = 0;
	while (fscanf(fph, "%s%s%s%d%d%d%s", manage[i].name , manage[i].number, manage[i].classify,&manage[i].price, &manage[i].amount, &manage[i].extant,manage[i].user_information ) != EOF)
	{
		i++;
	}//将订购信息放入到manage链表中
	if (i == 0)
	{
		printf("没有订购记录\n");
		return 0;
	}
	int j = 0;
	while (j < i)
	{
		printf("**************第%d个订购记录*****************\n", j + 1);
		printf("商品的名字:%s    ", manage[j].name);
		printf("商品的编号:%s    ", manage[j].number);
		printf("商品的分类:%s     ", manage[j].classify);
		printf("商品的价格:%d      ", manage[j].price);
		printf("商品的总库存:%d      ", manage[j].amount);
		printf("商品的现在库存:%d      ", manage[j].extant);//打印商品信息
		printf("\n订购商品的地址:%s\n", manage[j].user_information);
		printf("是否同意该订单:  1:同意     0:拒绝\n");
		int chose = choose_();
		int judge = 0;//用来判断
		if (chose == 1)
		{
			judge++;
			fprintf(fp, "%s %s %s %d %d %d %s\n", manage[i].name, manage[i].number, manage[i].classify, manage[i].price, manage[i].amount, manage[i].extant, manage[i].user_information);
			printf("已同意该订单\n");
		}
		if (judge == 0)
		{
			printf("已拒绝该订单\n");
		}
		j++;
	}




	fclose(fph);
	fclose(fp);
	FILE* fps = fopen("./history.txt", "w+");
	if (!fps)
	{
		printf("打开history失败\n");
		return 0;
	}
	//清空history中的信息
	fprintf(fps, " ");
	fclose(fp);
	return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值