📄 commoditymanager.c
字号:
//////////////////////////////////////////////////////////////////////////
// 商品管理
//////////////////////////////////////////////////////////////////////////
//商品管理选择窗口
#include <ncurses.h>
#include <stdlib.h>
#include "PosSystem.h"
#include "OracleDB.h"
//商品管理商品
//返回1进入查询商品";
//返回2进入添加商品";
//返回3进入修改商品";
//返回4进入删除商品";
//返回0为返回后台管理界面";
int CommodityManagerWin()
{
int ch,choose=0;
//后台管理界面的背景窗口
WINDOW * CommodityManagerWin=CreateWindow(25,80,0,0,Yes,BLUE_WHITE);
StringCenterPrint(CommodityManagerWin,5,"商品管理");
char menu1[]="1.查询商品";
char menu2[]="2.添加商品";
char menu3[]="3.修改商品";
char menu4[]="4.删除商品";
char menu5[]="0.返回后台管理界面";
mvwprintw(CommodityManagerWin,9,35,menu1);
mvwprintw(CommodityManagerWin,11,35,menu2);
mvwprintw(CommodityManagerWin,13,35,menu3);
mvwprintw(CommodityManagerWin,15,35,menu4);
mvwprintw(CommodityManagerWin,17,35,menu5);
wrefresh(CommodityManagerWin);
curs_set(0);//参数0为不显示光标 如参数为1时为显示
while(1)
{
SearchCommodity://查询商品
while(1)
{
StringRevers(CommodityManagerWin,9,35,menu1);
ch=GetChar(CommodityManagerWin,9,35);
switch(ch)
{
case KEY_DOWN:
mvwprintw(CommodityManagerWin,9,35,menu1);
goto AddCommodity;
break;
case '\n':
choose=1;
goto exit;
}
}
AddCommodity://添加商品
while(1)
{
StringRevers(CommodityManagerWin,11,35,menu2);
ch=GetChar(CommodityManagerWin,11,35);
switch(ch)
{
case KEY_UP:
mvwprintw(CommodityManagerWin,11,35,menu2);
goto SearchCommodity;
break;
case KEY_DOWN:
mvwprintw(CommodityManagerWin,11,35,menu2);
goto ModifyCommodity;
break;
case '\n':
choose=2;
goto exit;
}
}
ModifyCommodity://修改商品
while(1)
{
StringRevers(CommodityManagerWin,13,35,menu3);
ch=GetChar(CommodityManagerWin,13,35);
switch(ch)
{
case KEY_UP:
mvwprintw(CommodityManagerWin,13,35,menu3);
goto AddCommodity;
break;
case KEY_DOWN:
mvwprintw(CommodityManagerWin,13,35,menu3);
goto DelCommodity;
break;
case '\n':
choose=3;
goto exit;
}
}
DelCommodity://删除商品
while(1)
{
StringRevers(CommodityManagerWin,15,35,menu4);
ch=GetChar(CommodityManagerWin,15,35);
switch(ch)
{
case KEY_UP:
mvwprintw(CommodityManagerWin,15,35,menu4);
goto ModifyCommodity;
break;
case KEY_DOWN:
mvwprintw(CommodityManagerWin,15,35,menu4);
goto ReturnToBackManager;
break;
case '\n':
choose=4;
goto exit;
}
}
ReturnToBackManager:// 退出进入后台界面
while(1)
{
StringRevers(CommodityManagerWin,17,35,menu5);
ch=GetChar(CommodityManagerWin,17,35);
switch(ch)
{
case KEY_UP:
mvwprintw(CommodityManagerWin,17,35,menu5);
goto DelCommodity;
break;
case '\n':
goto exit;
}
}
}
exit:
DestroyWindow(CommodityManagerWin);
curs_set(1);//参数0为不显示光标 如参数为1时为显示
return choose;
}
//商品添加窗品
int AddCommodityManagerWin()
{
int ch,result=0;
//后台管理界面的背景窗口
WINDOW * AddCommodityWin=CreateWindow(25,80,0,0,Yes,BLUE_WHITE);
StringCenterPrint(AddCommodityWin,0,"欢迎光临XXX超市");
StringCenterPrint(AddCommodityWin,2,"添加商品");
char barcodeStr[10]="CN";//存放条形码
char nameStr[10]={'\0'};//存放名称
char unitStr[10]={'\0'};//存放单位
char specStr[10]={'\0'};//存放规格
char priceStr[10]={'\0'};//存放售价
char stockStr[10]={'\0'};//存放进货价格
char agioStr[10]={'\0'};//存放折扣
char amountStr[10]={'\0'};//存放数量
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 * stock=CreateWindow(1,45,14,21,No,WHITE_BLACK);//进货价格
WINDOW * agio=CreateWindow(1,45,16,21,No,WHITE_BLACK);//折扣
WINDOW * amount=CreateWindow(1,45,18,21,No,WHITE_BLACK);//数量
mvwprintw(barcode,0,0,barcodeStr);//在输入框中打印出"CN"
//刷新输入框
wrefresh(barcode);
wrefresh(name);
wrefresh(unit);
wrefresh(spec);
wrefresh(price);
wrefresh(stock);
wrefresh(agio);
wrefresh(amount);
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://条形码
while(1)
{
ch=GetNumber(barcode,0,2,&barcodeStr[2],6);
switch(ch)
{
case KEY_DOWN:
case '\n':
goto name;
break;
}
}
name://商品名称
while(1)
{
ch=GetString(name,0,0,nameStr,10);
switch(ch)
{
case KEY_UP:
goto barcode;
break;
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=GetFloat(price,0,0,priceStr,10);
switch(ch)
{
case KEY_UP:
goto spec;
break;
case KEY_DOWN:
case '\n':
goto stock;
break;
}
}
stock://进货价格
while(1)
{
ch=GetFloat(stock,0,0,stockStr,10);
switch(ch)
{
case KEY_UP:
goto price;
break;
case KEY_DOWN:
case '\n':
goto agio;
break;
}
}
agio://折扣
while(1)
{
ch=GetFloat(agio,0,0,agioStr,10);
switch(ch)
{
case KEY_UP:
goto stock;
break;
case KEY_DOWN:
case '\n':
goto amount;
break;
}
}
amount://数量
while(1)
{
ch=GetNumber(amount,0,0,amountStr,10);
switch(ch)
{
case KEY_UP:
goto agio;
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 amount;
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 searchResult;
if(isNull(&barcodeStr[2]))//当返回值等于0时说明该条形码以存在不能再用该条形码
{
Message_Box(10,30,10,10,RED_BLACK,"提示","条形码不能为空");
goto barcode;
}
searchResult=search_exist(barcodeStr);
if(searchResult==0)//当返回值等于0时说明该条形码以存在不能再用该条形码
{
Message_Box(10,30,10,10,RED_BLACK,"提示","该条形码以存在");
goto barcode;
}
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(stockStr,atof(stockStr),atof(stockStr));
if(isNull(stockStr))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","进货价格不能为空");
goto stock;
}
if(err==0)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","进货价格格式错误");
goto stock;
}
//折扣验证
err=Float_Input_Validate(agioStr,0,1);
if(isNull(agioStr))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品折扣不能为空");
goto agio;
}
if(err==0)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品折扣格式错误");
goto agio;
}
if(atof(agioStr)>1.0f || atof(agioStr)<0.0f)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品折扣只能在0.1-1.0之间");
goto agio;
}
//商品数量验证
if(isNull(amountStr))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品数量不能为空");
goto amount;
}
if(atoi(amountStr)<0)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品数量不能为负数");
goto amount;
}
/*
char barcodeStr[10]={'0'};//存放条形码
char nameStr[10]={'0'};//存放名称
char unitStr[10]={'0'};//存放单位
char specStr[10]={'0'};//存放规格
char priceStr[10]={'0'};//存放售价
char stockStr[10]={'0'};//存放进货价格
char agioStr[10]={'0'};//存放折扣
char amountStr[10]={'0'};//存放数量
*/
/*插入到product*/
Insert_Into_Product(barcodeStr,nameStr,unitStr,specStr,atof(priceStr),atof(stockStr),atoi(amountStr),atof(agioStr));
}
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(stock);
DestroyWindow(agio);
DestroyWindow(amount);
DestroyWindow(ok_button);
DestroyWindow(exit_button);
wclear(stdscr);
return result;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -