📄 function.cpp
字号:
{ _variant_t vTemp;
vTemp=m_pRecordset->Fields->GetItem((long )0)->GetValue();
if(vTemp.vt!=VT_NULL && vTemp.vt!=VT_EMPTY)
{
strReturn=(LPCTSTR)(_bstr_t)m_pRecordset->Fields->GetItem(long(0))->GetValue();
strncpy(tmpstr+nLen-strReturn.GetLength(),strReturn,strReturn.GetLength());
strReturn=(CString)tmpstr;
return strReturn;
}
}
m_pRecordset->Close();
}
catch(_com_error e)//捕捉异常
{
CString temp;
temp.Format("数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
strReturn=(CString)tmpstr;
return strReturn;
}
/********************************************
//得到自动编号
//sql:从数据库表中取最大值的SQL语句
//nLen:最右为数据的个数
********************************************/
CString GetAutoTydID(CString strCustomerName)
{
CString strReturn; //返回值
CString strCustomerID; //客户ID
CString strCustomerSE; //客户英文简写
_RecordsetPtr m_pRecordset; //定义数据集
CString sql="select CustomerShortEnglish,CustomerID from customer where CustomerName= '" + strCustomerName + "'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{ _variant_t vTemp;
vTemp=m_pRecordset->Fields->GetItem((long )0)->GetValue();
if(vTemp.vt!=VT_NULL && vTemp.vt!=VT_EMPTY)
{
strCustomerSE=(LPCTSTR)(_bstr_t)m_pRecordset->Fields->GetItem(long(0))->GetValue();
strCustomerID=(LPCTSTR)(_bstr_t)m_pRecordset->Fields->GetItem(long(1))->GetValue();
}
}
m_pRecordset->Close();
}
catch(_com_error e)//捕捉异常
{
CString temp;
temp.Format("数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
sql="select max(right(tydId,7))+1 from tiyoudan where customerid='"+strCustomerID+"'";
strReturn=strCustomerSE+GetAutoID(sql,7);
return strReturn;
}
/******************************
//得到客户ID
*******************************/
CString GetCustomerID(CString strCustomerName)
{
CString strReturn; //返回值
_RecordsetPtr m_pRecordset; //定义数据集
CString sql="select CustomerID from customer where CustomerName= '" + strCustomerName + "'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{ _variant_t vTemp;
vTemp=m_pRecordset->Fields->GetItem((long )0)->GetValue();
if(vTemp.vt!=VT_NULL && vTemp.vt!=VT_EMPTY)
{
strReturn=(LPCTSTR)(_bstr_t)m_pRecordset->Fields->GetItem(long(0))->GetValue();
}
}
m_pRecordset->Close();
}
catch(_com_error e)//捕捉异常
{
CString temp;
temp.Format("数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
return strReturn;
}
/**************************************
//得到自动编号
//sql:从数据库表中取最大值的SQL语句
//nLen:最右为数据的个数
************************************/
CString GetAutoFydID(CString sql,int nLen)
{
CString strReturn; //返回值
char tmpstr[20]; //临时串
_RecordsetPtr m_pRecordset; //定义数据集
memset(tmpstr,'0',nLen); //变量初始化
tmpstr[nLen]='\0';
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{ _variant_t vTemp;
vTemp=m_pRecordset->Fields->GetItem((long )0)->GetValue();
if(vTemp.vt!=VT_NULL && vTemp.vt!=VT_EMPTY)
{
strReturn=(LPCTSTR)(_bstr_t)m_pRecordset->Fields->GetItem(long(0))->GetValue();
strncpy(tmpstr+nLen-strReturn.GetLength(),strReturn,strReturn.GetLength());
strReturn=(CString)tmpstr;
return strReturn;
}
}
m_pRecordset->Close();
}
catch(_com_error e)//捕捉异常
{
CString temp;
temp.Format("数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
strReturn=(CString)tmpstr;
return strReturn;
}
/************************************************************
//把时间控件中的内容转化为字符串
*************************************************************/
CString FormatTimeCtrl(CDateTimeCtrl * pDataTimeCtrl)
{
CString strReturn;
CTime mTime;
pDataTimeCtrl->GetTime(mTime);
strReturn.Format("%04d-%02d-%02d",mTime.GetYear(),mTime.GetMonth(),mTime.GetDay());
return strReturn;
}
/**************************
得到服务器上时间
**************************/
CString GetSysDateTime()
{
CString strReturn; //返回值
_RecordsetPtr m_pRecordset; //定义数据集
CString sql="SELECT GETDATE()";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{ _variant_t vTemp;
vTemp=m_pRecordset->Fields->GetItem((long )0)->GetValue();
if(vTemp.vt!=VT_NULL && vTemp.vt!=VT_EMPTY)
{
strReturn=(LPCTSTR)(_bstr_t)m_pRecordset->Fields->GetItem(long(0))->GetValue();
}
}
m_pRecordset->Close();
}
catch(_com_error e)//捕捉异常
{
CString temp;
temp.Format("数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
return strReturn;
}
/************************************************************
//
*************************************************************/
CString GetBigMoney(double dMoney)
{
//这里没有对超出部份作异常,使用者要注意(现实中不会出现如此巨大的金额数)
CString strMoney;
strMoney.Format ("%.2f" , dMoney);
CString strUnit = "元拾佰仟万拾佰仟亿拾佰仟";
CString strNumber = "零壹贰叁肆伍陆柒捌玖";
CString strOtherUnit = "整角分";
//将数字分整数部份与小数部份处理
int nPos = strMoney.Find (".");
int nLength = strMoney.GetLength ();
if(nPos < 0)
nPos = nLength;
CString strReturnValue;
int nCount = 0;
bool bZero = false;
bool bNeedLevel = false; //对段的识别,用于是否需要出现段名,如亿,万等
//对整数部份进行反相识别处理
for(int i = nPos - 1;i >= 0;i --)
{
TCHAR ch = strMoney.GetAt (i);
if(nCount % 4 == 0 && nCount > 0)
{
//如果处理的数字为第四位(万),或第八位(亿)等,则要求置段
bNeedLevel = true;
}
if(ch == '0')
{
//只对拾佰仟位的0进行识别,主要考虑到拾的特殊性,即如10读壹拾,不会读壹拾零
if(nCount % 4 != 0)
bZero = true;
}
else
{
CString strTemp(strReturnValue);
strReturnValue = strNumber.Mid ((ch - 0x30) * 2 , 2);
if(nCount > 0)
{
strReturnValue += strUnit.Mid (nCount * 2 , 2);
if(nCount % 4 != 0 && bNeedLevel)
{
//这里判断是否需要读段名,如万,亿等
strReturnValue += strUnit.Mid (int(nCount / 4) * 8 , 2);
}
bNeedLevel = false;
}
if(bZero)
{
//只有比当前处理的位要低中有数字才补零
if(!strTemp.IsEmpty ())
strReturnValue += strNumber.Left (2);
bZero = false;
}
strReturnValue += strTemp;
}
nCount ++;
}
strReturnValue += strUnit.Left (2);
bool bAllZero = true;
//下面实现对小数点后面的处理
//先判断是否为全零,则不需要继续读
if(nPos < nLength)
{
if(nLength > 2)
nLength = 2;
for(int i = 0;i < nLength;i ++)
if(strMoney.GetAt (nPos + i + 1) != '0')
bAllZero = false;
}
if(bAllZero)
{
strReturnValue += strOtherUnit.Left (2);
}
else
{
//对分角的处理
for(int i = 0;i < nLength;i ++)
{
TCHAR ch = strMoney.GetAt (nPos + 1 + i);
if(ch == '0' && i > 0)
{
}
else
{
strReturnValue += strNumber.Mid ((ch - 0x30) * 2 , 2);
if(ch != '0')
strReturnValue += strOtherUnit.Mid ((i + 1) * 2 , 2);
}
}
}
return strReturnValue;
}
/*************************************************************/
UINT WorkerThread( LPVOID pParam )
{
//接收一个窗口类指针,然后设置窗口标题
for(int i=0;i<20;i++)
{
Sleep(2000);
}
return 0; // 返回并退出线程
//或者调用void AfxEndThread( UINT nExitCode );来退出
}
/*****************************初始化全局参数********************/
BOOL initGlobalParameter()
{
theGlobal.nHeavyOilPickers=2;
theGlobal.nLightOilPickers=4;
theGlobal.nPickerAmount=6;
theGlobal.TemplatePath="D:\\OilNew\\template\\";
theGlobal.strUserID="";
theGlobal.strUserName="";
theGlobal.strSpotName="";
//theGlobal.nMode="";
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -