⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commoditymanager.c

📁 在linux平台下模拟超市的收银系统即POS机
💻 C
📖 第 1 页 / 共 3 页
字号:
}

//商品条码输入窗口
int CommodityBarCodeInputWin(char * title,char * barcodeStr,product * productInfo)
{
	int ch,result=0;
	//帐户管理界面的背景窗口
	WINDOW * CommodityBarCodeInputWin=CreateWindow(25,80,0,0,Yes,BLUE_WHITE);
	StringCenterPrint(CommodityBarCodeInputWin,0,"欢迎光临XXX超市");
	StringCenterPrint(CommodityBarCodeInputWin,3,title);
	
	//char barcodeStr[10]="CN";//存放帐户ID
	
	mvwprintw(CommodityBarCodeInputWin,10,12,"条形码:");

	wrefresh(CommodityBarCodeInputWin);	
	//输入框
	WINDOW * barcode=CreateWindow(1,45,10,21,No,WHITE_BLACK);//帐户ID窗口
	mvwprintw(barcode,0,0,"CN");
	//刷新输入框
	wrefresh(barcode);

	WINDOW * ok_button=CreateWindow(3,8,20,25,Yes,RED_WHITE);
	mvwprintw(ok_button,1,2,"确定");
	wrefresh(ok_button);

	WINDOW * exit_button=CreateWindow(3,8,20,45,Yes,RED_WHITE);
	mvwprintw(exit_button,1,2,"退出");
	wrefresh(exit_button);

	//wgetch(AddCommodityWin);
 	curs_set(1);//参数0为不显示光标 如参数为1时为显示
	while(1)
	{
barcode://帐户ID
		while(1)
		{
			ch=GetNumber(barcode,0,2,&barcodeStr[2],6);
// 			mvwprintw(ModifyCommodityWindow,15,15,barcodeStr);
// 			wrefresh(ModifyCommodityWindow);
// 			wgetch(ModifyCommodityWindow);
			switch(ch)
			{
			case KEY_DOWN:
			case '\n':
				//开启"正确"按钮的回显
				wmove(ok_button,1,2);
				//mvchgat(1,2,4,A_BLINK,RED_WHITE,NULL);  //在ncurses书的第26页有注释
				//对 "正确"字符反白
				wattron(ok_button,A_REVERSE);
				mvwprintw(ok_button,1,2,"正确");
				wrefresh(ok_button);
				goto ok_button;
				break;
			}
		}

ok_button:// 确定按钮
		while(1)
		{
			ch=GetChar(ok_button,1,6);
			//ch=GetChar(ok_button,0,0);
			switch(ch)
			{
				//case KEY_LEFT:
				case KEY_UP://转上面
					wattroff(ok_button,A_REVERSE);
					wmove(ok_button,1,2);
					//wattron(exit_button,A_REVERSE);
					mvwprintw(ok_button,1,2,"正确");
					wrefresh(ok_button);
					goto barcode;
					break;
				case KEY_RIGHT:
				case KEY_DOWN:
					//关掉正确按钮的回显
					wattroff(ok_button,A_REVERSE);
					wmove(ok_button,1,2);
					//wattron(exit_button,A_REVERSE);
					mvwprintw(ok_button,1,2,"正确");
					wrefresh(ok_button);

					//开启退出按钮的回显
					wmove(exit_button,1,2);
					wattron(exit_button,A_REVERSE);
					mvwprintw(exit_button,1,2,"退出");
					wrefresh(exit_button);
					goto exit_button;
					break;
				case '\n':
					{
						int isExist,strlength,i;
						strlength=strlen(&barcodeStr[2]);
// 						mvwprintw(ModifyCommodityWindow,15,15,barcodeStr);
// 						wrefresh(ModifyCommodityWindow);
						if(strlength!=6)
						{
							Message_Box(8,30,5,20,RED_BLACK,"提示","输入的条形码只能是6个数字");
							wclear(barcode);
							mvwprintw(barcode,0,0,"CN");
							//刷新输入框
							wrefresh(barcode);
							goto barcode;
						}
						for(i=2;i<strlength;i++)
						{
							if(!isdigit(barcodeStr[i]))
							{
								Message_Box(8,30,5,20,RED_BLACK,"提示","输入的条形码只能是6个数字");
								wclear(barcode);
								mvwprintw(barcode,0,0,"CN");
								//刷新输入框
								wrefresh(barcode);
								goto barcode;
							}
						}
						isExist=Get_ProductInfo_By_Barcode(barcodeStr,productInfo);
						if(isExist!=0)
						{
							Message_Box(8,50,5,20,RED_BLACK,"提示","没有查找到该条形码相对应的商品");
							
							//关掉正确按钮的回显
							wattroff(ok_button,A_REVERSE);
							wmove(ok_button,1,2);
							//wattron(exit_button,A_REVERSE);
							mvwprintw(ok_button,1,2,"正确");
							wrefresh(ok_button);
							wclear(barcode);

							mvwprintw(barcode,0,0,"CN");
							//刷新输入框
							wrefresh(barcode);
							goto barcode;
						}
						result=0;
						goto exit;
					}
		
			}
		}
exit_button://退出按钮		
		while(1)
		{
			ch=GetChar(exit_button,1,6);
			switch(ch)
			{
				case KEY_UP:
				case KEY_LEFT://转上面

					//关掉'退出'回显
					wattroff(exit_button,A_REVERSE);
					wmove(exit_button,1,2);
					//wattron(exit_button,A_REVERSE);
					mvwprintw(exit_button,1,2,"退出");
					wrefresh(exit_button);

					//开启"正确"按钮的回显
					wmove(ok_button,1,2);
					//mvchgat(1,2,4,A_BLINK,RED_WHITE,NULL);  //在ncurses书的第26页有注释
					//对 "正确"字符反白
					wattron(ok_button,A_REVERSE);
					mvwprintw(ok_button,1,2,"正确");
					wrefresh(ok_button);

					goto ok_button;
					break;
				case '\n':
					result=1;//返回1为退出
					goto exit;
			}		
		}
	}

exit:

	DestroyWindow(CommodityBarCodeInputWin);
	DestroyWindow(barcode);
	DestroyWindow(ok_button);
	DestroyWindow(exit_button);

	wclear(stdscr);
	return result;
}




//修改商品窗口
int ModifyCommodityWin(char * bar_code,product * productInfo)
{
	int ch,result=0;
	//后台管理界面的背景窗口
	WINDOW * AddCommodityWin=CreateWindow(25,80,0,0,Yes,BLUE_WHITE);
	StringCenterPrint(AddCommodityWin,0,"欢迎光临XXX超市");
	StringCenterPrint(AddCommodityWin,2,"修改商品");
	
	char barcodeStr[10]={'\0'};//存放条形码
	char nameStr[31]={'\0'};//存放名称
	char unitStr[17]={'\0'};//存放单位
	char specStr[17]={'\0'};//存放规格
	char priceStr[30]={'\0'};//存放售价
	char purchase_priceStr[30]={'\0'};//存放进货价格
	char discountStr[30]={'\0'};//存放折扣
	char countStr[30]={'\0'};//存放数量

	strcpy(barcodeStr,productInfo->bar_code);
	strcpy(nameStr,productInfo->product_name);
	strcpy(unitStr,productInfo->unit);
	strcpy(specStr,productInfo->spec);
	sprintf(priceStr,"%f",productInfo->sale_price);
	sprintf(purchase_priceStr,"%f",productInfo->purchase_price);
	sprintf(discountStr,"%f",productInfo->discount);
	sprintf(countStr,"%d",productInfo->count);

	//mvwprintw(AddCommodityWin,1,5,"%f",productInfo->purchase_price);
	mvwprintw(AddCommodityWin,4,12,"条形码:");
	mvwprintw(AddCommodityWin,6,14,"名称:");
	mvwprintw(AddCommodityWin,8,14,"单位:");
	mvwprintw(AddCommodityWin,10,14,"规格:");
	mvwprintw(AddCommodityWin,12,14,"售价:");
	mvwprintw(AddCommodityWin,14,10,"进货价格:");
	mvwprintw(AddCommodityWin,16,14,"折扣:");
	mvwprintw(AddCommodityWin,18,14,"数量:");
	wrefresh(AddCommodityWin);	
	//输入框
	WINDOW * barcode=CreateWindow(1,45,4,21,No,WHITE_BLACK);//条形码
	WINDOW * name=CreateWindow(1,45,6,21,No,WHITE_BLACK);//商品名称
	WINDOW * unit=CreateWindow(1,45,8,21,No,WHITE_BLACK);//单位
	WINDOW * spec=CreateWindow(1,45,10,21,No,WHITE_BLACK);//规格
	WINDOW * price=CreateWindow(1,45,12,21,No,WHITE_BLACK);//售价
	WINDOW * purchase_price=CreateWindow(1,45,14,21,No,WHITE_BLACK);//进货价格
	WINDOW * discount=CreateWindow(1,45,16,21,No,WHITE_BLACK);//折扣
	WINDOW * count=CreateWindow(1,45,18,21,No,WHITE_BLACK);//数量

	//打印出数据
	mvwprintw(barcode,0,0,barcodeStr);
	mvwprintw(name,0,0,nameStr);	
	mvwprintw(unit,0,0,unitStr);
	mvwprintw(spec,0,0,specStr);
	mvwprintw(price,0,0,priceStr);
	mvwprintw(purchase_price,0,0,purchase_priceStr);
	mvwprintw(discount,0,0,discountStr);
	mvwprintw(count,0,0,countStr);
	//刷新输入框
	wrefresh(barcode);
	wrefresh(name);
	wrefresh(unit);
	wrefresh(spec);
	wrefresh(price);
	wrefresh(purchase_price);
	wrefresh(discount);
	wrefresh(count);

	WINDOW * ok_button=CreateWindow(3,8,20,25,Yes,RED_WHITE);
	mvwprintw(ok_button,1,2,"确定");
	wrefresh(ok_button);

	WINDOW * exit_button=CreateWindow(3,8,20,45,Yes,RED_WHITE);
	mvwprintw(exit_button,1,2,"退出");
	wrefresh(exit_button);

	//wgetch(AddCommodityWin);
 	curs_set(1);//参数0为不显示光标 如参数为1时为显示
	while(1)
	{
name://商品名称
		while(1)
		{
			ch=GetString(name,0,0,nameStr,10);
			switch(ch)
			{
			case KEY_DOWN:
			case '\n':
				goto unit;
				break;
			}
		}
unit://单位
		while(1)
		{
			ch=GetString(unit,0,0,unitStr,10);
			switch(ch)
			{
			case KEY_UP:
				goto name;
				break;
			case KEY_DOWN:
			case '\n':
				goto spec;
				break;
			}
		}

spec://商品规格
		while(1)
		{
			ch=GetString(spec,0,0,specStr,10);
			switch(ch)
			{
			case KEY_UP:
				goto unit;
				break;
			case KEY_DOWN:
			case '\n':
				goto price;
				break;
			}
		}
price://售价
		while(1)
		{
			ch=GetString(price,0,0,priceStr,10);
			switch(ch)
			{
			case KEY_UP:
				goto spec;
				break;
			case KEY_DOWN:
			case '\n':
				goto purchase_price;
				break;
			}
		}
purchase_price://进货价格
		while(1)
		{
			ch=GetString(purchase_price,0,0,purchase_priceStr,10);
			switch(ch)
			{
			case KEY_UP:

				goto price;
				break;
			case KEY_DOWN:
			case '\n':
				goto discount;
				break;
			}
		}
discount://折扣
		while(1)
		{
			ch=GetString(discount,0,0,discountStr,10);
			switch(ch)
			{
			case KEY_UP:

				goto purchase_price;
				break;
			case KEY_DOWN:
			case '\n':
				goto count;
				break;
			}
		}
count://数量
		while(1)
		{
			ch=GetString(count,0,0,countStr,10);
			switch(ch)
			{
			case KEY_UP:
				goto discount;
				break;
			case KEY_DOWN:
			case '\n':
				//开启"正确"按钮的回显
				wmove(ok_button,1,2);
				//mvchgat(1,2,4,A_BLINK,RED_WHITE,NULL);  //在ncurses书的第26页有注释
				//对 "正确"字符反白
				wattron(ok_button,A_REVERSE);
				mvwprintw(ok_button,1,2,"正确");
				wrefresh(ok_button);
				goto ok_button;
				break;
			}
		}
ok_button:// 确定按钮
		while(1)
		{
			ch=GetChar(ok_button,1,6);
			//ch=GetChar(ok_button,0,0);
			switch(ch)
			{
				//case KEY_LEFT:
				case KEY_UP://转上面
					wattroff(ok_button,A_REVERSE);
					wmove(ok_button,1,2);
					//wattron(exit_button,A_REVERSE);
					mvwprintw(ok_button,1,2,"正确");
					wrefresh(ok_button);
					goto count;
					break;
				case KEY_RIGHT:
				case KEY_DOWN:
					//关掉正确按钮的回显
					wattroff(ok_button,A_REVERSE);
					wmove(ok_button,1,2);
					//wattron(exit_button,A_REVERSE);
					mvwprintw(ok_button,1,2,"正确");
					wrefresh(ok_button);

					//开启退出按钮的回显
					wmove(exit_button,1,2);
					wattron(exit_button,A_REVERSE);
					mvwprintw(exit_button,1,2,"退出");
					wrefresh(exit_button);
					goto exit_button;
					break;
				case '\n':
					{
						int returnResult,strLength;


						if(isNull(nameStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品名称不能为空");
							goto name;
						}
						if(isNull(unitStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品单位不能为空");
							goto unit;
						}
						if(isNull(specStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品规格不能为空");
							goto spec;
						}
						int err;
						//商品售价验证
						err=Float_Input_Validate(priceStr,atof(priceStr),atof(priceStr));
						if(isNull(priceStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品售价不能为空");
							goto price;
						}
						if(err==0)
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品售价格式错误");
							goto price;
						}
						//进货价格验证
						err=Float_Input_Validate(purchase_priceStr,atof(purchase_priceStr),atof(purchase_priceStr));
						if(isNull(purchase_priceStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","进货价格不能为空");
							goto purchase_price;
						}
						if(err==0)
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","进货价格格式错误");
							goto purchase_price;
						}
						//折扣验证
						err=Float_Input_Validate(discountStr,0,1);
						if(isNull(discountStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品折扣不能为空");
							goto discount;
						}
						if(err==0)
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品折扣格式错误");
							goto discount;
						}
						if(atof(discountStr)>1.0f || atof(discountStr)<0.0f)
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品折扣只能在0.1-1.0之间");
							goto discount;
						}
						//商品数量验证
						if(isNull(countStr))
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品数量不能为空");
							goto count;
						}
						if(atoi(countStr)<0)
						{
							Message_Box(10,30,10,10,RED_BLACK,"提示","商品数量不能为负数");
							goto count;
						}

// 						mvwprintw(AddCommodityWin,1,1,"%f",productInfo->sale_price);
// 						mvwprintw(AddCommodityWin,1,20,"%f",productInfo->purchase_price);
// 						mvwprintw(AddCommodityWin,1,40,"%f",productInfo->discount);
// 						mvwprintw(AddCommodityWin,1,70,"%d",productInfo->count);

						
// 	char barcodeStr[10]={'0'};//存放条形码
// 	char nameStr[31]={'0'};//存放名称
// 	char unitStr[17]={'0'};//存放单位
// 	char specStr[17]={'0'};//存放规格
// 	char priceStr[30]={'0'};//存放售价
// 	char purchase_priceStr[30]={'0'};//存放进货价格
// 	char discountStr[30]={'0'};//存放折扣
// 	char countStr[30]={'0'};//存放数量

// 
// 						mvwprintw(AddCommodityWin,2,1,priceStr);
// 						mvwprintw(AddCommodityWin,2,20,purchase_priceStr);
// 						mvwprintw(AddCommodityWin,2,40,discountStr);
// 						mvwprintw(AddCommodityWin,2,70,countStr);


						strcpy(productInfo->bar_code,barcodeStr);
						strcpy(productInfo->product_name,nameStr);
						strcpy(productInfo->unit,unitStr);
						strcpy(productInfo->spec,specStr);
						productInfo->sale_price=atof(specStr);
						productInfo->purchase_price=atof(purchase_priceStr);
						productInfo->discount=atof(discountStr);
						productInfo->count=atoi(countStr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -