Example #1
0
CRecordset * CMyDatabase::getTableRecordset(CString TableName, CString Whereis)
{
	CString SqlString = _T("SELECT * FROM ")+TableName+Whereis;
	CRecordset *record;
	record= new CRecordset(this->m_nDatabase);
	record->Open(CRecordset::dynaset,SqlString);
	return record;
}
Example #2
0
void CRecordView::OnUpdateRecordNext(CCmdUI* pCmdUI)
{
    CRecordset* prs = OnGetRecordset();

    // enable if opened and >= 1 records present
    pCmdUI->Enable(prs->IsOpen() && !(prs->IsEOF() && prs->IsBOF())
                   // and not already on last record
                   && !IsOnLastRecord());
}
Example #3
0
void CRecordView::OnUpdateRecordLast(CCmdUI* pCmdUI)
{
    CRecordset* prs = OnGetRecordset();

    // enable if opened, can scroll,
    pCmdUI->Enable(prs->IsOpen() && prs->CanScroll() &&
                   // >= 1 records present and not already on last record
                   !(prs->IsEOF() && prs->IsBOF()) && !IsOnLastRecord());
}
Example #4
0
BOOL CBCGPODBCGridCtrl::GetFieldList (LPCTSTR lpszTable, CStringList& lstField)
{
	ASSERT (lpszTable != NULL);

	lstField.RemoveAll ();

	if (m_pDataBase == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	try
	{
		ASSERT_VALID (m_pDataBase);

		if (!m_pDataBase->IsOpen ())
		{
			ASSERT (FALSE);
			return FALSE;
		}

		CRecordset* pRecordSet = new CRecordset (m_pDataBase);

		CString strSQL = _T("SELECT * FROM ");
		strSQL += lpszTable;

		if (!pRecordSet->Open (CRecordset::forwardOnly, strSQL))
		{
			delete pRecordSet;
			return FALSE;
		}

		const short nColumns = pRecordSet->GetODBCFieldCount ();

		for (short nColumn = 0; nColumn < nColumns; nColumn++)
		{
			CODBCFieldInfo fieldinfo;
			pRecordSet->GetODBCFieldInfo (nColumn, fieldinfo);

			lstField.AddTail (fieldinfo.m_strName);
		}

		pRecordSet->Close ();
		delete pRecordSet;
	}
	catch (CDBException* pEx)
	{
		OnODBCException (pEx);
		pEx->Delete ();

		return FALSE;
	}

	return TRUE;
}
Example #5
0
BOOL CRecordView::IsOnLastRecord()
{
    ASSERT_VALID(this);
    CRecordset* pRecordset = OnGetRecordset();
    CRecordsetStatus status;
    pRecordset->GetStatus(status);
    if (!status.m_bRecordCountFinal)
        return FALSE;
    return ((status.m_lCurrentRecord+1 == pRecordset->GetRecordCount()));
}
Example #6
0
void CGateInfo::MakeNewUser(char *pszPacket)
{
    char				szDecodeMsg[256];
    char				szEncodeMsg[32];
    char				*pszID, *pszName, *pszPassword;
    _TDEFAULTMESSAGE	DefMsg;

    fnDecodeMessageA(&DefMsg, pszPacket);

    if (DefMsg.wIdent == CM_ADDNEWUSER)
    {
        int nPos = fnDecode6BitBufA((pszPacket + DEFBLOCKSIZE), szDecodeMsg, sizeof(szDecodeMsg));
        szDecodeMsg[nPos] = '\0';

        pszID		= &szDecodeMsg[0];

        pszName		= (char *)memchr(szDecodeMsg, '/', memlen(szDecodeMsg) - 1);
        *pszName = '\0';
        pszName++;

        pszPassword	= (char *)memchr(pszName, '/', memlen(pszName) - 1);
        *pszPassword = '******';
        pszPassword++;

        if ((memlen(pszID) - 1) || (memlen(pszName) - 1) || (memlen(pszPassword) - 1))
        {
            char szQuery[1024];
            sprintf( szQuery,
                     "INSERT TBL_ACCOUNT( FLD_LOGINID, FLD_PASSWORD, FLD_USERNAME, FLD_CERTIFICATION ) "
                     "VALUES( '%s', '%s', '%s', 0 )",
                     pszID, pszPassword, pszName );

            CRecordset *pRec = GetDBManager()->CreateRecordset();
            if ( pRec->Execute( szQuery ) && pRec->GetRowCount() )
                fnMakeDefMessageA( &DefMsg, SM_NEWID_SUCCESS, 0, 0, 0, 0 );
            else
                fnMakeDefMessageA( &DefMsg, SM_NEWID_FAIL, 0, 0, 0, 0 );
            GetDBManager()->DestroyRecordset( pRec );
            // -----------------------------------------------------------------------------------
        }
        else
            fnMakeDefMessageA(&DefMsg, SM_NEWID_FAIL, 0, 0, 0, 0);

        fnEncodeMessageA(&DefMsg, szEncodeMsg, sizeof(szEncodeMsg));

        szDecodeMsg[0] = '#';
        memmove(&szDecodeMsg[1], szEncodeMsg, DEFBLOCKSIZE);
        szDecodeMsg[DEFBLOCKSIZE + 1] = '!';
        szDecodeMsg[DEFBLOCKSIZE + 2] = '\0';

        send(sock, szDecodeMsg, DEFBLOCKSIZE + 2, 0);
    }
}
Example #7
0
void CRecordView::OnInitialUpdate()
{
    CRecordset* pRecordset = OnGetRecordset();
    // recordset must be allocated already
    ASSERT(pRecordset != NULL);

    if (!pRecordset->IsOpen())
    {
        CWaitCursor wait;
        pRecordset->Open();
    }

    CFormView::OnInitialUpdate();
}
Example #8
0
int CMyDatabase::getTypesID(CString TypesName)
{
	CString SqlString2 = _T("SELECT * FROM types WHERE Name='")+TypesName+_T("' ");
	CRecordset *record;
	record= new CRecordset(this->m_nDatabase);
	record->Open(CRecordset::dynaset,SqlString2);
	CString tempStr=_T("0");
	int PID=0;
	if (!record->IsEOF())
	{
		record->MoveFirst();
		record->GetFieldValue(_T("CID"),tempStr);
	}
	PID	= _ttoi(tempStr) ;
	return PID;
}
Example #9
0
int CMyDatabase::getProvinceid(CString provinceName)
{
	CString SqlString2 = _T("SELECT * FROM Province WHERE Province='")+provinceName+_T("' ");
	CRecordset *record;
	record= new CRecordset(this->m_nDatabase);
	record->Open(CRecordset::dynaset,SqlString2);
	CString tempStr=_T("0");
	int PID=0;
	if (!record->IsEOF())
	{
		record->MoveFirst();
		record->GetFieldValue(_T("ProvinceID"),tempStr);
	}
	PID	= _ttoi(tempStr) ;
	return PID;
}
Example #10
0
void CMyDatabase::addTypeName(CString TypeName,CString PTypeName)
{
	CString SqlString2 = _T("SELECT * FROM types WHERE Name='")+PTypeName+_T("' ");
	CRecordset *record;
	record= new CRecordset(this->m_nDatabase);
	record->Open(CRecordset::dynaset,SqlString2);
	CString tempStr=_T("0");
	if (!record->IsEOF())
	{
		record->MoveFirst();
		record->GetFieldValue(_T("CID"),tempStr);
	}

	CString SqlString;
	SqlString.Format(_T("INSERT INTO types (Name,PID) VALUES('%s',%s)"),TypeName,tempStr);
	this->m_nDatabase->ExecuteSQL(SqlString);
}
Example #11
0
void InitMonItemInfo()
{
	int			nMonIndex;
	char		szQuery[1024];
	CRecordset *pRec = g_pConnCommon->CreateRecordset();

	sprintf( szQuery, "SELECT * FROM TBL_MONITEM");

	if (pRec->Execute( szQuery ))
	{
		while (pRec->Fetch())
		{
			nMonIndex = atoi( pRec->Get( "FLD_MONSTER" ));

			CMonItem* pMonItem = new CMonItem;

			if (pMonItem)
			{
				pMonItem->m_btItemType	= atoi( pRec->Get( "FLD_TYPE" ));
				pMonItem->m_wItemIndex	= atoi( pRec->Get( "FLD_ITEM" ));
				pMonItem->m_nPoint		= atoi( pRec->Get( "FLD_PROBABLY" ));
				pMonItem->m_wCount		= atoi( pRec->Get( "FLD_COUNT" ));
			
				if (g_pMonRaceInfo && (nMonIndex <= g_nNumOfMonRaceInfo))
					g_pMonRaceInfo[nMonIndex].m_xMonItemList.AddNewNode(pMonItem);
			}
		}	
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #12
0
//-------------------------------------------------------------->>>
//函数:DBOpenRecordset
//功能:执行 SQL 语句得到视图
//参数:
//		nOpenType	:返回的记录集类型
//			dynaset		= 0,uses SQLExtendedFetch, keyset driven cursor
//			snapshot	= 1,uses SQLExtendedFetch, static cursor
//			forwardOnly	= 2,uses SQLFetch
//			dynamic		= 3,uses SQLExtendedFetch, dynamic cursor
//		sSQL	:要执行的SQL语句
//返回:
//		CRecordset	:返回记录集,注:记录集用完要先关闭后删除.
//		NULL		:SQL语句错误
//-------------------------------------------------------------->>>
CRecordset * CDBManager::DBOpenRecordset(UINT nOpenType, CString sSQL)
{
CRecordset	*reSet;

	reSet = new(CRecordset);
	reSet->m_pDatabase = &m_DB;
	try
	{
		reSet->Open(nOpenType, sSQL);
	}
	catch(CDBException)
	{
		delete reSet;
		m_ErrorMsg = "SQL语句错误!";
		return(NULL);
	};
	return(reSet);
}
Example #13
0
void InitMoveMapEventInfo()
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_MOVEMAPEVENT");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nNumOfMoveMapEventInfo = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nNumOfMoveMapEventInfo < 0) return;

	g_pMoveMapEventInfo = new CMoveMapEventInfo[g_nNumOfMoveMapEventInfo];

	sprintf( szQuery, "SELECT * FROM TBL_MOVEMAPEVENT ORDER BY FLD_INDEX");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nNumOfMoveMapEventInfo; i++)
		{
			if (pRec->Fetch())								 
			{
				strcpy(g_pMoveMapEventInfo[i].szSMapFileName, pRec->Get( "FLD_SMAPFILENAME" ) );
				strcpy(g_pMoveMapEventInfo[i].szDMapFileName, pRec->Get( "FLD_DMAPFILENAME" ) );

				g_pMoveMapEventInfo[i].nSX = atoi( pRec->Get( "FLD_SX" ) );
				g_pMoveMapEventInfo[i].nSY = atoi( pRec->Get( "FLD_SY" ) );
				g_pMoveMapEventInfo[i].nDX = atoi( pRec->Get( "FLD_DX" ) );
				g_pMoveMapEventInfo[i].nDY = atoi( pRec->Get( "FLD_DY" ) );

				g_pMoveMapEventInfo[i].fIsOpen = FALSE;
			}
		}

		InsertLogMsgParam(IDS_FETCH_MOVEMAPEVENT, &g_nNumOfMoveMapEventInfo, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #14
0
void CGateInfo::ReceiveServerMsg(char *pszPacket)
{
    char		*pszPos;
    int			nCertification;
    int			nLen = memlen(pszPacket);

    if (pszPos = (char *)memchr(pszPacket, '/', nLen))
    {
        *pszPos++ = '\0';
        nCertification = AnsiStrToVal(pszPos);

        char szQuery[256];
        sprintf( szQuery,
                 "UPDATE TBL_ACCOUNT SET FLD_CERTIFICATION=%d WHERE FLD_LOGINID='%s'",
                 nCertification, pszPacket );

        CRecordset *pRec = GetDBManager()->CreateRecordset();
        pRec->Execute( szQuery );
        GetDBManager()->DestroyRecordset( pRec );
    }
}
Example #15
0
void LoadCharacterRecords()
{
	InsertLogMsg(IDS_LOADACCOUNTRECORDS);

	CRecordset *pRec = GetDBManager()->CreateRecordset();
	if ( pRec->Execute( "SELECT * FROM TBL_GAMEGATEINFO" ) )
	{
		GAMESERVERINFO *pServerInfo;

		while ( pRec->Fetch() )
		{
			pServerInfo = new GAMESERVERINFO;
			if ( !pServerInfo )
				break;

			pServerInfo->index = atoi( pRec->Get( "FLD_SERVERIDX" ) );
			strcpy( pServerInfo->name, pRec->Get( "FLD_SERVERNAME" ) );
			strcpy( pServerInfo->ip,   pRec->Get( "FLD_SERVERIP" ) );
			pServerInfo->connCnt = 0;

			g_xGameServerList.AddNewNode( pServerInfo );
		}
	}
	GetDBManager()->DestroyRecordset( pRec );
}
Example #16
0
void CGateInfo::DeleteExistCharacter(SOCKET s, _LPTCREATECHR lpTCreateChr)
{
	_TDEFAULTMESSAGE	DefaultMsg;
	char				szEncodeMsg[32];
	char				szQuery[256];
	CRecordset			*pRec;

	sprintf( szQuery, "DELETE FROM TBL_CHARACTER WHERE FLD_LOGINID='%s' AND FLD_CHARNAME='%s'", lpTCreateChr->szID, lpTCreateChr->szName );

	pRec = GetDBManager()->CreateRecordset();
	pRec->Execute( szQuery );
	GetDBManager()->DestroyRecordset( pRec );

	sprintf( szQuery, "DELETE FROM TBL_CHARACTER_GENITEM WHERE FLD_LOGINID='%s' AND FLD_CHARNAME='%s'", lpTCreateChr->szID, lpTCreateChr->szName );

	pRec = GetDBManager()->CreateRecordset();
	pRec->Execute( szQuery );
	GetDBManager()->DestroyRecordset( pRec );

	sprintf( szQuery, "DELETE FROM TBL_CHARACTER_ITEM WHERE FLD_LOGINID='%s' AND FLD_CHARNAME='%s'", lpTCreateChr->szID, lpTCreateChr->szName );

	pRec = GetDBManager()->CreateRecordset();
	pRec->Execute( szQuery );
	GetDBManager()->DestroyRecordset( pRec );

	sprintf( szQuery, "DELETE FROM TBL_CHARACTER_MAGIC WHERE FLD_LOGINID='%s' AND FLD_CHARNAME='%s'", lpTCreateChr->szID, lpTCreateChr->szName );

	pRec = GetDBManager()->CreateRecordset();
	pRec->Execute( szQuery );
	GetDBManager()->DestroyRecordset( pRec );

	fnMakeDefMessageA(&DefaultMsg, SM_DELCHR_SUCCESS, 0, 4, 0, 0);
	int nPos = fnEncodeMessageA(&DefaultMsg, szEncodeMsg, sizeof(szEncodeMsg));
	szEncodeMsg[nPos] = '\0';
	
	SendToGate(s, szEncodeMsg);
}
Example #17
0
UINT WINAPI LoadAccountRecords(LPVOID lpParameter)
{
	InsertLogMsg(IDS_LOADACCOUNTRECORDS);

	CRecordset *pRec = GetDBManager()->CreateRecordset();
	pRec->Execute( "UPDATE TBL_ACCOUNT SET FLD_CERTIFICATION=0 WHERE FLD_CERTIFICATION >= 30" );
	GetDBManager()->DestroyRecordset( pRec );
	// ----------------------------------------------------------------------------------------

	GAMESERVERINFO *pServerInfo;

	pRec = GetDBManager()->CreateRecordset();
	if ( pRec->Execute( "SELECT * FROM TBL_SERVERINFO" ) )
	{
		while ( pRec->Fetch() )
		{			
			pServerInfo = new GAMESERVERINFO;
			if ( !pServerInfo )
				break;

			pServerInfo->index = atoi( pRec->Get( "FLD_SERVERIDX" ) );
			strcpy( pServerInfo->name, pRec->Get( "FLD_SERVERNAME" ) );
			strcpy( pServerInfo->ip,   pRec->Get( "FLD_SERVERIP" ) );
			pServerInfo->connCnt = 0;

			g_xGameServerList.AddNewNode( pServerInfo );
		}
	}
	GetDBManager()->DestroyRecordset( pRec );

	char szTmp[64];
	for ( PLISTNODE pNode = g_xGameServerList.GetHead(); pNode; pNode = g_xGameServerList.GetNext( pNode ) )
	{
		pServerInfo = g_xGameServerList.GetData( pNode );
		
		sprintf( szTmp, "%d,%s,", pServerInfo->index, pServerInfo->name );
		strcat( g_szServerList, szTmp );
	}
	// ----------------------------------------------------------------------------------------

	InitServerThreadForMsg();

	if (InitServerSocket(g_gcSock, &g_gcAddr, _IDM_GATECOMMSOCK_MSG, 5500, 1))
		SwitchMenuItem(TRUE);

	return 0L;
}
Example #18
0
void InitMagicInfo()
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_MAGIC");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nNumOfMagicInfo = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nNumOfMagicInfo < 0) return;

	g_pMagicInfo = new CMagicInfo[g_nNumOfMagicInfo];

	sprintf( szQuery, "SELECT * FROM TBL_MAGIC ORDER BY FLD_INDEX");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nNumOfMagicInfo; i++)
		{
			if (pRec->Fetch())								 
			{
				g_pMagicInfo[i].nIndex			= atoi( pRec->Get( "FLD_INDEX" ) );
				
				strcpy(g_pMagicInfo[i].szName, pRec->Get( "FLD_NAME" ) );
				ChangeSpaceToNull(g_pMagicInfo[i].szName);

				g_pMagicInfo[i].sEffectType		= atoi( pRec->Get( "FLD_EFFECTTYPE" ) );
				g_pMagicInfo[i].sEffect			= atoi( pRec->Get( "FLD_EFFECT" ) );
				g_pMagicInfo[i].sSpell			= atoi( pRec->Get( "FLD_SPELL" ) );
				g_pMagicInfo[i].sPower			= atoi( pRec->Get( "FLD_POWER" ) );
				g_pMagicInfo[i].sMaxPower		= atoi( pRec->Get( "FLD_MAXPOWER" ) );
				g_pMagicInfo[i].sDefSpell		= atoi( pRec->Get( "FLD_DEFSPELL" ) );
				g_pMagicInfo[i].sDefPower		= atoi( pRec->Get( "FLD_DEFPOWER" ) );
				g_pMagicInfo[i].sDefMaxPower	= atoi( pRec->Get( "FLD_DEFMAXPOWER" ) );
				g_pMagicInfo[i].sJob			= atoi( pRec->Get( "FLD_JOB" ) );
				g_pMagicInfo[i].sNeed[0]		= atoi( pRec->Get( "FLD_NEEDL1" ) );
				g_pMagicInfo[i].nTrain[0]		= atoi( pRec->Get( "FLD_L1TRAIN" ) );
				g_pMagicInfo[i].sNeed[1]		= atoi( pRec->Get( "FLD_NEEDL2" ) );
				g_pMagicInfo[i].nTrain[1]		= atoi( pRec->Get( "FLD_L2TRAIN" ) );
				g_pMagicInfo[i].sNeed[2]		= atoi( pRec->Get( "FLD_NEEDL3" ) );
				g_pMagicInfo[i].nTrain[2]		= atoi( pRec->Get( "FLD_L3TRAIN" ) );
				g_pMagicInfo[i].sDelay			= atoi( pRec->Get( "FLD_DELAY" ) );
			}
		}

		InsertLogMsgParam(IDS_FETCH_MAGICDATA, &g_nNumOfMagicInfo, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #19
0
void CEdRptDoc::GetStaticData(CRecordset &rc)
{
	if (!rc.IsOpen())
		return;

	CString csTmp;

	GV_ITEM Item;
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX;	
	Item.row = m_Grid.GetRowCount() - 1;	
	Item.col = 0;
	Item.szText = "总计";
	m_Grid.SetItem(&Item);

	CString csFormat;
	CODBCFieldInfo fi;
	for (Item.col = 1; Item.col < m_ColFmt.GetSize(); Item.col++)
	{
		if (m_ColFmt[Item.col].format.IsEmpty())
		{
			rc.GetODBCFieldInfo(short(Item.col), fi);
			if (fi.m_nSQLType == SQL_NUMERIC || fi.m_nSQLType == SQL_DECIMAL)
			{
				if (fi.m_nScale == 0)
				{
					fi.m_nSQLType = SQL_INTEGER;
					csFormat.Format("%%%dd", fi.m_nPrecision);				
				}
				else
				{
					fi.m_nSQLType = SQL_FLOAT;
					csFormat.Format("%%%d.%df", fi.m_nPrecision, fi.m_nScale);				
				}
			}
		}
		else
		{
			csFormat = m_ColFmt[Item.col].format;
			if (csFormat.FindOneOf("dioux") > 0)
				fi.m_nSQLType = SQL_INTEGER;
			else if (csFormat.FindOneOf("eEfgG") > 0)
				fi.m_nSQLType = SQL_FLOAT;
			else
				fi.m_nSQLType = SQL_DATETIME;
		}

		switch(fi.m_nSQLType)
		{
		case SQL_INTEGER:
		case SQL_SMALLINT:
		case SQL_TINYINT:
		case SQL_BIGINT:
			fi.m_nSQLType = SQL_INTEGER;
			if (csFormat.IsEmpty())
				csFormat = _T("%d");
			break;

		case SQL_FLOAT:
		case SQL_REAL:
		case SQL_DOUBLE:
			fi.m_nSQLType = SQL_FLOAT;
			if (csFormat.IsEmpty())
				csFormat = _T("%f");
			break;
		default:
			break;
		}
		
		double fSum = 0.0;
		if (fi.m_nSQLType == SQL_INTEGER || fi.m_nSQLType == SQL_FLOAT)
		{
			CString csTmp;
			for (int j = 1; j < m_Grid.GetRowCount() - 1; j++)
			{
				csTmp = m_Grid.GetItemText(j, Item.col);
				fSum += atof(csTmp);
			}
		}
		
		if (fi.m_nSQLType == SQL_INTEGER)
			Item.szText.Format(csFormat, (int)fSum);
		else if (fi.m_nSQLType == SQL_FLOAT)
			Item.szText.Format(csFormat, fSum);
		else
			Item.szText = "--:--";

		Item.szText.TrimLeft();
		Item.szText.TrimRight();
		m_Grid.SetItem(&Item);	
	}
	
}
Example #20
0
void CGateInfo::ProcLogin(SOCKET s, char *pszData)
{
    char				szIDPassword[32];
    char				*pszID, *pszPassword;
    char				szEncodePacket[64];
    _TDEFAULTMESSAGE	DefMsg;
    int					nPos;
    char				szQuery[256];

    if (memlen(pszData) - 1 <= 0) return;

    PLISTNODE pListNode = xUserInfoList.GetHead();

    while (pListNode)
    {
        CUserInfo *pUserInfo = xUserInfoList.GetData(pListNode);

        if (pUserInfo->sock == s)
        {
            int nDecodeLen = fnDecode6BitBufA(pszData, szIDPassword, sizeof(szIDPassword));
            szIDPassword[nDecodeLen] = '\0';

            pszID		= &szIDPassword[0];

            if (pszPassword	= (char *)memchr(szIDPassword, '/', sizeof(szIDPassword)))
            {
                *pszPassword = '******';
                pszPassword++;

                sprintf( szQuery, "SELECT * FROM TBL_ACCOUNT WHERE FLD_LOGINID='%s'", pszID );

                CRecordset *pRec = GetDBManager()->CreateRecordset();

                if ( !pRec->Execute( szQuery ) || !pRec->Fetch() )
                    fnMakeDefMessageA( &DefMsg, SM_ID_NOTFOUND, 0, 0, 0, 0 );
                else if ( CompareDBString( pszPassword, pRec->Get( "FLD_PASSWORD" ) ) != 0 )
                    fnMakeDefMessageA( &DefMsg, SM_PASSWD_FAIL, 0, 0, 0, 0 );
                else
                {
                    int nCertCode = atoi( pRec->Get( "FLD_CERTIFICATION" ) );
                    /*
                    			if ( nCertCode > 0 && nCertCode < 30 )
                    				fnMakeDefMessageA(&DefMsg, SM_CERTIFICATION_FAIL, (nCertCode + 1), 0, 0, 0);
                    			else if ( nCertCode >= 30 )
                    				fnMakeDefMessageA(&DefMsg, SM_CERTIFICATION_FAIL, 1, 0, 0, 0);
                    			else*/
                    {
                        char szEncodeServerList[512];
                        char szEncodeAllPacket[1024];

                        fnMakeDefMessageA(&DefMsg, SM_PASSOK_SELECTSERVER, 0, 1, 0, 0);
                        nPos = fnEncodeMessageA(&DefMsg, szEncodePacket, sizeof(szEncodePacket));
                        szEncodePacket[nPos] = '\0';

                        int nPos2 = fnEncode6BitBufA((unsigned char *)g_szServerList, szEncodeServerList, memlen(g_szServerList), sizeof(szEncodeServerList));
                        szEncodeServerList[nPos2] = '\0';

                        memmove(szEncodeAllPacket, szEncodePacket, nPos);
                        memmove(&szEncodeAllPacket[nPos], szEncodeServerList, memlen(szEncodeServerList));

                        SendToGate(s, szEncodeAllPacket);

                        GetDBManager()->DestroyRecordset( pRec );

                        pUserInfo->nCertification = GetCertification();

                        //				pRec = GetDBManager()->CreateRecordset();
                        //				sprintf( szQuery,
                        //					"UPDATE TBL_ACCOUNT SET FLD_CERTIFICATION=%d WHERE FLD_LOGINID='%s'",
                        //					GetCertification(), pszID );
                        //				pRec->Execute( szQuery );

                        //				GetDBManager()->DestroyRecordset( pRec );

                        return;
                    }
                }

                GetDBManager()->DestroyRecordset( pRec );

                nPos = fnEncodeMessageA(&DefMsg, szEncodePacket, sizeof(szEncodePacket));
                szEncodePacket[nPos] = '\0';

                SendToGate(s, szEncodePacket);
            }
        }

        pListNode = xUserInfoList.GetNext(pListNode);
    }
}
Example #21
0
BOOL CFieldContentsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	try
	{		
	//	prüfe Parameter
		ASSERT (NULL != m_pDatabase && m_pDatabase -> IsOpen ());
		ASSERT (!m_strField.IsEmpty ());
		ASSERT (!m_strTable.IsEmpty ());

	//	Listbox füllen
		CWaitCursor wc;

	//	zuerst SelectString zusammenbauen
		CString strSelect;
		AfxFormatString2 (strSelect, IDS_SELECT_FIELD, m_strField, m_strTable);
		CRecordset rs (m_pDatabase);
		VERIFY (rs.Open (CRecordset::forwardOnly, strSelect, CRecordset::readOnly));
		CString strVal;
		int iMax = 0;
		while (!rs.IsEOF ())
		{
			rs.GetFieldValue (m_strField, strVal);
			if (!strVal.IsEmpty ())
			{
				if (m_lbFields.AddString (strVal) < 0)
					AfxThrowMemoryException ();
				iMax = max (iMax, strVal.GetLength ());
			}
			rs.MoveNext ();
		}

	//	HorizontalExtent setzen
		if (iMax > 0)
		{
			WORD wUnits = LOWORD (:: GetDialogBaseUnits ());
			m_lbFields.SetHorizontalExtent (wUnits * iMax);
		}

	//	TypInfo ausgeben
		CODBCFieldInfo FieldInfo;
		rs.GetODBCFieldInfo (m_strField, FieldInfo);
		switch (FieldInfo.m_nSQLType)
		{
			case SQL_DATE:		//	Zeitformate
			case SQL_TIME:
			case SQL_TIMESTAMP:		
			{
				m_uiResID = IDS_DATETIME_FORMAT;
				VERIFY (m_strFieldType.LoadString (IDS_DATE_TIME));
			}
			break;
			case SQL_DECIMAL:   
			case SQL_NUMERIC:   
			case SQL_BIGINT: 
			case SQL_CHAR:
			case SQL_VARCHAR:
			{
				m_uiResID = IDS_STRING_FORMAT;
				VERIFY (m_strFieldType.LoadString (IDS_TEXT));
			}
			break;
			default:			//	 alle Zahlenformate
				VERIFY (m_strFieldType.LoadString (IDS_ZAHL));
			break;
		}
	
	//	Caption setzen
		CString strFormat;
		GetWindowText (strFormat);
		strVal.Format (strFormat, m_strTable);
		SetWindowText (strVal);

	//	Feldname setzen
		m_strFieldName = FieldInfo.m_strName;

	//	Controls setzen
		m_lbFields.EnableWindow (m_lbFields.GetCount () > 0);	
		m_btOk.EnableWindow (FALSE);

		rs.Close ();

		UpdateData (FALSE);
	}
	catch (CException *e)
	{
		e -> ReportError ();
		e -> Delete ();
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Example #22
0
void InitMonsterGenInfo()
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_MONGEN");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nNumOfMonGenInfo = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nNumOfMonGenInfo < 0) return;

	g_pMonGenInfo = new CMonsterGenInfo[g_nNumOfMonGenInfo + 1];

	sprintf( szQuery, "SELECT * FROM TBL_MONGEN ORDER BY FLD_MAPNAME");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nNumOfMonGenInfo; i++)
		{
			if (pRec->Fetch())								 
			{
				strcpy(g_pMonGenInfo[i].szMapName, pRec->Get( "FLD_MAPNAME" ) );
				strcpy(g_pMonGenInfo[i].szMonName, pRec->Get( "FLD_MONNAME" ) );
				
				g_pMonGenInfo[i].dwZenTime		= atoi( pRec->Get( "FLD_GENTIME" ) ) * 60000;
				g_pMonGenInfo[i].dwStartTime	= 0;

				g_pMonGenInfo[i].nMonIndex		= atoi( pRec->Get( "FLD_MONINDEX" ) );

				g_pMonGenInfo[i].nCount			= atoi( pRec->Get( "FLD_COUNT" ) );

				g_pMonGenInfo[i].nX				= atoi( pRec->Get( "FLD_X" ) );
				g_pMonGenInfo[i].nY				= atoi( pRec->Get( "FLD_Y" ) );

				g_pMonGenInfo[i].nAreaX			= atoi( pRec->Get( "FLD_AREA_X" ) );
				g_pMonGenInfo[i].nAreaY			= atoi( pRec->Get( "FLD_AREA_Y" ) );
			}
		}

		InsertLogMsgParam(IDS_FETCH_MONGEN, &g_nNumOfMonGenInfo, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #23
0
void InitStdItemSpecial()
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_STDITEM");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nStdItemSpecial = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nStdItemSpecial < 0) return;

	g_pStdItemSpecial = new CStdItemSpecial[g_nStdItemSpecial];

	sprintf( szQuery, "SELECT * FROM TBL_STDITEM ORDER BY FLD_INDEX");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nStdItemSpecial; i++)
		{
			if (pRec->Fetch())								 
			{
				strcpy(g_pStdItemSpecial[i].szName, pRec->Get( "FLD_NAME" ) );

				g_pStdItemSpecial[i].wStdMode		= (SHORT)atoi( pRec->Get( "FLD_STDMODE" ) );
				g_pStdItemSpecial[i].btType			= (BYTE)atoi( pRec->Get( "FLD_TYPE" ) );
				g_pStdItemSpecial[i].wShape			= (SHORT)atoi( pRec->Get( "FLD_SHAPE" ) );
				g_pStdItemSpecial[i].wWeight		= (SHORT)atoi( pRec->Get( "FLD_WEIGHT" ) );
				g_pStdItemSpecial[i].wAniCount		= (SHORT)atoi( pRec->Get( "FLD_ANICOUNT" ) );
				g_pStdItemSpecial[i].wSource		= (SHORT)atoi( pRec->Get( "FLD_SOURCE" ) );
				g_pStdItemSpecial[i].dwLooks		= (LONG)atoi( pRec->Get( "FLD_LOOKS" ) );
				g_pStdItemSpecial[i].wDuraMax		= (WORD)atoi( pRec->Get( "FLD_DURAMAX" ) );
				g_pStdItemSpecial[i].wAC			= (BYTE)atoi( pRec->Get( "FLD_AC" ) );
				g_pStdItemSpecial[i].wAC2			= (BYTE)atoi( pRec->Get( "FLD_AC2" ) );
				g_pStdItemSpecial[i].wMAC			= (BYTE)atoi( pRec->Get( "FLD_MAC" ) );
				g_pStdItemSpecial[i].wMAC2			= (BYTE)atoi( pRec->Get( "FLD_MAC2" ) );
				g_pStdItemSpecial[i].wDC			= (BYTE)atoi( pRec->Get( "FLD_DC" ) );
				g_pStdItemSpecial[i].wDC2			= (BYTE)atoi( pRec->Get( "FLD_DC2" ) );
				g_pStdItemSpecial[i].wMC			= (BYTE)atoi( pRec->Get( "FLD_MC" ) );
				g_pStdItemSpecial[i].wMC2			= (BYTE)atoi( pRec->Get( "FLD_MC2" ) );
				g_pStdItemSpecial[i].wSC			= (BYTE)atoi( pRec->Get( "FLD_SC" ) );
				g_pStdItemSpecial[i].wSC2			= (BYTE)atoi( pRec->Get( "FLD_SC2" ) );
				g_pStdItemSpecial[i].wNeed			= (SHORT)atoi( pRec->Get( "FLD_NEED" ) );
				g_pStdItemSpecial[i].wNeedLevel		= (SHORT)atoi( pRec->Get( "FLD_NEEDLEVEL" ) );
				g_pStdItemSpecial[i].dwPrice		= (LONG)atoi( pRec->Get( "FLD_PRICE" ) );
				g_pStdItemSpecial[i].dwStock		= (LONG)atoi( pRec->Get( "FLD_STOCK" ) );

				g_pStdItemSpecial[i].m_btWater		= (BYTE)atoi( pRec->Get( "FLD_WATER1" ) );
				g_pStdItemSpecial[i].m_btWater2		= (BYTE)atoi( pRec->Get( "FLD_WATER2" ) );
				g_pStdItemSpecial[i].m_btFire		= (BYTE)atoi( pRec->Get( "FLD_FIRE1" ) );
				g_pStdItemSpecial[i].m_btFire2		= (BYTE)atoi( pRec->Get( "FLD_FIRE2" ) );
				g_pStdItemSpecial[i].m_btWind		= (BYTE)atoi( pRec->Get( "FLD_WIND1" ) );
				g_pStdItemSpecial[i].m_btWind2		= (BYTE)atoi( pRec->Get( "FLD_WIND2" ) );
				g_pStdItemSpecial[i].m_btLight		= (BYTE)atoi( pRec->Get( "FLD_LIGHT1" ) );
				g_pStdItemSpecial[i].m_btLight2		= (BYTE)atoi( pRec->Get( "FLD_LIGHT2" ) );
				g_pStdItemSpecial[i].m_btEarth		= (BYTE)atoi( pRec->Get( "FLD_EARTH1" ) );
				g_pStdItemSpecial[i].m_btEarth2		= (BYTE)atoi( pRec->Get( "FLD_EARTH2" ) );
			}
		}

		InsertLogMsgParam(IDS_FETCH_STDITEMACCESSORY, &g_nStdItemSpecial, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #24
0
void InitMonRaceInfo()
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_MONSTER");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nNumOfMonRaceInfo = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nNumOfMonRaceInfo < 0) return;

	g_pMonRaceInfo = new CMonRaceInfo[g_nNumOfMonRaceInfo];

	sprintf( szQuery, "SELECT * FROM TBL_MONSTER ORDER BY FLD_INDEX");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nNumOfMonRaceInfo; i++)
		{
			if (pRec->Fetch())								 
			{
				g_pMonRaceInfo[i].nIndex	= i;

				strcpy(g_pMonRaceInfo[i].szMonName, pRec->Get( "FLD_NAME" ) );
				ChangeSpaceToNull(g_pMonRaceInfo[i].szMonName);

				g_pMonRaceInfo[i].nMonRace		= atoi( pRec->Get( "FLD_RACE" ) );
				g_pMonRaceInfo[i].nAppear		= atoi( pRec->Get( "FLD_APPR" ) );

				g_pMonRaceInfo[i].btUndead		= (BYTE)atoi( pRec->Get( "FLD_UNDEAD" ) );
				g_pMonRaceInfo[i].Level			= (BYTE)atoi( pRec->Get( "FLD_LEVEL" ) );

				g_pMonRaceInfo[i].HP			= atoi( pRec->Get( "FLD_HP" ) );
				g_pMonRaceInfo[i].MP			= atoi( pRec->Get( "FLD_MP" ) );

				g_pMonRaceInfo[i].AC			= atoi( pRec->Get( "FLD_AC" ) );
				g_pMonRaceInfo[i].MAC			= atoi( pRec->Get( "FLD_MAC" ) );
				g_pMonRaceInfo[i].DC			=  MAKEWORD((BYTE)atoi( pRec->Get( "FLD_DC" ) ), (BYTE)atoi( pRec->Get( "FLD_MAXDC" ) ));

				g_pMonRaceInfo[i].dwAttackSpeed = atoi( pRec->Get( "FLD_ATTACKSPEED" ) );
				g_pMonRaceInfo[i].dwWalkSpeed	= atoi( pRec->Get( "FLD_WALKSPEED" ) );

				g_pMonRaceInfo[i].Speed			= atoi( pRec->Get( "FLD_SPEED" ) );
				g_pMonRaceInfo[i].Hit			= atoi( pRec->Get( "FLD_HIT" ) );

				g_pMonRaceInfo[i].ViewRange		= (BYTE)atoi( pRec->Get( "FLD_VIEWRANGE" ) );

				g_pMonRaceInfo[i].wRaceIndex	= atoi( pRec->Get( "FLD_RACEINDEX" ) );

				g_pMonRaceInfo[i].Exp			= atoi( pRec->Get( "FLD_EXP" ) );

				g_pMonRaceInfo[i].wEscape		= atoi( pRec->Get( "FLD_ESCAPE" ) );

				g_pMonRaceInfo[i].m_wWater		= MAKEWORD((BYTE)atoi( pRec->Get( "FLD_WATER1" ) ), (BYTE)atoi( pRec->Get( "FLD_WATER2" ) ));
				g_pMonRaceInfo[i].m_wFire		= MAKEWORD((BYTE)atoi( pRec->Get( "FLD_FIRE1" ) ), (BYTE)atoi( pRec->Get( "FLD_FIRE2" ) ));
				g_pMonRaceInfo[i].m_wWind		= MAKEWORD((BYTE)atoi( pRec->Get( "FLD_WIND1" ) ), (BYTE)atoi( pRec->Get( "FLD_WIND2" ) ));
				g_pMonRaceInfo[i].m_wLight		= MAKEWORD((BYTE)atoi( pRec->Get( "FLD_LIGHT1" ) ), (BYTE)atoi( pRec->Get( "FLD_LIGHT2" ) ));
				g_pMonRaceInfo[i].m_wEarth		= MAKEWORD((BYTE)atoi( pRec->Get( "FLD_EARTH1" ) ), (BYTE)atoi( pRec->Get( "FLD_EARTH2" ) ));
			}
		}

		InsertLogMsgParam(IDS_FETCH_MONSTER, &g_nNumOfMonRaceInfo, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );

	InitMonItemInfo();
}
UINT ThreadUpdatePLSModel(LPVOID lpParam)
{
	double coeff=2;//系数

	CDBManageTrueDlg* pCDBManageTrueDlg=(CDBManageTrueDlg*)lpParam;
	CTrueWineLib TrueWineLib;

	CWineTypeIndex WineTypeIndex;
	CAlcoholTypeIndex AlcoholTypeIndex;
	CFlavourTypeIndex FlavourTypeIndex;
	CBrandTypeIndex BrandTypeIndex;

	CPLSModel PLSModel;

	map<CString,int> map_TrueWineIndex;
	map<CString, int> map_AlcoholContent;
	map<CString,int> map_Flavour;
	map<CString,int> map_Brand;

	if(!PLSModel.Open())
	{
		pCDBManageTrueDlg->MessageBox(L"打开PLS模型库失败",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	if(!PLSModel.IsEOF())
	{
		PLSModel.MoveFirst();
	}

	while(!PLSModel.IsEOF())
	{
		PLSModel.Delete();
		PLSModel.MoveNext();
	}

	//打开索引库
	if(!WineTypeIndex.Open())
	{
		pCDBManageTrueDlg->MessageBox(L"打开真酒索引库失败",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	if(0==WineTypeIndex.GetRecordCount())
	{
		pCDBManageTrueDlg->MessageBox(L"光谱管理信息出现错误,请尝试更新!",L"更新模型失败",MB_ICONERROR);
		return -1;
	}

	if(!AlcoholTypeIndex.Open())
	{
		pCDBManageTrueDlg->MessageBox(L"打开酒精度索引库失败",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	if(0==AlcoholTypeIndex.GetRecordCount())
	{
		pCDBManageTrueDlg->MessageBox(L"光谱管理信息出现错误,请尝试更新!",L"更新模型失败",MB_ICONERROR);
		return -1;
	}

	if(!FlavourTypeIndex.Open())
	{
		pCDBManageTrueDlg->MessageBox(L"打开香型索引库失败",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	if(0==FlavourTypeIndex.GetRecordCount())
	{
		pCDBManageTrueDlg->MessageBox(L"光谱管理信息出现错误,请尝试更新!",L"更新模型失败",MB_ICONERROR);
		return -1;
	}

	if(!BrandTypeIndex.Open())
	{
		pCDBManageTrueDlg->MessageBox(L"打开品牌索引库失败",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	if(0==BrandTypeIndex.GetRecordCount())
	{
		pCDBManageTrueDlg->MessageBox(L"光谱管理信息出现错误,请尝试更新!",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	/////////////////////////
	WineTypeIndex.MoveFirst();
	while(!WineTypeIndex.IsEOF())
	{
		map_TrueWineIndex[WineTypeIndex.m_WineName]=WineTypeIndex.m_TypeIndex;
		WineTypeIndex.MoveNext();
	}


	AlcoholTypeIndex.MoveFirst();
	while(!AlcoholTypeIndex.IsEOF())
	{
		map_AlcoholContent[AlcoholTypeIndex.m_AlcoholContent]=AlcoholTypeIndex.m_AlcoholIndex;
		AlcoholTypeIndex.MoveNext();
	}
	AlcoholTypeIndex.MoveFirst();

	FlavourTypeIndex.MoveFirst();
	while(!FlavourTypeIndex.IsEOF())
	{
		map_Flavour[FlavourTypeIndex.m_Flavour]=FlavourTypeIndex.m_FlavourIndex;
		FlavourTypeIndex.MoveNext();
	}
	FlavourTypeIndex.MoveFirst();

	BrandTypeIndex.MoveFirst();
	while(!BrandTypeIndex.IsEOF())
	{
		map_Brand[BrandTypeIndex.m_Brand]=BrandTypeIndex.m_BrandIndex;
		BrandTypeIndex.MoveNext();
	}
	BrandTypeIndex.MoveFirst();



	if(!TrueWineLib.Open())
	{
		pCDBManageTrueDlg->MessageBox(L"打开真酒库失败",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	if(TrueWineLib.IsEOF())
	{
		pCDBManageTrueDlg->MessageBox(L"真酒库中无光谱记录",L"更新模型失败",MB_ICONERROR);
		return -1;
	}
	TrueWineLib.MoveFirst();
	while(!TrueWineLib.IsEOF())
	{
		TrueWineLib.MoveNext();
	}
	TrueWineLib.MoveFirst();

	//酒精度分类模型
	int Num_of_AlcoholContent=AlcoholTypeIndex.GetRecordCount();
	if(1!=Num_of_AlcoholContent)
	{
		CMatrix MNum_EachLabel(1,Num_of_AlcoholContent);
		CMatrix MLabels(1,Num_of_AlcoholContent);

		CMatrix X_1(TrueWineLib.GetRecordCount(),869);
		CMatrix Y_1(TrueWineLib.GetRecordCount(),1);

		int AlcoholTypeCount=0;
		//CSVMobj tempsvmobj1(869);
		if(!AlcoholTypeIndex.IsEOF())
		{
			TrueWineLib.MoveFirst();
			while(!TrueWineLib.IsEOF())
			{
				TrueWineLib.MoveNext();
			}
			int Num_inX_1=0;

			AlcoholTypeIndex.MoveFirst();	
			while(!AlcoholTypeIndex.IsEOF())
			{


				TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s'",AlcoholTypeIndex.m_AlcoholContent);
				TrueWineLib.m_strSort=L"WineName";
				if(!TrueWineLib.Requery())
				{
					pCDBManageTrueDlg->MessageBox(L"查询真酒库失败",L"更新酒精度模型失败",MB_ICONERROR);
					return -1;
				}
				TrueWineLib.MoveFirst();
				while(!TrueWineLib.IsEOF())
				{
					TrueWineLib.MoveNext();
				}			
				int Num_of_EachAlcoholContent=TrueWineLib.GetRecordCount();



				TrueWineLib.MoveFirst();
				CMatrix tempMatrix(1,869);
				int m=1;
				TrueWineLib.MoveFirst();

				while(!TrueWineLib.IsEOF())
				{
					CString2Matrix(tempMatrix,TrueWineLib.m_SpectrumData,L",");
					X_1.SetRow(Num_inX_1+m,tempMatrix);
					Y_1.SetItem(Num_inX_1+m,1,map_AlcoholContent[TrueWineLib.m_AlcoholContent]);
					TrueWineLib.MoveNext();
					m++;
				}
				//TrueWineLib.Close();
				AlcoholTypeCount++;
				Num_inX_1+=Num_of_EachAlcoholContent;
				MLabels.SetItem(1,AlcoholTypeCount,map_AlcoholContent[TrueWineLib.m_AlcoholContent]);	
				MNum_EachLabel.SetItem(1,AlcoholTypeCount,Num_of_EachAlcoholContent);
				AlcoholTypeIndex.MoveNext();

			}
		}		
		//训练酒精度分类模型
		CMatrix Y_1map=BuildMapLabel(Y_1);

		//CMatrix X_1_mean=X_1.Mean();

		CMatrix CV=Plscvfold(X_1,Y_1map,X_1.m_row,"center");
		CMatrixIndex CV_indexmin;
		CV.FindMin(CV_indexmin);
		int bestPC=CV_indexmin.column;

		CMatrix W(X_1.m_column,bestPC);
		CMatrix T(X_1.m_row,bestPC);
		CMatrix P(X_1.m_column,bestPC);
		CMatrix Q(bestPC,1);

		CMatrix para2(1,X_1.m_column);//=X_1.Mean();
		CMatrix para1(1,X_1.m_column);//=X_1.Mean();
		CMatrix para2_X(1,X_1.m_column);//=X_1.Mean();
		CMatrix para1_X(1,X_1.m_column);//=X_1.Mean();	
		Pretreat(X_1,"center",para1_X,para2_X);
		CMatrix X_1_mean=para1_X;		

		//map<int,int> Label_map;



		CMatrix para2_Y(1,Y_1map.m_column);
		CMatrix para1_Y(1,Y_1map.m_column);
		Pretreat(Y_1map,"center",para1_Y,para2_Y);
		CMatrix Y_1_mean=para1_Y;

		CMatrix B=Pls_nipals(X_1,Y_1map,W,T,P,Q,bestPC);

		CMatrix StandardPC(AlcoholTypeCount,bestPC);



		int begin=1;
		for(int i=1;i<=AlcoholTypeCount;i++)
		{
			StandardPC.SetRow(i,(T.GetRows(begin,begin+MNum_EachLabel(1,i)-1)).Mean());
			begin+=MNum_EachLabel(1,i);
		}
		//计算阈值
		CMatrix Threshold(1,AlcoholTypeCount);//计算样本与标准值之间的最大距离,样本与标准值之间的平均距离的coeff倍,取较大的那个

		//CMatrix Threshold2(1,AlcoholTypeCount);//计算
		begin=1;
		for(int i=1;i<=AlcoholTypeCount;i++)
		{
			CMatrix tempdist(MNum_EachLabel(1,i),1);
			CMatrix tempPC=T.GetRows(begin,begin+MNum_EachLabel(1,i)-1);
			CMatrix covPC=tempPC.covariance();
			covPC.Inv();
			int k=1;
			for(int j=begin;j<=begin+MNum_EachLabel(1,i)-1;j++)
			{

				CMatrix diff=T.GetRow(j)-StandardPC.GetRow(i);
				tempdist.SetItem(k,1,(diff*covPC*diff.Transposition())(1,1));
				k++;
			}
			Threshold.SetItem(1,i,Max(tempdist.GetMax(),tempdist.GetMean()*coeff));
			begin=begin+MNum_EachLabel(1,i);
		}



		CString Weight;
		CString Labels;
		CString Num_EachLabel;
		CString standardPC;
		CString TrainsetPC;

		CString TrainsetMean;
		CString threshold;



		//Weight
		W.Matrix2CString(Weight,L",");
		//Labels
		MLabels.Matrix2CString(Labels,L",");
		//Num_EachLabel
		MNum_EachLabel.Matrix2CString(Num_EachLabel,L",");
		//standardPC
		StandardPC.Matrix2CString(standardPC,L",");
		//TrainsetPC
		T.Matrix2CString(TrainsetPC,L",");
		//TrainsetMean
		X_1_mean.Matrix2CString(TrainsetMean,L",");
		//阈值
		Threshold.Matrix2CString(threshold,L",");


		//保存模型
		PLSModel.AddNew();
		PLSModel.m_FactorNum=bestPC;
		PLSModel.m_ClassCount=AlcoholTypeCount;
		PLSModel.m_Weight=Weight;
		PLSModel.m_Labels=Labels;
		PLSModel.m_Num_EachLabel=Num_EachLabel;
		PLSModel.m_StandardPC=standardPC;
		PLSModel.m_TrainsetPC=TrainsetPC;
		PLSModel.m_TrainsetMean=TrainsetMean;	
		PLSModel.m_Threshold=threshold;
		PLSModel.Update();
	}	
	//开始香型
	AlcoholTypeIndex.MoveFirst();
	while(!AlcoholTypeIndex.IsEOF())
	{


		CString command=_T("SELECT DISTINCT Flavour FROM TrueWineLib");

		CString tempFlavourInAlconhol;
		CDatabase m_db;
		CRecordset rsforFlavour;
		rsforFlavour.m_strFilter.Format(L"AlcoholContent='%s'",AlcoholTypeIndex.m_AlcoholContent);
		m_db.OpenEx(_T("DSN=白酒鉴定与溯源数据库;"),CDatabase::noOdbcDialog);
		rsforFlavour.m_pDatabase = &m_db;	
		if (!rsforFlavour.Open(AFX_DB_USE_DEFAULT_TYPE,command))
		{
			CString str;
			str.Format(L"更新%s度香型分类模型失败!",AlcoholTypeIndex.m_AlcoholContent);
			pCDBManageTrueDlg->MessageBox(str,L"打开数据库失败",MB_ICONERROR);
			return -1;
		}

		if(!rsforFlavour.IsEOF())
		{
			rsforFlavour.MoveFirst();

			while(!rsforFlavour.IsEOF())
			{
				rsforFlavour.MoveNext();
			}
		}
		int Num_of_FlavourInAlcoholContent=rsforFlavour.GetRecordCount();
		if(1!=Num_of_FlavourInAlcoholContent)
		{
			TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s'",AlcoholTypeIndex.m_AlcoholContent);
			TrueWineLib.Requery();
			TrueWineLib.MoveFirst();
			while(!TrueWineLib.IsEOF())
			{
				TrueWineLib.MoveNext();
			}
			TrueWineLib.MoveFirst();
			CMatrix MNum_EachLabel(1,Num_of_FlavourInAlcoholContent);
			CMatrix MLabels(1,Num_of_FlavourInAlcoholContent);

			CMatrix X_2(TrueWineLib.GetRecordCount(),869);
			CMatrix Y_2(TrueWineLib.GetRecordCount(),1);

			int FlavourTypeCount=0;
			int Num_inX_2=0;

			rsforFlavour.MoveFirst();			
			while(!rsforFlavour.IsEOF())
			{

				rsforFlavour.GetFieldValue(L"Flavour",tempFlavourInAlconhol);

				TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s'AND Flavour='%s'",AlcoholTypeIndex.m_AlcoholContent,tempFlavourInAlconhol);

				if(!TrueWineLib.Requery())
				{
					pCDBManageTrueDlg->MessageBox(L"查询真酒库失败",L"更新香型模型失败",MB_ICONERROR);
					return -1;
				}
				if(!TrueWineLib.IsEOF())
				{
					TrueWineLib.MoveFirst();
					while(!TrueWineLib.IsEOF())
					{
						TrueWineLib.MoveNext();
					}
					TrueWineLib.MoveFirst();
				}

				int Num_of_EachFlavorInAlcoholContent=TrueWineLib.GetRecordCount();


				CMatrix tempMatrix(1,869);
				int m=1;
				while(!TrueWineLib.IsEOF())
				{
					CString2Matrix(tempMatrix,TrueWineLib.m_SpectrumData,L",");
					X_2.SetRow(Num_inX_2+m,tempMatrix);
					Y_2.SetItem(Num_inX_2+m,1,map_Flavour[TrueWineLib.m_Flavour]);
					TrueWineLib.MoveNext();
					m++;
				}
				FlavourTypeCount++;
				Num_inX_2+=Num_of_EachFlavorInAlcoholContent;
				MLabels.SetItem(1,FlavourTypeCount,map_Flavour[TrueWineLib.m_Flavour]);		
				MNum_EachLabel.SetItem(1,FlavourTypeCount,Num_of_EachFlavorInAlcoholContent);
				rsforFlavour.MoveNext();
			}
			//训练香型分类模型
			//CMatrix X_2_mean=X_2.Mean();
			CMatrix Y_2map=BuildMapLabel(Y_2);
			CMatrix CV=Plscvfold(X_2,Y_2map,X_2.m_row,"center");
			CMatrixIndex CV_indexmin;
			CV.FindMin(CV_indexmin);
			int bestPC=CV_indexmin.column;

			CMatrix W(X_2.m_column,bestPC);
			CMatrix T(X_2.m_row,bestPC);
			CMatrix P(X_2.m_column,bestPC);
			CMatrix Q(bestPC,1);

			CMatrix para2_X(1,X_2.m_column);//=X_1.Mean();
			CMatrix para1_X(1,X_2.m_column);//=X_1.Mean();	
			Pretreat(X_2,"center",para1_X,para2_X);
			CMatrix X_2_mean=para1_X;		




			CMatrix para2_Y(1,Y_2map.m_column);//=X_1.Mean();
			CMatrix para1_Y(1,Y_2map.m_column);//=X_1.Mean();	
			Pretreat(Y_2map,"center",para1_Y,para2_Y);
			CMatrix Y_2_mean=para1_Y;

			CMatrix B=Pls_nipals(X_2,Y_2map,W,T,P,Q,bestPC);

			CMatrix StandardPC(FlavourTypeCount,bestPC);


			int begin=1;
			for(int i=1;i<=FlavourTypeCount;i++)
			{
				StandardPC.SetRow(i,(T.GetRows(begin,begin+MNum_EachLabel(1,i)-1)).Mean());
				begin+=MNum_EachLabel(1,i);
			}
			//计算阈值
			CMatrix Threshold(1,FlavourTypeCount);//计算样本与标准值之间的最大距离,样本与标准值之间的平均距离的coeff倍,取较大的那个
			begin=1;
			for(int i=1;i<=FlavourTypeCount;i++)
			{
				CMatrix tempdist(MNum_EachLabel(1,i),1);
				CMatrix tempPC=T.GetRows(begin,begin+MNum_EachLabel(1,i)-1);
				CMatrix covPC=tempPC.covariance();
				covPC.Inv();
				int k=1;
				for(int j=begin;j<=begin+MNum_EachLabel(1,i)-1;j++)
				{

					CMatrix diff=T.GetRow(j)-StandardPC.GetRow(i);
					tempdist.SetItem(k,1,(diff*covPC*diff.Transposition())(1,1));
					k++;
				}
				Threshold.SetItem(1,i,Max(tempdist.GetMax(),tempdist.GetMean()*coeff));
				begin=begin+MNum_EachLabel(1,i);
			}



			CString Weight;
			CString Labels;
			CString Num_EachLabel;
			CString standardPC;
			CString TrainsetPC;

			CString TrainsetMean;
			CString threshold;



			//Weight
			W.Matrix2CString(Weight,L",");
			//Labels
			MLabels.Matrix2CString(Labels,L",");
			//Num_EachLabel
			MNum_EachLabel.Matrix2CString(Num_EachLabel,L",");
			//standardPC
			StandardPC.Matrix2CString(standardPC,L",");
			//TrainsetPC
			T.Matrix2CString(TrainsetPC,L",");
			//TrainsetMean
			X_2_mean.Matrix2CString(TrainsetMean,L",");
			//阈值
			Threshold.Matrix2CString(threshold,L",");


			//保存模型
			PLSModel.AddNew();
			PLSModel.m_AlcoholContent=AlcoholTypeIndex.m_AlcoholContent;
			PLSModel.m_FactorNum=bestPC;
			PLSModel.m_ClassCount=FlavourTypeCount;
			PLSModel.m_Weight=Weight;
			PLSModel.m_Labels=Labels;
			PLSModel.m_Num_EachLabel=Num_EachLabel;
			PLSModel.m_StandardPC=standardPC;
			PLSModel.m_TrainsetPC=TrainsetPC;
			PLSModel.m_TrainsetMean=TrainsetMean;	
			PLSModel.m_Threshold=threshold;
			PLSModel.Update();
		}
		/////////////////////////////////////////////
		//开始品牌
		rsforFlavour.MoveFirst();
		while(!rsforFlavour.IsEOF())
		{
			CString tempFlavour;
			rsforFlavour.GetFieldValue(L"Flavour",tempFlavour);


			CString command=_T("SELECT DISTINCT Brand FROM TrueWineLib");
			CDatabase m_db;
			CRecordset rsforBrand;

			rsforBrand.m_strFilter.Format(L"AlcoholContent='%s' AND Flavour='%s'",AlcoholTypeIndex.m_AlcoholContent,tempFlavour);

			m_db.OpenEx(_T("DSN=白酒鉴定与溯源数据库;"),CDatabase::noOdbcDialog);
			rsforBrand.m_pDatabase = &m_db;	
			if (!rsforBrand.Open(AFX_DB_USE_DEFAULT_TYPE,command))
			{
				CString str;
				str.Format(L"更新%s度%s分类模型失败!",AlcoholTypeIndex.m_AlcoholContent,tempFlavour);
				pCDBManageTrueDlg->MessageBox(str,L"打开数据库失败",MB_ICONERROR);
				return -1;
			}

			if(!rsforBrand.IsEOF())
			{
				rsforBrand.MoveFirst();
			}
			while(!rsforBrand.IsEOF())
			{
				rsforBrand.MoveNext();
			}

			int Num_of_BrandInFlavour=rsforBrand.GetRecordCount();
			if(1!=Num_of_BrandInFlavour)
			{			
				TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s' AND Flavour='%s'",AlcoholTypeIndex.m_AlcoholContent,tempFlavour);
				TrueWineLib.Requery();
				TrueWineLib.MoveFirst();
				while(!TrueWineLib.IsEOF())
				{
					TrueWineLib.MoveNext();
				}
				TrueWineLib.MoveFirst();
				CMatrix MNum_EachLabel(1,Num_of_BrandInFlavour);
				CMatrix MLabels(1,Num_of_BrandInFlavour);

				CMatrix X_3(TrueWineLib.GetRecordCount(),869);
				CMatrix Y_3(TrueWineLib.GetRecordCount(),1);

				int BrandTypeCount=0;
				int Num_inX_3=0;
				rsforBrand.MoveFirst();			
				while(!rsforBrand.IsEOF())
				{
					CString tempBrandInFlavour;

					rsforBrand.GetFieldValue(L"Brand",tempBrandInFlavour);

					TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s'AND Flavour='%s' AND Brand='%s'",AlcoholTypeIndex.m_AlcoholContent,tempFlavour,tempBrandInFlavour);

					if(!TrueWineLib.Requery())
					{
						pCDBManageTrueDlg->MessageBox(L"打开真酒库失败",L"更新酒精度模型失败",MB_ICONERROR);
						return -1;
					}
					if(!TrueWineLib.IsEOF())
					{
						TrueWineLib.MoveFirst();
						while(!TrueWineLib.IsEOF())
						{
							TrueWineLib.MoveNext();
						}	
						TrueWineLib.MoveFirst();
					}

					int Num_of_EachBrandInFlavour=TrueWineLib.GetRecordCount();

					CMatrix tempMatrix(1,869);
					int m=1;
					//TrueWineLib.MoveFirst();
					while(!TrueWineLib.IsEOF())
					{
						CString2Matrix(tempMatrix,TrueWineLib.m_SpectrumData,L",");
						X_3.SetRow(Num_inX_3+m,tempMatrix);
						Y_3.SetItem(Num_inX_3+m,1,map_Brand[TrueWineLib.m_Brand]);
						TrueWineLib.MoveNext();
						m++;
					}
					BrandTypeCount++;
					Num_inX_3+=Num_of_EachBrandInFlavour;
					MLabels.SetItem(1,BrandTypeCount,map_Brand[TrueWineLib.m_Brand]);	
					MNum_EachLabel.SetItem(1,BrandTypeCount,Num_of_EachBrandInFlavour);
					rsforBrand.MoveNext();
				}
				//
				//	CMatrix X_3_mean=X_3.Mean();
				CMatrix Y_3map=BuildMapLabel(Y_3);

				CMatrix CV=Plscvfold(X_3,Y_3map,X_3.m_row,"center");
				CMatrixIndex CV_indexmin;
				CV.FindMin(CV_indexmin);
				int bestPC=CV_indexmin.column;

				CMatrix W(X_3.m_column,bestPC);
				CMatrix T(X_3.m_row,bestPC);
				CMatrix P(X_3.m_column,bestPC);
				CMatrix Q(bestPC,1);

				CMatrix para2_X(1,X_3.m_column);//=X_1.Mean();
				CMatrix para1_X(1,X_3.m_column);//=X_1.Mean();	
				Pretreat(X_3,"center",para1_X,para2_X);
				CMatrix X_3_mean=para1_X;



				CMatrix para2_Y(1,Y_3map.m_column);//=X_1.Mean();
				CMatrix para1_Y(1,Y_3map.m_column);//=X_1.Mean();	
				Pretreat(Y_3map,"center",para1_Y,para2_Y);
				CMatrix Y_3_mean=para1_Y;

				CMatrix B=Pls_nipals(X_3,Y_3map,W,T,P,Q,bestPC);
				CMatrix StandardPC(BrandTypeCount,bestPC);

				int begin=1;
				for(int i=1;i<=BrandTypeCount;i++)
				{
					StandardPC.SetRow(i,(T.GetRows(begin,begin+MNum_EachLabel(1,i)-1)).Mean());
					begin+=MNum_EachLabel(1,i);
				}
				//计算阈值
				CMatrix Threshold(1,BrandTypeCount);//计算样本与标准值之间的最大距离,样本与标准值之间的平均距离的coeff倍,取较大的那个
				begin=1;
				for(int i=1;i<=BrandTypeCount;i++)
				{
					CMatrix tempdist(MNum_EachLabel(1,i),1);
					CMatrix tempPC=T.GetRows(begin,begin+MNum_EachLabel(1,i)-1);
					CMatrix covPC=tempPC.covariance();
					covPC.Inv();
					int k=1;
					for(int j=begin;j<=begin+MNum_EachLabel(1,i)-1;j++)
					{

						CMatrix diff=T.GetRow(j)-StandardPC.GetRow(i);
						tempdist.SetItem(k,1,(diff*covPC*diff.Transposition())(1,1));
						k++;
					}
					Threshold.SetItem(1,i,Max(tempdist.GetMax(),tempdist.GetMean()*coeff));
					begin=begin+MNum_EachLabel(1,i);
				}



				CString Weight;
				CString Labels;
				CString Num_EachLabel;
				CString standardPC;
				CString TrainsetPC;

				CString TrainsetMean;
				CString threshold;



				//Weight
				W.Matrix2CString(Weight,L",");
				//Labels
				MLabels.Matrix2CString(Labels,L",");
				//Num_EachLabel
				MNum_EachLabel.Matrix2CString(Num_EachLabel,L",");
				//standardPC
				StandardPC.Matrix2CString(standardPC,L",");
				//TrainsetPC
				T.Matrix2CString(TrainsetPC,L",");
				//TrainsetMean
				X_3_mean.Matrix2CString(TrainsetMean,L",");
				//阈值
				Threshold.Matrix2CString(threshold,L",");


				//保存模型
				PLSModel.AddNew();
				PLSModel.m_AlcoholContent=AlcoholTypeIndex.m_AlcoholContent;
				PLSModel.m_Flavour=tempFlavour;
				PLSModel.m_FactorNum=bestPC;
				PLSModel.m_ClassCount=BrandTypeCount;
				PLSModel.m_Weight=Weight;
				PLSModel.m_Labels=Labels;
				PLSModel.m_Num_EachLabel=Num_EachLabel;
				PLSModel.m_StandardPC=standardPC;
				PLSModel.m_TrainsetPC=TrainsetPC;
				PLSModel.m_TrainsetMean=TrainsetMean;	
				PLSModel.m_Threshold=threshold;
				PLSModel.Update();
			}
			/////////////////////////////////////////
			//开始品牌内
			rsforBrand.MoveFirst();
			while(!rsforBrand.IsEOF())
			{
				CString tempBrand;
				rsforBrand.GetFieldValue(L"Brand",tempBrand);


				CString command=_T("SELECT DISTINCT WineName FROM TrueWineLib");

				CString tempInBrand;
				CDatabase m_db;
				CRecordset rsforInBrand;

				rsforInBrand.m_strFilter.Format(L"AlcoholContent='%s' AND Flavour='%s' AND Brand='%s'",AlcoholTypeIndex.m_AlcoholContent,tempFlavour,tempBrand);

				m_db.OpenEx(_T("DSN=白酒鉴定与溯源数据库;"),CDatabase::noOdbcDialog);
				rsforInBrand.m_pDatabase = &m_db;	
				if (!rsforInBrand.Open(AFX_DB_USE_DEFAULT_TYPE,command))
				{
					CString str;
					str.Format(L"更新%s度%s%s分类模型失败!",AlcoholTypeIndex.m_AlcoholContent,tempFlavour,tempBrand);
					pCDBManageTrueDlg->MessageBox(str,L"打开数据库失败",MB_ICONERROR);
					return -1;
				}

				if(!rsforInBrand.IsEOF())
				{
					rsforInBrand.MoveFirst();

				}
				while(!rsforInBrand.IsEOF())
				{
					rsforInBrand.MoveNext();
				}

				int Num_of_InBrand=rsforInBrand.GetRecordCount();
				if(1!=Num_of_InBrand)
				{				
					TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s' AND Flavour='%s' AND Brand='%s'",AlcoholTypeIndex.m_AlcoholContent,tempFlavour,tempBrand);
					TrueWineLib.Requery();
					TrueWineLib.MoveFirst();
					while(!TrueWineLib.IsEOF())
					{
						TrueWineLib.MoveNext();
					}
					TrueWineLib.MoveFirst();
					CMatrix MNum_EachLabel(1,Num_of_InBrand);
					CMatrix MLabels(1,Num_of_InBrand);

					CMatrix X_4(TrueWineLib.GetRecordCount(),869);
					CMatrix Y_4(TrueWineLib.GetRecordCount(),1);

					int InBrandTypeCount=0;
					int Num_inX_4=0;
					rsforInBrand.MoveFirst();			
					while(!rsforInBrand.IsEOF())
					{

						rsforInBrand.GetFieldValue(L"WineName",tempInBrand);

						TrueWineLib.m_strFilter.Format(L"AlcoholContent='%s'AND Flavour='%s' AND Brand='%s' AND WineName='%s'",
							AlcoholTypeIndex.m_AlcoholContent,tempFlavour,tempBrand,tempInBrand);

						if(!TrueWineLib.Requery())
						{
							pCDBManageTrueDlg->MessageBox(L"打开真酒库失败",L"更新品牌内模型失败",MB_ICONERROR);
							return -1;
						}
						if(!TrueWineLib.IsEOF())
						{
							TrueWineLib.MoveFirst();
							while(!TrueWineLib.IsEOF())
							{
								TrueWineLib.MoveNext();
							}	
							TrueWineLib.MoveFirst();
						}

						int Num_of_EachTypeInBrand=TrueWineLib.GetRecordCount();
						CMatrix tempMatrix(1,869);
						int m=1;
						//TrueWineLib.MoveFirst();
						int DataStrlenth=TrueWineLib.m_SpectrumData.GetLength();
						while(!TrueWineLib.IsEOF())
						{
							CString2Matrix(tempMatrix,TrueWineLib.m_SpectrumData,L",");
							X_4.SetRow(Num_inX_4+m,tempMatrix);
							Y_4.SetItem(Num_inX_4+m,1,map_TrueWineIndex[TrueWineLib.m_WineName]);
							TrueWineLib.MoveNext();
							m++;
						}
						InBrandTypeCount++;
						Num_inX_4+=Num_of_EachTypeInBrand;					
						MLabels.SetItem(1,InBrandTypeCount,map_TrueWineIndex[TrueWineLib.m_WineName]);
						MNum_EachLabel.SetItem(1,InBrandTypeCount,Num_of_EachTypeInBrand);
						rsforInBrand.MoveNext();
					}
					//
					//	CMatrix X_4_mean=X_4.Mean();
					CMatrix Y_4map=BuildMapLabel(Y_4);
					CMatrix CV=Plscvfold(X_4,Y_4map,X_4.m_row,"center");
					CMatrixIndex CV_indexmin;
					CV.FindMin(CV_indexmin);
					int bestPC=CV_indexmin.column;

					CMatrix W(X_4.m_column,bestPC);
					CMatrix T(X_4.m_row,bestPC);
					CMatrix P(X_4.m_column,bestPC);
					CMatrix Q(bestPC,1);

					CMatrix para2_X(1,X_4.m_column);//=X_1.Mean();
					CMatrix para1_X(1,X_4.m_column);//=X_1.Mean();	
					Pretreat(X_4,"center",para1_X,para2_X);
					CMatrix X_4_mean=para1_X;	

					//map<int,int> Label_map;

					CMatrix para2_Y(1,Y_4map.m_column);//=X_1.Mean();
					CMatrix para1_Y(1,Y_4map.m_column);//=X_1.Mean();	
					Pretreat(Y_4map,"center",para1_Y,para2_Y);
					CMatrix Y_4_mean=para1_Y;

					CMatrix B=Pls_nipals(X_4,Y_4map,W,T,P,Q,bestPC);

					CMatrix StandardPC(InBrandTypeCount,bestPC);


					int begin=1;
					for(int i=1;i<=InBrandTypeCount;i++)
					{
						StandardPC.SetRow(i,(T.GetRows(begin,begin+MNum_EachLabel(1,i)-1)).Mean());
						begin+=MNum_EachLabel(1,i);
					}

					CMatrix Threshold(1,InBrandTypeCount);//计算样本与标准值之间的最大距离,样本与标准值之间的平均距离的coeff倍,取较大的那个
					begin=1;
					for(int i=1;i<=InBrandTypeCount;i++)
					{
						CMatrix tempdist(MNum_EachLabel(1,i),1);
						CMatrix tempPC=T.GetRows(begin,begin+MNum_EachLabel(1,i)-1);
						CMatrix covPC=tempPC.covariance();
						covPC.Inv();
						int k=1;
						for(int j=begin;j<=begin+MNum_EachLabel(1,i)-1;j++)
						{

							CMatrix diff=T.GetRow(j)-StandardPC.GetRow(i);
							tempdist.SetItem(k,1,(diff*covPC*diff.Transposition())(1,1));
							k++;
						}
						Threshold.SetItem(1,i,Max(tempdist.GetMax(),tempdist.GetMean()*coeff));
						begin=begin+MNum_EachLabel(1,i);
					}

					CString Weight;
					CString Labels;
					CString Num_EachLabel;
					CString standardPC;
					CString TrainsetPC;
					CString TrainsetMean;
					CString threshold;
					//Weight
					W.Matrix2CString(Weight,L",");
					//Labels
					MLabels.Matrix2CString(Labels,L",");
					//Num_EachLabel
					MNum_EachLabel.Matrix2CString(Num_EachLabel,L",");
					//standardPC
					StandardPC.Matrix2CString(standardPC,L",");
					//TrainsetPC
					T.Matrix2CString(TrainsetPC,L",");
					//TrainsetMean
					X_4_mean.Matrix2CString(TrainsetMean,L",");
					//阈值
					Threshold.Matrix2CString(threshold,L",");

					//保存模型
					PLSModel.AddNew();
					PLSModel.m_AlcoholContent=AlcoholTypeIndex.m_AlcoholContent;
					PLSModel.m_Flavour=tempFlavour;
					PLSModel.m_Brand=tempBrand;
					PLSModel.m_FactorNum=bestPC;
					PLSModel.m_ClassCount=InBrandTypeCount;
					PLSModel.m_Weight=Weight;
					PLSModel.m_Labels=Labels;
					PLSModel.m_Num_EachLabel=Num_EachLabel;
					PLSModel.m_StandardPC=standardPC;
					PLSModel.m_TrainsetPC=TrainsetPC;
					PLSModel.m_TrainsetMean=TrainsetMean;	
					PLSModel.m_Threshold=threshold;
					PLSModel.Update();

				}
				rsforBrand.MoveNext();
			}
			///////////////////////////////
			rsforFlavour.MoveNext();
		}
		AlcoholTypeIndex.MoveNext();
	}

	TrueWineLib.Close();
	WineTypeIndex.Close();
	AlcoholTypeIndex.Close();
	FlavourTypeIndex.Close();
	BrandTypeIndex.Close();
	pCDBManageTrueDlg->MessageBox(L"模型更新成功!",L"模型更新",MB_ICONINFORMATION);
	//删除不需要的模型文件

}
void CDBManageTrueDlg::UpdateIndexTable(void)
{
	//CTrueWineLib TrueWineLib;

	CDatabase m_db;
	CRecordset rs;
	m_db.OpenEx(_T("DSN=白酒鉴定与溯源数据库;"),CDatabase::noOdbcDialog);
	rs.m_pDatabase = &m_db;

	CString WineName;
	CString AlcoholContent;
	CString Flavour;
	CString Brand;
	CString ProductionBatchNo;

	//更新白酒类型索引
	CWineTypeIndex WineTypeIndex;

	if(!WineTypeIndex.Open())
	{
		MessageBox(L"打开光谱索引库失败",L"更新失败",MB_ICONERROR);
		return;
	}
	if(!WineTypeIndex.IsEOF())
	{
		WineTypeIndex.MoveFirst();
		while(!WineTypeIndex.IsEOF())
		{
			WineTypeIndex.Delete();
			WineTypeIndex.MoveNext();
		}
	}
	CString command=_T("SELECT DISTINCT WineName,AlcoholContent,Flavour,Brand,ProductionBatchNo FROM TrueWineLib");
	if(!rs.Open(AFX_DB_USE_DEFAULT_TYPE,command))
	{
		MessageBox(L"打开真酒库失败",L"更新失败",MB_ICONERROR);
		return;
	}

	if(!rs.IsEOF())
	{
		int count=1;
		rs.MoveFirst();
		while(!rs.IsEOF())
		{
			rs.GetFieldValue(L"WineName",WineName);
			rs.GetFieldValue(L"AlcoholContent",AlcoholContent);
			rs.GetFieldValue(L"Flavour",Flavour);
			rs.GetFieldValue(L"Brand",Brand);
			rs.GetFieldValue(L"ProductionBatchNo",ProductionBatchNo);

			WineTypeIndex.AddNew();
			WineTypeIndex.m_WineName=WineName;   //不知道为什么使用了select distinct 得到某几列记录时,自动把这一列分配给最前面的类型相同的列
			WineTypeIndex.m_AlcoholContent=AlcoholContent;
			WineTypeIndex.m_Flavour=Flavour;
			WineTypeIndex.m_Brand=Brand;
			WineTypeIndex.m_ProductionBatchNo=ProductionBatchNo;
			WineTypeIndex.m_TypeIndex=count;
			count++;
			rs.MoveNext();
			WineTypeIndex.Update();
		}
	}
	rs.Close();
	//更新酒精度索引
	CAlcoholTypeIndex AlcoholTypeIndex;

	if(!AlcoholTypeIndex.Open())
	{
		MessageBox(L"打开光谱索引库失败",L"更新失败",MB_ICONERROR);
		return;
	}
	if(!AlcoholTypeIndex.IsEOF())
	{
		AlcoholTypeIndex.MoveFirst();
		while(!AlcoholTypeIndex.IsEOF())
		{
			AlcoholTypeIndex.Delete();
			AlcoholTypeIndex.MoveNext();
		}
	}

	command=_T("SELECT DISTINCT AlcoholContent FROM TrueWineLib");
	if(!rs.Open(AFX_DB_USE_DEFAULT_TYPE,command))
	{
		MessageBox(L"打开真酒库失败",L"更新失败",MB_ICONERROR);
		return;
	}
	CString alcohol;


	if(!rs.IsEOF())
	{
		rs.MoveFirst();
		int i=1;
		while(!rs.IsEOF())
		{		
			rs.GetFieldValue(_T("AlcoholContent"),alcohol); 
			AlcoholTypeIndex.AddNew();
			AlcoholTypeIndex.m_AlcoholContent=alcohol;
			AlcoholTypeIndex.m_AlcoholIndex=i;
			i++;
			AlcoholTypeIndex.Update();
			rs.MoveNext();

		}
	}
	AlcoholTypeIndex.Close();
	rs.Close();

	//更新香型索引
	CFlavourTypeIndex FlavourTypeIndex;

	if(!FlavourTypeIndex.Open())
	{
		MessageBox(L"打开光谱索引库失败",L"更新失败",MB_ICONERROR);
		return;
	}
	if(!FlavourTypeIndex.IsEOF())
	{
		FlavourTypeIndex.MoveFirst();
		while(!FlavourTypeIndex.IsEOF())
		{
			FlavourTypeIndex.Delete();
			FlavourTypeIndex.MoveNext();
		}
	}
	command=_T("SELECT DISTINCT Flavour FROM TrueWineLib");
	if(!rs.Open(AFX_DB_USE_DEFAULT_TYPE,command))
	{
		MessageBox(L"打开真酒库失败",L"更新失败",MB_ICONERROR);
		return;
	}

	if(!rs.IsEOF())
	{
		int count=1;
		rs.MoveFirst();
		while(!rs.IsEOF())
		{
			rs.GetFieldValue(L"Flavour",Flavour);
			FlavourTypeIndex.AddNew();
			FlavourTypeIndex.m_Flavour=Flavour;
			FlavourTypeIndex.m_FlavourIndex=count;
			count++;
			rs.MoveNext();
			FlavourTypeIndex.Update();
		}
	}
	rs.Close();

	//更新品牌索引
	CBrandTypeIndex BrandTypeIndex;

	if(!BrandTypeIndex.Open())
	{
		MessageBox(L"打开光谱索引库失败",L"更新失败",MB_ICONERROR);
		return;
	}
	if(!BrandTypeIndex.IsEOF())
	{
		BrandTypeIndex.MoveFirst();
		while(!BrandTypeIndex.IsEOF())
		{
			BrandTypeIndex.Delete();
			BrandTypeIndex.MoveNext();
		}
	}
	command=_T("SELECT DISTINCT Brand FROM TrueWineLib");
	if(!rs.Open(AFX_DB_USE_DEFAULT_TYPE,command))
	{
		MessageBox(L"打开真酒库失败",L"更新失败",MB_ICONERROR);
		return;
	}

	if(!rs.IsEOF())
	{
		int count=1;
		rs.MoveFirst();
		while(!rs.IsEOF())
		{
			rs.GetFieldValue(L"Brand",Brand);
			BrandTypeIndex.AddNew();
			BrandTypeIndex.m_Brand=Brand;
			BrandTypeIndex.m_BrandIndex=count;
			count++;
			rs.MoveNext();
			BrandTypeIndex.Update();
		}
	}
	rs.Close();


}
Example #27
0
void InitStdItemEtcInfo()
{
	char szQuery[1024];

	CRecordset *pRec;
	
	pRec= g_pConnCommon->CreateRecordset();

	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_STDITEM_ETC");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nStdItemEtc = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nStdItemEtc < 0) return;

	g_pStdItemEtc = new CStdItem[g_nStdItemEtc];

	sprintf( szQuery, "SELECT * FROM TBL_STDITEM_ETC ORDER BY FLD_INDEX");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nStdItemEtc; i++)
		{
			if (pRec->Fetch())								 
			{
				strcpy(g_pStdItemEtc[i].szName, pRec->Get( "FLD_NAME" ) );

				g_pStdItemEtc[i].wStdMode	= atoi( pRec->Get( "FLD_STDMODE" ) );
				g_pStdItemEtc[i].wShape		= atoi( pRec->Get( "FLD_SHAPE" ) );
				g_pStdItemEtc[i].wWeight	= atoi( pRec->Get( "FLD_WEIGHT" ) );
				g_pStdItemEtc[i].dwLooks	= atoi( pRec->Get( "FLD_LOOKS" ) );
				g_pStdItemEtc[i].wDuraMax	= atoi( pRec->Get( "FLD_VAL1" ) );
				g_pStdItemEtc[i].dwRSource	= atoi( pRec->Get( "FLD_VAL2" ) );
				g_pStdItemEtc[i].dwPrice	= atoi( pRec->Get( "FLD_PRICE" ) );
			}
		}

		InsertLogMsgParam(IDS_FETCH_STDITEMETC, &g_nStdItemEtc, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #28
0
void InitMerchantInfo()
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_MERCHANT");

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nNumOfMurchantInfo = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nNumOfMurchantInfo < 0) return;

	g_pMerchantInfo = new CMerchantInfo[g_nNumOfMurchantInfo];

	sprintf( szQuery, "SELECT * FROM TBL_MERCHANT ORDER BY FLD_ID");

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nNumOfMurchantInfo; i++)
		{
			if (pRec->Fetch())								 
			{
				strcpy(g_pMerchantInfo[i].szNPCName, pRec->Get( "FLD_NPCNAME" ) );
				ChangeSpaceToNull(g_pMerchantInfo[i].szNPCName);
				strcpy(g_pMerchantInfo[i].szMapName, pRec->Get( "FLD_MAPNAME" ) );
				ChangeSpaceToNull(g_pMerchantInfo[i].szMapName);

				g_pMerchantInfo[i].nPosX = atoi( pRec->Get( "FLD_POSX" ) );
				g_pMerchantInfo[i].nPosY = atoi( pRec->Get( "FLD_POSY" ) );
				g_pMerchantInfo[i].sFace = atoi( pRec->Get( "FLD_FACE" ) );
				g_pMerchantInfo[i].sBody = atoi( pRec->Get( "FLD_BODY" ) );
				g_pMerchantInfo[i].sGender = atoi( pRec->Get( "FLD_GENDER" ) );
			}
		}

		InsertLogMsgParam(IDS_FETCH_MERCHANT, &g_nNumOfMurchantInfo, LOGPARAM_INT);
	}

	g_pConnCommon->DestroyRecordset( pRec );
}
Example #29
0
BOOL CRecordView::OnMove(UINT nIDMoveCommand)
{
    CRecordset* pSet = OnGetRecordset();
    if (pSet->CanUpdate() && !pSet->IsDeleted())
    {
        pSet->Edit();
        if (!UpdateData())
            return TRUE;

        pSet->Update();
    }

    switch (nIDMoveCommand)
    {
    case ID_RECORD_PREV:
        pSet->MovePrev();
        if (!pSet->IsBOF())
            break;

    case ID_RECORD_FIRST:
        pSet->MoveFirst();
        break;

    case ID_RECORD_NEXT:
        pSet->MoveNext();
        if (!pSet->IsEOF())
            break;
        if (!pSet->CanScroll())
        {
            // clear out screen since we're sitting on EOF
            pSet->SetFieldNull(NULL);
            break;
        }

    case ID_RECORD_LAST:
        pSet->MoveLast();
        break;

    default:
        // Unexpected case value
        ASSERT(FALSE);
    }

    // Show results of move operation
    UpdateData(FALSE);
    return TRUE;
}
Example #30
0
CMapInfo* InitMapInfo(int nServerIndex)
{
	char szQuery[1024];

	CRecordset *pRec = g_pConnCommon->CreateRecordset();
	sprintf( szQuery, "SELECT COUNT(*) AS FLD_COUNT FROM TBL_MAPINFO WHERE FLD_SERVERINDEX = %d", nServerIndex );

	if (pRec->Execute( szQuery ))
	{
			if (pRec->Fetch())
				g_nNumOfMapInfo = atoi( pRec->Get( "FLD_COUNT" ) );
	}

	g_pConnCommon->DestroyRecordset( pRec );

	if (g_nNumOfMapInfo < 0) return NULL;

	CMapInfo* pMapInfo = new CMapInfo[g_nNumOfMapInfo];

	sprintf( szQuery, "SELECT * FROM TBL_MAPINFO WHERE FLD_SERVERINDEX = %d", nServerIndex );

	pRec = g_pConnCommon->CreateRecordset();
	
	if (pRec->Execute( szQuery ))
	{
		for (int i = 0; i < g_nNumOfMapInfo; i++)
		{
			if (pRec->Fetch())
			{
				strcpy(pMapInfo[i].szMapFileName, pRec->Get( "FLD_MAPFILENAME" ) );
				ChangeSpaceToNull(pMapInfo[i].szMapFileName);
				strcpy(pMapInfo[i].szMapName, pRec->Get( "FLD_MAPNAME" ) );
				ChangeSpaceToNull(pMapInfo[i].szMapName);

				pMapInfo[i].dwAttribute			= atoi( pRec->Get( "FLD_ATTRIBUTE" ) );

				pMapInfo[i].btMapSeries			= atoi( pRec->Get( "FLD_MAPSERIES" ) );
				pMapInfo[i].btMapSeriesValue	= atoi( pRec->Get( "FLD_MAPSERIESVAL" ) );
			}
		}
	}

	g_pConnCommon->DestroyRecordset( pRec );

	return pMapInfo;
}