📄 accountmanager.c
字号:
wrefresh(name);
wrefresh(password);
wrefresh(type);
wrefresh(remark);
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,15);
switch(ch)
{
case KEY_DOWN:
case '\n':
goto password;
break;
}
}
password://密码
while(1)
{
ch=GetString(password,0,0,passwordStr,16);
switch(ch)
{
case KEY_UP:
goto name;
break;
case KEY_DOWN:
case '\n':
goto type;
break;
}
}
type://身份
while(1)
{
ch=GetNumber(type,0,0,typeStr,1);
switch(ch)
{
case KEY_UP:
goto password;
break;
case KEY_DOWN:
case '\n':
goto remark;
break;
}
}
remark://备注
while(1)
{
ch=GetString(remark,0,0,remarkStr,30);
switch(ch)
{
case KEY_UP:
goto type;
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 remark;
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':
{
if(isNull(nameStr))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品名称不能为空");
goto name;
}
if(isNull(passwordStr))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","商品单位不能为空");
goto password;
}
if(strlen(passwordStr)<6 || strlen(passwordStr)>12)
{
Message_Box(10,36,10,10,RED_BLACK,"提示","用户密码只能是6-12个字符");
goto password;
}
if(isNull(typeStr))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","身份类型不能为空");
goto type;
}
if(atoi(typeStr)<0 || atoi(typeStr)>2)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","身份类型只能是0,1,2");
goto type;
}
strcpy(staff_info->name,nameStr);
strcpy(staff_info->pwd,passwordStr);
strcpy(staff_info->remark,remarkStr);
staff_info->type=atoi(typeStr);
Update_Staff_By_ID(staff_info->id,staff_info);
}
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(ModifyAccountWin);
DestroyWindow(ID);
DestroyWindow(name);
DestroyWindow(password);
DestroyWindow(type);
DestroyWindow(remark);
DestroyWindow(ok_button);
DestroyWindow(exit_button);
wclear(stdscr);
return result;
}
//删除帐户窗口
int DeleteAccountWin(staff * staff_info)
{
int ch,result=0;
//帐户管理界面的背景窗口
WINDOW * ModifyAccountWin=CreateWindow(25,80,0,0,Yes,BLUE_WHITE);
StringCenterPrint(ModifyAccountWin,0,"欢迎光临XXX超市");
StringCenterPrint(ModifyAccountWin,3,"删除帐户");
char IDStr[10]={'\0'};//存放帐户ID
char nameStr[10]={'\0'};//存放帐户名称
char passwordStr[10]={'\0'};//存放密码
char typeStr[10]={'\0'};//存放身份
char remarkStr[10]={'\0'};//存放备注
strcpy(IDStr,staff_info->id);
strcpy(nameStr,staff_info->name);
strcpy(passwordStr,staff_info->pwd);
sprintf(typeStr,"%d",staff_info->type);
strcpy(remarkStr,staff_info->remark);
mvwprintw(ModifyAccountWin,6,12,"帐户ID:");
mvwprintw(ModifyAccountWin,8,12,"用户名:");
mvwprintw(ModifyAccountWin,10,14,"密码:");
mvwprintw(ModifyAccountWin,12,14,"身份:");
mvwprintw(ModifyAccountWin,14,14,"备注:");
wrefresh(ModifyAccountWin);
//输入框
WINDOW * ID=CreateWindow(1,45,6,21,No,WHITE_BLACK);//帐户ID窗口
WINDOW * name=CreateWindow(1,45,8,21,No,WHITE_BLACK);//帐户名称窗口
WINDOW * password=CreateWindow(1,45,10,21,No,WHITE_BLACK);//密码窗口
WINDOW * type=CreateWindow(1,45,12,21,No,WHITE_BLACK);//身份窗口
WINDOW * remark=CreateWindow(1,45,14,21,No,WHITE_BLACK);//备注窗口
mvwprintw(ID,0,0,IDStr);
mvwprintw(name,0,0,nameStr);
mvwprintw(password,0,0,passwordStr);
mvwprintw(type,0,0,typeStr);
mvwprintw(remark,0,0,remarkStr);
//刷新输入框
wrefresh(ID);
wrefresh(name);
wrefresh(password);
wrefresh(type);
wrefresh(remark);
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)
{
//开启"正确"按钮的回显
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);
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 choose;
choose=DialogWindow(10,30,10,10,"是否要删除该帐户",RED_BLACK);
if(choose!=0) //0 选择“是”按钮 1选择“否按钮”
{
break;
}
Delete_Staff_By_ID(staff_info->id);
}
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(ModifyAccountWin);
DestroyWindow(ID);
DestroyWindow(name);
DestroyWindow(password);
DestroyWindow(type);
DestroyWindow(remark);
DestroyWindow(ok_button);
DestroyWindow(exit_button);
wclear(stdscr);
return result;
}
//0为返回后台管理界面
//1为进入查询帐户
//2为进入添加帐户
//3为进入修改帐户
//4为进入删除帐户
//帐户管理入口函数
int AccountManager()
{
int choose=0;
while(1)
{
choose=AccountManagerWin();
//选0 返回到后台管理界面
if(0==choose)
{
return 0;
}else if(1==choose) //选1为进入查询帐户
{
StaffPaginationShowWin();
//AccountManagerWin();
}else if(2==choose) //选1为进入添加帐户
{
AddAccountWin();
}else if(3==choose) //选1为进入修改帐户
{
char staff_id[10]={'\0'};
staff staff_info;
int result;
//帐户ID输入窗口
result=AccountIDInputWin("修改帐户",staff_id,&staff_info);
if(result==0)
{
//修改帐户窗口
ModifyAccountWin(&staff_info);
}
//ModifyAccountWin();
}else if(4==choose) //选1为进入删除帐户
{
char staff_id[10]={'\0'};
staff staff_info;
int result;
//帐户ID输入窗口
result=AccountIDInputWin("修改帐户",staff_id,&staff_info);
if(result==0)
{
//修改帐户窗口
DeleteAccountWin(&staff_info);
}
}
}
}
//帐户查询分页窗口
int StaffSearchWin()
{
WINDOW* CommoditySearchWin=CreateWindow(25,80,0,0,Yes,BLACK_WHITE);
char title[]="";
int scrWidth=80;
StringCenterPrint(CommoditySearchWin,0,"欢迎光临XXX超市");
StringCenterPrint(CommoditySearchWin,1,"查询帐户");
wrefresh(CommoditySearchWin);
printhline(CommoditySearchWin,2,1,scrWidth-2);
mvwprintw(CommoditySearchWin,3,1,"%2s%8s%10s%16s%6s%10s%10s%6s%6s","序列","条形码","商品名","单位","规格","销售价格","进货价格","数量","折扣");
//"序列","条形码","商品名","单位","规格","销售价格","进货价格","数量","折扣");
printhline(CommoditySearchWin,4,1,scrWidth-2);
printhline(CommoditySearchWin,21,1,scrWidth-2);
wrefresh(CommoditySearchWin);
mvwprintw(CommoditySearchWin,22,1,"%2s%8s%10s%16s","第一页(Home)","上一页(PageUp)","下一页(PageDown)","最后一页(End)");
wgetch(CommoditySearchWin);
DestroyWindow(CommoditySearchWin);
}
//打印帐户信息 参数recordNum是代表每页显示多少条记录
void PrintStaffInfo(WINDOW * win,int pageNumber,int recordNum)
{
LINKLIST * list=(LINKLIST *)malloc(sizeof(LINKLIST));
link_init(list);//要初始化一下列表
Get_Staff_By_PageNumber(list,pageNumber,recordNum);
//mvwprintw(win,0,0,"%d",list->count);
NODE *node=list->head;
int No=recordNum*(pageNumber-1)+1;//记录号
staff *pstaff;
int row=0;
while(node!=NULL)
{ pstaff=(staff*)(node->node_data);
mvwprintw(win,row,0,"%-6d%-8s%-18s%-14s%-12d%-10s",No,pstaff->id,pstaff->name,pstaff->pwd,pstaff->type,pstaff->remark);
No++;
row++;
node=node->next;
}
wrefresh(win);
free_list(list);
}
//帐户分页显示窗口
int StaffPaginationShowWin()
{
WINDOW* StaffShowWin=CreateWindow(25,80,0,0,Yes,BLACK_WHITE);
int scrWidth=80;
int currentpageNo=1;//页码 如1代表第1页
int maxRecordNum=15;//每 页显示多少条记录
char gotoPageNo[10];
StringCenterPrint(StaffShowWin,0,"欢迎光临XXX超市");
StringCenterPrint(StaffShowWin,1,"查询帐户");
wrefresh(StaffShowWin);
printhline(StaffShowWin,2,1,scrWidth-2);
mvwprintw(StaffShowWin,3,1,"%4s%8s%8s%20s%14s%8s","序列","帐户ID","帐户名","帐户密码","帐户类型","备注");
printhline(StaffShowWin,4,1,scrWidth-2);
printhline(StaffShowWin,20,1,scrWidth-2);
wrefresh(StaffShowWin);
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(StaffShowWin,21,1,"%17s%18s%20s%18s","第一页(Home)","上一页(PageUp)","下一页(PageDown)","最后一页(End)");
mvwprintw(StaffShowWin,23,26,"跳转到第[ ]页");
mvwprintw(StaffShowWin,23,60,"退出[ F1 ]");
wrefresh(StaffShowWin);
mvwprintw(currenPageNumberWin,0,0,"当前第[ %d ]",1);
wrefresh(currenPageNumberWin);
/*获取商品信息总页数 返回总页码 */
int PageCount=Get_Staff_TotalPageNumber(maxRecordNum);
LINKLIST *list;
if(PageCount==0)
{
Message_Box(10,30,10,10,RED_BLACK,"提示","没有商品信息可以查询");
goto exit;
}
int ch;
while(1)
{
wclear(printWin);
PrintStaffInfo(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(StaffShowWin);
DestroyWindow(printWin);
DestroyWindow(currenPageNumberWin);
DestroyWindow(pageNumberInputWin);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -