📄 venditionmanager.c
字号:
DestroyWindow(endYear);
DestroyWindow(endMonth);
DestroyWindow(endDay);
DestroyWindow(ok_button);
DestroyWindow(exit_button);
wclear(stdscr);
return result;
}
//按帐户ID查询销售的窗口
int SearchVenditionByAccountIDWin(char * accountID)
{
int ch,result=0;
//帐户管理界面的背景窗口
WINDOW * ModifyCommodityWindow=CreateWindow(25,80,0,0,Yes,BLUE_WHITE);
StringCenterPrint(ModifyCommodityWindow,0,"欢迎光临XXX超市");
StringCenterPrint(ModifyCommodityWindow,3,"员工ID查询销售记录");
//char barcodeStr[10]={'0'};//存放帐户ID
mvwprintw(ModifyCommodityWindow,10,12,"员工ID:");
wrefresh(ModifyCommodityWindow);
//输入框
WINDOW * accountidinputwin=CreateWindow(1,45,10,21,No,WHITE_BLACK);//帐户ID窗口
//刷新输入框
wrefresh(accountidinputwin);
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)
{
accountid://帐户ID
while(1)
{
ch=GetNumber(accountidinputwin,0,0,accountID,6);
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 accountid;
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;
isExist=search_staff_id_exist(accountID);
if(isExist!=0) // 不等于0说明帐户ID不存在 等于0说明存在
{
Message_Box(10,30,10,10,RED_BLACK,"提示","该帐户ID不存在");
wclear(accountidinputwin);
wrefresh(accountidinputwin);
//关掉正确按钮的回显
wattroff(ok_button,A_REVERSE);
wmove(ok_button,1,2);
//wattron(exit_button,A_REVERSE);
mvwprintw(ok_button,1,2,"正确");
wrefresh(ok_button);
goto accountid;
}
}
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(ModifyCommodityWindow);
DestroyWindow(accountidinputwin);
DestroyWindow(ok_button);
DestroyWindow(exit_button);
wclear(stdscr);
return result;
}
//销售管理入口函数
int VenditionManager()
{
int choose=0;
while(1)
{
choose=VenditionManagerWin();
//选0 返回到后台管理界面
switch(choose)
{
case 0: //0返回上级界面
return 0;
break;
case 1://选1进入销售日期查询
{
char startdate[20];
char enddate[20];
int result;
result=SearchVenditionByDateWin(startdate,enddate);
if(result!=0)//0代表输入成功 1代表返回不查询
{
break;
}
//按日期查询销售窗口
SearchSaleByDateShowWin(startdate,enddate);
}
break;
case 2://进入id查询
{
char staff_id[20];
int resutl;
resutl=SearchVenditionByAccountIDWin(staff_id);
if(resutl!=0) //退出查询才返回不为0的值
{
break;
}
//按员工编号查询销售窗口
SearchSaleByStaffIDShowWin(staff_id);
}
break;
}
}
}
//按日期查询销售窗口
int SearchSaleByDateShowWin(char * startdate,char * enddate)
{
WINDOW* win=CreateWindow(25,80,0,0,Yes,BLACK_WHITE);
int scrWidth=80;
int currentpageNo=1;//页码 如1代表第1页
int maxRecordNum=15;//每 页显示多少条记录
char gotoPageNo[10];
StringCenterPrint(win,0,"欢迎光临XXX超市");
StringCenterPrint(win,1,"查询商品");
wrefresh(win);
printhline(win,2,1,scrWidth-2);
mvwprintw(win,3,1,"%-6s%-22s%-14s%-10s%-16s%-5s","序列","销售ID","交易号","员工ID","销售日期","销售金额");
printhline(win,4,1,scrWidth-2);
printhline(win,20,1,scrWidth-2);
wrefresh(win);
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(win,21,1,"%17s%18s%20s%18s","第一页(Home)","上一页(PageUp)","下一页(PageDown)","最后一页(End)");
mvwprintw(win,23,26,"跳转到第[ ]页");
mvwprintw(win,23,60,"退出[ F1 ]");
wrefresh(win);
mvwprintw(currenPageNumberWin,0,0,"当前第[ %d ]",1);
wrefresh(currenPageNumberWin);
LINKLIST * list=(LINKLIST *)malloc(sizeof(LINKLIST));
link_init(list);
Search_SaleInfo_By_Date(list,startdate,enddate);
//mvwprintw(win,5,5,"总共有%d",list->count);
int recordTotal=list->count;
int more=(recordTotal%maxRecordNum==0)?0:1;//用来判断页数是否加1 当不为每页记录数的整数倍时就要加1
int pageCount=recordTotal/maxRecordNum+more;
/*获取商品信息总页数 返回总页码 */
//int PageCount=Get_ProductInfo_TotalPageNumber(maxRecordNum);
if(pageCount==0)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","没有商品信息可以查询");
goto exit;
}
int ch;
NODE * node;
sale *pSale;
while(1)
{
wclear(printWin);
int recordNo=(currentpageNo-1)*maxRecordNum+1;//每页的第一条记录编号
node=get_node_by_index(list,recordNo);
int i=0;//用来控制每次打印的条数
while(node!=NULL)
{
pSale=(sale *)(node->node_data);
mvwprintw(printWin,i,0,"%-6d%-22s%-14s%-10s%-16s%-5.2f",recordNo,pSale->sale_id,pSale->trans_id,pSale->staff_id,pSale->sale_date,pSale->sale_money);
node=node->next;
recordNo++;
i++;
if(i>=maxRecordNum)
{
break;
}
}
wrefresh(printWin);
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:
free_list(list);
DestroyWindow(win);
DestroyWindow(printWin);
DestroyWindow(currenPageNumberWin);
DestroyWindow(pageNumberInputWin);
return 0;
}
//按员工编号查询销售窗口
int SearchSaleByStaffIDShowWin(char * staff_id)
{
WINDOW* win=CreateWindow(25,80,0,0,Yes,BLACK_WHITE);
int scrWidth=80;
int currentpageNo=1;//页码 如1代表第1页
int maxRecordNum=15;//每 页显示多少条记录
char gotoPageNo[10];
StringCenterPrint(win,0,"欢迎光临XXX超市");
StringCenterPrint(win,1,"查询商品");
wrefresh(win);
printhline(win,2,1,scrWidth-2);
mvwprintw(win,3,1,"%-6s%-22s%-14s%-10s%-16s%-5s","序列","销售ID","交易号","员工ID","销售日期","销售金额");
printhline(win,4,1,scrWidth-2);
printhline(win,20,1,scrWidth-2);
wrefresh(win);
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(win,21,1,"%17s%18s%20s%18s","第一页(Home)","上一页(PageUp)","下一页(PageDown)","最后一页(End)");
mvwprintw(win,23,26,"跳转到第[ ]页");
mvwprintw(win,23,60,"退出[ F1 ]");
wrefresh(win);
mvwprintw(currenPageNumberWin,0,0,"当前第[ %d ]",1);
wrefresh(currenPageNumberWin);
LINKLIST * list=(LINKLIST *)malloc(sizeof(LINKLIST));
link_init(list);
/*按员工编号查询销售*/
Search_SaleInfo_By_StaffID(list,staff_id);
//mvwprintw(win,5,5,"总共有%d",list->count);
int recordTotal=list->count;
int more=(recordTotal%maxRecordNum==0)?0:1;//用来判断页数是否加1 当不为每页记录数的整数倍时就要加1
int pageCount=recordTotal/maxRecordNum+more;
/*获取商品信息总页数 返回总页码 */
//int PageCount=Get_ProductInfo_TotalPageNumber(maxRecordNum);
if(pageCount==0)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","没有商品信息可以查询");
goto exit;
}
int ch;
NODE * node;
sale *pSale;
while(1)
{
wclear(printWin);
int recordNo=(currentpageNo-1)*maxRecordNum+1;//每页的第一条记录编号
node=get_node_by_index(list,recordNo);
int i=0;//用来控制每次打印的条数
while(node!=NULL)
{
pSale=(sale *)(node->node_data);
mvwprintw(printWin,i,0,"%-6d%-22s%-14s%-10s%-16s%-5.2f",recordNo,pSale->sale_id,pSale->trans_id,pSale->staff_id,pSale->sale_date,pSale->sale_money);
node=node->next;
recordNo++;
i++;
if(i>=maxRecordNum)
{
break;
}
}
wrefresh(printWin);
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:
free_list(list);
DestroyWindow(win);
DestroyWindow(printWin);
DestroyWindow(currenPageNumberWin);
DestroyWindow(pageNumberInputWin);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -