📄 data_comparison.cpp
字号:
#include"data_cmp.h"
#include<iostream>
#include "CAccManager.h"
#include "check_date.h "
#include<string.h>
using namespace std;
#define DOUBLE_MIN -50.00
#define DOUBLE_MAX 100.00
#define CONSUM_MIN 0.00
#define CONSUM_MAX 999.99
#define MIN_YEAR 1900
#define MAX_YEAR 2010
#define MIN_MONTH 1
#define MAX_MONTH 12
extern CAccManager acc_admin;
int C_check_cmp::check_doulble(string str_double)
{
if(atof(str_double.c_str())>=DOUBLE_MIN&&atof(str_double.c_str())<=DOUBLE_MAX)
{
return 1;
}
else
{
return 4;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_date(string str_date)
{
if((C_check_date::getYear()>=MIN_YEAR)&&(C_check_date::getYear()<=MAX_YEAR))
{
return 1;
}
else
{
return 3;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_int(string str_int,int num)
{
return 2;
}
/////////////////////////////////////////////////////
int C_check_cmp::check_char(char ch,int num)
{
if(ch>='0'&&ch<='0'+num)
{
return 1;
}
{
return 0;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_sex(string str_sex)
{
if(str_sex[0]=='M'||str_sex[0]=='m'||str_sex[0]=='F'||str_sex[0]=='f')
{
return 1;
}
else
{
return 8;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_Id(string str_Id)
{
int id=atoi (str_Id.c_str());
if((id>0)&&(id<=acc_admin.getCount())&&( acc_admin.getVeAcc( id ).GetAccFlags() ==true ) )
{
return 1;
}
else
{
return -7;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_consumMoney(string str_double)
{
if(atof(str_double.c_str())>CONSUM_MIN&&atof(str_double.c_str())<CONSUM_MAX)
{
return 1;
}
else
{
return -9;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_consumTotalNum(string str_int)
{
int num=atoi (str_int.c_str());
if((num>0)&&(num<=acc_admin.getUseAbleCount()))
{
return 1;
}
else
{
return 2;
}
}
/////////////////////////////////////////////////////
int C_check_cmp::check_joincomsumId(string str_id,int num)
{
int n=str_id.size();
if(str_id[0]=='/')
{
return -10;
}
if(str_id[n]=='/')
{
return -10;
}
if((str_id.size()==1)&&(num==1))
{
if((str_id[0]<'0')&&(str_id[0]>'9'))
{
return -10;//************** 只能由数字和/ 组成
}
else
{
if((atoi(str_id.c_str())>0)&&(atoi(str_id.c_str())<=acc_admin.getCount())&& (acc_admin.getVeAcc( atoi(str_id.c_str()) ).GetAccFlags() ==true ))
{
return 1;//***************正确返回
}
else
{
return -11;
}
}
}
for(int i=0;i<n;i++)
{
if(!((str_id[i]>='0')&&(str_id[i]<='9'))&&(str_id[i]!='/'))
{
return -10;
}
else
{
if((str_id[i]=='/')&&(str_id[i+1]=='/'))
{
return -10;
}
if(!((str_id[i+1]>='0')&&(str_id[i+1]<='9'))&&(str_id[i]=='/'))
{
return -10;
}
continue;
}
}
int m=0;
int n1=0;
int count=0;
char *temp=NULL;
const char *str;
char str_temp[1024];
str=str_id.c_str();
temp=strchr(str,'/');
while(str[m]!='\0')
{
if(str[m]!='/')
{
str_temp[n1]=str[m];
}
else
{
str_temp[n1]='\0';
n1=-1;
if((atoi(str_temp)>0)&&(atoi(str_temp)<=acc_admin.getCount())&& ( acc_admin.getVeAcc( atoi(str_temp) ).GetAccFlags() ==true ) )
{
count++;
}
else
{
return -11;
}
}
m++;
n1++;
}
str_temp[n1]='\0';
if((atoi(str_temp)>0)&&(atoi(str_temp)<=acc_admin.getCount()) && ( acc_admin.getVeAcc( atoi(str_temp) ).GetAccFlags() ==true ) )
{
count++;
}
else
{
return -11;
}
if(count!=num)
{
return -11;
}
return 1;
}
/////////////////////////////////////////////////////
int C_check_cmp::check_absentcomsumId(string str_id,int num)
{
int n=str_id.size();
if(str_id[0]=='/')
{
return -10;
}
if(str_id[n]=='/')
{
return -10;
}
if((str_id.size()==1)&&((acc_admin.getUseAbleCount()-num)==1))
{
if((str_id[0]<'0')&&(str_id[0]>'9'))
{
return -10;//************** 只能由数字和/ 组成
}
else
{
if((atoi(str_id.c_str())>0)&&(atoi(str_id.c_str())<=acc_admin.getCount()) && (acc_admin.getVeAcc( atoi(str_id.c_str()) ).GetAccFlags() ==true ) )
{
return 1;//***************正确返回
}
else
{
return -11;
}
}
}
for(int i=0;i<n;i++)
{
if(!((str_id[i]>='0')&&(str_id[i]<='9'))&&(str_id[i]!='/'))
{
return -10;
}
else
{
if((str_id[i]=='/')&&(str_id[i+1]=='/'))
{
return -10;
}
if(!((str_id[i+1]>='0')&&(str_id[i+1]<='9'))&&(str_id[i]=='/'))
{
return -10;
}
continue;
}
}
int m=0;
int n1=0;
int count=0;
char *temp=NULL;
const char *str;
char str_temp[1024];
str=str_id.c_str();
temp=strchr(str,'/');
while(str[m]!='\0')
{
if(str[m]!='/')
{
str_temp[n1]=str[m];
}
else
{
str_temp[n1]='\0';
n1=-1;
if((atoi(str_temp)>0)&&(atoi(str_temp)<=acc_admin.getCount())&& ( acc_admin.getVeAcc( atoi(str_temp) ).GetAccFlags() ==true ) )
{
count++;
}
else
{
return -11;
}
}
m++;
n1++;
}
str_temp[n1]='\0';
if((atoi(str_temp)>0)&&(atoi(str_temp)<=acc_admin.getCount())&& (acc_admin.getVeAcc( atoi(str_temp) ).GetAccFlags() ==true ) )
{
count++;
}
else
{
return -11;
}
if(count!=(acc_admin.getUseAbleCount()-num))
{
return -11;
}
return 1;
}
//////////////////////////////////////////////////////////////
int C_check_cmp::check_searchConsumId(string str_id)
{
int n = atoi(str_id.c_str());
if((n>0)&&(n<=acc_admin.getCount())) //&&( acc_admin.getVeAcc( n ).GetAccFlags() ==true )
{
return 1;
}
else
{
return -12;
}
}
/////////////////////////////////////////////////////////////////////
int C_check_cmp::check_searchBegin_LastDay(string begin_date,string last_date)
{
int begin_year,begin_month,begin_day,last_year,last_month,last_day;
C_check_date::check_date(begin_date);
begin_year = C_check_date::getYear();
begin_month = C_check_date::getMonth();
begin_day = C_check_date::getDay();
C_check_date::check_date(last_date);
last_year = C_check_date::getYear();
last_month = C_check_date::getMonth();
last_day = C_check_date::getDay();
if(last_year < begin_year)
{
return -13;
}
if(last_year > begin_year)
{
return 1;
}
if(last_year == begin_year)
{
if(last_month < begin_month)
{
return -13;
}
if(last_month > begin_month)
{
return 1;
}
if(last_month == begin_month)
{
if(last_day < begin_day)
{
return -13;
}
if(last_day >begin_day)
{
return 1;
}
if(last_day == begin_day)
{
return 1;
}
}
}
return -80;
}
////////////////////////////////////////////////
int C_check_cmp::checkFileName(string fileName)
{
char str[512];
strcpy(str,fileName.c_str());
char ch='\\';
char ch1='/';
char ch2=':';
char ch3='*';
char ch4='?';
char ch5='<';
char ch6='>';//***************************返回相应错误类型
char ch7='|';
char ch8='"';
char ch9='.';
int n;
n=strlen(str);
if( !isalpha( *(str) ) )
{
return -15;
}
if( *(str+1) != ':' )
{
return -15;
}
if( *(str+2) != '\\' )
{
return -15;
}
if( *(str+n-1)!= '\\' )
{
return -15;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -