Private Sub cmdok_Click()
Dim strSql As String
Dim cn As New ADODB.Connection '* 数据库连接
Dim rs As New ADODB.Recordset '* 数据库记录
On Error Resume Next
'* 连接数据库源
cn.CursorLocation = adUseClient
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\user.mdb" '数据库名称
rs.Open "select username from information where username = '" & Trim(txtuser.Text) & "'", conn, adOpenDynamic, adLockOptimistic
If rs.RecordCount < 0 Then
MsgBox "密码或用户名错误,请重新输入", vbQuestion, "输入错误"
txtuser = ""
txtkey = ""
txtuser.SetFocus
Else
MsgBox "登录成功,欢迎使用本系统!", vbInformation, "登录成功"
End If
End Sub
Dim strSql As String
Dim cn As New ADODB.Connection '* 数据库连接
Dim rs As New ADODB.Recordset '* 数据库记录
On Error Resume Next
'* 连接数据库源
cn.CursorLocation = adUseClient
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\user.mdb" '数据库名称
rs.Open "select username from information where username = '" & Trim(txtuser.Text) & "'", conn, adOpenDynamic, adLockOptimistic
If rs.RecordCount < 0 Then
MsgBox "密码或用户名错误,请重新输入", vbQuestion, "输入错误"
txtuser = ""
txtkey = ""
txtuser.SetFocus
Else
MsgBox "登录成功,欢迎使用本系统!", vbInformation, "登录成功"
End If
End Sub
解决方案 »
- 用英文版vb6,可以开发简体中文的程序吗?运行平台是winxp简体中文版
- excel空的问题
- 关于addnew将txt文本文件导入到oracle数据库中
- 简单问题
- winsock通讯问题,有代码,欢迎访问
- 我是菜鸟,谁能教我用vb做连连看?
- vba子程序可以带参数吗?
- 请教:设置状态为非 当前窗体如何实现?
- 拜托斑竹帮我看看这个问题:: http://www.csdn.net/expert/topic/486/486202.shtm 好久没有解决了!
- VB5.0的Project带有Crystal Report4.6如何转到VB6.0中???
- 高手们帮我看看这段代码有何问题?
- 用户名是否正确都提示错误
2)完成上面的修改后,不存在时记录数应该是 =0,不可能有 <0 的状态。
3)你只比较了用户名,哪里用到密码了?
If rs.RecordCount = 0 Then
MsgBox "密码或用户名错误,请重新输入", vbQuestion, "输入错误"
int getNumOfSepFlag(char* pLine){int iNumofSepFlag = 0;char* pTmp2 = NULL;char* pTmp1 = pLine;
while ((pTmp2 = strstr(pTmp1, SeparateFlag)) != NULL){ iNumofSepFlag++; pTmp1 = pTmp2 + 1; }
return iNumofSepFlag;}
TBool getWorkPath(int iNodeIndex, char* sCurPath){if (NULL == sCurPath) { y2;}
if (ACCOUNT == y8.m_iNodeType){ sprintf(sCurPath, "%s/%s", TRANSBALANCEACCOUNT_DIR, y8.m_sNodeNo);
}else {sprintf(sCurPath, "%s/%s",TRANSBALANCEOSS_DIR, y8.m_sNodeNo);}y1;}
TBool CompensateFileOper(int iNodeIndex, char* pcCheckDate,char* pcLogSerial, char* pcFileName,
TCompensateResult eResult){z3 j1;z3 szDestFileName;z3 szTmpString;char szSuffix[7];
memset(szSuffix, 0, 7);memcpy(szSuffix, pcFileName + strlen(pcFileName) - 6, 6);
memset(szTmpString, 0, sizeof(szTmpString));if (0 == strcmp(szSuffix, "_retry")) {
memcpy(szTmpString, pcFileName, strlen(pcFileName) - 6);} else{ strcpy(szTmpString, pcFileName);}
switch (y8.m_iNodeType){case ACCOUNT: sprintf(j1, "%s/%s/%s", TRANSBALANCEACCOUNT_DIR,y8.m_sNodeNo,
pcFileName);break;case BANK: sprintf(j1, "%s/%s/%s", TRANSBALANCEBANK_DIR,y8.m_sNodeNo, pcFileName);
break;}char sCurDate[DateFieldLength + 1];char sCurTime[TimeFieldLength + 1];getCurDateAndTime(
sCurDate, sCurTime);sprintf(szDestFileName, "%s/%s_%s%s%s%s%s", TRANSBALANCECOMPENSATE_DIR, szTmpString,
y8.m_sNodeNo,pcCheckDate, pcLogSerial,sCurDate, sCurTime);switch (eResult){ case COMPENSATE_SUCCEED:
case COMPENSATE_FAILED:case COMPENSATE_FILENAME_ERROR:case COMPENSATE_HEAD_INCORRECT:
//文件名不正确、文件头不正确等,不重试。y2; case COMPENSATE_FILE_ERROR:{ //文件错误时,要重试整个文件。
if (access(j1, F_OK | R_OK) == 0){char szCommand[1024];if (0 == strcmp(szSuffix, "_retry")){
sprintf(szCommand, "mv %s %s 1>/dev/null 2>&1", j1, szDestFileName); } else {sprintf(szCommand,
"cp %s %s 1>/dev/null 2>&1",j1, szDestFileName);}if (system(szCommand) != 0) {ERRORLOG; y2; } } else
{ ERRORLOG; y2; }} break;case COMPENSATE_EXP_FAILED: case COMPENSATE_UNLOCK_FAILED:
//case COMPENSATE_SENDBILLS_FAILD: 因为有消息交互,且现网无应用,暂不处理。如果要重试,需要在主进程中处理。
{//在获取文件头后,要将文件头中的笔数字修改为0,以避免重复统计。 z3 szFileHead;FILE* pfSrcFile =
fopen(j1, "r");if (NULL == pfSrcFile){ERRORLOG; y2;}if (NULL == fgets(szFileHead, LengthOfGeneralString,
pfSrcFile)){ERRORLOG;fclose(pfSrcFile);y2;}fclose(pfSrcFile);memset(szFileHead + strlen(szFileHead) - 10
, '0', 10);FILE* pfDestFile = fopen(szDestFileName, "w+");if (NULL == pfDestFile){ ERRORLOG; y2;}
if (fputs(szFileHead, pfDestFile) < 0){ERRORLOG;fclose(pfDestFile); y2;}fclose(pfDestFile);
if (0 == strcmp(szSuffix, "_retry")){ unlink(j1); } } break; default: y2; } y1;}
#if defined(_SUN_UNIX) || defined(_AIX_UNIX) || defined (_TANDEM_UX)||defined (_WARE_UNIX) || defined(__LINUX__) y4
GettingMessageLength y5 m_rcvMsgBuf.rcvBuf y6 m_rcvMsgBuf.pCurrentPosition y7
m_rcvMsgBuf.lengthToRead y8 m_rcvMsgBuf.readState y9 m_rcvMsgBuf.msgLength j1
Close == m_state j2 return Right j3 errlen = sizeof(err) j4 iLen = sizeof(struct sockaddr_in) j5
return 0 j6 msgSendQueueSend j7 return code j8 code.length j9 code.content z1
iTmpLengthOfDataInBuf z2 m_readBegin z3 pTemp->lengthToWrite z4 m_nrOfMsgSendQueue z5
m_pSendQueueTail z6 m_pSendQueueHead z7 resultOfReadBuffer z8 msgSendQueueAdd z9
//socket.C Socket通信的基本 class的实现.. "socket.hpp".. "commonfunc.hpp"
#ifdef __LINUX__ #include <string.h> #endif
TSocket::TSocket(){memset(&m_remoteAddr, 0, sizeof(m_remoteAddr));memset(&m_localAddr,
0, sizeof(m_localAddr));m_fdSocket = -1;m_state = Close; m_stLastCheckTime = 0;
memset(y6, 0, sizeof(y6));y7 = y6; y8 = 4; // 消息头四字节是长度
y9 = y5; // 读状态为取消息长度 j1 = 0;memset(m_readBuf, 0, MaxReadBuf);z3 = 0;
m_readEnd = 0;memset(m_writeBuf, 0, MaxWriteBuf); m_writeBegin = 0;m_writeEnd = 0;
z7 = NULL;z6 = NULL;z5 = 0; m_sSocketName[0] = '\0';}
TSocket::~TSocket(){y2;clearWriteBuf(); // 释放发送缓冲区
clearSendQueue(); // 释放发送队列}
//TSocket功能函数,根据指定端口,建立TCP的套接字服务器端
TBool TSocket::openServer(int iPortNumber) //建立Server侦听端口{
if (iPortNumber < 1024 || iPortNumber > 65535){ ERRORLOG; y3;}//创建套接字
m_fdSocket = socket(AF_INET, SOCK_STREAM, 0);if (m_fdSocket < 0){
ERRORLOG("openServer(): Create socket failed! errorno:" << errno << " error reason :"
<< strerror(errno) << "."); y3; }//设置为非阻塞
if (iFcntlResutl < 0){ERRORLOG("openServer(): Set socket NOBLOCK failed!errorno:"
<< errno << " error reason :" << strerror(errno) << ".");y2; y3;}// 设置SO_REUSEADDR选项
int iSetResult = setReuseAddr();if (iSetResult < 0){ERRORLOG("openServer(): Set socket
SO_REUSEADDR option failed."); y2; y3;} //设置套接字信息 m_localAddr.sin_family = AF_INET;
m_localAddr.sin_addr.s_addr = INADDR_ANY;m_localAddr.sin_port = htons(iPortNumber);
//绑定IP地址 y4int iBindResult = bind(m_fdSocket, (struct sockaddr*)&m_localAddr,
sizeof(m_localAddr)); #else int iBindResult = bind(m_fdSocket, &m_localAddr,
sizeof(m_localAddr)); #endif if (iBindResult < 0){ERRORLOG("..errorno:" << errno<<
" error reason :" << strerror(errno) << ".");y2;y3;}//建立侦听
int iListenResult = listen(m_fdSocket, LengthOfListenQueue);if (iListenResult < 0)
{ERRORLOG("...errorno:" << errno << " error reason :" << strerror(errno) << ".");
y2; y3;}m_state = Open;RUNLOG("Successfully build server, port = " << iPortNumber << ".");j3;}
//TSocket功能函数,根据目的服务器的地址信息,建立与服务器的连接
TBool TSocket::openClient(unsigned int iRemoteIP, int iRemotePort, unsigned int iLocalIP, int iLocalPort)
{if (iRemotePort <= 0) { ERRORLOG; y3; }m_fdSocket = socket(AF_INET, SOCK_STREAM, 0);if (m_fdSocket < 0)
{ERRORLOG("..errorno: "<< errno << " error reason :" << strerror(errno)); y3; }//设置为非阻塞套接字
int iFcntlResutl = fcntl(m_fdSocket, F_SETFL, fcntl(m_fdSocket, F_GETFL) | O_NONBLOCK);if (iFcntlResutl < 0)
{ERRORLOG("...errorno:"<< errno << " error reason :" << strerror(errno));y2;y3; }// 设置SO_REUSEADDR选项
int iSetResult = setReuseAddr();if (iSetResult < 0){ ERRORLOG("openClient(): Set socket SO_REUSEADDR
option failed.");y2; y3; }//设置SO_KEEPALIVE选项 iSetResult = setKeepAlive(m_fdSocket); if (iSetResult < 0)
{ERRORLOG("openClient(): Set socket SO_KEEPALIVE option failed."); y2; y3; }//设置SO_LINGER选项
iSetResult = setLinger(m_fdSocket);if (iSetResult < 0) {ERRORLOG("openClient(): Set socket SO_LINGER
option failed.");y2; y3; } //如果本地端口号大于0,则绑定本地端口号if (iLocalPort > 0) {
m_localAddr.sin_family = AF_INET; m_localAddr.sin_addr.s_addr = iLocalIP;m_localAddr.sin_port =
htons(iLocalPort);y4 int iBindResult = bind(m_fdSocket, (struct sockaddr*)&m_localAddr, sizeof(m_localAddr));
#else int iBindResult = bind(m_fdSocket, &m_localAddr, sizeof(m_localAddr)); #endif if (iBindResult < 0)
{ERRORLOG("openClient(): bind LocalInfo failed, localip[" << iLocalIP << "],localport[" << iLocalPort
<< "] errorno:"<< errno << " error reason :" << strerror(errno));y2; y3; }}