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

📄 varcomm.cpp

📁 一个可以读取Access数据库表的简单实例.可应用于办公室系统中.
💻 CPP
字号:
//=======================================================================================================================
//
//  文件: VarComm.H
//
//  版本: V1.0
//
//  描述:
//
//  作者: 徐力
//
//  创建日期:2003-2-17
//
//  修改历史:	日期		修改内容
//
//
//=======================================================================================================================

#include "stdafx.h"
#include "VarComm.h"
#include "XDebug.h"


void Trim ( CString & str )
{
	str.TrimLeft () ;
	str.TrimRight () ;
}

BOOL Is_Number ( CString str ) 
{
	Trim ( str ) ;

	if ( str.IsEmpty() )
		return FALSE ;

	BOOL Flag = FALSE ;
	int n = 0 , len = str.GetLength () ;
	char ch ;
	
	for ( int i = 0 ; i < len ; i ++ )
	{
		ch = str [ i ]  ;
		if ( ( ! ( ch >= '0' && ch <= '9' ) ) && ch != '.'  )
			goto end ;
	}
	
	for ( i = 0 ; i < len ; i ++ )
	{
		ch = str [ i ]  ;
		if ( ch == '.' )
			n ++ ;
	}
	
	if ( n > 1 )
		goto end ;
	
	Flag = TRUE ;
	
end:	
	
	if ( ! Flag )
		Show_Msg ( "%s不是合法的数值" , str ) ;
	
	return Flag ;
}


void Var_Safe ( _variant_t & va ) 
{
	if ( va.vt == VT_NULL )
		va.SetString ( "0" ) ;
}


CString vartoString ( _variant_t va ) 
{
	CString str ;
	str = ( LPCSTR )( _bstr_t ) va ;  
	str.TrimLeft () ;
	str.TrimRight () ;
	return str ;
}


CString GetDataString ( void ) 
{
	CTime t = CTime::GetCurrentTime () ;
	CString str ;
	str.Format ( "%04d%02d%02d" , t.GetYear() , t.GetMonth() , t.GetDay() ) ;
	return str ;
}


BOOL Is_Date_valid ( CString strDate ) 
{
	int len = strDate.GetLength () ;
	if ( len != 8 )
	{	
		Show_Msg ( "日期的表达式%s位数不符合标准!\n应该为 YYYYMMMDD" , strDate ) ;
		return FALSE ;
	}

	int iYaer , iMonth , iDay ;
	sscanf ( strDate , "%04d%02d%02d" , & iYaer , & iMonth , & iDay ) ;
	if ( iMonth < 1 || iMonth > 12 )
	{
		Show_Msg ( "日期的表达式%s中, 月份的有效范围是(1-12)!" , strDate ) ;
		return FALSE ;
	}
	if ( iDay < 1 || iDay > 31 )
	{
		Show_Msg ( "日期的表达式%s中, 天的有效范围是(1-31)!" , strDate ) ;
		return FALSE ;
	}
	

	if ( ! Is_Number ( strDate) )
	{
		Show_Msg ( "日期的表达式%s有不合法的字符存在!" , strDate ) ;
		return FALSE ;
	}

	return TRUE ;
}


BOOL Is_Time_valid ( CString strTime ) 
{
	int len = strTime.GetLength () ;
	if ( len != 6 )
	{	
		Show_Msg ( "时间的表达式%s位数不符合标准!\n应该为 HHMMSS" , strTime ) ;
		return FALSE ;
	}

	int iHour , iMin , iSec ;
	sscanf ( strTime , "%04d%02d%02d" , & iHour , & iMin , & iSec ) ;
	if ( iHour < 0 || iHour > 23 )
	{
		Show_Msg ( "时间的表达式%s中, 小时的有效范围是(0-23)!" , strTime )  ;
		return FALSE ;
	}
	if ( iMin < 0 || iMin > 59 )
	{
		Show_Msg ( "时间的表达式%s中, 分钟的有效范围是(0-59)!" , strTime ) ;
		return FALSE ;
	}
	if ( iSec < 0 || iSec > 59 )
	{
		Show_Msg ( "时间的表达式%s中, 秒的有效范围是(0-59)!" , strTime ) ;
		return FALSE ;
	}
	
	
	if ( ! Is_Number ( strTime) )
	{
		Show_Msg ( "时间的表达式%s有不合法的字符存在!" , strTime ) ;
		return FALSE ;
	}
	
	return TRUE ;
}

⌨️ 快捷键说明

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