📄 statdlg.cpp
字号:
AfxMessageBox(_T("你输入的红球5无效,请重新输入!"));
return false;
}
bool bIsValidRedBall6 = CheckRedBallValidity( m_csRedBall6, IDC_EDIT_RED_BALL6 );
if ( !bIsValidRedBall6 )
{
AfxMessageBox(_T("你输入的红球6无效,请重新输入!"));
return false;
}
// 保存6个红球到数组
m_csarRedBall.RemoveAll();
m_csarRedBall.Add( m_csRedBall1 );
m_csarRedBall.Add( m_csRedBall2 );
m_csarRedBall.Add( m_csRedBall3 );
m_csarRedBall.Add( m_csRedBall4 );
m_csarRedBall.Add( m_csRedBall5 );
m_csarRedBall.Add( m_csRedBall6 );
return true;
}
// 检查红球的有效性
bool CStatDlg::CheckRedBallValidity(CString csRedBall, UINT uRedBallID)
{
if ( csRedBall.IsEmpty() )
{
AfxMessageBox(_T("红球不能为空"));
GetDlgItem(uRedBallID)->SetFocus();
return false;
}
else
{
// 检查输入的红球是否是数字.
bool bIsDigit = CCommonTool::CheckDigit( csRedBall, csRedBall.GetLength() );
if ( !bIsDigit )
{
AfxMessageBox(_T("你输入的红球不是纯数字,请重新输入"));
GetDlgItem(uRedBallID)->SetWindowText(_T(""));
GetDlgItem(uRedBallID)->SetFocus();
return false;
}
// 检查输入的红球是否是1~33之间的某个数字.
csRedBall.TrimLeft();
csRedBall.TrimRight();
int nRedBall = atoi( csRedBall );
if ( nRedBall < 1 || nRedBall > 33 )
{
AfxMessageBox(_T("你输入的红球是不合法的,必须是1到33之间的一个数字"));
GetDlgItem(uRedBallID)->SetWindowText(_T(""));
GetDlgItem(uRedBallID)->SetFocus();
return false;
}
}
return true;
}
// 检查1个蓝球
bool CStatDlg::CheckOneBlueBall()
{
bool bIsValidBlueBall = CheckBlueBallValidity( m_csBlueBall );
if ( !bIsValidBlueBall )
{
AfxMessageBox(_T("你输入的蓝球无效,请重新输入!"));
return false;
}
return true;
}
// 检查蓝球的有效性
bool CStatDlg::CheckBlueBallValidity(CString csBlueBall)
{
if ( csBlueBall.IsEmpty() )
{
AfxMessageBox(_T("蓝球不能为空"));
GetDlgItem(IDC_EDIT_BLUE_BALL)->SetFocus();
return false;
}
else
{
// 检查输入的蓝球是否是数字.
bool bIsDigit = CCommonTool::CheckDigit( csBlueBall, csBlueBall.GetLength() );
if ( !bIsDigit )
{
AfxMessageBox(_T("你输入的蓝球不是纯数字,请重新输入"));
GetDlgItem(IDC_EDIT_BLUE_BALL)->SetWindowText(_T(""));
GetDlgItem(IDC_EDIT_BLUE_BALL)->SetFocus();
return false;
}
// 检查输入的红球是否是1~16之间的某个数字.
csBlueBall.TrimLeft();
csBlueBall.TrimRight();
int nBlueBall = atoi( csBlueBall );
if ( nBlueBall < 1 || nBlueBall > 16 )
{
AfxMessageBox(_T("你输入的蓝球是不合法的,必须是1到16之间的一个数字"));
GetDlgItem(IDC_EDIT_BLUE_BALL)->SetWindowText(_T(""));
GetDlgItem(IDC_EDIT_BLUE_BALL)->SetFocus();
return false;
}
}
return true;
}
void CStatDlg::GetIssue(CStringArray& csarIssue)
{
if ( !myFile.Open(RED_BLUE_BALL_FILE_PATH, CFile::modeRead|CFile::typeText, NULL) )
{
AfxMessageBox( _T("^_^ 打开文件失败") );
return ;
}
CString csBuf = "";
CStringArray arcsRedBlueBallInfo;
csarIssue.RemoveAll();
while ( myFile.ReadString(csBuf) )
{
arcsRedBlueBallInfo.RemoveAll();
int nResult = CCommonTool::SplitString( csBuf, "|", arcsRedBlueBallInfo );
CString csIssue = arcsRedBlueBallInfo.GetAt( 0 );
csarIssue.Add( csIssue );
}
myFile.Close();
}
// 获取红球
void CStatDlg::GetRedBallString(CStringArray& csarRedBallString)
{
if ( !myFile.Open(RED_BLUE_BALL_FILE_PATH, CFile::modeRead|CFile::typeText, NULL) )
{
AfxMessageBox( _T("^_^ 打开文件失败") );
return ;
}
CString csBuf = _T("");
CStringArray arcsRedBlueBallInfo;
csarRedBallString.RemoveAll();
while ( myFile.ReadString(csBuf) ) // 按行读取文件
{
arcsRedBlueBallInfo.RemoveAll();
int nResult = CCommonTool::SplitString( csBuf, _T("|"), arcsRedBlueBallInfo );
CString csRedBallString = arcsRedBlueBallInfo.GetAt( 1 );
csarRedBallString.Add( csRedBallString ); // 存入数组
}
myFile.Close();
}
// 获取所有红球
void CStatDlg::GetAllRedBall(CStringArray& csarRedBallString,
CStringArray& csarRedBall)
{
// 检查输入参数.
int nSize = csarRedBallString.GetSize();
if ( nSize <= 0 )
{
AfxMessageBox(_T("空数组"));
return;
}
// 初始化数组.
csarRedBall.RemoveAll();
// 从数组csarRedBallString中获得红球.
for ( int i = 0; i < csarRedBallString.GetSize(); i++ )
{
CString csRedBallString = csarRedBallString.GetAt( i );
int nResult = CCommonTool::SplitString( csRedBallString,
_T(","),
csarRedBall );
}
}
// 获取所有蓝球
void CStatDlg::GetAllBlueBall(CStringArray& csarBlueBall)
{
if ( !myFile.Open(RED_BLUE_BALL_FILE_PATH,
CFile::modeRead|CFile::typeText, NULL) )
{
AfxMessageBox( _T("^_^ 打开文件失败") );
return ;
}
CString csBuf = _T("");
CStringArray arcsRedBlueBallInfo;
csarBlueBall.RemoveAll();
while ( myFile.ReadString(csBuf) ) // 按行读取文件
{
arcsRedBlueBallInfo.RemoveAll();
int nResult = CCommonTool::SplitString( csBuf, _T("|"), arcsRedBlueBallInfo );
CString csBlueBall = arcsRedBlueBallInfo.GetAt( 2 );
csarBlueBall.Add( csBlueBall ); // 存入数组
}
myFile.Close(); // 关闭文件
}
// 获取单个红球出现的次数
void CStatDlg::GetSingleRedBallTimes(int nRedBallFlag,
CStringArray& csarRedBall)
{
if ( nRedBallFlag < 1 || nRedBallFlag > 33 )
{
AfxMessageBox(_T("红球必须是1到33之间的一个数字"));
return;
}
int nSize = csarRedBall.GetSize(); // 数组的大小
if ( nSize <= 0 )
{
AfxMessageBox(_T("空数组"));
return;
}
CString csRedBallFlag = _T("");
csRedBallFlag.Format( _T("%d"), nRedBallFlag );
m_csRedBallFlag = csRedBallFlag;
CString csRedBall = _T("");
CStringArray csarSingleRedBall; // 字符串数组
csarSingleRedBall.RemoveAll();
for ( int i = 0; i < csarRedBall.GetSize(); i++ )
{
csRedBall = csarRedBall.GetAt( i );
csRedBall.TrimLeft();
csRedBall.TrimRight();
if ( 0 == csRedBall.Compare(csRedBallFlag) )
{
csarSingleRedBall.Add( csRedBall ); // 存入数组
}
}
CStringArray csarIssue;
GetIssue( csarIssue );
int nCurMaxIssue = csarIssue.GetSize();
CString csCurMaxIssue = _T("");
csCurMaxIssue.Format( _T("%d"), nCurMaxIssue );
CString csTipInfo = _T("^_^截止到第");
csTipInfo += csCurMaxIssue;
csTipInfo += _T("期,");
int nTimes = csarSingleRedBall.GetSize(); // 出现的次数
if ( 0 == nTimes ) // 还没有出现过
{
m_csRedBallTimes = _T("0");
csTipInfo += _T("红球");
csTipInfo += csRedBallFlag;
csTipInfo += _T("还没有出现过!");
int nCheckStatus = m_chkRedBlueBall.GetCheck();
if ( 0 == nCheckStatus && !m_bIsAllStat )
{
MessageBox( csTipInfo, _T("友情提示"), MB_ICONASTERISK );
}
}
else
{
CString csTimes = _T("");
csTimes.Format( _T("%d"), nTimes );
m_csRedBallTimes = csTimes;
csTipInfo += _T("红球");
csTipInfo += csRedBallFlag;
csTipInfo += _T("已经出现过");
csTipInfo += csTimes;
csTipInfo += _T("次!");
int nCheckStatus = m_chkRedBlueBall.GetCheck();
if ( 0 == nCheckStatus && !m_bIsAllStat )
{
MessageBox( csTipInfo, _T("友情提示"), MB_ICONASTERISK );
}
}
}
// 获取单个蓝球出现的次数
void CStatDlg::GetSingleBlueBallTimes(int nBlueBallFlag,
CStringArray& csarBlueBall)
{
if ( nBlueBallFlag < 1 || nBlueBallFlag > 16 )
{
AfxMessageBox(_T("蓝球必须是1到16之间的一个数字"));
return;
}
int nSize = csarBlueBall.GetSize(); // 数组的大小
if ( nSize <= 0 )
{
AfxMessageBox(_T("空数组"));
return;
}
CString csBlueBallFlag = _T("");
csBlueBallFlag.Format( _T("%d"), nBlueBallFlag );
m_csBlueBallFlag = csBlueBallFlag;
CString csBlueBall = _T("");
CStringArray csarSingleBlueBall; // 字符串数组
csarSingleBlueBall.RemoveAll();
for ( int i = 0; i < csarBlueBall.GetSize(); i++ )
{
csBlueBall = csarBlueBall.GetAt( i );
csBlueBall.TrimLeft();
csBlueBall.TrimRight();
if ( 0 == csBlueBall.Compare(csBlueBallFlag) )
{
csarSingleBlueBall.Add( csBlueBall ); // 存入数组
}
}
CStringArray csarIssue;
GetIssue( csarIssue );
int nCurMaxIssue = csarIssue.GetSize();
CString csCurMaxIssue = _T("");
csCurMaxIssue.Format( _T("%d"), nCurMaxIssue );
CString csTipInfo = _T("^_^截止到第");
csTipInfo += csCurMaxIssue;
csTipInfo += _T("期,");
int nTimes = csarSingleBlueBall.GetSize(); // 数组的大小
if ( 0 == nTimes ) // 还没有出现过
{
m_csBlueBallTimes = _T("0");
csTipInfo += _T("蓝球");
csTipInfo += csBlueBallFlag;
csTipInfo += _T("还没有出现过!");
int nCheckStatus = m_chkRedBlueBall.GetCheck();
if ( 0 == nCheckStatus && !m_bIsAllStat )
{
MessageBox( csTipInfo, _T("友情提示"), MB_ICONASTERISK );
}
}
else
{
CString csTimes = _T("");
csTimes.Format( _T("%d"), nTimes );
m_csBlueBallTimes = csTimes;
csTipInfo += _T("蓝球");
csTipInfo += csBlueBallFlag;
csTipInfo += _T("已经出现过");
csTipInfo += csTimes;
csTipInfo += _T("次!");
int nCheckStatus = m_chkRedBlueBall.GetCheck();
if ( 0 == nCheckStatus && !m_bIsAllStat )
{
MessageBox( csTipInfo, _T("友情提示"), MB_ICONASTERISK );
}
}
}
// 检查期号
bool CStatDlg::CheckIssue(CStringArray& csarIssue, CString csInput)
{
int nSize = csarIssue.GetSize();
if ( 0 == nSize )
{
AfxMessageBox( _T("空数组") );
return false;
}
CString csIssue = _T("");
for ( int i = 0; i < nSize; i++ )
{
csIssue = csarIssue.GetAt( i );
CCommonTool::DeleteLeftRightSpaceFromCString( csIssue );
CCommonTool::DeleteLeftRightSpaceFromCString( csInput );
if ( i == nSize -1 )
{
if ( 0 != csIssue.Compare(csInput) )
{
return false;
}
}
if ( 0 == csIssue.Compare(csInput) )
{
return true;
}
else
{
continue;
}
}
return true;
}
// 获得指定期号的红球和蓝球
void CStatDlg::GetSpecifiedRedBlueBall(CString csInputFrom,
CString csInputTo,
CStringArray& csarSpecifiedRedBlueBall)
{
if ( !myFile.Open(RED_BLUE_BALL_FILE_PATH,
CFile::modeRead|CFile::typeText, NULL) )
{
AfxMessageBox( _T("^_^ 打开文件失败") );
return ;
}
CString csBuf = _T("");
CString csIssue = _T("");
csarSpecifiedRedBlueBall.RemoveAll();
int nFrom = atoi( csInputFrom );
int nTo = atoi( csInputTo );
int nIssue = 0;
while ( myFile.ReadString(csBuf) ) // 按行读取文件
{
CCommonTool::DeleteLeftRightSpaceFromCString( csBuf );
int nIndex = csBuf.Find( _T("|"), 0 );
csIssue = csBuf.Mid( 0, nIndex);
nIssue = atoi( csIssue );
if ( (nIssue >= nFrom) && (nIssue <= nTo) )
{
csarSpecifiedRedBlueBall.Add( csBuf ); // 存入数组
}
else
{
if ( nIssue > nTo )
{
return;
}
continue;
}
}
}
void CStatDlg::OnButtonQuit()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -