📄 public.cpp
字号:
// Public.cpp : implementation file
//
#include "stdafx.h"
#include "短信群发.h"
#include "Public.h"
#include "into.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CPublic::CPublic()
{
m_str.Empty();
m_com.Empty();
m_service.Empty();
m_strpwd.Empty();
m_strUserName.Empty();
}
BOOL CPublic::PhoneCheck(CString& str)
{
m_str=str;
if (m_str.IsEmpty())
{
AfxMessageBox("电话号码不能为空");
return FALSE;
}
else if(m_str.Find("106")==0)
{
if(LengthCheck2(m_str,20))
{
return TRUE;
}
else
{
AfxMessageBox("小灵通的号码小于20!");
return FALSE;
}
}
else if(m_str.Find("+86")==0 || m_str.Find("13")==0 || m_str.Find("15")==0)
{
int length;
BOOL flag;
CString str1;
length = m_str.GetLength();
if(LengthCheck1(m_str,14))
{
str1=m_str;
if (m_str.Find("+8613")==0 || m_str.Find("+8615")==0)
{
str1.Delete(0,5);
if(!NumberCheck(str1))
{
AfxMessageBox("号码必须是纯数字组成");
return FALSE;
}
else
str.Delete(0,3);
return TRUE;
}
else
{
AfxMessageBox("号码有误");
return FALSE;
}
}
else if (LengthCheck1(m_str,11))
{
if(m_str.Find("13")==0 || m_str.Find("15")==0)
{
str1=m_str;
str1.Delete(0,2);
if(!NumberCheck(str1))
{
AfxMessageBox("号码必须是纯数字组成");
return FALSE;
}
else
return TRUE;
}
}
else
{
AfxMessageBox("号码的长度是11或者14");
return FALSE;
}
}
else
{
AfxMessageBox("手机号码以'+86','13','15'开头,小灵通以'106'开头");
return FALSE;
}
}
BOOL CPublic::PhoneCheck1(CString& str)
{
m_str=str;
if (m_str.IsEmpty())
{
return FALSE;
}
else if(m_str.Find("106")==0)
{
if(LengthCheck2(m_str,20))
{
return TRUE;
}
else
{
return FALSE;
}
}
else if(m_str.Find("+86")==0 || m_str.Find("13")==0 || m_str.Find("15")==0)
{
int length;
BOOL flag;
CString str1;
length = m_str.GetLength();
if(LengthCheck1(m_str,14))
{
str1=m_str;
if (m_str.Find("+8613")==0 || m_str.Find("+8615"))
{
str1.Delete(0,5);
if(!NumberCheck(str1))
{
return FALSE;
}
else
str.Delete(0,3);
return TRUE;
}
else
{
return FALSE;
}
}
else if (LengthCheck1(m_str,11))
{
if(m_str.Find("13")==0 || m_str.Find("15")==0)
{
str1=m_str;
str1.Delete(0,2);
if(!NumberCheck(str1))
{
return FALSE;
}
else
return TRUE;
}
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}
BOOL CPublic::NumberCheck(CString str)
{
int length;
length=str.GetLength();
for(int i=0;i<length;i++)
{
if(!isdigit(str.GetAt(i)))
{
return FALSE;
}
}
return TRUE;
}
BOOL CPublic::LengthCheck1(CString str,int length)
{
if(length==str.GetLength())
{
return TRUE;
}
else
return FALSE;
}
BOOL CPublic::LengthCheck2(CString str,int length)
{
if(str.GetLength()<=length)
{
return TRUE;
}
else
return FALSE;
}
BOOL CPublic::numOrCharCheck()
{
int len;
len=m_str.GetLength();
for (int i=0;i<len;i++)
{
if ( !(isdigit(m_str.GetAt(i)) || isalpha(m_str.GetAt(i))) )
{
AfxMessageBox("只能由数字或字母组成");
return FALSE;
}
}
return TRUE;
}
BOOL CPublic::userNameCheck(CString str, int length)
{
m_str=str;
if(m_str.IsEmpty())
{
AfxMessageBox("用户不能为空");
return FALSE;
}
else if(!LengthCheck2(m_str,12))
{
AfxMessageBox("用户长度最大为12");
return FALSE;
}
else
{
return numOrCharCheck();
}
}
BOOL CPublic::pwdCheck(CString str, int length)
{
m_str=str;
if(m_str.IsEmpty())
{
AfxMessageBox("密码不能为空");
return FALSE;
}
else if(!LengthCheck2(m_str,12))
{
AfxMessageBox("密码长度最大为12");
return FALSE;
}
else
{
return numOrCharCheck();
}
}
BOOL CPublic::userNameCheck1(CString str, int length)
{
if(!userNameCheck(str,length))
{
return FALSE;
}
if(researchUserName(str))
{
AfxMessageBox("该用户已存在!");
return FALSE;
}
return TRUE;
}
BOOL CPublic::researchUserName(CString strName)
{
CADORecordset record;
CString userName;
record.Open(db.m_pConnection,"USERS",CADORecordset::openTable);
while (!record.IsEof())
{
record.GetFieldValue("USERNAME",userName);
if (strName==userName)
{
return TRUE;
}
record.MoveNext();
}
return FALSE;
}
void CPublic::com(int com)
{
switch(com)
{
case 0:
m_com="COM1";
break;
case 1:
m_com="COM2";
break;
case 2:
m_com="COM3";
break;
case 3:
m_com="COM4";
break;
case 4:
m_com="COM5";
break;
case 5:
m_com="CO6";
break;
case 6:
m_com="COM7";
break;
case 7:
m_com="COM8";
break;
case 8:
m_com="COM9";
break;
}
}
void CPublic::service(int iService)
{
if (iService==0)
{
m_service="中国联通";
}
else
{
m_service="中国移动";
}
}
int CPublic::GetMaxID(CString tableName)
{
CADORecordset record;
int id;
int maxID=-1;
record.Open(db.m_pConnection,tableName,CADORecordset::openTable);
if (!record.IsBof())
{
record.MoveFirst();
}
if (record.IsEof)
{
maxID=0;
}
while (!record.IsEof())
{
record.GetFieldValue("ID",id);
if (id>maxID)
{
maxID=id;
}
record.MoveNext();
}
record.Close();
return maxID;
}
BOOL CPublic::TimeCheck(COleDateTime beginDay,COleDateTime endDay)
{
if (beginDay>endDay)
{
AfxMessageBox("时间错误,结束时间早于开始时间!");
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -