⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cformbase.cpp

📁 AA制消费管理系统(简易型) 实现账户信息
💻 CPP
字号:
#include "link.h"
#include <stdio.h>
/*************************************************************************
function:光标定位函数
param:光标的行与列坐标
return:无
**************************************************************************/

void CFormBase::GotoXY(int x, int y)
{
	COORD pos = {x,y};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut, pos);
}
/*************************************************************************
function:获取光标位置函数
param:光标行与列坐标的地址
return:光标所在位置的行与列坐标
**************************************************************************/
void CFormBase::WhereXY(int *x, int *y)
{
	HANDLE hOut;	
	CONSOLE_SCREEN_BUFFER_INFO bInfo;
	COORD pos;
	hOut = GetStdHandle(STD_OUTPUT_HANDLE);
   	GetConsoleScreenBufferInfo( hOut, &bInfo );	
	pos = bInfo.dwCursorPosition;
	*x = pos.X;
	*y = pos.Y;
}
/************************************************************************
function:字符串定长函数
param:接收字符串变量与字符串最大长度
return:无
************************************************************************/

void CFormBase::GetString(string &_str,int maxlen)
{
	char str[200];
	char ch;
	int i=0;
	if(_str.length()>0)
	{
		for(i=0;i<_str.length();i++)
		{
			str[i]=_str[i];
		}
		str[i]='\0';
		cout<<str;
	}
	do 
	{
		ch=getch();
		CMessageBox::ShowMessage("");
		if (ch==27)
		{
			str[i]=27;
			str[i+1]='\0';
			_str=str;
			return;
		}
		if (i>=maxlen && ch!=13 && ch!=8)
		{
			continue;
		}
		if (ch==-32 || ch==0 || ch==9)
		{
			ch=getch();
			continue;
		}
		if (ch==13)
		{
			str[i]='\0';
			_str=str;
			break;
		}
		else if (ch==8)
		{
			if (i==0)
			{
				continue;
			}
			else
			{
				cout<<"\b \b";	//退格
				i--;
				continue;
			}
		}
		else
		{
			str[i]=ch;
			cout<<ch;
			i++;
		}
	} while (1);
}
/************************************************************************
function:基类构造函数
param:无
return:
************************************************************************/

CFormBase::CFormBase()
{
	
}
/************************************************************************
function:界面基类框架
param:无
return:无
************************************************************************/
void CFormBase::load()
{
	int x,y;
	system("chcp 437");//936是中文
	system("cls");
	GotoXY(0,0);
	cout<<(char)213;cout.flush();				//边框,//1格
	GotoXY(1,0);
	for(x=1,y=0;x<34;x++)			//24格
	{
		cout<<(char)205;cout.flush();
	}
	cout<<"  MIS AACM  ";cout.flush();//29格
	for(x=47,y=1;x<80;x++)			//25格
	{
		cout<<(char)205;cout.flush();
	}
	cout<<(char)184;cout.flush();				//1格//1行
	for(y=1;y<28;y++)				//27行
	{
		GotoXY(0,y);
		cout<<(char)179;cout.flush();
		GotoXY(79,y);
		cout<<(char)179;cout.flush();
	}
	GotoXY(0,23);					//信息提示框
	cout<<(char)195;cout.flush();				//1格
	for(x=1;x<35;x++)				//34格
	{
		cout<<(char)196;cout.flush();
	}
	cout<<" Message ";cout.flush();			//9格
	for(x=45;x<80;x++)				//35格
	{	
		cout<<(char)196;cout.flush();
	}
	cout<<(char)180;cout.flush();				//1格
	GotoXY(0,28);					//第29行				
	cout<<(char)192;cout.flush();				//1格
	for(x=1;x<79;x++)				//78格
	{
		cout<<(char)196;cout.flush();
	}
	cout<<(char)217;cout.flush();				//1格
	cout<<"  Ver 1.0\t\tAuthor:ZhengRongZong";//第30行
	struct tm *now;
	now=CDateTime::NowDate();
	cout<<"\t\t\tDate:"<<now->tm_year+1900<<"-"<<now->tm_mon+1<<"-"<<now->tm_mday;
	GotoXY(26,2);					//标题框
	cout<<(char)218;cout.flush();
	for(x=26;x<52;x++)				//22格
	{
		cout<<(char)196;cout.flush();
	}
	cout<<(char)191;cout.flush();				//1格
	for(y=3;y<4;y++)				//2行
	{
		GotoXY(26,y);
		cout<<(char)179;cout.flush();
		GotoXY(53,y);
		cout<<(char)179;cout.flush();
	}
	GotoXY(26,4);					
	cout<<(char)192;cout.flush();
	for(x=26;x<52;x++)				//22格
	{
		cout<<(char)196;cout.flush();
	}
	cout<<(char)217;cout.flush();
}
/************************************************************************/
/* 打印函数                                                             */
/************************************************************************/
void CFormBase::Print()
{
	char temp[100]={0};
	GotoXY(22,5);
	sprintf(temp,"---------------------------------------");
	cout<<temp<<ends;
	GotoXY(22,7);
	cout<<temp<<ends;
	GotoXY(22,8+PAGENUMBER);
	cout<<temp<<ends;
	GotoXY(22,6);
	sprintf(temp,"%-4s%-21s%14s","ID","Name","Balance");
	cout<<temp<<ends;
	GotoXY(3,21);
	sprintf(temp,"%s","[Esc]Return [Home]Firstpage [End]Lastpage [Left]PageUp [Right]PageDown");
	cout<<temp<<ends;
	GotoXY(22,9+PAGENUMBER);
	sprintf(temp,"%s","Total Records:");
	cout<<temp<<ends;
}
/************************************************************************/
/* 翻页函数                                                             */
/************************************************************************/
bool CFormBase::PrintPage(vector<CAccount>&vecacc,int maxpage,int page)
{
	char temp[50]={0};
	int _id;
	string _name;
	float _balance;
	int size=vecacc.size();
	for(int k=0;k<PAGENUMBER;k++)
	{
		GotoXY(22,8+k);
		CMessageBox::Clear(22,40);
	}
	for(int i=(page-1)*PAGENUMBER,j=0;i<page*PAGENUMBER&&i<size;i++)
	{
		_id=vecacc[i].GetID();
		_name=vecacc[i].GetName();
		_balance=vecacc[i].GetBalance();
		sprintf(temp,"%-4d%-21s%14.2f",_id,_name.c_str(),_balance);
		GotoXY(22,8+j);j++;
		cout<<temp<<ends;
	}
	return true;
}
/************************************************************************/
/* 页码确认函数                                                         */
/************************************************************************/
bool CFormBase::ChangePage(char ch,int maxpage,int &page)
{
	if (ch==73 || ch==72 || ch==75)
	{
		if (page==1)
		{
			CMessageBox::ShowMessage("This is the first page .");
			return false;
		}
        if (page>1 && page <= maxpage)
		{
			page--;
			return true;
		}
	}
	else if(ch==81 || ch==77 || ch==80)
	{	
		if (page == maxpage)
		{
			CMessageBox::ShowMessage("This is the last page");
			return false;
		}
		if (page>=1 && page<maxpage)		
		{
			page++;
			return true;
		}
	}
	else if(ch==71)
	{
		if (page==1)
			return false;
		if (page<=maxpage && page>1)	
		{
			page=1;
			return true;
		}
	}
	else if (ch==79)
	{
		if (page == maxpage)
			return false;
		if (page>=1 && page<maxpage)
		{
			page=maxpage;
			return true;
		}		
	}
	else if(isdigit(ch))
	{	
		int ich=CMyString::CharToInt(ch);
		if(ich>0 && ich<=maxpage)
		{
			page=ich;
			return true;
		}
		else
		{
			if(ich>maxpage)
				page=maxpage;
			CMessageBox::ShowMessage("It's out of the page .");
			return true;
		}
	}
	else 
		return false;
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -