cinput.cpp
来自「软件的名称:AA制用餐管理系统 软件的功能:管理消费中产生的费用」· C++ 代码 · 共 279 行
CPP
279 行
#include "CInput.h"
#include "ErrorMessage.h"
#include "CValidate.h"
#include "function.h"
#include "CValidate.h"
#include "ErrorMessage.h"
#include "CTrim.h"
#include "CDate.h"
#include "CConvert.h"
#include <conio.h>
#include <iostream>
#include <string>
#include <cstring>
#define INPUTCOLOR 124
using namespace std;
/////////////////////////////////////////////////////////
int CInput::Getstring(char *str, int len)
{
int i=0;
int ch;
while(1)
{
ch=getch();
if(ch==0xe0)
{
ch=getch();//方向键不接收
//continue;
}
else if(ch==27)
{
return 1;//按ESC退出
}
else if(ch==8)
{
if(i>0)
{
printf("\b");//光标前移,然后用空格代替光标当前位置的字符
printf(" ");
printf("\b");
i--;
str[i]='\0';
}
}
else if(ch==13)
{
str[i]='\0';
return 0;
}
else if(i<len)
{
if(isprint(ch))//isprint(ch)判断ch是否是可打印字符,不包括Tab键
{
str[i++]=ch;
putchar(ch);
}
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
int CInput::Getstring(string& str, int len)
{
int i=0;
int ch;
while(1)
{
ch=getch();
if(ch==0xe0)
{
ch=getch();//方向键不接收
//continue;
}
else if(ch==27)
{
return 1;//按ESC退出
}
else if(ch==8)
{
if(i>0)
{
printf("\b");//光标前移,然后用空格代替光标当前位置的字符
printf(" ");
printf("\b");
i--;
//str[i]='\0';
str.erase(i,1);
}
}
else if(ch==13)
{
//str[i]='\0';
str.append(1,'\0');
return 0;
}
else if(i<len)
{
if(isprint(ch))//isprint(ch)判断ch是否是可打印字符,不包括Tab键
{
//str[i++]=ch;
str.append(1,ch);
i++;
putchar(ch);
}
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int CInput::InputMenuSelect(int menucount,int x,int y)//menucount代表菜单选项个数
{
char str[3];
int len=2;
int geti;
int value;
while(1)
{
function::SetXY(x,y);
Getstring(str,1);
geti =CValidate::IsSelectRight(str,menucount);
if(!geti)
break;
ErrorMessage::SelectErr(1,19,geti);//在信息框提示错误信息
function::ClearScreen(1,19,78,21);//清除信息框内容
function::ClearScreen(x,y,78,y);//清除前一次输入的
}
value =atoi(str);
return value;
}
///////////////////////////////////////////////////////////
string CInput::InputName(int x,int y)
{
string name;
//name
while(1)
{
function::SetTextCorlor(INPUTCOLOR);
function::SetXY(x+12,y+2);
int geti;
geti=Getstring(name,20);
if(geti==1)
return "0";
int getj;
getj =CValidate::IsLetterOrSpace(name);
if(!getj)
break;
function::SetTextCorlor(15);
ErrorMessage::LettreOrSpaceErr(1,19,getj);
function::ClearScreen(1,19,78,21);//清除信息框内容
function::ClearScreen(x+12,y+2,78,y+2);//清除前一次输入的
/*重画输入框*/
function::DrawInputFrame(INPUTCOLOR,x+12,y+2,21);
name.erase(0,name.size());
//cout<<"#"<<name<<endl;
}
return name;
}
//////////////////////////////////////////////////////////
char CInput::InputSex(int x,int y)
{
char sexch;
string sex;
//sex
while(1)
{
function::SetTextCorlor(INPUTCOLOR);
function::SetXY(x+12,y+4);
int geti;
geti=Getstring(sex,1);
if(geti==1)
return '0';
int getj;
getj =CValidate::IsTureSex(sex);
if(!getj)
break;
function::SetTextCorlor(15);
ErrorMessage::SexErr(1,19,getj);
function::ClearScreen(1,19,78,21);//清除信息框内容
function::ClearScreen(x+12,y+4,78,y+4);//清除前一次输入的
/*重画输入框*/
function::DrawInputFrame(INPUTCOLOR,x+12,y+4,21);
sex.erase(0,sex.size());
//cout<<"#"<<sex<<endl;
}
sexch =*(sex.c_str());
return sexch;
}
////////////////////////////////////////////////////////////////
string CInput::InputMobile(int x,int y,int sign)
{
string mobiletel;
//mobiletel
while(1)
{
function::SetTextCorlor(INPUTCOLOR);
function::SetXY(x+12,y+6);
int geti;
geti =Getstring(mobiletel,12);
if(geti==1)
return "0";
if(!sign)
return "0";
else
{
int getj;
getj =CValidate::IsMobileTel(mobiletel,1);
if(!getj)
break;
function::SetTextCorlor(15);
ErrorMessage::MobileErr(1,19,getj);
function::ClearScreen(1,19,78,21);//清除信息框内容
function::ClearScreen(x+12,y+6,78,y+6);//清除前一次输入的
/*重画输入框*/
function::DrawInputFrame(INPUTCOLOR,x+12,y+6,21);
mobiletel.erase(0,mobiletel.size());
}
//cout<<"#"<<mobiletel<<endl;
}
return mobiletel;
}
///////////////////////////////////////////////////////////
string CInput::InputDate(int x,int y,int sign)
{
string date;
//birthday
while(1)
{
function::SetTextCorlor(INPUTCOLOR);
function::SetXY(x+12,y+8);
int geti;
geti =Getstring(date,12);
if(geti==1)
return "0";
if(!sign)
return "0";
else
{
int getj;
getj =CValidate::IsDateString(date,1);
if(getj)
{
function::SetTextCorlor(15);
ErrorMessage::DateStringErr(1,19,getj);
continue;
}
else
{
int getk;
CDate currentDate =CConvert::StrToDate(date);
CDate beginDate(1900,1,1),endDate(2010,12,31);
getk =CValidate::DateRangle(currentDate,beginDate,endDate);
if(!getk)
break;
else
{
function::SetTextCorlor(15);
ErrorMessage::DateRangleErr(1,19,getj);
function::ClearScreen(1,19,78,21);//清除信息框内容
function::ClearScreen(x+12,y+6,78,y+6);//清除前一次输入的
/*重画输入框*/
function::DrawInputFrame(INPUTCOLOR,x+12,y+6,21);
date.erase(0,date.size());
}
}
}
function::SetTextCorlor(15);
//cout<<"#"<<birthday<<endl;
}
return date;
}
/////////////////////////////////////////////////////////////////////////////////
void CInput::InputAccountInfo(int x,int y)
{
string name,sex,mobile,date;
name =InputName(x,y);
sex =InputSex(x,y);
mobile =InputMobile(x,y,)
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?