服装销售系统

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <graphics.h>
#define INITSIZE 40
#include "assert.h"
#pragma  comment  (lib,"winmm.lib")


//struct Name {
	//char hat_name[20];
//	char short_name[20];
	//char sleeve_name[20];
//};

typedef struct Goods {
	int  good_id;
	char name[20];
	int size;
	double price;
	int num;
}Goods;

Goods arr[INITSIZE];//全局变量
int  size;//有效数据个数
void InitGoods(Goods* pgood, Goods* pname, Goods* psize, Goods* pprice, Goods* pnum);
void InsertGoods(Goods* array);
void DeleteByID(Goods* array);
void Change(Goods* array);
void SearchByPriceRange(Goods* array);
void Show(Goods* array);
Goods gs;
void InitGoods(Goods* pgs) {
	assert(pgs != NULL);
	//从键盘输入属性信息,初始化 pgs 所指的数据
	InputBox(pgs->name, 10, "服装名称", "服装名称信息录入");//输入数据  ---字符串接受

	char buff[10];

	memset(buff, 0, 10);
	InputBox(buff, 10, "服装库存数量", "服装库存数量信息录入");
	pgs->num = atoi(buff);

	memset(buff, 0, 10);
	InputBox(buff, 10, "服装尺寸", "服装尺寸信息录入");
	pgs->size = atoi(buff);

	memset(buff, 0, 10);
	InputBox(buff, 10, "服装编号", "服装编号信息录入");
	pgs->good_id = atoi(buff);

	memset(buff, 0, 10);
	InputBox(buff, 10, "服装价格", "服装价格信息录入");
	pgs->price = atof(buff);
}
void  InsertGoods(Goods* parr)
{
	assert(parr != NULL);//debug 断言  assert.h
	Goods gs;
	InitGoods(&gs);
	arr[size] = gs;
	size++;
	MessageBox(NULL, "服装信息录入成功", "录入结果", IDOK);
}

void  DeleteByID(Goods* arr)
{
	assert(arr != NULL);
	char buff[10] = { 0 };
	InputBox(buff, 10, "待删除的服装类型编号", "删除数据");
	int id = atoi(buff);
	//在数组中找到元素id,将数据从数组删除
	int flag = 0;
	for (int i = 0; i < size; i++) {
		if (arr[i].good_id == id) {//strcmp(arr[i].name,name)==0  string.h
			flag = 1;
			//数据移动
			for (int j = i; j < size; j++) {
				arr[j] = arr[j + 1];
			}
			size--;
		}
	}
	if (flag == 1)//若删除成功
		MessageBox(NULL, "删除服装成功!", "删除服装信息", IDOK);
	else
		MessageBox(NULL, "不存在该服装!", "删除服装信息", IDOK);
}
int SearchByPrice(Goods* arr) {
	char buff[20] = { 0 };
	InputBox(buff, 20, "待查找服装", "通过价格查找服装");
	int price = atoi(buff);
	for (int i = 0; i < size; i++) {
		if (arr[i].price == price) {
			MessageBox(NULL, "查找成功!", "结果展示", MB_OKCANCEL);
			return i;
		}
	}
	MessageBox(NULL, "不存在!", "结果展示", MB_OKCANCEL);
	return -1;
}

void ChangeByPrice(Goods* arr) {
	//先查找数据 input,后进行元素修改
	int index = -1;
	if ((index = SearchByPrice(arr)) == -1) {
		MessageBox(NULL, "不存在该服装", "修改结果", MB_OKCANCEL);//不存在该学生
		return;
	}
	char buff[20] = { 0 };
	int flag = 0;
	InputBox(buff, 20, "待修改服装属性:price,num,size,id,name", "更新"); //提示  请输入待修改的属性 : price 库存量
	if (strcmp(buff, "price") == 0 || strcmp(buff, "num") == 0 || strcmp(buff, "size") == 0 || strcmp(buff, "id") == 0 || strcmp(buff, "name") == 0) {//比较  属性名  == 
		if (strcmp(buff, "price") == 0) {
			InputBox(buff, 20, "价格", "更新价格");//修改的新价格为
			arr[index].price = atof(buff);
			flag = 1;
		}
		if (strcmp(buff, "num") == 0) {
			InputBox(buff, 20, "库存数量", "更新库存数量");//修改的新价格为
			arr[index].num = atoi(buff);
			flag = 1;
		}
		if (strcmp(buff, "size") == 0) {
			InputBox(buff, 20, "尺寸", "更新尺寸");//修改的新价格为
			arr[index].size = atoi(buff);
			flag = 1;
		}
		if (strcmp(buff, "id") == 0) {
			InputBox(buff, 20, "编号", "更新编号");//修改的新价格为
			arr[index].good_id = atoi(buff);
			flag = 1;
		}
		if (strcmp(buff, "name") == 0) {
			InputBox(buff, 20, "名称", "更新名称");//修改的新价格为
			strcpy(arr[index].name, buff);
			flag = 1;
		}
	}
	if (flag == 0)
		MessageBox(NULL, "更新失败!", "修改结果", MB_OKCANCEL);
	else
		MessageBox(NULL, "更新成功!", "修改结果", MB_OKCANCEL);
}
void Show(Goods* arr) {
	char buff[256] = { 0 };
	char res[1024] = { 0 };
	strcat(res, "编号  名称  库存数量  价格  尺寸\n");//连接
	for (int i = 0; i < size; i++) {
		sprintf(buff, "%d      %s     %d    %lf    %d    \n", arr[i].good_id, arr[i].name, arr[i].num, arr[i].price, arr[i].size);
		strcat(res, buff);
		memset(buff, 0, 128);
	}
	MessageBox(NULL, res, "结果展示", MB_OKCANCEL);
}

int main() {
	initgraph(700, 600, SHOWCONSOLE);//创建背景
	IMAGE img;
	loadimage(&img, "C:/1.png", 700, 600, true);
	putimage(0, 0, &img);
	MOUSEMSG msg;
	while (1) {
		msg = GetMouseMsg();//监听
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 520 && msg.x <= 666 && msg.y >= 320 && msg.y <= 410) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			//printf("")
			mciSendString("open D:/Snow.mp3 alias s", 0, 0, 0);
			mciSendString("play s repeat", 0, 0, 0);//音乐播放
		}

		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 290 && msg.x <= 420 && msg.y >= 340 && msg.y <= 400) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			//printf("")
			loadimage(&img, "C:/4.png", 700, 600, true);
			putimage(0, 0, &img);
			break;//跳转界面
		}
	}

	while (1) {
		msg = GetMouseMsg();//监听
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 290 && msg.x <= 400 && msg.y >= 90 && msg.y <= 185) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			mciSendString("close s", 0, 0, 0);
		}
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 300 && msg.x <= 410 && msg.y >= 285 && msg.y <= 390) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			loadimage(&img, "C:/1.png", 700, 600, true);
			putimage(0, 0, &img);
		}
		//添加服装
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 30 && msg.x <= 150 && msg.y >= 60 && msg.y <= 165) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			InsertGoods(arr);
		}
		//删除服装
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 40 && msg.x <= 145 && msg.y >= 240 && msg.y <= 350) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			DeleteByID(arr);
		}
		//修改服装
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 35 && msg.x <= 140 && msg.y >= 400 && msg.y <= 510) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			ChangeByPrice(arr);
		}
		//查找服装
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 540 && msg.x <= 650 && msg.y >= 60 && msg.y <= 170) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			SearchByPrice(arr);
		}
		//展示服装
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 540 && msg.x <= 645 && msg.y >= 220 && msg.y <= 330) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			Show(arr);
		}
		//退出系统
		if (msg.uMsg == WM_LBUTTONDOWN && msg.x >= 545 && msg.x <= 650 && msg.y >= 390 && msg.y <= 510) {
			//printf("x:%d y:%d\n", msg.x, msg.y);
			exit(0);
		}
	}
	system("pause");
	closegraph();
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值