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

📄 commoditymanager.c

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


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

						if(isNull(nameStr))//商品名称
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","商品名称不能为空");
							goto name;
							break;
						}

						if(isNull(unitStr))//商品单位
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","商品单位不能为空");
							goto unit;
							break;
						}
						if(isNull(specStr))//商品规格
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","商品规格不能为空");
							goto spec;
							break;
						}
						if(isFloat(priceStr))//商品售价
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","输入商品售价格式不合法");
							goto price;
							break;
						}
						if(isFloat(purchase_priceStr) )//商品进货价
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","输入商品进货价格式不合法");
							goto purchase_price;
							break;
						}
						if(isFloat(discountStr))//商品折扣
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","输入商品折扣格式不合法");
							goto discount;
							break;
						}
						if(isNull(countStr))//商品数量
						{
							Message_Box(10,10,30,10,RED_BLACK,"提示","商品数量不能为空");
							goto count;
							break;
						}

 						Update_ProductInfo_By_Barcode(barcodeStr,productInfo);
					}
					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(AddCommodityWin);
	DestroyWindow(barcode);
	DestroyWindow(name);
	DestroyWindow(unit);
	DestroyWindow(spec);
	DestroyWindow(price);
	DestroyWindow(purchase_price);
	DestroyWindow(discount);
	DestroyWindow(count);
	DestroyWindow(ok_button);
	DestroyWindow(exit_button);
	wclear(stdscr);
	return result;
}







//修改商品窗口
int DeleteCommodityWin(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时为显示

	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);
	while(1)
	{
ok_button:// 确定按钮
		while(1)
		{
			ch=GetChar(ok_button,1,6);
			//ch=GetChar(ok_button,0,0);
			switch(ch)
			{
				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 chooseResutl;
						chooseResutl=DialogWindow(10,30,10,10,"是否确定要删除",RED_BLACK);
 						//选 “是”按钮时返回0  “否” 按钮返回1
						if(chooseResutl!=0)
						{
							goto ok_button;
						}
						//先择“是”按钮时就删除
						Delete_ProductInfo_By_Barcode(barcodeStr);
					}
					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(AddCommodityWin);
	DestroyWindow(barcode);
	DestroyWindow(name);
	DestroyWindow(unit);
	DestroyWindow(spec);
	DestroyWindow(price);
	DestroyWindow(purchase_price);
	DestroyWindow(discount);
	DestroyWindow(count);
	DestroyWindow(ok_button);
	DestroyWindow(exit_button);
	wclear(stdscr);
	return result;
}





//1进入查询商品"
//2进入添加商品"
//3进入修改商品"
//4进入删除商品"
//0为返回后台管理界面"
//帐户管理入口函数
int CommodityManager()
{
	int choose=0;

	while(1)
	{
		choose=CommodityManagerWin();
		switch(choose)
		{
		case 0: //选0 返回到后台管理界面 0为返回后台管理界面"
			return 0;
			break;
		case 1: //1进入查询商品"
			{
				LINKLIST linklist;
				 CommodityPaginationShowWin(&linklist);
			}
			break;
		case 2: //2进入添加商品"
			{
				AddCommodityManagerWin();
			}
			break;
		case 3: //3进入修改商品"
			{
				int result;
				char barcodeStr[10]="CN";//存放帐户ID
				product productInfo;
				//修改商品的条码输入窗品
				result=CommodityBarCodeInputWin("修改商品",barcodeStr,&productInfo);
				if(result==0)//当result为0时说是找到要修改的商品
				{
					ModifyCommodityWin(barcodeStr,&productInfo);//按确定按钮返回0
				}
			}
			break;
		case 4:  //4进入删除商品"
			{
				int result;
				char barcodeStr[10]="CN";//存放帐户ID
				product productInfo;
				//修改商品的条码输入窗品
				result=CommodityBarCodeInputWin("删除商品",barcodeStr,&productInfo);
				//修改商品窗口
				if(result==0)
				{
					DeleteCommodityWin(barcodeStr,&productInfo);
				}
			}
			break;
		}
	}
	
}

//打印商品信息  参数recordNum是代表每页显示多少条记录
void PrintProductInfo(WINDOW * win,int pageNumber,int recordNum)
{
	LINKLIST * list=(LINKLIST *)malloc(sizeof(LINKLIST));
	link_init(list);//要初始化一下列表
	Get_ProductInfo_By_PageNumber(list,pageNumber,recordNum);
	//mvwprintw(win,0,0,"%d",list->count);
    NODE *node=list->head;
	int No=recordNum*(pageNumber-1)+1;//记录号
 	product *pro;
	int row=0;
    while(node!=NULL)
    {	pro=(product*)(node->node_data);
	//%-6d%-10s%-30s%-6s%-7s%-7.2f%-6d%-6.2f
		mvwprintw(win,row,0,"%-6d%-10s%-18s%-6s%-6s%-10.2f%-10.2f%-6d%-6.2f",No,pro->bar_code,pro->product_name,pro->unit,pro->spec,pro->sale_price,pro->purchase_price,pro->count,pro->discount);
   		//mvwprintw(win,No-1,0,"%2d%8s%10s%16s%6s%10s%10s%6s%6s",No,pro->bar_code,pro->product_name,pro->unit,pro->unit,pro->sale_price,pro->purchase_price,pro->count,pro->discount);
		No++;
		row++;
		node=node->next;
    }

	wrefresh(win);
	free_list(list);
}

//商品分页显示窗口
int CommodityPaginationShowWin()
{
	WINDOW* CommodityShowWin=CreateWindow(25,80,0,0,Yes,BLACK_WHITE);
	int scrWidth=80;
	int currentpageNo=1;//页码 如1代表第1页
	int maxRecordNum=15;//每 页显示多少条记录
	char gotoPageNo[10];
	StringCenterPrint(CommodityShowWin,0,"欢迎光临XXX超市");
	StringCenterPrint(CommodityShowWin,1,"查询商品");
	wrefresh(CommodityShowWin);
	printhline(CommodityShowWin,2,1,scrWidth-2);
	mvwprintw(CommodityShowWin,3,1,"%2s%8s%10s%16s%6s%10s%10s%6s%6s","序列","条形码","商品名","单位","规格","销售价格","进货价格","数量","折扣");

	printhline(CommodityShowWin,4,1,scrWidth-2);
	printhline(CommodityShowWin,20,1,scrWidth-2);
	wrefresh(CommodityShowWin);

 	WINDOW * printWin=CreateWindow(15,78,5,1,No,BLACK_WHITE);//打印商品信息窗口
	WINDOW * currenPageNumberWin=CreateWindow(1,15,23,6,No,BLACK_WHITE);//打印当前页码
	WINDOW * pageNumberInputWin=CreateWindow(1,6,23,37,No,BLACK_WHITE);//页码输入框

	mvwprintw(CommodityShowWin,21,1,"%17s%18s%20s%18s","第一页(Home)","上一页(PageUp)","下一页(PageDown)","最后一页(End)");
	mvwprintw(CommodityShowWin,23,26,"跳转到第[          ]页");
	mvwprintw(CommodityShowWin,23,60,"退出[ F1 ]");
	wrefresh(CommodityShowWin);

	mvwprintw(currenPageNumberWin,0,0,"当前第[ %d ]",1);
	wrefresh(currenPageNumberWin);


	/*获取商品信息总页数 返回总页码 */

	int PageCount=Get_ProductInfo_TotalPageNumber(maxRecordNum);
	LINKLIST *list;
	if(PageCount==0)
	{
		Message_Box(10,30,10,10,RED_BLACK,"提示","没有商品信息可以查询");
		goto exit;
	}
	int ch;
while(1)
{
	wclear(printWin);
	PrintProductInfo(printWin,currentpageNo,maxRecordNum);
	mvwprintw(currenPageNumberWin,0,0,"当前第[ %d ]",currentpageNo);
	wrefresh(currenPageNumberWin);
	ch=GetNumber(pageNumberInputWin,0,0,gotoPageNo,4);
	switch(ch)
	{
	case KEY_HOME:
		{
			currentpageNo=1;
		}
		break;
	case KEY_END:
		{
			currentpageNo=PageCount;
		}
		break;
	case KEY_PPAGE:
		{
			if(currentpageNo!=1)
			{
				currentpageNo--;

			}
			else
			{
				wclear(pageNumberInputWin);
				wrefresh(pageNumberInputWin);
				Message_Box(10,30,10,10,RED_BLACK,"提示","当前以是最后一页");
				break;			
			}
		}
		break;
	case KEY_NPAGE:
		{
			if(currentpageNo!=PageCount)
			{
				currentpageNo++;
			}
			else
			{
				wclear(pageNumberInputWin);
				wrefresh(pageNumberInputWin);
				Message_Box(10,30,10,10,RED_BLACK,"提示","当前以是第一页");
				break;		
			}
		}
		break;
	case '\n':
		{
			Trim(gotoPageNo);
			int pageNo=atoi(gotoPageNo);
			if(pageNo<1 || pageNo >PageCount)
			{
				wclear(pageNumberInputWin);
				wrefresh(pageNumberInputWin);
				Message_Box(10,30,10,10,RED_BLACK,"提示","输入的页码超出范围");
				break;
			}
			else
			{
				wclear(pageNumberInputWin);
				wrefresh(pageNumberInputWin);
				currentpageNo=pageNo;
			}
		}
		break;
	case KEY_F(1):
		goto exit;
		break;
	}
}

exit:
	DestroyWindow(CommodityShowWin);
 	DestroyWindow(printWin);
	DestroyWindow(currenPageNumberWin);
	DestroyWindow(pageNumberInputWin);
	return 0;
}










⌨️ 快捷键说明

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