📄 loginwindow.c
字号:
//////////////////////////////////////////////////////////////////////////
// 登入窗口
//////////////////////////////////////////////////////////////////////////
#include <ncurses.h>
#include <stdlib.h>
#include "PosSystem.h"
extern char id[20];
int CreateLoginWindow(int higth,int width,int startY,int startX)
{
//char id[16]={'\0'};
char pwd[16]={'\0'};
int result=0;
int sign=0;
int idtype=0;//帐户类型
//登入界面的上部分
WINDOW * login_win_top=CreateWindow(1,80,0,0,No,WHITE_BLACK);
mvwprintw(login_win_top,0,0,"超市收银系统");
wrefresh(login_win_top);
//界面的中间部分的背景色
WINDOW * login_win_mid=CreateWindow(23,80,1,0,No,BLUE_WHITE);
wrefresh(login_win_mid);
//登入窗口阴影
WINDOW * login_win_shadow=CreateWindow(11,34,8,24,No,BLACK_WHITE);
wrefresh(login_win_shadow);
//登入窗口
WINDOW * login_win=CreateWindow(11,34,7,23,Yes,WHITE_BLACK);
char title[]=" 欢迎进入登入窗口 ";
int titlelength=strlen(title),maxY,maxX;
getmaxyx(login_win,maxY,maxX);
mvwprintw(login_win,0,(maxX-titlelength)/2,title);
mvwprintw(login_win,2,6,"帐号:");
//输入帐号窗口
WINDOW * account_input_box=CreateWindow(1,15,9,36,No,RED_BLACK);
wrefresh(account_input_box);
mvwprintw(login_win,4,6,"密码:");
//输入密码窗口
WINDOW * password_input_box=CreateWindow(1,15,11,36,No,RED_BLACK);
wrefresh(password_input_box);
//刷新登入窗口内容
wrefresh(login_win);
//确定按钮阴影
WINDOW * ok_button_shadow=CreateWindow(3,8,14,30,No,BLACK_WHITE);
wrefresh(ok_button_shadow);
//确定按钮
WINDOW * ok_button=CreateWindow(3,8,13,29,Yes,RED_WHITE);
mvwprintw(ok_button,1,2,"确定");
wrefresh(ok_button);
//退出按钮阴影
WINDOW * exit_button_shadow=CreateWindow(3,8,14,44,No,BLACK_WHITE);
wrefresh(exit_button_shadow);
//退出按钮
WINDOW * exit_button=CreateWindow(3,8,13,43,Yes,RED_WHITE);
mvwprintw(exit_button,1,2,"退出");
wrefresh(exit_button);
//界面的底部
WINDOW * login_win_bottom=CreateWindow(1,80,24,0,No,WHITE_BLACK);
mvwprintw(login_win_bottom,0,0,"Linux POS version 1.0 Author Lin Jia Xing");
wrefresh(login_win_bottom);
int y,x,ch,i;
int strlength;
while(1)
{
account_input:
while(1)
{
ch=GetNumber(account_input_box,0,0,id,6);
switch(ch)
{
case KEY_F(1):
case KEY_DOWN:
case '\n':
//DialogWindow(7,25,15,15,"是否挂单",RED_BLACK);
//NewListWindow(10,10,"删除明细表");
//InputAdminPwdWin(10,10);//接收管理员密码
//ReturningAProductWin(10,10);//退货窗口
//Reckoning_Window(10,10);//结帐窗口
//Message_Box(10,30,10,10,RED_WHITE,"消息","测试是否保存成功");
//break;
goto passwork_input;
break;
}
}
while(1)
{
passwork_input:
ch=GetPasswordString(password_input_box,0,0,pwd,14);
switch(ch)
{
case KEY_UP:
goto account_input;
break;
case KEY_DOWN:
case '\n'://转到ok_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;
}
}
while(1)
{
ok_button:
ch=GetChar(ok_button,1,6);
//ch=GetChar(ok_button,0,0);
switch(ch)
{
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 passwork_input;
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':
{
wattroff(ok_button,A_REVERSE);
wmove(ok_button,1,2);
//wattron(exit_button,A_REVERSE);
mvwprintw(ok_button,1,2,"正确");
wrefresh(ok_button);
int idlength;
idlength=strlen(id);
if(isNull(id))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","输入的帐户ID不能为空");
wclear(account_input_box);
wrefresh(account_input_box);
wclear(password_input_box);
wrefresh(password_input_box);
goto account_input;
}
if(idlength<6)
{
Message_Box(10,20,10,10,RED_BLACK,"提示","输入的帐户ID太短");
wclear(account_input_box);
wrefresh(account_input_box);
wclear(password_input_box);
wrefresh(password_input_box);
goto account_input;
}
if(isNull(pwd))
{
Message_Box(10,30,10,10,RED_BLACK,"提示","输入的密码不能为空");
wclear(account_input_box);
wrefresh(account_input_box);
wclear(password_input_box);
wrefresh(password_input_box);
goto passwork_input;
}
// mvwprintw(login_win,1,1,"%d",atoi(pwd));
// wrefresh(login_win);
if(strlen(pwd)<6 || strlen(pwd)>12)
{
Message_Box(10,36,10,10,RED_BLACK,"提示","用户密码只能是6-12个字符");
wclear(password_input_box);
wrefresh(password_input_box);
goto passwork_input;
}
}
sign=0;
goto exit;
break;
// DestroyWindow(login_win_top);
// DestroyWindow(login_win_shadow);
// DestroyWindow(login_win_mid);
// DestroyWindow(account_input_box);
// DestroyWindow(password_input_box);
// DestroyWindow(ok_button);
// DestroyWindow(ok_button_shadow);
// DestroyWindow(exit_button);
// DestroyWindow(exit_button_shadow);
// DestroyWindow(login_win_bottom);
// //清除一下stdscr这个标准虚窗口
// wclear(stdscr);
/* return 0;*/
}
}
while(1)
{
exit_button:
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':
{
int isExit;
isExit=DialogWindow(10,30,10,10,"是否退出POS系统",RED_BLACK);
if(isExit==0)
{
sign=1; //为 1 的时候退出
goto exit;
}
}
break;
// return 1;//返回1为退出
}
}
exit:
if(1==sign) //等于是退出
{
idtype=0;
break;
}
strlength=strlen(id);
if(strlength!=6)
{
Message_Box(8,30,5,20,RED_BLACK,"提示","输入的帐户只能是6个数字");
wclear(account_input_box);
wrefresh(account_input_box);
wclear(password_input_box);
wrefresh(password_input_box);
goto account_input;
}
for(i=0;i<strlength;i++)
{
if(!isdigit(id[i]))
{
Message_Box(8,30,5,20,RED_BLACK,"提示","输入的帐户只能是6个数字");
goto account_input;
}
}
Trim(pwd);
strlength=strlen(pwd);
if((strlength<6) || (strlength>12))
{
Message_Box(8,30,5,20,RED_BLACK,"提示","输入的密码只能有6-12个字符");
wclear(account_input_box);
wrefresh(account_input_box);
wclear(password_input_box);
wrefresh(password_input_box);
goto passwork_input;
}
result=check_login(id,pwd,&idtype);
if(result!=0 || idtype==0) //非0就是无效,没有查到帐户跟密码 idtype==0说明这个帐户只能进行退货处理的帐户而不能登入
{
Message_Box(8,30,5,20,RED_BLACK,"提示","帐户或密码无效");
wclear(account_input_box);
wrefresh(account_input_box);
wclear(password_input_box);
wrefresh(password_input_box);
}
else
{
break;
}
}
wrefresh(account_input_box);
DestroyWindow(login_win_top);
DestroyWindow(login_win_shadow);
DestroyWindow(login_win_mid);
DestroyWindow(account_input_box);
DestroyWindow(password_input_box);
DestroyWindow(ok_button);
DestroyWindow(ok_button_shadow);
DestroyWindow(exit_button);
DestroyWindow(exit_button_shadow);
DestroyWindow(login_win_bottom);
return idtype; //如果返回1是为进入后台管理界面 2的时候就是结帐界面
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -